Skip to content

fix(reference): preserve physical symlink targets - #3562

Closed
shoyann wants to merge 11 commits into
morluto:mainfrom
shoyann:fix/reference-selected-path
Closed

shoyann wants to merge 11 commits into
morluto:mainfrom
shoyann:fix/reference-selected-path

Conversation

@shoyann

@shoyann shoyann commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closed: core fix superseded upstream

Closing this PR without merging after verifying upstream main a2e2c29b59e8775b0e6aedb09a9eb16adf32646b on 2026-10-27.

The core physical symlink target fixes are now implemented upstream in 09acf217: preserve native path traversal, validate it with stat before realpath, classify containment from the actual destination, and retain unresolved path spelling. The earlier selected-root issue was already fixed in 5e8f8b31.

Supersession verification

Executed on macOS x64 with Node 24.22.1 / npm 11.16.0, using an isolated checkout of that upstream commit with no production changes:

  • Built the upstream runtime and passed 82 tests across 7 focused files: the reader, import projection, graph schema, filesystem imports, symlink races, upstream compiled CLI symlink-path regression, and a temporary replay of this PR's original 12-link fixture.
  • The original regression body was first run unchanged and failed at its old unknown/null expectation. This is recorded as a failed run, not an unchanged-test pass.
  • Upstream intentionally reports those four invalid paths as missing with their uncollapsed absolute spelling. A separate contract-aligned replay verified those exact paths, confirmed that native stat rejects both the links and returned paths, and checked partial inventory and schema validity. Every other original assertion remained: correct internal/external targets, external paths returning inside the root, ordinary and backslash-containing missing paths, the exact file inventory, and no outside-file contents.
  • Independent comparison confirmed that the replay preserved the original fixtures and all non-representation assertions. The unchanged upstream CLI regression additionally passed retargeting, deletion, and movement outside the root.

The core user-visible bug is therefore covered upstream. This does not claim the two implementations are identical in every representation choice. Linux, Windows, and the complete suite were not rerun for this closure; no new implementation was pushed.

Earlier proposal and validation, retained for history

Summary

Resolve imported symlinks through the filesystem before recording their target. With current -> actual/nested, a link to current/../target.js points to actual/target.js; main currently records the unrelated target.js. The same premature normalization can misclassify targets as internal/external or make an invalid path appear valid.

The reader validates native lookup with stat, then resolves the observed link itself. Ordinary missing targets retain their spelling; paths whose intent cannot be preserved in a normalized identity remain unknown with the original target and error code. Resolution reads metadata, not target contents. Existing identity checks, cleanup, and upstream raw-byte/UTF-8/BOM handling are retained.

The diff against main is limited to five symlink implementation/test files. The selected-root fix is already upstream in 5e8f8b3. The race fixture timestamp adjustment makes directory replacement observable on coarse filesystems. No public schema or CLI/MCP option changes.

CI repair

Synced main 1173c0a9dc1b352a60943a491462294db8f353ae to include two upstream corrections for the previous CI failures:

No new production changes or weakened assertions were added for these failures.

Validation

Current head: 1a1955244869cfefdfde810a6b34013320163d5b (same tested tree as d43268de). Local macOS x64, Node 24.22.1, npm 11.16.0:

  • Runtime build passed. 232 tests passed, 2 platform skips across 16 focused files (15 passed files, one platform-skipped file): reference reader/import/graph, filesystem imports and failures, symlink races, compiled CLI directory and UTF-8 cases, Apple metadata and real MCP bound-target recovery, and JavaScript factory export/index analysis.

  • npm run check, npm run check:fast, and diff whitespace checks passed. The normal pre-commit hook passed; its unrelated upstream import cleanups were excluded. The published tree exactly matches the focused-test and full-check tree.

  • Independent review found no actionable integration issue in the retained five-file diff.

  • The complete applicationWorkflowCli.test.ts run could not finish locally because the host Swift SDK/compiler reports a duplicate SwiftBridging module when compiling the process helper. This was reproduced with a direct compiler invocation; the affected run was stopped and the remaining 16 files were rerun successfully. Hosted Linux CI subsequently passed that complete CLI regression.

  • Native Windows and the complete deterministic suite were not run locally.

  • The first synchronized CI run passed 18,921 source tests, static/build/native package checks, then failed one MCP recovery assertion in javascriptAnalysisResources.test.ts: parent_result_budget_bytes: 0 after retaining the oversized timeout observation. Other shards were cancelled by fail-fast. This is the intermittent parent-capacity failure also documented in test(mcp): verify recovery before reading retained views #7029 and fix(artifacts): handle ASAR cancellation before output consumption #5672; the same main 1173c0a9 has a successful selected CI run. The current empty verification commit triggers one controlled repeat with identical code, limits, fixtures, and assertions. The identical-tree repeat passed; this does not establish that the upstream flake is fixed.

  • Final CI run 40257362462 passed on exact head 1a1955244869cfefdfde810a6b34013320163d5b: 33,855 tests passed, zero failed, 237 skipped, all eight built-test shards, source/static/build/native package checks, Portable tests, and CI required succeeded. The Apple error-contract tests, complete application CLI suite (including the Webpack factory case), and the previously intermittent MCP timeout/recovery case passed. Runtime limits, deadlines, fixture sizes, and assertions remain unchanged.

