Repository navigation
feat(core): registered foldable authoring helpers — phase/output fold, foldResource non-literal first arg (#1082) - #1091
Merged
Conversation
#1082) Call-shaped things may fold only via a declared, per-helper opt-in — the decision #1044 settled for lexicon intrinsics. This is the same registry one level up, for chant's own authoring API, written by hand rather than read from a lexicon manifest. The module carries the admission criteria and, next to each entry, why it passes them — plus the audit of what was deliberately left out (env(), Op(), the composite definition helpers, createResource/createProperty, and call-form lexicon intrinsics, which remain #1044's registry to admit). No behavior yet: nothing imports this.
…ositionally (#1082) Two blockers that no amount of user-side rewriting could lift. phase()/output() and peers are chant's own documented API, so every file using components or outputs fell back to run on the first call. fold() now reduces a call to a REGISTERED helper to a symbolic {__helper, args} envelope — still executing nothing — exactly as a registered intrinsic tagged template reduces to {__intrinsic}. fold-import revives it by resolving the name through the folding file's own imports and checking the import really is chant's (a published chant specifier, or a path inside chant-core's own tree), then invoking the real function. So the function that runs is the one the source named, and fold cannot diverge from run by construction. A same-named helper of the project's own, or one declared in the file, resolves to nothing chant owns and the file falls back. foldResource assumed constructor argument 0 was the props object, so the AWS deploy-time Parameter — (type, props) — could never fold anywhere. Arguments are now folded positionally and the entity is constructed with exactly what the source wrote; the classic (props)/(props, attributes) shape is reported unchanged. findSubsetViolation accepts both, keeping it at least as permissive as fold() — otherwise EVL001 would flag source that folds cleanly. It checks the helper NAME only; provenance needs the module graph, which is fold-import's, and that asymmetry is documented alongside the three that already existed. An argument that is a same-file {__attrRef} envelope is rejected rather than passed to a helper: output() derefs its ref's parent WeakRef to learn the lexicon, and a look-alike plain object would produce wrong output rather than none.
…ove (#1082) Corpus fold coverage 21 -> 24 of 98, drift 0. The three new entries (aws fargate-alb, multi-service-alb, vpc) are the corpus's new Parameter("String", {...}) users, unblocked by positional constructor arguments. Recorded name-by-name in EXPECTED_FOLD so a future regression on them fails loudly, and the published count regenerated. Documents the allowlist as a supported pattern, with the two conditions a call must meet, and why env() is excluded.
Contributor
Author
|
Orchestrator verification, all measurements re-run independently:
Criterion 5 (corpus) exceeded, criterion 6 (loomster) correctly not claimed — it needs #1044 plus a loomster-side sn() migration, both now filed. The pre-existing |
This was referenced Jul 27, 2026
Merged
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.
Closes #1082.
Acceptance criteria, restated
phase("Apply", [...])inside aComponentobject literal — must fold statically instead of falling the whole file back to running.new Parameter("String", {...})must fold.foldResourcerequired constructor argument 0 to be the props object literal, so the AWS deploy-timeParameter(signature(type, props)) could never fold whatever surrounded it. The fix is to drop the positional assumption and reconstruct the entity with exactly the arguments the source wrote.just fold-differentialmust stay at ≥ 21 of 98 folding, with zero drift on any entry that folds.findSubsetViolation(which EVL001/EVL003 use) must never be stricter thanfold(). Sincefold()now accepts allowlisted helper calls, the shared classifier must accept them too, or lint would flag source that folds.One clarification on the issue's own numbers: the acceptance line says "13/57" while the table shows loomster
mainat 13 fold / 42 run-fallback (55 files) and the migrated tree at 13/44 (57). 13/57 is the migrated tree. loomster#156 is not merged, so the tree I could measure ismain— see the measurements section, which reproduces the issue'smainrow exactly.Design: how the allowlist is declared, and why it stays closed
The registry is
packages/core/src/fold/foldable-helpers.ts— a hand-written array of names, each carrying the module that defines it and why it passes the admission criteria. It is data, not a rule about what calls look like.A name being in it is not permission to invoke whatever it is bound to. Folding a helper call is a two-key operation:
fold()andfindSubsetViolation: the callee is a bare identifier naming a registered helper that this file has not shadowed with its ownconst.fold()reduces the call to a symbolic{ __helper, args }envelope and executes nothing — the same treatment a registered intrinsic tagged template gets from{ __intrinsic }.fold-import.ts: the envelope revives by resolving that name through the folding file's ownimportbindings and checking the import actually comes from chant — a published@intentius/chant*specifier, or a specifier resolving inside chant-core's own tree (which is how in-repo and test callers import it). Only then is the real function invoked with the folded arguments.So the function that runs is the one the source's own
importnames. Fold never substitutes a reimplementation of a helper, which is why this registry cannot drift from the helpers' real behavior — a whole category of bug that a table of hand-written reducers would have introduced. It also means a project's ownphaseimported from./helpers, or declared in the file, resolves to nothing chant owns and the file falls back to run, unchanged.Registration is by name, and two of the names are defined twice in chant (
phase/gateby both the component contract and the Op builders;stackOutputby both the component contract and the cross-stack primitive). That needs no disambiguation, precisely because step 2 invokes whichever one the file imported — and both definitions of each name independently satisfy the admission criteria, which is what makes sharing the name safe.One extra guard for
output(): it is pure but identity-sensitive, reading through its ref'sWeakRefto the parent entity to learn the lexicon. An argument that revived to a symbolic{ __attrRef }envelope is rejected rather than handed over, because constructing aLexiconOutputfrom a look-alike plain object produces output that is wrong rather than absent. A ref that resolved cross-file to a genuine liveAttrRefpasses through untouched. This reuses the existing rejection that already guarded intrinsic interiors, generalised frominsideIntrinsictorequireLiveRefs.Admitted
phase,gate,activity,stackOutput,output.Deliberately not admitted
env()(env.ts) readsprocess.env. Its result depends on the environment rather than on its arguments, so folding it would freeze one run's environment into a statically-derived value. It is exactly the call fold must keep rejecting. Build-time parameters (feat(core): build-time parameter injection — DECIDED: option 1 (unblocks loomster, folds 13/55 today) #1064) are the supported answer.Op()(op/builders.ts) constructs anOpResource, aDeclarable.fold()already rejects a nestednew Type(...)used as a value for a real, differential-caught reason; a factory returning one is the same hazard wearing a call.propagate(),withDefaults(),resource(),mergeDefaults()(composite.ts) are composite definition helpers, not value-position helpers.propagate()mutates its argument in place, and fold-import's composite spine already resolves it live.createResource()/createProperty()(runtime.ts) build classes at a lexicon module's top level; they never appear as a value in a project file.Ref(...),Join(...)) are lexicon surface, not chant's own, and belong to feat(core): fold registered plain-call intrinsics (per-intrinsic opt-in) — DECIDED: yes #1044'sIntrinsicDefregistry. Only their tagged-template form folds today; this PR does not change that.Scope item 2: constructor argument positions
foldResourcenow folds every argument in source order intoFoldedResource.args, andresolveResourceEntityspreads that list into the constructor. The classic(props)/(props, attributes)shape is detected and reported exactly as before, with noargslist, so no existing folded spec changes shape.findSubsetViolationwas relaxed in step, classifying every argument on its own terms rather than rejecting one for its position — a widening, keeping it permissive relative tofold().resourceCtorArgMessagehad no remaining caller and was removed.Measurements
All numbers below are from runs on this branch, rebased onto
405bb9b5(chant-v0.20.0, i.e. after #1081 merged), in a clean worktree with its ownnpm install.Corpus —
just fold-differential405bb9b5)Newly folding:
lexicons/aws/examples/fargate-alb,lexicons/aws/examples/multi-service-alb,lexicons/aws/examples/vpc— all three are the corpus'snew Parameter("String", {...})users. No entry regressed; all three are added toEXPECTED_FOLDso a future regression on them fails by name. The published count intypescript-as-data.mdxwas regenerated withnpm run generate:fold-coverage.loomster —
chant build src --lexicon aws --fold, run from loomster root with this branch'schantbinloomster is at
df687ad(main); loomster#156 is unmerged, so this is the issue's "loomstermain" row, which the before-run reproduces exactly (13 fold / 42 run-fallback / 15processblockers under00bfbd75).The file count did not move, and I am not going to dress that up. Every blocker this issue targets is gone — all 10 of them — but each of those files has a user-defined function call immediately behind the chant one, which is the category the issue puts out of scope:
phase(...)output(...)sn(...)(loomster's own, readsprocess.envat module scope)literalOutputValue(...)(loomster's own composite helper)The 7 component files each stop at
stack: sn("loom-db"); the 2 output files atliteralOutputValue(...).downstream-stub/params.ts— thenew Parameter(...)file — now folds in isolation and is held back only by the existing fold-taint rule, which is why the last row moved 2 → 3.So acceptance criterion 6 is not met as stated on the tree I can measure. What is demonstrated is that chant's own API surface is no longer the ceiling: the next blocker in every case is application code, and the issue's own out-of-scope note ("worth confirming separately for loomster's helpers") is now the confirmed next step.
sn()in particular is a build-time-parameter migration away from disappearing — it exists only to readLOOM_PROJECT/LOOM_ENV/LOOM_INSTANCE— so the migrated tree plus asnrewrite is where the count actually moves. I would rather report the measured 13 than pick a scope that flatters it.Test evidence
just build(tsc core) — clean.just lint— clean.just test— full suite; see the check run.just fold-differential— 24/98, drift 0 (raw before/after logs kept).New tests:
fold.test.ts— helper call folds to the envelope with arguments folded in order; helpers nest; an unfoldable argument still rejects the call; an unregistered name is still rejected naming the callee; a registered name shadowed by a local const is rejected; a registered name reached as a method (ns.phase(...)) is rejected; a spread argument is rejected. Constructor positions: props-second folds with anargslist; a bare(type)call folds without inventing a props object; both classic shapes report unchanged; a non-foldable argument in any position rejects.subset.test.ts— helper calls added to the shared supported/unsupported equivalence corpus (so EVL and fold must agree on them, including position of the rejection); a new documented divergence for helper shadowing.subset-doc-parity.test.ts— the new doc section's own snippet is pulled out of the.mdxand classified for real, so the prose cannot drift from the classifier.fold-import.test.ts— end-to-end against chant's real helpers: a component withphase/gate/stackOutputfolds to the exact plain data the helpers return, with athrowsentinel proving the module never executed; nested fan-out phases revive bottom-up; a registered name imported from the project's own code does not fold; one declared in the file does not fold; an unregistered chant import (inferArchetype) still falls back, proving registration is per-helper and not per-module;output()folds against a real cross-fileAttrRefinto a genuineLexiconOutput(sourceLexiconproves theWeakRefderef happened) and falls back over a same-file reference. Constructor positions are covered end-to-end against a(type, props)class structurally identical to the real AWSParameter.