Skip to content

fix(core): fold fallback reasons lead with the cause, one line, unified wording (#1054) - #1109

Merged
lex00 merged 2 commits into
mainfrom
fix/1054-fold-reason-diagnostics
Jul 27, 2026
Merged

lex00 merged 2 commits into
mainfrom
fix/1054-fold-reason-diagnostics

Conversation

@lex00

@lex00 lex00 commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1054.

Restatement of acceptance criteria

  • No fold fallback reason embeds node.getText() of a multi-line node — every reason stays on one line, so a line-oriented consumer (grep, a log aggregator) sees the whole thing.
  • The underlying error (position + message) must survive line-based truncation — it can't be pushed past the point a naive log viewer cuts a line.
  • The two different wordings for the same "a bare call used where a value is needed" rejection — function call as a value is not foldable: ... (fold.ts) vs call expression as a value is not foldable: ... (fold-import.ts) — collapse to one wording, so a tool grouping fallback reasons by text stops silently under-counting one of them.
  • Nested reasons (a reason embedding a child reason with its own position) stay readable on one line without losing inner positions.
  • This is diagnostics/formatting only: fold decisions are untouched. just fold-differential stays 53/98 fold with zero drift, and the per-entry report is unchanged.
  • just build, just lint, just test green; just check-lexicons no regression.

The issue named two lines (fold-import.ts's destructured-export reason). Since main has grown (#1044/#1063 call-form intrinsics + lexicon-package folding, #1091/#1097/#1105 today), I audited every reason-construction site across packages/core/src/discovery/fold-import.ts and packages/core/src/fold/*.ts rather than just those two lines. Found 7 diagnostic-text sites embedding raw getText() (the 2 the issue names, plus resolveCallExpression's two call-as-value throws, fold.ts's nested-new-as-value message, and subset.ts's 3 shared message builders used by fold()'s foldError). All 7 now go through one bounded, single-line-safe helper. I also found 3 more getText() sites that are data, not diagnostic text (the resource type name captured in the folded spec, the tag name used for intrinsic-registry lookup, and destructuring binding-name extraction) — touching those would risk changing what gets serialized, so they're deliberately untouched.

The fix

  • briefNodeText(node, maxLength = 60) (new, fold/subset.ts): collapses a node's getText() — internal whitespace including newlines — down to single spaces, then truncates with a trailing ... past the cap. Used everywhere a node fragment gets embedded in a message.
  • Destructured export reason (fold-import.ts): now identifies the export by its binding names and the source's callee, never the raw call: "<names>" (destructured from <Callee>(...)) is not foldable: <error>.
  • Wording unification: resolveCallExpression no longer hand-rolls "call expression as a value is not foldable: ...". It now calls subset.ts's exported callExpressionMessage(node) directly — the same builder fold() already uses for a call used as a prop value. One wording, one source of truth, reused rather than a third string invented. subset.ts already documents itself as the shared-message-builder module fold() and the EVL lint classifier both import from, so this fixes the one place that had drifted from it.
  • Nested reasons are untouched in shape (still err.message (reason)) — they were already single-line once their inner pieces stopped embedding raw multi-line text, which the briefNodeText fix above takes care of.

Before / after (pasted from real corpus runs — examples/cockroachdb-multi-region-gke)

Before:

[fold:run] east/infra/cluster.ts — destructured export from "GkeCluster({
  name: config.clusterName,
  location: config.region,
  machineType: "n2-standard-2",
  network: "crdb-multi-region",
  subnetwork: "crdb-multi-region-east-nodes",
  minNodeCount: 1,
  maxNodeCount: 3,
  diskSizeGb: 100,
  releaseChannel: "REGULAR",
  workloadIdentity: true,
  privateNodes: true,
  masterCidr: "172.16.0.0/28",
})" is not foldable: 15:9 - unresolved identifier: config (10:24 - "config" is not foldable: 6:6 - unresolved identifier: CRDB_CLUSTER (3:59 - "CRDB_DOMAIN" is not foldable: 33:28 - ambient "process" read is not foldable — declare a build-time parameter instead (chant.config.ts's buildParams + `chant build --param name=value`/`--params-file`) and reference it via `import { params } from "@intentius/chant/params"`, rather than reading process.env directly))
[fold:run] shared/iam-crdb.ts — "crdbServiceAccounts" is not foldable: call expression as a value is not foldable: REGIONS.map(...)
[fold:run] east/k8s/namespace.ts — "crdbIngressPolicy" is not foldable: 46:15 - function call as a value is not foldable: ALL_CIDRS.map(...)

