Skip to content

fix(reference): resolve emitted extensions to TypeScript source - #755

Closed
rudycelekli wants to merge 2 commits into
morluto:mainfrom
rudycelekli:fix/rea-reference-runtime-source-extensions-20261006
Closed

rudycelekli wants to merge 2 commits into
morluto:mainfrom
rudycelekli:fix/rea-reference-runtime-source-extensions-20261006

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary

Resolve a TypeScript historical-source import's emitted .js, .jsx, .mjs or .cjs extension to its present source counterpart when the literal runtime file is absent. This repairs source-reference edges for ordinary NodeNext source trees.

Problem and expected behavior

main.ts exporting from ./dep.js, with dep.ts present, was reported as unresolved. The actual installed TypeScript 7.0.2 NodeNext compiler accepts this tree. The built public import-reference-source CLI reported all eight tested source counterparts as unresolved before the fix.

Change and scope

Add source-extension fallbacks for TypeScript callers after existing file candidates. Present runtime files retain precedence. Declaration files retain their actual source identity. JavaScript callers do not acquire TypeScript runtime fallbacks. Counterparts cover explicit filenames, not directory/index resolution. This does not implement full tsconfig or package resolution, nor establish runtime execution of declaration sources.

Contract and boundary impact

  • Semantic owner and earliest changed stage: filesystem source import relationship resolution, ReferenceSourceImportEntries.
  • CLI and MCP/tool-catalog contract: no schema or catalog change; CLI historical-source relationship output is corrected.
  • Provider, bridge, target-format, or platform compatibility: local filesystem importer; no Hopper/Ghidra bridge change.
  • Evidence, artifact, provenance, or reconstruction contract: actual present source paths and hashes retained; unsupported resolutions remain unresolved.
  • Process execution, authorization, cleanup, or containment impact: importer still does not execute source or perform network requests.
  • Generated metadata (docs/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: real filesystem imports for eight counterpart cases; existing runtime-file precedence and JavaScript negative controls. Maintainer follow-up adds three legitimate declaration-caller cases (.d.ts/.d.mts/.d.cts), verified with actual TypeScript NodeNext strict noEmit compilation.
  • Base reproduction or other evidence: 8 failures / 3 controls passed on base; 26 focused tests passed after, including existing import regressions. Actual TypeScript 7.0.2 NodeNext compiler accepts all eight owned fixtures.
  • User-visible CLI/MCP output: built CLI changed all eight fixture edges from unresolved emitted paths to internal present source paths.
  • Remaining proof gaps: no complete deterministic suite, Windows filesystem run or provider execution was performed.

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 run test:focused -- tests/boundary/filesystem/referenceSourceTypeScriptExtensions.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts — 26 passed.
  • Actual TypeScript 7.0.2 tsc -p on owned NodeNext fixture tree — exit 0.
  • Built rea import-reference-source ... --json — all eight source counterparts internal; base had eight unresolved.
  • npm run check — all five tasks passed, 124 existing lint warnings and zero errors.
  • Oxfmt and git diff --check — pass.
  • npm run check:fast — pass (both cached tasks).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: native macOS filesystem and actual TypeScript compiler only; no Hopper/Ghidra/browser claim.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no authorization/network/path containment change; owned public fixture data only. No related issue because this includes a self-contained regression. AI assisted implementation and tests; I reviewed and ran the checks.

Review checklist

  • 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 follow-up: signed bb640c7cb241cdb0fce6afd580b7a17fd352dc76 adds only the scope comment and declaration-caller controls; the existing valid caller gate is retained. New hosted checks pending, separate from the original all19 green head.

@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Reviewed: TS source-extension fallbacks (./dep.js -> dep.ts/.tsx/.d.ts, .mjs->.mts etc. after runtime candidates, TS-callers only) correctly mirror NodeNext behavior with precedence pinned (present runtime wins) and JS callers conservative. 8 counterpart + precedence + JS-negative controls cover it. APPROVE. Two non-blocking nits: caller gate also matches .d.ts importers (consider excluding /.d.(ts|mts|cts)$/), and new suffixes lack index variants — worth a one-line out-of-scope comment.

@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Review — APPROVE (two non-blocking nits)

Summary

resolveInternalSpecifier in src/application/ReferenceSourceImportEntries.ts gains source-extension fallbacks for TypeScript callers: a missing ./dep.js (etc.) resolves to a present dep.ts / .tsx / .d.ts (and .mjs→.mts, .cjs→.cts, .jsx→.tsx), only after existing runtime-file candidates, and never for JavaScript callers.

Verification

  • Precedence and scoping are right: fallbacks are appended after the existing candidate list so present runtime files win (pinned by the both-present control), the caller gate plus the JS-negative control keeps JS callers conservative, and the eight counterpart cases mirror actual TS 7.0.2 NodeNext behavior.
  • No execution / network / path-containment change; genuinely missing targets stay visibly unresolved.
  • 8 counterpart cases + 2 precedence controls + 1 JS negative control cover the change and its boundaries.
  • CI: all 19 checks SUCCESS. No TOOL_CONTRACTS or catalog update needed (relationship values corrected, schema unchanged).

Nits (non-blocking)

  1. src/application/ReferenceSourceImportEntries.ts:92 — the caller gate also matches declaration files (foo.d.ts ends in .ts, likewise .d.mts / .d.cts), so a .d.ts importer would get runtime-extension fallbacks. Harmless in practice, but if declaration sources should keep source identity without substitution, consider excluding them, e.g. !/\.d\.(?:ts|mts|cts)$/u.test(fromPath).
  2. Same location — the new source suffixes are stem-only with no ${stem}/index… variants (e.g. ./sub.js → sub.ts/index.ts). Fine to leave unsupported/unresolved for now, but worth a one-line comment that directory-index emitted-extension mapping is out of scope.

@rudycelekli

Copy link
Copy Markdown
Author

Thank you. Signed follow-up bb640c7cb241cdb0fce6afd580b7a17fd352dc76 adds the explicit-filename/index-resolution scope comment and three declaration-caller controls. I retained the caller gate: real TypeScript 7.0.2 tsc --noEmit --module NodeNext --moduleResolution NodeNext --strict accepts .d.ts -> ./dep.js -> dep.d.ts, .d.mts -> ./dep.mjs -> dep.d.mts, and .d.cts -> ./dep.cjs -> dep.d.cts, each with exit 0. The public source importer resolves all three declaration relationships correctly; excluding declaration callers would lose valid source-level imports, without those declarations being executed.

The relevant importer selection passes 26 tests across two files. check and check:fast pass (124 existing lint warnings, zero errors). The follow-up changes only the comment and these three cases; hosted checks for the new head are pending. Prepared with Codex assistance on behalf of @rudycelekli.

@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Superseded by #815, which integrated this change and has now merged (3af3811). Thanks @rudycelekli for the fix and the thorough verification — much appreciated!

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

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants