test(alias): guard that absolute path aliasing is not skipped#553
test(alias): guard that absolute path aliasing is not skipped#553alexander-akait merged 4 commits intomainfrom
Conversation
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
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds a regression test covering both branches of the alias matcher
for absolute-path names:
raw-resolvehook withrequest.requestbeing an absolute path(hits the
nameWithSlashstartsWith branch).filehook afterJoinRequestPlugin(hits the normalizedabsolutePathstartsWith branch).The existing fixture already declares
"/d/dir": "/c/dir"and"/d/index.js": "/c/index"but was only exercised through barespecifiers, leaving the raw-absolute-request path untested. This
locks in the current behavior so future optimizations to
AliasUtils(e.g. thefirstCharCodescreen) cannot silentlyregress absolute-path alias matching.
Verified by fault-injecting
if (item.absolutePath !== null) return callback();intoaliasResolveHandler— the new test fails, therest of the suite still passes, confirming the test targets the
right code path.
https://claude.ai/code/session_013YaMjJMBeJYiu5WVfwEv2G