Repository navigation
fix(source): retain CommonJS requires spelled as exact no-substitution templates - #4511
Conversation
…n templates Admit expression-free template arguments at the CommonJS require gate and read their single cooked quasi through the shared exact-literal reader. Scope is the require path only: static ESM template declarations keep their parse failures and dynamic import() keeps the explicit unknown/partial <dynamic-import> relationship with no invented target. Refs: morluto#4382
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no blocking issues were found. SummaryRetains CommonJS dependencies written as expression-free templates by using the shared exact-literal reader.
Reviews (2) · Last reviewed commit: "fix(source): admit TypeScript-wrapped ex..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c60dea6be5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
… shared literal reader Address review: the require gate matched the outer AST node, so runtime-transparent TS wrappers (as const, !, satisfies) around exact strings or expression-free templates were still silently omitted even though readExactJavaScriptLiteral unwraps them. Remove the gate and let the shared exact-literal reader own argument exactness; computed arguments remain silent and dynamic import() behavior is unchanged. Refs: morluto#4382
baron
left a comment
There was a problem hiding this comment.
Source review of this head found no additional actionable defect. The require extractor now delegates exactness to the existing unwrap-aware literal reader; loader-identity checks and runtime-require selection remain in place. The prior wrapper finding is structurally addressed rather than patched with another spelling-specific gate. I also checked the changed boundary expectations and related dynamic-import/shadowing consumers.
HOLD for human readiness: all three current Author readiness declarations remain unchecked. CI including CI required is green, but CI does not make that declaration. No local tests/build/install or real-provider runs were performed for this PR in this review; this is a source/CI assessment, not an independent execution of the reported boundary suite.
|
@baron On your HOLD: all three Author readiness declarations were ticked at 2026-10-17 11:33 UTC, ~4h after your review, so at review time they were indeed unchecked. What they rest on, from the body:
If any specific local receipt would clear the hold for you — a particular command, build/install, or a real-provider run — name it and I will run it and post the output here. |
Summary
Fixes #4382. The historical-source graph producer silently drops CommonJS dependencies spelled as exact no-substitution templates:
require(`mod`)yields{relationships: [], parse_failures: [], limitations: []}whilerequire("mod")yields a parsedrequiresedge.Problem and expected behavior
Smallest trigger: a
.cjssource file containingrequire(`mod`). Violated invariant: the supported historical-source CommonJS parser retains a dependency for an unshadowed loader called with an exact string, and an expression-free template supplies one exact string.Root cause (source-inspected): in
src/domain/referenceSourceImportParsing.ts, the require branch is gated byisModuleExpression, which narrows toStringLiteral | CallExpression. A no-substitutionTemplateLiteralpasses the callee and unshadowed-binding checks, then is filtered at that gate beforemoduleSpecifierFromExpressioncan run, so it exits with no relationship, no parse failure, and no limitation. The extractor andsafeModuleNameare likewise StringLiteral-only.Change and scope
TemplateLiteralarguments at the CommonJS require gate (isExactTemplateExpression).readExactJavaScriptLiteral(src/domain/javascript/javascriptAstValues.ts), which already treats zero-expression templates as exact strings.c09ab40fd): the require-branch gate matched the outer AST node while the reader unwraps runtime-transparent TS wrappers, sorequire(pkgas const)andrequire(pkg!)were still omitted. The gate was removed; the shared reader alone owns argument exactness, which also retains TS-wrapped quoted requires (same root cause, superset of the typed outcome).Intentionally not included, per the issue's typed outcome:
import()keeps the explicit<dynamic-import>partial with no invented target (template or computed).require(`./${name}.js`)) stay silent rather than guessing a target.safeModuleNameandImportExpressionhandling are untouched.Contribution scope: not applicable — ordinary fix within existing domain boundaries; no provider, capability, or maintainer scope decision involved.
Contract and boundary impact
src/domain/referenceSourceImportParsing.ts(domain graph producer); earliest changed stage is reference-source relationship emission during artifact/evidence registration.requiresedge for exact-template spellings (relationship sets can gain entries relative to 6.5.0).docs/public/product-catalog.json), package, or installation impact: none; no generated files touched.Expected effects:
Evidence and regression coverage
tests/boundary/filesystem/referenceSourceTemplateRequire.test.ts(template + quoted controls, computed require and computed dynamic-import controls);tests/boundary/filesystem/referenceSourceComputedRequire.test.tsgains the now-correctrequire(`./dep.js`)edge inunknown.cjs(previously encoded the silent omission this issue reports; member-callee variants remain gated by mutation indexing and produce no new edges).templatedassertion only (quoted control passes, all four issue controls pass), matching the issue's probe output. The issue's probe asserts the pre-fix omission, so the fixed behavior was verified by asserting its typed outcome instead (below).For evidence-bearing changes:
Validation performed
npm ci— locked dependency installation refreshed (main's lockfile addedtsx).npm run test:focused -- tests/boundary/filesystem/referenceSourceTemplateRequire.test.ts— RED before fix (template edge missing, quoted control passing), 1/1 pass after.npm run test:focused -- tests/boundary/filesystem/referenceSourceTemplateRequire.test.ts tests/boundary/filesystem/referenceSourceComputedRequire.test.ts tests/boundary/filesystem/referenceSourceDynamicImports.test.ts tests/boundary/filesystem/referenceSourceShadowedRequire.test.ts tests/boundary/cli/referenceSourceDirectoryImports.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts— 6 files, 26/26 pass after updating the staleunknown.cjsexpectation.tsx,parseReferenceSourceImportsonfixture.cjs):require(\mod`)returns{to: "mod", kind: "requires", resolution: "external", parse_state: "parsed", resolutionStrategy: "runtime-require"}; computed require returns no relationship;import(`mod`)stayspartial;import(`./${name}.js`)stays resolutionunknown`; static ESM template import/export still report parse failures — all issue controls asserted, exit 0.tsx):require(pkgas const),require("pkg" as const),require(pkg!), andrequire(pkgsatisfies string)each returnto: "pkg",parse_state: "parsed";require(a${x}cas const)stays silent;import(pkgas const)stays<dynamic-import>partial.npm run test:focusedafter review fix (c09ab40fd) — 6 files, 27/27 pass (adds.ts+createRequireboundary coverage: plain,as const,!, wrapped-string all retained; computed wrapped template silent).npm run check:fast— typecheck + lint, 2/2 tasks successful (rerun after review fix).Compatibility, safety, and release
requiresentries for template spellings relative to earlier releases.Author readiness
Human owner: @hemv-857
Before merge
type(scope): outcome.Maintainer blocker verification
The require-wrapper finding is already fixed at the producing parser: exactness delegates to readExactJavaScriptLiteral through moduleSpecifierFromExpression rather than an AST-kind gate. On this exact head, the focused referenceSourceTemplateRequire and referenceSourceComputedRequire suites passed 3/3, including as-const/non-null wrappers and unresolved computed-template controls. No additional source edit was needed.