Author readiness

Human owner: @shoyann

  • 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.

@shoyann
shoyann marked this pull request as ready for review October 14, 2026 16:30
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no actionable findings from this re-review.

Summary

The PR resolves symlinks through the filesystem before recording their targets.

  • Reference-source imports record the filesystem destination of each symlink.
  • The directory-race test makes its rename visible on coarse-timestamp filesystems.

The current tree matches the previously reviewed tree. No previous finding threads were supplied, and no new actionable issues or repository-rule violations were found. The security check found no new issue; target lookup reads metadata, not target contents. Tests were not run during this review. Supersession could not be checked because GitHub access was unavailable.

Reviews (10) · Last reviewed commit: "ci: recheck transient JavaScript recover..." · Reviewed by Greptile

@rahul05ranjan rahul05ranjan 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.

Reviewed this against the PR head (single-file run of tests/boundary/filesystem/referenceSourceImport.test.ts: 19/19 pass, including the new link-target regression).

The ordering fix in resolveRoot is the right one, and the reasoning in the comment holds: stat(requestedRoot) already let the kernel resolve symlink parents, so the old resolve() before realpath() meant the directory check and the canonicalization could disagree about which tree was selected. With current -> actual/nested, current/../source stat'd the selected tree but imported the decoy. Passing the selected path straight to realpath makes both agree, and the new CLI case covering absolute, relative, and canonical spellings pins that down.

Same story in readSymlinkTarget: realpath(absolute) on the observed link instead of pre-normalizing the target is the correct order, since the lexical form of outward/../private.js or ../outside/back/actual/target.js names either the wrong file or the wrong side of the root boundary. Resolving the link itself classifies by actual destination, and since only metadata is resolved, the no-follow content guarantee holds (the OUTSIDE_NOT_READ assertion confirms it).

The unknown fallback is well-reasoned — once resolution fails you genuinely can't collapse .. or trailing-separator intent without risking naming a different file, and keeping the raw readlink spelling plus the errno in a limitation is the honest representation. I checked that the graph schema already had the target: null / target_state: "unknown" variant, so no schema change was needed, and the cross-field symlink validation skips null-target entries, so nothing else needed updating.

Two smaller things:

  1. A broken link whose raw target points lexically outside the root (e.g. ../outside/absent.js) now records missing with a link-relative target where it previously recorded external with an absolute path. The PR description calls this out, and it's defensible (an unresolved chain could loop back through a symlink, so a lexical external was always a guess), but any consumer that used external to decide "this link leaves the root" now has to re-derive containment for missing entries from the link-relative spelling. Worth keeping in mind if anything downstream keys off that distinction.

  2. Spellings that fail realpath but are unambiguous, like ./absent.js, now degrade to unknown (normalize("./absent.js") !== "./absent.js" trips the guard) even though their intent — absent.js next to the link — is clear. Links written as ./x do occur in the wild. Emitting the normalized form with the raw spelling in a limitation would be an alternative if you ever see this in practice; not worth blocking on.

Minor: on POSIX the nativeTarget.endsWith(sep) check is redundant since normalize() already strips trailing separators and the inequality fires first — harmless given sep differs elsewhere, just noting it.

@CassieFox23

CassieFox23 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Linux. On current main, the 2 new tests fail and the 19 older ones pass. With this PR applied, all 21 pass.

Edit: I retested this PR on its new head, 9d81b1e, and posted the results here. Both fixes still hold on Node 22, 24 and 26, but GitHub now reports a merge conflict with main.

Results

This PR is still open. Its head is 08e16bd. I ran the two test files named in the PR on current main (c7f6b8b), before and after applying the PR's diff.

Check Main c7f6b8b Main + PR
New CLI case: selected root fails passes
New filesystem case: link targets fails passes
The other 19 cases in the same two files 19 pass 19 pass

The CLI case is imports the selected root before resolving symlink parent components. The filesystem case is records physical link targets and retains unresolved path intent. The failures on main match the bug in the PR text. The first case imports the lexical source folder instead of the selected one. The second case records target.js where it expects actual/target.js.

