Repository navigation
feat(core): fold cross-file references into active lexicon package exports (#1063) - #1105
Merged
Merged
Conversation
…ports #1020 taught fold to resolve an identifier across the module graph, but only through relative/absolute specifiers — `isProjectFileSpecifier` skipped bare package specifiers outright. So an identifier imported from a LEXICON package failed as "unresolved identifier" even when what it named was plain static data: azure's `Azure` and gcp's `GCP` pseudo-parameter namespaces, aws's `S3Actions`, gitlab's `CI`. Every one of those is an `as const` object literal the folder has always handled; the gap was purely the resolver's scope. `buildExternals` now follows a bare specifier into a package, and only into a package, that is an ACTIVE LEXICON of this build. The allowlist is the lexicon names the build already resolved before discovery ran, threaded down as `DiscoveryOptions.lexicons` and matched by TEXT — nothing is resolved to find out what it is, which is what keeps `resolveModulePath`'s pathological cold-resolution path (measured at up to ~361s for a genuinely new bare specifier, regressed twice during #1020) out of reach. Subpaths are excluded for the same reason: the fast resolver only recognizes a package root, so a subpath specifier would fall through to exactly that slow path, and lexicons re-export their whole surface from the barrel anyway. What comes back is the real export off the real module, imported through the session-wide import cache — the same module object the run path gets, since `importModule` is a plain `import()` with no cache-busting. So identity holds by construction, and `reviveFoldedValue` grows a passthrough for live `Intrinsic` instances: without it the generic object walk rebuilds `Azure.ResourceGroupLocation` as a plain `{}`, dropping the prototype that carries `toJSON` and serializing `{}` where run emits `[resourceGroup().location]`. Callable exports stay out. A lexicon's resource classes, composite factories and intrinsic functions already have resolution paths that know how to invoke them; binding them as identifier values would widen what folds well beyond what this needs. No `liveSources` edge is recorded for a lexicon-package value. That mechanism exists for a folded file that captured another discovered FILE's objects, so it can be invalidated when that file is forced back to run. A lexicon package has no fold/run duality: it is not a discovered file, `planFoldTaint` filters to the discovered set anyway, and both paths reach it through the identical import of the identical path. `process` and every other ambient environment read still fail, with a test that pins it alongside an active lexicon package in scope.
The differentials build through core's `build()` rather than the CLI, so they have to reproduce `cli/commands/build.ts`'s active-lexicon step the same way they already reproduce its `intrinsics` one — otherwise fold is measured without the allowlist real `chant build --fold` gives it. Corpus entries now carry their lexicon names: the full set for the root tutorials (which deliberately mix lexicons), the one lexicon for a `lexicons/*/examples/*` fixture, matching how serializers and intrinsics are already selected. 21 entries move run-fallback to fold: all 13 azure examples and all 8 gcp examples. Each was a single file failing on `Azure.<PseudoParameter>` / `GCP.<PseudoParameter>`. Nothing else changes — 45 entries still fall back, drift stays 0, and the suite runs in 4.31s against 4.33s before. The same change clears every remaining `S3Actions`, `CI` and value-position `AWS` failure in the corpus, but those sit in `docs-snippets` entries with several unrelated blockers apiece, so they move no entry on their own.
…blocker snapshot Adds the new subset bullet, and refreshes the measured blocker breakdown the page carries: the lexicon-package cause is gone (116 files, 36 entries -> 0), a nested `new Type(...)` used as a value is now the largest at 63 files and 22 sole-blocker entries, and the per-lexicon lines read azure 13/13, gcp 8/8, aws 12/18.
Contributor
Author
|
Orchestrator verification, re-run independently: fold-differential 53/98, drift 0 (confirmed across 5 full-suite runs); 5 consecutive clean suite runs, 24–26s, 8703 passed — no hang-class regression; diff read for the two regression classes that have bitten (module-init probing: none added; cold bare-specifier resolution: scope decided by Set.has on the build's own lexicon names, resolution stays behind the existing memoized paths). Azure 0/13→13/13 and GCP 0/8→8/8 as claimed. The two flagged judgment calls (no liveSources for lexicon-package values; isIntrinsic passthrough in revival) both check out — lexicon packages have no fold/run duality so taint doesn't apply, and the passthrough is what keeps toJSON envelopes intact. Merging. |
This was referenced Jul 27, 2026
Merged
lex00
added a commit
that referenced
this pull request
Jul 27, 2026
…ps flagging calls that fold (#1106) (#1110) * fix(lint): thread the active lexicons' intrinsic registry into runLint findSubsetViolation (fold/subset.ts) has taken an optional IntrinsicDef registry since #1044 and answers a registered, opted-in call-form intrinsic (Ref(...), GetAtt(...)) exactly like fold() does. EVL001 calls that same predicate but runLint never had a registry to hand it, so chant lint kept flagging calls that fold cleanly. Add LintContext.intrinsics, thread it through runLint's signature, and pass it in from the three places that build a LintContext for a real project: the lint command's initial pass, its --fix re-lint, and the LSP's per-file diagnostics. Each gathers its intrinsics from the same loaded lexicon plugins the build path already reads plugin.intrinsics?.() off of, mirroring how discover() has threaded IntrinsicDef[] into the fold path since #1039/#1105. A LintContext built without that plumbing (a bare unit test, a consumer that hasn't resolved a project's lexicons) keeps the pre-#1044 conservative answer: every call is a violation. * test(lint): flip the EVL/fold divergence test to convergence, add coverage subset.test.ts pinned "registry-less EVL is STRICTER than fold on an opted-in call" as a known, tracked property. Now that runLint threads the intrinsic registry through, a LintContext built with it converges with fold() instead of diverging from it — flip the test to assert that, and add one confirming a LintContext built without the registry still keeps the old conservative answer. Add unit coverage in evl001-non-literal-expression.test.ts for context.intrinsics directly (registered+opted-in passes, registered without the opt-in still flags, unregistered still flags), and an end-to-end lintCommand test using the real aws lexicon plugin proving chant lint no longer flags Ref(...) but still flags an unregistered call in the same project.
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 #1063.
What this is, restated
#1020 gave fold cross-file identifier resolution, but
isProjectFileSpecifierlimits it to relative/absolute specifiers. A bare package specifier is skipped, so an identifier imported from a lexicon package fails asunresolved identifierand takes the whole file back to the run path — even though what it names is plain static data the folder has always handled.AzureandGCP(pseudo-parameter namespaces), aws'sS3Actions, gitlab'sCIare allas constobject literals.This extends resolution to bare specifiers that name an active lexicon package of this build, and to nothing else. Specifically:
node_modules.processand every other environment-dependent reference must keep failing. That is the subset's point, and there is a test pinning it with an active lexicon package in scope.discovery/fold— those modules bundle into the feat(core): sandbox the --fold run-fallback path (partial coverage currently gives zero security benefit) #1045 sandbox child under--permission, where an init-time probe throws.Design: how "active lexicon package" is decided without cold resolution
The build already knows its lexicons by name, long before discovery runs:
resolveProjectLexicons()readschant.config.ts'slexiconsor falls back todetectLexicons()'s text scan, thenloadPlugins()imports@intentius/chant-lexicon-<name>for each. That name list is now threaded down asDiscoveryOptions.lexiconsinto the fold session, which turns it into aSetof package specifiers.Deciding whether a bare specifier is in scope is then a
Set.hason a string. Nothing is probed, read, or resolved to find out what a specifier is — which is the whole point, sinceresolveModulePath's bare branch can fall through tocreateRequire(fromFile).resolve(specifier), the call #1020's own history measured at 60s, then 69s, then 361s for successive new packages in one process. This is the same shape #1064 used for@intentius/chant/params: recognize by text, never resolve to check.Three restrictions fall out of that, each deliberate:
fastResolveBareSpecifieronly recognizes a package root (it looks for<node_modules>/<specifier>/package.json), so a subpath specifier falls straight through to the slowcreateRequire().resolve(). Lexicons re-export their whole surface from the barrel and every example imports it that way, so subpaths buy nothing and cost exactly the thing this avoids.@intentius/chant-lexicon-*package that happens to be installed but wasn't loaded is as out of scope asnode:fs. A caller that supplies no lexicon list gets no bare-specifier resolution at all, rather than a looser fallback.resolveResourceEntity,resolveCallExpression,reviveFoldedValue). Binding them as identifier values would widen what folds well past what this needs — none ofAzure/GCP/S3Actions/CIis a function.Once a specifier is in scope, the value comes from the real module, imported through the session-wide
importCache(at most one realimport()per package per build).importModuleis a plain dynamicimport()with no cache-busting, so that is the same module object the run path gets.Identity, and #1097's
liveSourcesreviveFoldedValuegrows one passthrough: a liveIntrinsicinstance. Without it the generic object walk rebuildsAzure.ResourceGroupLocationas a plain{}, dropping the prototype that carriestoJSON— which serializes{}where the run path emits[resourceGroup().location].isIntrinsickeys offSymbol.for("chant.intrinsic"), a global symbol, so it holds across separately-loaded copies of chant-core.No
liveSourcesedge is recorded for a lexicon-package value, and I don't think one should be. That mechanism exists so a folded file which captured another discovered file's objects is invalidated when that file is forced back to run — a fold/run disagreement about identity. A lexicon package has no such duality. It is not a discovered source file, soplanFoldTaintwould drop the edge anyway (if (!fileSet.has(source)) continue). It never falls back to run. And both paths reach it through the identical un-cache-bustedimport()of the identical resolved path, so the object fold captures is the object the run path holds. There is nothing for the two sides to disagree about. This is also not new behavior:resolveSymbolicValuehas resolvedAWS.StackNamethrough exactly this mechanism since #1039, with the differential green throughout.Sandbox
No module-scope filesystem access is added.
lexiconPackageNameandactiveLexiconPackageare pure string arithmetic; the resolve/import happens lazily insideresolveActiveLexiconExport. Same rule PR #1081's7d63ee54established forparamsModulePath().Numbers
just fold-differential2ab05b8c)Sorted per-entry diff of the report — 21 lines change, all in the same direction, nothing else moves:
EXPECTED_FOLDgains exactly those 21 names. No entry that folded before regressed.Azure's 13, checked one by one
#1097 reported that all 13 azure corpus entries had this issue as their sole remaining blocker. That held: 13 of 13 flipped. Each had exactly one file, and its reason named
Azure:GCP is the same story, 8 of 8, all on
GCPin anannotationsinitializer.Corpus-wide
unresolved identifiertalliesWhole-block parse of every run-fallback reason (both wordings, multi-line reasons kept intact), before and after:
AzureGCPCIS3ActionsAWS(value position)configCRDB_CLUSTERsharedGCP_PROJECT_IDCI,S3ActionsandAWSall cleared, but each lives in adocs-snippetsentry carrying several unrelated blockers, so they move no entry on their own — the files behind them now stop on their next blocker instead. E.g.lexicons/aws/examples/lambda-api/src/process-api.tswent from11:15 - unresolved identifier: S3Actionsto34:20 - unresolved identifier: dataBucket (… nested new ServerSideEncryptionByDefault(...) as a value …).What deliberately still fails
processand every other environment read. It is unchanged and covered by a test that puts an active lexicon package in scope alongside it, so the pass is not vacuous:It is also visible in the corpus:
examples/temporal-crdb-deploy'snetworking.tsused to stop onGCP; it now resolves past that and stops onprocess.envfurther down the chain, which is the correct outcome.Also still rejected, by the same tests: a lexicon package not loaded by this build, a bare specifier with no active lexicons at all, a non-lexicon package installed right next to one that is active, and a lexicon's callable export used as a value.
Runtime — repeat runs, not a single pass
npx vitest run examples/fold-differential.test.ts, three consecutive runs each side, same machine, same session:main2ab05b8cFull
just test:main30.17s, this branch 26.51s (and 24.97s on an earlier run). 756 test files, 8703 tests, 1 file / 18 tests skipped, both sides.Other gates
just build— clean.just lint— clean.just test— 756 passed, 1 skipped.just check-lexicons— 15 known tracked failures, no untracked failures. Same asmain.chant build src --lexicon azure --foldinlexicons/azure/examples/basic-storage: both files report[fold:fold] … no module execution, andlocationserializes as[resourceGroup().location]— the Intrinsic passthrough doing its job outside the test harness.Not done here
import * as azure from "@intentius/chant-lexicon-azure") are not resolved. Nothing in the corpus uses one, and the named-import path covers every reference feat(core): fold cross-file references into lexicon package exports (Azure/GCP pseudo-params, action constants) #1063 names; a namespace import would pull the entire barrel — every resource class included — into the identifier scope, which is a much wider change than this needs.