Skip to content

test(alias): guard that absolute path aliasing is not skipped#553

Merged
alexander-akait merged 4 commits intomainfrom
claude/fix-absolute-path-aliasing-ioTgA
Apr 22, 2026
Merged

test(alias): guard that absolute path aliasing is not skipped#553
alexander-akait merged 4 commits intomainfrom
claude/fix-absolute-path-aliasing-ioTgA

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

Adds a regression test covering both branches of the alias matcher
for absolute-path names:

  • raw-resolve hook with request.request being an absolute path
    (hits the nameWithSlash startsWith branch).
  • file hook after JoinRequestPlugin (hits the normalized
    absolutePath startsWith branch).

The existing fixture already declares "/d/dir": "/c/dir" and
"/d/index.js": "/c/index" but was only exercised through bare
specifiers, leaving the raw-absolute-request path untested. This
locks in the current behavior so future optimizations to
AliasUtils (e.g. the firstCharCode screen) cannot silently
regress absolute-path alias matching.

Verified by fault-injecting if (item.absolutePath !== null) return callback(); into aliasResolveHandler — the new test fails, the
rest of the suite still passes, confirming the test targets the
right code path.

https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G

claude added 4 commits April 22, 2026 20:48
Adds a regression test covering both branches of the alias matcher
for absolute-path names:

- `raw-resolve` hook with `request.request` being an absolute path
  (hits the `nameWithSlash` startsWith branch).
- `file` hook after `JoinRequestPlugin` (hits the normalized
  `absolutePath` startsWith branch).

The existing fixture already declares `"/d/dir": "/c/dir"` and
`"/d/index.js": "/c/index"` but was only exercised through bare
specifiers, leaving the raw-absolute-request path untested. This
locks in the current behavior so future optimizations to
`AliasUtils` (e.g. the `firstCharCode` screen) cannot silently
regress absolute-path alias matching.

Verified by fault-injecting `if (item.absolutePath !== null) return
callback();` into `aliasResolveHandler` — the new test fails, the
rest of the suite still passes, confirming the test targets the
right code path.

https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G
…uests

Before, `aliasResolveHandler` matched raw absolute-path requests
(`hasRequestString === true`) only via `nameWithSlash`, which
unconditionally appends a forward slash. On Windows this meant a
raw request with the native backslash separator (e.g.
`C:\\abs\\foo\\baz`) failed `startsWith("C:\\abs\\foo/")` and the
alias was silently skipped. The `!hasRequestString` branch (file
hook) already used the normalized `absolutePath` and matched
correctly.

Mirror the `absolutePath` check into the `hasRequestString` branch
as an additive fallback — posix matches keep firing via the
existing `nameWithSlash` short-circuit, and windows backslash
subpaths now also match via the normalized form.

Tests

Adds a new `describe("absolute path aliasing (posix + windows
shapes)")` block that drives `aliasResolveHandler` directly
through a minimal `{ join, doResolve }` stub (the full-resolver
tests above use `memfs`, which is posix-only and cannot store
backslash paths). Coverage:

  posix:
    - raw absolute subpath request (raw-resolve hook)
    - joined absolute path (file hook)
    - exact equality match
    - negative: different prefix ("/abs/foo" vs "/abs/food")
  windows:
    - joined absolute path with native backslashes (file hook)
    - exact equality for raw windows absolute request
    - raw absolute subpath with native backslashes
      (the regression this commit fixes)
    - raw absolute subpath with forward slashes
    - negative: different prefix
    - negative: different drive letter

Confirmed the new windows-backslash-subpath test fails on the
pre-fix code and passes after; full suite is 1007/1007,
`npx tsc` and `npx eslint` clean.

https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G
Replaces the hand-rolled `{ join, doResolve }` stub with a real
`new Resolver(...)` wired to the `AliasPlugin` under test. A
capture tap on the target hook records the aliased request and
ends the resolve, so the filesystem is still untouched and both
path dialects can run on the same machine — but every code path
now goes through the same `Resolver.doResolve` / `ensureHook` /
`resolveStep` plumbing the real pipeline uses.

Also factors the common alias-options setup into a
`createAliasRunner(options)` helper, one per `describe` group, so
each test only spells out the request shape it is exercising.

Re-verified by fault-injecting the pre-fix matcher into
`aliasResolveHandler` — only the windows-backslash-subpath test
fails, confirming the real-Resolver path still exercises the
regression. Full suite 1007/1007, tsc and eslint clean.

https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G
Replaces the Resolver+capture-tap variant with a plain
`resolver.resolve(...)` call against the real `test/fixtures/`
tree, using `CachedInputFileSystem` (no filesystem stub) and
constructing every path through the Node `path` module.

Because `path.join` / `path.resolve` emit OS-native separators,
the same source covers both dialects on CI:

  Linux   →  `/absolute/imaginary-foo/index`  (posix)
  Windows →  `C:\...\imaginary-foo\index`     (backslash)

That means Windows CI exercises the raw-resolve-hook backslash
subpath case the previous commit fixed, without requiring any
platform-specific test code or a bespoke sync FS.

Cases covered:

  - raw absolute subpath request (raw-resolve hook).
  - request equals the alias name (exact equality).
  - relative request whose joined absolute path is aliased
    at the file hook after JoinRequestPlugin.
  - negative: a different absolute prefix sharing the same
    head must not accidentally fire (`imaginary-foo` vs
    `imaginary-food`).

The `imaginary-foo` directory is intentionally absent from
`test/fixtures/`, so every passing case must have gone through
the alias transform — if the matcher regresses the resolve fails
with ENOENT instead of silently landing on the wrong file.

Full suite 1001/1001; `npx tsc` and `npx eslint` clean.

https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

⚠️ No Changeset found

Latest commit: 87fddc1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.60%. Comparing base (8757f67) to head (87fddc1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #553      +/-   ##
==========================================
+ Coverage   96.57%   96.60%   +0.03%     
==========================================
  Files          50       50              
  Lines        2800     2802       +2     
  Branches      863      865       +2     
==========================================
+ Hits         2704     2707       +3     
+ Misses         80       79       -1     
  Partials       16       16              
Flag Coverage Δ
integration 96.60% <100.00%> (+0.03%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 22, 2026

Merging this PR will not alter performance

✅ 69 untouched benchmarks


Comparing claude/fix-absolute-path-aliasing-ioTgA (87fddc1) with main (faa178f)

Open in CodSpeed

@alexander-akait alexander-akait merged commit f5adeee into main Apr 22, 2026
33 of 34 checks passed
@alexander-akait alexander-akait deleted the claude/fix-absolute-path-aliasing-ioTgA branch April 22, 2026 21:56
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.

2 participants