Node 24.18.0 was used for both runs. Each run took about 4 seconds.

Not run

  • The other 17 reference-source test files that the author ran. I only ran the 2 files named in the PR.
  • npm run check and git diff --check.
  • Any full suite. I also skipped tests/acceptance/setup/ on purpose, because some tests there run rea doctor. I grepped both test files for "doctor" and found nothing.
  • macOS and Windows. The PR does not claim Windows support.
  • The author's manual run of import-reference-source on the built fix.
  • Real CI. I did not run it. The PR's own CI is green on this head. That is secondhand, read from the PR page. Test shards 1 to 5, Source tests, Portable tests and Static checks passed. The declaration check has one cancelled run and one pass.

The PR branched from 0f62373, and main has since moved. The diff still applied cleanly. One source file, ReferenceSourceImportEntries.ts, differs from the PR head only by later changes already on main. So my "after" tree is main plus this PR, not the PR head alone.

No test in these two files makes a network call. Both build their folders and links in temporary directories. The setup step npm ci did use the npm registry.

Thanks, shoyann, for the clear tests.

Commands
git -C ~/code/rea-mirror/rea.git archive c7f6b8bad1a34d5efb30ff2a017672dea1fcdabb | tar -x -C <tree>
git diff c7f6b8bad1a34d5efb30ff2a017672dea1fcdabb...refs/pull/3562/head > 3562.diff
npm ci && npm run build && npm run test:prepare
# before: copy the PR's two test files onto main, then
npm run test:focused -- tests/boundary/cli/referenceSourceDirectoryImports.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts
# after: git apply --exclude='tests/*' 3562.diff, rebuild, run the same command

Exit codes: before 1 (2 failed, 19 passed), after 0 (21 passed).

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0
  • Head / base: 08e16bd / c7f6b8b
  • Other: the box was shared with other test agents during the runs

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

shoyann and others added 3 commits October 16, 2026 20:37
…tibility

Sync main to include native process-exit ownership fixes. Validate symlink targets with stat before realpath so macOS does not turn invalid directory components into internal-file observations. Keep the existing graph assertions and use native lookup as the failure oracle.

Encode the Flutter ABI slash as a hex escape so advertised patterns remain valid in Unicode-set mode and survive lint --fix.

Validated on macOS x64 with Node 24.18.0 / npm 11.16.0: 32 focused files, 170 passed and 2 existing skips; npm run check; npm run docs:check. Local provider/setup checks are limited by the installed Swift compiler/SDK mismatch.
@shoyann

shoyann commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Hey @morluto, could you take a look at this one when you get a chance? The bug still appears to be present on main. Happy to make any changes if needed. Thanks!

@CassieFox23

CassieFox23 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: At head 9d81b1e, both of my 15 Oct findings are still fixed on Node 22, 24 and 26. The 2 new tests fail on main and pass with this PR's changes. My main runs used a Node below main's new minimum, with npm's engine check off. But GitHub now says this PR conflicts with main, because a new main commit rewrites the same function.

I tested head 9d81b1e as pushed (committed 23 Oct, 03:43 UTC). My last result was at 08e16bd6. Seven commits came after it. The only source change since then is one new call, await stat(absolute) before realpath(absolute) in ReferenceSourceReaderEntries.ts, plus its import. The source change is otherwise the same as at 08e16bd. I checked by comparing the PR's own source diff against its own base at each head.

Results

Run Node 22.23.1 Node 24.18.0 Node 26.11.1
The 2 test files (28 tests) on main ecd997e plus this PR's test changes 2 fail, 26 pass 2 fail, 26 pass 2 fail, 26 pass
The same 2 files on main ecd997e plus this PR's source and test changes 28 pass 28 pass 28 pass
The same 2 files at PR head 9d81b1e 28 pass 28 pass 28 pass
30 other reference-source test files at the PR head 194 pass, 2 skipped 194 pass, 2 skipped 194 pass, 2 skipped

The two failing tests on main are the same two as on 15 Oct. imports the selected root before resolving symlink parent components imports decoy.ts where it expects selected.ts. records physical link targets and retains unresolved path intent records target.js where it expects actual/target.js. Both pass on all three Nodes with this PR.

On 15 Oct the two files held 21 tests; now they hold 28 (26 older ones plus the 2 new ones). I did not trace where the 7 extra older tests came from. The 2 skipped tests are Windows-only cases in referenceSourceImportStatus.test.ts.

My 15 Oct finding Now
Selected root imported as the lexical folder Fixed. ReferenceSourceImportPolicy.ts:91 calls realpath(requestedRoot). The CLI test passes.
Link targets recorded after collapsing parent steps Fixed. ReferenceSourceReaderEntries.ts:374 calls realpath(absolute). The filesystem test passes.

