Skip to content

feat(core): fold call-form composite/intrinsic calls (Checkout(...) factories, helm include/printf) - #1965

Merged
lex00 merged 1 commit into
mainfrom
feat/1174-call-form-folds
Aug 26, 2026
Merged

lex00 merged 1 commit into
mainfrom
feat/1174-call-form-folds

Conversation

@lex00

@lex00 lex00 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Baseline vs after

Command (same both times): npx vitest run examples/fold-differential.test.ts --reporter=verbose (after just regen to build fresh lexicon artifacts).

fold run-fallback drift corpus
baseline (this branch's parent) 82 26 0 108/108
after this PR 89 19 0 108/108

The corpus grew from the 101 the issue measured against (#1172's close-out) to 108 by the time this PR started — unrelated additions between #1169 and now. EXPECTED_FOLD in examples/fold-differential.test.ts only lists the 7 entries this PR moves; a handful of other entries fold today without ever having been added to that list (a pre-existing gap, out of scope here).

Per-entry, the 7 that flip:

lexicons/forgejo/examples/ci-workflow    run-fallback -> fold
lexicons/github/examples/deploy-pages    run-fallback -> fold
lexicons/github/examples/getting-started run-fallback -> fold
lexicons/github/examples/release-please  run-fallback -> fold
lexicons/helm/examples/cron-job          run-fallback -> fold
lexicons/helm/examples/multi-container   run-fallback -> fold
lexicons/helm/examples/stateful-service  run-fallback -> fold

Docs regenerated with npm run generate:fold-coverage (82 -> 89 of 108 in both typescript-as-data.mdx and sandbox.mdx).

Mechanism (a) — composite factory calls narrowed to .step

Checkout({...}).step, SetupNode({...}).step — every lexicon's single-action Composite() wrapper, embedded inline in a Job's steps array exactly as composites.mdx documents. fold() had no case for a CallExpression used as a value beyond three closed allowlists (a registered chant helper, an opted-in intrinsic, a project-local foldable function, #1373) — a composite factory call fell straight through to "function call as a value is not foldable."

This is deliberately narrower than "any call, any member access." fold() now recognizes exactly the <Identifier>(...).step shape — the same one chant #1544 already carved out of EVL001 as a documented, correct fallback (allowCompositeStepAccess) rather than a lint error. The callee must be a bare identifier not already claimed by one of the three existing call shapes; the member must be literally "step". It reduces to a new envelope, FoldedCompositeStepCall (packages/core/src/fold/fold.ts), carrying the callee name and folded arguments — nothing is imported or invoked inside fold() itself, matching every other envelope-producing branch there.

Revival (packages/core/src/discovery/fold-import.ts) resolves the callee through the folding file's own imports via a new resolveCompositeCall, which is the nested-value counterpart to the existing resolveCallExpression the top-level declarator path (export const x = Checkout({...})) already used: try interpreting the factory body when it's a project-file registered Composite (chant #1023's existing, unmodified machinery), otherwise import and invoke it for real — the arm every lexicon-package composite (Checkout, SetupNode, …) always takes, exactly as it already does for a top-level declarator. invokeImportedCallee was split into a node-free invokeResolvedCallee core so this reuses the identical refusal/resolve/import/callable-check/call sequence rather than a second copy — including the --sandbox gate (sandboxedExecutionRefusal), unchanged.

Soundness: this is not a new execution class. A lexicon-package composite invoked from a nested value position goes through the exact same in-process invocation a top-level export const x = Checkout({...}) already performs today — same trust boundary, same --sandbox refusal for a project-owned factory. The --sandbox differential (examples/sandbox-execution-boundary.test.ts) still reports 0 project source executed in-process after this change.

subset.ts's allowCompositeStepAccess EVL-only opt-in is removed (not just left in place): once fold() accepts the shape unconditionally, keeping a separate opt-in flag around would make the shared predicate answer differently from fold() for a caller that forgets to pass it — exactly the divergence direction subset.ts's own module doc says it may never have. findSubsetViolation/checkObjectMember/checkArrayElement now accept <call>(...).step unconditionally, matching how a nested new Type(...) has been unconditional since #1169.

Residual, found while measuring: 4 more github entries (docker-build, matrix-test, node-ci, reusable-workflow) also call Checkout(...) but do not flip — each stops one blocker behind it, on an unrelated .toString() method call (github.actor.toString(), matrix("os").toString(), inputs("node-version").toString()) or an array .join(...) inside a step's run: string. These are plain functions from the github lexicon's expression.ts (not registered intrinsics), followed by a method call — a different, unscoped gap (method-call folding in general has no case in fold(), by design) that this PR does not attempt. The composite-call cause itself is fully closed wherever it was the actual blocker.

Mechanism (b) — helm's call-form intrinsics opted into foldsAsCall

Helm has no tagged templates at all — every intrinsic is a plain call — so before this PR helm had registered every intrinsic with isTag: false and never opted any of them into foldsAsCall (chant #1044's existing mechanism, already used by AWS and Azure). A single include(...)/printf(...)/toYaml(...) anywhere in a chart's resources forced the whole file back to run.

Opted in, one at a time, in lexicons/helm/src/plugin.ts: include, required, helmDefault, toYaml, quote, printf, tpl, lookup, filesGet, filesGlob, filesAsConfig, filesAsSecrets. Only include/printf/toYaml are actually exercised by the corpus (all three helm entries use all three together, so all three needed opting in before any one entry could flip) — the rest are audited to the identical standard and opted in for consistency with how AWS/Azure's audits cover their full applicable set, not just what their examples happen to exercise.

Soundness, per IntrinsicDef.foldsAsCall's criterion ("calling the intrinsic is a pure function of its arguments that builds a deterministic data envelope"): every one of the 12 is a pure string-interpolation function (lexicons/helm/src/intrinsics.ts) that builds a HelmTpl (or, for lookup, the same shape) from its arguments — no I/O, no mutation, no dependency on anything but the arguments. lookup's own side effect (a live cluster read) happens when Helm renders the resulting template at deploy time, not when this JS function runs at chant build time, so invoking it while folding is indistinguishable from invoking it during a real run of the file — the exact bar the field's doc sets.

Deliberately left out, each for a specific reason:

  • values/Release/ChartRef/Capabilities/Template are proxy objects, never called — nothing to opt in.
  • withOrder/argoWave return a plain record meant to be spread ({...withOrder(1)}). fold()'s object-spread handling (Object.assign(obj, src)) runs synchronously on the immediately-folded value, before the async revival that turns a folded call into its real result — opting these in would spread the folded {__intrinsic, args} envelope's own keys into the object instead of the real record. A genuine soundness hazard, not an oversight.
  • If/ElseIf/Range/With take an arbitrary body/elseBody that is often an arrow function (Range(list, (item) => ({...}))) or a nested Declarable. fold() already rejects a function used as a value on its own terms, so opting these in buys nothing measured on this corpus; left for a future PR to size against real usage rather than widened on speculation.

What remains

  • The 4 github entries with a .toString()/.join() method-call blocker (mechanism (a)'s residual above) — a different, unscoped cause.
  • lexicons/github/examples/docs-snippets uses a named const checkout = Checkout({...}) referenced later as checkout.step — a shape this PR doesn't cover (only the inline Checkout({...}).step form, matching the one EVL already carved out and the one the target corpus entries actually use).
  • If/ElseIf/Range/With/withOrder/argoWave helm intrinsics, and any lexicon-package composite pattern beyond .step, as noted above.

Both mechanisms named in #1174 are fully implemented and sound; the residuals above are new causes this PR's own measurement surfaced, not gaps in what #1174 asked for.

Tests

  • npx tsc --noEmit -p packages/core/tsconfig.json — clean
  • npx eslint packages/ — 0 errors (2 pre-existing warnings, unrelated)
  • npx vitest run examples/fold-differential.test.ts --reporter=verbose — 112/112, zero drift
  • npx vitest run examples/sandbox-differential.test.ts examples/sandbox-execution-boundary.test.ts --reporter=verbose — 220/220, of which project-owned: 0
  • npx vitest run packages/core — 5017/5017
  • npx vitest run lexicons/helm lexicons/github lexicons/forgejo — 837+474+95 passed
  • npx tsx scripts/check-lexicons.ts — all 15 lexicons 23/23 tier-1 (helm included)
  • npx vitest run (whole repo) — 14281 passed, 0 failed

Fixes #1174

🤖 Generated with Claude Code

… intrinsics

Closes the top remaining fold-corpus gate (#1174): a function call used as
a value was the sole blocker in most of the 12 github/forgejo/helm entries
still falling back to run.

Two independent mechanisms, both landed:

- fold() gains a narrow case for the `<Identifier>(...).step` composite-
  consumer idiom (`Checkout({...}).step`, `SetupNode({...}).step`) — the
  exact shape chant #1544 already carved out of EVL001 as a documented,
  correct fallback. fold-import.ts's bridge resolves the callee through the
  folding file's own imports (interpreting a project-file Composite per
  #1023, invoking a lexicon-package one for real otherwise, exactly as a
  top-level `export const x = Checkout({...})` already does) and reads
  `.step` off the real result. The now-redundant `allowCompositeStepAccess`
  EVL-only opt-in in subset.ts is removed — the shape is unconditionally
  admissible in both fold() and the shared predicate, closing the
  divergence #1544 documented.

- helm's plugin.ts opts `include`/`required`/`helmDefault`/`toYaml`/
  `quote`/`printf`/`tpl`/`lookup`/`filesGet`/`filesGlob`/`filesAsConfig`/
  `filesAsSecrets` into `foldsAsCall` (chant #1044's existing mechanism,
  previously unused by helm since it has no tagged templates at all).
  `withOrder`/`argoWave` are deliberately left out: they return a plain
  record meant to be spread, and fold()'s object-spread runs synchronously
  before the async revival that turns a folded call into its real result,
  so opting them in would spread the envelope's own keys instead.
  `If`/`ElseIf`/`Range`/`With` are left out too — their bodies are often
  arrow functions or nested Declarables fold() already rejects on its own
  terms, and none of the corpus needs them.

Corpus: 82 -> 89 of 108 folding, zero drift on both differentials.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lex00
lex00 merged commit a6dba9e into main Aug 26, 2026
7 checks passed
@lex00
lex00 deleted the feat/1174-call-form-folds branch August 26, 2026 19:02
lex00 added a commit that referenced this pull request Aug 29, 2026
fold() had no case for a CallExpression whose callee is a property
access, so github.actor.toString()/matrix("os").toString()/[...].join(...)
all fell through to "function call as a value is not foldable" one
blocker behind the composite-call fix in #1965.

Two additions to fold():
- a lexicon-package plain function registered with the new
  IntrinsicDef.foldsEagerly evaluates immediately (not enveloped for
  later revival), since its result is commonly embedded straight into
  a template literal and needs to be the real value to stringify
  correctly at fold time
- a method call whose receiver already resolves to a real, non-symbolic
  value invokes the named method directly, with no restriction on the
  method name beyond the receiver not being one of fold's own envelope
  shapes

findSubsetViolation (EVL001's shared predicate) is widened in lockstep
so it never rejects a shape fold() now accepts. github's expression.ts
helpers (matrix, inputs, needs, secrets, ...) are registered
foldsEagerly in the github lexicon plugin.

Fixes #1966
lex00 added a commit that referenced this pull request Aug 29, 2026
…1994)

fold() had no case for a CallExpression whose callee is a property
access, so github.actor.toString()/matrix("os").toString()/[...].join(...)
all fell through to "function call as a value is not foldable" one
blocker behind the composite-call fix in #1965.

Two additions to fold():
- a lexicon-package plain function registered with the new
  IntrinsicDef.foldsEagerly evaluates immediately (not enveloped for
  later revival), since its result is commonly embedded straight into
  a template literal and needs to be the real value to stringify
  correctly at fold time
- a method call whose receiver already resolves to a real, non-symbolic
  value invokes the named method directly, with no restriction on the
  method name beyond the receiver not being one of fold's own envelope
  shapes

findSubsetViolation (EVL001's shared predicate) is widened in lockstep
so it never rejects a shape fold() now accepts. github's expression.ts
helpers (matrix, inputs, needs, secrets, ...) are registered
foldsEagerly in the github lexicon plugin.

Fixes #1966
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant