Skip to content

fix(browser): retain optional source-map requires - #2886

Merged
morluto merged 1 commit into
morluto:mainfrom
JFSAS:codex/source-map-optional-require
Oct 13, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
JFSAS:codex/source-map-optional-require

Conversation

@JFSAS

@JFSAS JFSAS commented Oct 13, 2026

Copy link
Copy Markdown

Summary

Fixes #2883. A source-map original containing require?.("./dep.cjs") now produces the same literal dependency candidate as the ordinary call. Locally shadowed and computed calls remain excluded.

Problem and expected behavior

On 3e7c6302, a fetched map containing ordinary and optional calls reports included but retains only the ordinary dependency. Real Chrome runs through compiled CLI and stdio MCP reproduce that omission. After this change both dependencies are retained with their existing resolved URLs and unchanged source-map bytes/digest.

Change and scope

The source-map adapter accepts OptionalCallExpression and returns its callee together with the dependency. The consumer validates that retained callee through the existing lexical reference analysis, rather than independently checking the AST call kind. This keeps optional calls subject to the same shadowing gate and leaves TypeScript import-equals declarations on their existing path.

Ordinary static-analysis correctness fix; maintainer scope decision: not applicable. #2842 changes literal reading in the adjacent extractor and addresses a separate trigger; the two fixes may need a small hunk reconciliation when merging.

Contract and boundary impact

  • Semantic owner and earliest changed stage: source-map original dependency extraction in WebSourceMapFetcher.
  • Contribution scope: existing read-only captured-source analysis.
  • CLI/MCP catalog: unchanged schemas, names and arguments.
  • Provider/platform compatibility: shared browser adapter; no new engine or host requirement.
  • Evidence: additional supported dependency edges; retained source-map text, digest, original source text and URL resolution preserved.
  • Target selection/authority/cleanup: unchanged. No new fetch, execution, mutation or resource owner.
  • Generated metadata/package/installation: none.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

A real loopback HTTP boundary test covers ordinary and optional literal calls, a shadowed optional call, a computed argument, resolved URLs and retained map/original evidence. It failed before the producer fix and passes afterward.

The same map (SHA-256 d9d6a38307044d56516840ff08aef4a583f37a188fd228ebdd21e2db69ef82c1) was served to Chrome 155.0.8059.40 and inspected by both public interfaces on macOS arm64:

Build CLI and stdio MCP specifiers
Base 3e7c6302 ./normal.cjs
Fixed ./normal.cjs, ./optional.cjs

The shadowed call is absent in both builds. REA does not execute the original CommonJS text, and the edges do not establish runtime execution. Windows/Linux and other browsers were not run.

  • 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

Node 24.18.0 / npm 11.16.0:

  • npm run test:focused -- tests/boundary/browser/optionalSourceMapRequire.test.ts tests/boundary/browser/webSourceMapFetcher.test.ts tests/boundary/browser/webSourceMapNestedCoordinates.test.ts tests/boundary/browser/webSourceMapHttpStatus.test.ts tests/boundary/browser/webSourceMapResponseCleanup.test.ts: 104/104 passed. The strengthened final regression was rerun and passed.
  • Before/after compiled CLI and stdio MCP against real Chrome and loopback HTTP: passed the respective baseline/fixed assertions, including hash retention and owned-browser cleanup.
  • npm run build:cached, npm run check:fast, npm run knip, npm run verify:architecture-guards, npm run verify:test-discovery: passed. The pre-push hook also passed check:fast on the committed version.
  • npm run check: blocked by existing formatting errors in unchanged src/domain/functionComparison.test.ts and src/ida/IdaOperationRunner.ts. Formatting for both changed files passed. The separate fast checks, knip and architecture guards above completed successfully.

Compatibility, safety, and release

No breaking schema or installation change. No native decompiler claim; browser validation is limited to the macOS/Chrome configuration stated above. No original-source execution or additional network access is introduced.

Before merge

  • Concrete reproduced problem and linked issue.
  • Scope and authority questions resolved for this ordinary fix.
  • One focused outcome and Conventional Commit title.
  • Regression and relevant failure/negative controls verified.
  • No owning contract or generated metadata change required.
  • Representative public CLI/MCP behavior documented.
  • Final diff checked for unrelated changes, secrets and unsupported claims.

Prepared with AI assistance; all reported executions were run locally.

Carry the require callee from dependency extraction into lexical scope
validation so optional calls remain visible without admitting shadowed
loaders.

Fixes morluto#2883
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T15:42:13.695841Z 1319c19 PR opened
ℹ️ 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 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR retains literal require?.(...) dependencies from source-map originals.

  • Optional require calls now appear as source-map dependencies.

Reviews (1) · Last reviewed commit: "fix(browser): retain optional source-map..." · Reviewed by Greptile

