Repository navigation
fix(core): stackOutput derives lexicon from a directly-referenced Declarable (Ref(param)) (#1152) - #1164
Merged
Conversation
…larable (Ref(param)) (#1152) `stackOutput()`'s anchor search only ever looked for a nested AttrRef to borrow a wrapping intrinsic's lexicon from. `Ref(param)`/`Ref(resource)` wrap the referenced entity itself, not one of its attributes — and a CloudFormation Parameter carries no attributes at all, so `Ref(param)` could never contain an AttrRef for the old search to find. The anchor silently came back empty, `lexicon` fell back to "unknown", and `partitionByLexicon` bucketed the output where no serializer ever looks — dropped from the template with no error, matching the post-build template-injection workaround described in the issue. `findAnchor` now also recognizes a directly-referenced Declarable (via `isDeclarable`'s dual-copy-safe marker) and derives the lexicon from its own `.lexicon` field. Confirmed the specific "throws" framing in the issue's original report no longer applies (RefIntrinsic already carries the Intrinsic marker, so the input-validation guard already accepted it) — the real, still-live bug was this silent misrouting, not a thrown error. Extends lexicons/aws/examples/stack-outputs (built for this class of case in #1123) with a Parameter + stackOutput(Ref(parameter)) output, fold and run confirmed byte-identical.
This was referenced Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1152.
What was actually wrong
The issue's original report claimed
stackOutput(Ref(param), { exportName })andstackOutput(Sub\${Ref(param)}`, ...)"throw the not-an-intrinsic guard error." That claim doesn't hold — the issue's own follow-up comment retracts it after a cleaner bisect (stackOutput(Ref(param))"works fine"; the real crash it found wasstackOutput(role.RoleName)`-style non-attribute property access, re-scoping the issue to two smaller, unrelated asks).Reproduced from scratch to confirm which claim was right before touching anything:
Ref(param)already carriesRefIntrinsic'sINTRINSIC_MARKER, sostackOutput()'s input-validation guard (isIntrinsic(ref)) already accepts it — no throw, confirmed empirically. But it isn't harmless either: it silently deriveslexicon: "unknown".partitionByLexicon(packages/core/src/build.ts) buckets an "unknown"-lexiconStackOutputwhere no serializer ever looks, so the output silently vanishes from the template — no error, exit 0. That's the exact shape of the workaround described in the original report ("post-build template injection in the deploy script").Root cause:
stackOutput()'s anchor search (firstAttrRef) only ever looked for a nestedAttrRefto borrow a wrapping intrinsic's lexicon from.Ref(param)/Ref(resource)wrap the referenced entity itself, not one of its attributes — and a CloudFormationParametercarries no attributes at all (real CFN parameters have noFn::GetAtt-returnable attributes), soRef(param)can never contain anAttrReffor an AttrRef-only search to find, no matter how deep it looks.The fix
packages/core/src/stack-output.ts: generalized the anchor search (renamedfirstAttrRef→findAnchor) to recognize two shapes, not one — a nestedAttrRef(borrow its parent's.lexicon, unchanged) or a directly-referencedDeclarable(use its own.lexicon, new). TheDeclarablecheck usesisDeclarable(Symbol.formarker), which is already dual-copy-safe the same way #1137 made the AttrRef checks here dual-copy-safe.This is a pure widening — every existing anchor-derivation path (bare AttrRef, AttrRef nested in an intrinsic, foreign-copy AttrRef via #1137) is unchanged and still covered by the pre-existing test suite (all 13 pre-existing
stack-output.test.tstests pass unmodified).Ref(resource)(as opposed toRef(parameter)) already derived the correct lexicon before this fix too, just via an indirect route (recursing into the referenced resource's own AttrRef properties) — this fix reaches the same entity directly instead, with no change in the final derived value.Why this is the right semantics (not a thrown error)
The task brief asked me to decide, from
chant graph --stacks's consumer (computeStackGraphinbuild.ts), whether a parameter-valued output is legitimate or needs a loud rejection. AParameteris a real, valid, lexicon-scoped entity —Ref(param)is exactly how CloudFormation asks for its resolved value at deploy time (the consuming stack receives whatever value the parameter takes). There's nothing invalid about the shape; the bug was purely in routing the output to the right lexicon partition once produced. Rejecting it loudly would be wrong — silently losing it was the actual defect, and deriving the correct lexicon fixes that outright rather than trading a silent failure for a noisy one.Fold-path parity (#1091/#1123)
stackOutputis a registered foldable authoring helper (fold/foldable-helpers.ts) withrequireLiveRefsalready enforced at its call site infold-import.ts. This fix lives entirely instack-output.ts's own logic, which both the fold and run paths call identically — no fold-specific branching needed. Verified directly:lexicons/aws/examples/stack-outputsextended with aParameter+stackOutput(Ref(parameter), { exportName })output (the shape #1123 built this example for), andchant build --foldvs. plain run produce byte-identical output, both correctly including the newEnvironmentNameoutput (missing before the fix, on both paths identically — confirming this was never fold-specific).Added 3 new unit tests to
stack-output.test.tsfor the new Declarable-anchor path (bare, nested one level deeper via aSub-style wrapper, andoptions.lexiconstill overriding a Declarable-derived anchor) — 16/16 passing, all 13 pre-existing tests untouched and passing.Note on the issue's re-scoped asks
The issue's follow-up comment re-scopes it to two different, smaller DX asks that this PR does not address (they're a separate concern from the anchor-derivation bug this PR fixes):
stackOutput()'s guard-error message (today only the file is reported).GetAttproperty on a generated resource (e.g.role.RoleName) returning something outputtable instead ofundefined.I looked at (2) enough to flag a real hazard worth knowing about before anyone picks it up: the generated resource classes (
createResourceinpackages/core/src/runtime.ts) are walked,JSON.stringify'd, and duck-typed (.then,.toJSON, etc.) pervasively across discovery/fold/serializers — aProxythat throws on any unset property (the literal reading of "throw a named error at access time") would very likely breakJSON.stringifyitself (it always probes.toJSONdefensively) and other generic duck-typing across the codebase. The safer half of the issue's own either/or (return the declared prop value when set, leave itundefinedotherwise) avoids that blast radius, but is a distinct piece of work from this PR. Recommend tracking those two asks separately rather than folding them in here.Gates
just fold-differential— measured on origin/main first, then after:Identical — no corpus entry changed classification (
stack-outputswas alreadyfoldand still is), and no count moved since this PR enriches an existing corpus entry rather than adding a new one.just sandbox-differential— same before/after measurement:Identical, both runs.
Test plan
just build/just lintcleannpm run build -w @intentius/chant-lexicon-awscleanjust test— +3 tests, 0 regressionsjust check-lexicons— no regression (2 known tracked failures, unchanged)just fold-differential— zero drift, corpus counts unchanged from mainjust sandbox-differential— zero drift, corpus counts unchanged from main