Skip to content

fix(source): retain CommonJS requires spelled as exact no-substitution templates - #4511

Merged
morluto merged 2 commits into
morluto:mainfrom
hemv-857:fix-4382-template-require
Oct 21, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
hemv-857:fix-4382-template-require

Conversation

@hemv-857

@hemv-857 hemv-857 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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: []} while require("mod") yields a parsed requires edge.

Problem and expected behavior

Smallest trigger: a .cjs source file containing require(`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 by isModuleExpression, which narrows to StringLiteral | CallExpression. A no-substitution TemplateLiteral passes the callee and unshadowed-binding checks, then is filtered at that gate before moduleSpecifierFromExpression can run, so it exits with no relationship, no parse failure, and no limitation. The extractor and safeModuleName are likewise StringLiteral-only.

Change and scope

  • Admit expression-free TemplateLiteral arguments at the CommonJS require gate (isExactTemplateExpression).
  • Read exact string arguments through the existing shared exact-literal reader readExactJavaScriptLiteral (src/domain/javascript/javascriptAstValues.ts), which already treats zero-expression templates as exact strings.
  • Per Codex review (P2, addressed in c09ab40fd): the require-branch gate matched the outer AST node while the reader unwraps runtime-transparent TS wrappers, so require(pkg as const) and require(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:

  • Dynamic import() keeps the explicit <dynamic-import> partial with no invented target (template or computed).
  • Computed template requires (require(`./${name}.js`)) stay silent rather than guessing a target.
  • Static ESM template declarations keep their Babel parse failures.
  • safeModuleName and ImportExpression handling are untouched.

Contribution scope: not applicable — ordinary fix within existing domain boundaries; no provider, capability, or maintainer scope decision involved.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/referenceSourceImportParsing.ts (domain graph producer); earliest changed stage is reference-source relationship emission during artifact/evidence registration.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries — not applicable.
  • CLI and MCP/tool-catalog contract: no new tool, option, or schema; observable effect is that the reference-source graph now includes the previously omitted requires edge for exact-template spellings (relationship sets can gain entries relative to 6.5.0).
  • Provider, bridge, target-format, or platform compatibility: none affected.
  • Evidence, artifact, provenance, or reconstruction contract: no invented targets; computed specifiers remain unknown/partial; quoted spellings unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none; no generated files touched.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: new tests/boundary/filesystem/referenceSourceTemplateRequire.test.ts (template + quoted controls, computed require and computed dynamic-import controls); tests/boundary/filesystem/referenceSourceComputedRequire.test.ts gains the now-correct require(`./dep.js`) edge in unknown.cjs (previously encoded the silent omission this issue reports; member-callee variants remain gated by mutation indexing and produce no new edges).
  • Base reproduction: on the base revision, the new test fails on the templated assertion 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).
  • User-visible CLI/MCP output (if applicable): reference-source graph relationships only; no new tool output.
  • Remaining proof gaps: no full CLI/MCP end-to-end import run for this spelling; evidence is the boundary workflow plus direct parser assertions.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm ci — locked dependency installation refreshed (main's lockfile added tsx).
  • 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 stale unknown.cjs expectation.
  • Direct parser probe (tsx, parseReferenceSourceImports on fixture.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.
  • Direct TS-wrapper parser probe (tsx): require(pkg as const), require("pkg" as const), require(pkg!), and require(pkg satisfies string) each return to: "pkg", parse_state: "parsed"; require(a${x}c as const) stays silent; import(pkg as const) stays <dynamic-import> partial.
  • npm run test:focused after review fix (c09ab40fd) — 6 files, 27/27 pass (adds .ts + createRequire boundary 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).
  • Node v24.18.0, macOS arm64. No native provider involved (synthetic source bytes).

Compatibility, safety, and release

  • Breaking changes or migration steps: none intended; graphs may gain correct requires entries for template spellings relative to earlier releases.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable — source-boundary parser change, no provider or target interaction.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new I/O, execution, or authority; only parsing of already-selected source bytes.

Author readiness

Human owner: @hemv-857

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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.

…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
@hemv-857
hemv-857 marked this pull request as ready for review October 16, 2026 15:51
Copilot AI balanced review requested due to automatic review settings October 16, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T16:16:48.748011Z c09ab40 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Retains CommonJS dependencies written as expression-free templates by using the shared exact-literal reader.

  • Exact-template require calls now appear as parsed dependency edges.

Reviews (2) · Last reviewed commit: "fix(source): admit TypeScript-wrapped ex..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 baron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hemv-857

Copy link
Copy Markdown
Contributor Author

@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:

  1. Final diff reviewed, edge cases understood, responsibility for AI-assisted work — diff c60dea6b..c09ab40f; the require extractor delegates exactness to the existing unwrap-aware literal reader (your own summary of the head), loader-identity checks and runtime-require selection untouched.
  2. Evidence checked, gaps recorded — Validation section has the local receipts: npm ci, focused boundary suites RED before fix / 26/26 then 27/27 after your review fix (c09ab40fd), npm run check:fast 2/2, direct parser probes for all issue controls, Node v24.18.0. Remaining gap stated openly: no full CLI/MCP end-to-end import run for this spelling.
  3. Ready for initial maintainer review — CI required green at c09ab40f; the SKIPPED lanes are path-filtered, and Conventional PR title shows CANCELLED (superseded re-run), not failed.

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.

@morluto
morluto merged commit 4842f23 into morluto:main Oct 21, 2026
39 of 41 checks passed
@morluto morluto added the bug Something isn't working label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Reference source graphs omit CommonJS dependencies written as static templates

4 participants