@morluto
morluto merged commit f104500 into morluto:main Oct 13, 2026
1 check passed
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: This PR merged on 2026-10-13 at 16:57 UTC as f104500 (#2886), so this is a record test. On Linux with real headless Chromium, f104500 keeps the require?.(...) edge and 69bd81f (#2910) drops it. Shadowed and computed calls stay out in both.

Results

The merge holds the same two files as the PR head 1319c19, byte for byte. Its diff matches gh pr diff 2886. Nothing else touched the fetcher file between the PR base 3e7c630 (#2848) and the merge parent.

I served the exact map from issue #2883 on a loopback page, with the same SHA-256 as the issue. I opened it in Chromium 154.0.8037.57 (BSD-3-Clause) and ran the issue's rea analyze-web-bundle command on a build of each commit. All runs exited 0.

Build original_module_edges specifiers
69bd81f (#2910) ./normal.cjs
f104500 (#2886) ./normal.cjs, ./optional.cjs

A second page had one original file per form. A direct fetcher call and the CLI agreed on every form. Shadowed, computed, member and template forms stay out in both builds. The full table is folded below.

Test file Node 22.23.1 Node 24.18.0 Node 26.11.1
optionalSourceMapRequire.test.ts at f104500 pass pass pass
optionalSourceMapRequire.test.ts copied into 69bd81f fail fail fail
webSourceMapFetcher.test.ts at f104500 pass pass pass

Not run

Thanks, JFSAS, for the clear issue, the small fix and the real-browser repro.

Forms, before and after
Form in the original Edge at 69bd81f Edge at f104500
require("./plain.cjs") (control) yes yes
require?.("./optional.cjs") no yes
require shadowed, plain call no no
require shadowed, optional call no no
computed argument, plain call no no
computed argument, optional call no no
window.require?.("./member-optional.cjs") no no
optional call with a template literal no no
Test setup
Commands

Same change as the PR head:

  • git diff --quiet f1045001f 1319c19fc on the two files, exit 0.
  • Blob 5c8f86ea0 is the fetcher in both. Blob e7e861d77 is the test in both.
  • cmp on git diff f1045001f^ f1045001f and gh pr diff 2886, exit 0.

Builds, one tree per commit, with Node 24 first on PATH:

  • git archive f1045001f^ | tar -x -C /tmp/pr2886/before, exit 0
  • git archive f1045001f | tar -x -C /tmp/pr2886/after, exit 0
  • npm ci then npm run build in each tree, exit 0 for all four

Tests, with HOME and TMPDIR set to folders in the job dir. Each ran on /usr/bin/node, /usr/bin/node-24 and ~/.local/opt/node26/bin/node:

  • env -C /tmp/pr2886/after NODE scripts/run-development-tests.mjs focused tests/boundary/browser/optionalSourceMapRequire.test.ts, exit 0 on all three
  • env -C /tmp/pr2886/after NODE scripts/run-development-tests.mjs focused tests/boundary/browser/webSourceMapFetcher.test.ts, exit 0 on all three
  • env -C /tmp/pr2886/before NODE scripts/run-development-tests.mjs focused tests/boundary/browser/optionalSourceMapRequire.test.ts, exit 1 on all three

Here NODE stands for each Node binary, and the script is what npm run test:focused calls.

Direct fetcher call, on both trees, with dist/browser/WebSourceMapFetcher.js and a loopback server for the second page's map:

  • node-24 fetcher-cases.mjs /tmp/pr2886/before full/app.js.map, exit 0
  • node-24 fetcher-cases.mjs /tmp/pr2886/after full/app.js.map, exit 0

CLI, with two static loopback servers (ports 39101 and 39102) and one headless Chromium on CDP port 39103:

  • chromium-browser --headless=new --remote-debugging-port=39103 --remote-allow-origins=* --user-data-dir=/tmp/pr2886/chrome-profile --no-first-run --no-default-browser-check --disable-gpu http://127.0.0.1:39101/
  • curl -X PUT 'http://127.0.0.1:39103/json/new?http://127.0.0.1:39102/' for the second page
  • rea list-browser-targets http://127.0.0.1:39103 --json, exit 0
  • rea analyze-web-bundle http://127.0.0.1:39103 TARGET_ID --allowed-origins ORIGIN --fetch-source-maps --observation-ms 0 --json, exit 0 on all four runs (two pages, two trees)

Here rea is node-24 scripts/rea.mjs from each tree. I read the edges from the JSON with jq. I stopped the Chromium and both servers by their own PIDs, so nothing still runs.

Fixtures

The first page is the issue's own layout: /, /app.js and /app.js.map, with the map exactly as the issue shows it. Its SHA-256 is d9d6a38307044d56516840ff08aef4a583f37a188fd228ebdd21e2db69ef82c1. The second page has the same layout and a map with nine original files:

  • case-plain.cjs: require("./plain.cjs");
  • case-optional.cjs: require?.("./optional.cjs");
  • case-shadowed-plain.cjs: function local(require) { require("./shadowed-plain.cjs"); }
  • case-shadowed-optional.cjs: function local(require) { require?.("./shadowed-optional.cjs"); }
  • case-computed-plain.cjs: require(selectedModule);
  • case-computed-optional.cjs: require?.(selectedModule);
  • case-member-optional.cjs: window.require?.("./member-optional.cjs");
  • case-template-optional.cjs: a template literal with no expression inside require?.(...)
  • case-pr-test.cjs: the four lines from the PR test. It splits the same way: ./normal.cjs before, ./normal.cjs and ./optional.cjs after.

The new test fails on 69bd81f because ./optional.cjs is missing from the edge list.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks for catching optional require?.() dependencies in source-map originals, @JFSAS, and for keeping shadowed calls excluded. Welcome to the project!

@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Source-map dependency extraction silently omits optional require calls

3 participants