(Line 1 is 13 physical lines, grep 'unresolved identifier' on [fold:run] output never matches it. Lines 2 and 3 are the same rejection shape with two different wordings.)

After:

[fold:run] east/infra/cluster.ts — "cluster, nodePool, defaultPool" (destructured from GkeCluster(...)) is not foldable: 15:9 - unresolved identifier: config (10:24 - "config" is not foldable: 6:6 - unresolved identifier: CRDB_CLUSTER (3:59 - "CRDB_DOMAIN" is not foldable: 33:28 - ambient "process" read is not foldable — declare a build-time parameter instead (chant.config.ts's buildParams + `chant build --param name=value`/`--params-file`) and reference it via `import { params } from "@intentius/chant/params"`, rather than reading process.env directly))
[fold:run] shared/iam-crdb.ts — "crdbServiceAccounts" is not foldable: function call as a value is not foldable: REGIONS.map(...)
[fold:run] east/k8s/namespace.ts — "crdbIngressPolicy" is not foldable: 46:15 - function call as a value is not foldable: ALL_CIDRS.map(...)

One line each, the actual cause (unresolved identifier: config, REGIONS.map(...)) is present and grep-able, and lines 2/3 now read identically for the identical rejection shape.

Checked the full corpus, not just this one entry: before the fix there were 11 multi-line destructured-export reasons and 3 occurrences of the old call expression as a value wording (vs. ~15 already using function call as a value for the equivalent case) across the 98-entry corpus. After the fix: 0 remaining multi-line reasons, 0 occurrences of the old wording, and every [fold:*] line the CLI would print is exactly one line.

Wording decision

Kept function call as a value is not foldable: <callee>(...) (fold.ts/subset.ts's existing text) as the one wording, and had fold-import.ts's resolveCallExpression call subset.ts's exported callExpressionMessage() directly instead of inventing a third string. subset.ts already frames itself as the shared-message-builder module both fold() and the EVL lint classifier import from specifically so the same violation never has two different diagnostic strings — resolveCallExpression's own hand-rolled "call expression as a value" copy was the one place that had drifted from that. Reusing the existing builder was less code than merging two wordings into a new third one, and keeps future changes to this message in one place.

Gate evidence

just build (tsc --noEmit -p packages/core/tsconfig.json):

$ npx tsc --noEmit -p packages/core/tsconfig.json
BUILD OK

just lint:

$ npx eslint packages/
LINT OK

just test (full suite):

Test Files  757 passed | 1 skipped (758)
     Tests  8712 passed | 18 skipped (8730)

just fold-differential (the hard constraint — decisions unchanged):

── Fold differential report (#1025) ──────────────────────────────
corpus: 98/98 source directories built both ways
  fold: 53   run-fallback: 45   empty: 0   drift: 0   isolated-retry: 1
  ...
✓ fold coverage regression gate — every entry known to fold today still folds
✓ published fold coverage count matches this run's live count

53/98, zero drift, identical to main — confirmed independently with a scratch script that reproduces the CLI's [fold:*] output and diffs the per-file fold/run mode assignment for all 409 file-level decisions in the corpus before vs. after: 0 differences (only reason text changed).

just check-lexicons:

No untracked tier-1 failures.

(14 pre-existing KNOWN failures, all tracked against other issues — unchanged by this PR.)

Docs: docs/src/content/docs/concepts/typescript-as-data.mdx's generated fold-coverage block and its "published fold coverage count matches this run's live count" guard both stayed green with no edits needed — the count is unaffected (diagnostics only) and no doc text quotes either of the changed wordings.

Tests

  • packages/core/src/fold/subset.test.ts: new briefNodeText unit tests (short text passes through, multi-line collapses to one line, over-cap text truncates) and a callExpressionMessage test proving a multi-line argument list never leaks into the message.
  • packages/core/src/discovery/fold-import.test.ts: strengthened the existing "composite factory defined locally" test to an exact-match assertion locking in the unified wording; added a case for a non-identifier callee (builder.build(...)); added two new tests for the destructured-export reason format (a resolution failure and a "not an object" failure) — this path had zero prior test coverage of its reason text.

All of the above are .toBe(...) exact matches or meaningful .toContain(...) checks, not weakened to substrings loose enough to pass on garbage.

Out of scope (per the task): wiring the intrinsic registry into EVL lint rules is #1106; runLint is untouched.

lex00 added 2 commits July 26, 2026 22:03
fold()'s shared message builders (subset.ts's computedPropertyNameMessage,
dynamicElementAccessMessage, callExpressionMessage) and two hand-written
fold.ts messages (an unregistered tagged-template name, a nested `new
Type(...)` used as a value) all embedded a node's raw getText(). For most
call sites that's a short identifier, but nothing bounded it: a callee that
happens to span multiple lines would leak straight into a fold fallback
reason exactly like #1054's destructured-export case.

Add briefNodeText() (subset.ts): collapses internal whitespace/newlines to
single spaces and caps the result to a bounded length, so every message
built from it is guaranteed single-line regardless of the node's own
formatting. Applied to all four sites. Behavior is identical for the
short, single-line nodes every existing test exercises (whitespace-collapse
and truncation are no-ops when the text already fits) — this is diagnostics
text only, no fold decision changes.
…nify call-as-value wording (#1054)

Two problems in fold-import.ts's fallback reasons, found while measuring
fold blockers across the corpus (#1020/#1044):

- A destructured composite export's failure reason embedded
  decl.node.getText() — the ENTIRE call expression. For a real multi-prop
  composite call that's 20+ lines, so the actual error (e.g. "unresolved
  identifier: config") landed after all of it, and any line-oriented
  consumer of `[fold:run]` output only ever saw the opening line. Now
  reports `"<bound names>" (destructured from <Callee>(...)) is not
  foldable: <error>` — brief, always one line, nested positions preserved.

- resolveCallExpression had its own hand-written "call expression as a
  value is not foldable: ..." string, distinct from fold()'s "function call
  as a value is not foldable: ..." for the identical rejection (a bare call
  used where a value is needed). Both wordings are real in the corpus today
  (e.g. shared/iam-crdb.ts's `REGIONS.map(...)` vs
  east/k8s/namespace.ts's `ALL_CIDRS.map(...)`), so a tool grouping
  fallback reasons by text has to match both or silently under-count one.
  resolveCallExpression now calls subset.ts's callExpressionMessage
  directly instead of building its own copy — one wording, one builder.

Verified against the real corpus: fold-differential stays 53/98 fold with
zero drift, and the per-file fold/run mode assignment is unchanged for all
409 fold decisions across the corpus — only reason text changed.
@lex00

lex00 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Orchestrator verification: fold-differential re-run independently — 53/98, drift 0, decisions unchanged (the diagnostics-only contract holds); 3 clean full-suite runs at baseline (26s, 8712 passed). Wording unification onto subset.ts's shared builder and the data-vs-diagnostic getText() split both check out on diff read. Merging.

@lex00
lex00 merged commit 691b46b into main Jul 27, 2026
5 checks passed
@lex00
lex00 deleted the fix/1054-fold-reason-diagnostics branch August 3, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): fold fallback reasons embed the whole source node, truncating the real error

1 participant