fix(resolver): return not-found for unmatched path segments#24
Conversation
Previously, when a path segment didn't match any route (no exact match, wildcard, or virtual fallback), the resolver silently skipped it and continued to the next segment. This caused paths like `/x/y` to incorrectly resolve the `/y` handler when no `/x` route existed. Also removes a duplicate guard invocation that called the guard function twice per level during path traversal.
WalkthroughRoute resolution logic was simplified by removing optional guard special handling and adding early termination for unmatched segments. Test coverage was expanded to include not-found scenarios, guard behavior across nested levels, and wildcard parameter matching. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/esroute/src/route-resolver.spec.ts (1)
7-7:⚠️ Potential issue | 🟡 MinorShared mock
notFoundis never reset, causing potential test pollution.The
notFoundmock is created once at thedescribeblock level and reused across all tests without being reset. Tests assertingexpect(notFound).toHaveBeenCalled()(lines 117, 127, 137, 145, 155) will pass ifnotFoundwas called in any previous test, masking actual failures.Proposed fix: Reset mock between tests
describe("Resolver", () => { const notFound = vi.fn(); + + beforeEach(() => { + notFound.mockClear(); + });Alternatively, add
vi.clearAllMocks()in abeforeEachto reset all mocks.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/esroute/src/route-resolver.spec.ts` at line 7, The shared mock notFound defined at the describe scope is never reset and can cause test pollution; update tests to clear or reset mocks between tests by adding a beforeEach that calls vi.clearAllMocks() or notFound.mockClear() (or notFound.mockReset()) so assertions like expect(notFound).toHaveBeenCalled() in the individual tests only reflect that test's calls; locate the notFound mock and add the beforeEach reset near the describe block to ensure isolation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/esroute/src/route-resolver.spec.ts`:
- Line 7: The shared mock notFound defined at the describe scope is never reset
and can cause test pollution; update tests to clear or reset mocks between tests
by adding a beforeEach that calls vi.clearAllMocks() or notFound.mockClear() (or
notFound.mockReset()) so assertions like expect(notFound).toHaveBeenCalled() in
the individual tests only reflect that test's calls; locate the notFound mock
and add the beforeEach reset near the describe block to ensure isolation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7646c4df-34d0-4c0f-bd41-821443cb29f6
📒 Files selected for processing (2)
packages/esroute/src/route-resolver.spec.tspackages/esroute/src/route-resolver.ts
Summary
/x/yto incorrectly resolve the/yhandler when no/xroute existed.checkGuard()and again by an inline duplicate check.Test plan
/x/ydoesn't resolve when only/yexists (and vice versa)Summary by CodeRabbit
Bug Fixes
New Features