The merge conflict

GitHub reports mergeable: false and mergeable_state: dirty for this PR, read at 16:14 UTC today. Earlier in this job the same API said mergeable: true, and a read at 15:55 UTC said clean (that one is secondhand, from another agent). The head did not move. Main commit 7ba0521 is dated 16:11:41 UTC today, between those reads. It is "fix(reference): preserve raw symlink target identity". Its message says it fixes issue 6765, a closed bug report about lossy UTF-8 decoding of symlink targets. Main is now at b784912 or later. That commit rewrites readSymlinkTarget to read the link as bytes. git apply --check of this PR's diff onto b784912 fails. The message is patch failed: src/reference/ReferenceSourceReaderEntries.ts:363. The same diff applied cleanly to ecd997e, the main I tested on. I read b784912 and it still has realpath(resolve(requestedRoot)) and realpath(lexicalTarget), so the bug is still on main. I did not build or test b784912.

The Node problem

Main now requires Node ^22.23.4 || ^24.22.1 || >=26.12.1 (package.json at ecd997e). I have 22.23.1, 24.18.0 and 26.11.1, which are below that. This PR's head and base still require ^22.19.0 || ^24.11.0 || >=26.0.0, which my Nodes meet, so the PR-head runs used no override. I set npm_config_engine_strict=false for the two main runs (rows 1 and 2) before installing, so I did not see npm's engine error this time. I did not install a newer Node. I do not know if a patched Node changes any result.

Comments since 15 Oct

One comment came after mine: shoyann asking morluto to take a look. It does not ask me anything. There are no inline review threads on this PR. Greptile's summary comment gives 5/5 and no actionable issues. CI on 9d81b1e shows success for all 8 test shards, Source tests, Portable tests and Static checks. I read that from GitHub and did not run it.

Not run

  • tests/boundary/cli/clientProfileLifecycle.test.ts, which this PR changed by 4 lines. It runs rea doctor, so I skipped it on purpose.
  • Anything on b784912, the PR merged with new main, or a hand-resolved conflict.
  • macOS and Windows. The new stat(absolute) line has a comment about macOS realpath, and I cannot test that on Linux.
  • npm run check, a full suite, and the author's manual import-reference-source run.

Thanks, shoyann, for the clear tests.

Commands
git archive 9d81b1eaa -> /tmp/rt-3562-r2/head ; git archive ecd997e51 -> /tmp/rt-3562-r2/main
npm ci --ignore-scripts && npm run prepare && npm run build:cached && npm run test:prepare   (Node 24; main needed engine_strict=false)
# main, before: git apply the PR's changes to the 2 test files only
# main, after: git apply the PR's changes under src/, then npm run build:cached && npm run test:prepare
node scripts/run-exact-tests.mjs --reporter=verbose tests/boundary/cli/referenceSourceDirectoryImports.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts   (Node 22, 24, 26)
node scripts/run-exact-tests.mjs --reporter=verbose <30 other reference-source files>   (PR head, Node 22, 24, 26)

Exit codes: main before 1 on all three Nodes (2 failed, 26 passed). Main after 0. PR head 0, for both groups.

The 30 other files: src/application/ReferenceSource*.test.ts, src/domain/referenceSource*.test.ts, src/reference/*.test.ts, tests/boundary/{cli,filesystem}/referenceSource*.test.ts (without the two above), tests/process-global/referenceSourceSymlinkRace.test.ts and tests/boundary/filesystem/sourceToBundlePaths.test.ts. I grepped them for doctor before running; none mention it.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (all below main's new minimum; npm_config_engine_strict=false for the main runs only)
  • Head / base: 9d81b1e / f850b7c
  • Other: main ecd997e for the runs; main b784912 when I checked for conflicts. Earlier head 08e16bd.

Other test jobs may have run on this box. These are pass and fail results, so timing does not matter.

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@shoyann shoyann changed the title fix(reference): preserve selected roots and symlink targets fix(reference): preserve physical symlink targets Oct 24, 2026
Bring in the upstream Apple metadata error-contract tests (morluto#6945) and
Webpack factory fixture correction (morluto#6951). Preserve the five-file
physical symlink target fix relative to main.
Keep the tested tree unchanged. The first synchronized CI run encountered
the same intermittent parent-result budget failure documented upstream
in morluto#7029 and morluto#5672; main 1173c0a passes its selected CI.

Repeat the existing checks once without changing runtime limits, fixture
size, deadlines, or assertions.
@shoyann shoyann closed this Oct 27, 2026
@shoyann
shoyann deleted the fix/reference-selected-path branch October 28, 2026 06:46
@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.

4 participants