Skip to content

fix(index): resolve sibling refs of files outside BasePath - #738

Open
pcbeingused333 wants to merge 1 commit into
pb33f:mainfrom
pcbeingused333:fix/relative-ref-outside-basepath
Open

pcbeingused333 wants to merge 1 commit into
pb33f:mainfrom
pcbeingused333:fix/relative-ref-outside-basepath

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #735

Root cause: resolveRelativeFilePath only accepted the path relative to the current file when it was inside a configured local file system root. For a file outside BasePath, pathExistsInFS rejected the correct sibling, and resolution moved on to BasePath + ref. If a file with that name existed there (here, the root spec), the ref silently resolved to the wrong document.

Fix: before trying BasePath and the other roots, the sibling of the current file is used if it exists on disk. This only applies when the current file's directory is absolute and a local file system reads straight from the OS (no DirFS). It does not widen what can be read: that same path is already returned, and opened, whenever no file of that name exists under a root. Virtual file systems behave as before.

Tests: TestIssue735_RelativeRefOutsideBasePath reproduces the layout from the issue and fails without the change. TestResolveRelativeFilePath_SiblingOutsideRoots covers the OS file system, a DirFS and a relative base directory. go test ./... passes.

This change was prepared with the help of an AI coding assistant.

A relative ref in a file outside every local file system root was rejected
by pathExistsInFS even though the file exists next to it, so resolution fell
back to BasePath and could pick a different document with the same name.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ef96408) to head (7851b5e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #738   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          316       316           
  Lines        40239     40247    +8     
=========================================
+ Hits         40239     40247    +8     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A relative ref in a file outside BasePath resolves against BasePath and can hit the wrong file

1 participant