Fix ModuleResolver alias segment boundary matching#149
Conversation
📝 WalkthroughWalkthroughEnforces segment-boundary validation in module alias prefix matching by introducing a shared helper function that ensures aliases match only exact specifiers or paths delimited by Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
🧹 Nitpick comments (1)
units/Goccia.ModuleResolver.Test.pas (1)
37-44: Add tests for aliases that end with/(e.g.,@/,@/components/).Current cases won’t catch regressions for the alias format used in embedding docs, where trailing
/is common.🧪 Suggested additional test cases
procedure TModuleResolverTests.SetupTests; begin Test('HasAlias matches exact alias', TestHasAliasMatchesExactAlias); Test('HasAlias matches child path on segment boundary', TestHasAliasMatchesSegmentChild); Test('HasAlias rejects partial segment match', TestHasAliasRejectsPartialSegmentMatch); Test('ApplyAliases leaves partial segment unchanged', TestApplyAliasesLeavesPartialSegmentUnchanged); Test('ApplyAliases uses longest boundary-matched alias', TestApplyAliasesUsesLongestBoundaryMatchedAlias); + Test('HasAlias matches child path for trailing-slash alias', TestHasAliasMatchesTrailingSlashAliasChild); + Test('ApplyAliases rewrites trailing-slash alias child path', TestApplyAliasesRewritesTrailingSlashAliasChildPath); end;procedure TModuleResolverTests.TestHasAliasMatchesTrailingSlashAliasChild; var Resolver: TTestModuleResolver; begin Resolver := CreateResolver; try Resolver.AddAlias('@/', 'src/'); Expect<Boolean>(Resolver.HasAlias('@/utils/math')).ToBe(True); finally Resolver.Free; end; end; procedure TModuleResolverTests.TestApplyAliasesRewritesTrailingSlashAliasChildPath; var Resolver: TTestModuleResolver; begin Resolver := CreateResolver; try Resolver.AddAlias('@/', 'src/'); Expect<string>(Resolver.ExposedApplyAliases('@/utils/math')).ToBe( Resolver.BaseDirectory + 'src/utils/math'); finally Resolver.Free; end; end;Also applies to: 107-121
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@units/Goccia.ModuleResolver.Test.pas` around lines 37 - 44, Add tests covering aliases that end with '/' by implementing two new test methods: TestHasAliasMatchesTrailingSlashAliasChild and TestApplyAliasesRewritesTrailingSlashAliasChildPath (create them following the pattern of existing tests that use CreateResolver, AddAlias('@/','src/'), call HasAlias('@/utils/math') and ExposedApplyAliases('@/utils/math') respectively). Register these new methods in TModuleResolverTests.SetupTests alongside the other Test(...) registrations so they run with the suite; also add the actual test implementations near the other test methods (the block around the existing ApplyAliases/HasAlias tests).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@units/Goccia.ModuleResolver.Test.pas`:
- Around line 37-44: Add tests covering aliases that end with '/' by
implementing two new test methods: TestHasAliasMatchesTrailingSlashAliasChild
and TestApplyAliasesRewritesTrailingSlashAliasChildPath (create them following
the pattern of existing tests that use CreateResolver, AddAlias('@/','src/'),
call HasAlias('@/utils/math') and ExposedApplyAliases('@/utils/math')
respectively). Register these new methods in TModuleResolverTests.SetupTests
alongside the other Test(...) registrations so they run with the suite; also add
the actual test implementations near the other test methods (the block around
the existing ApplyAliases/HasAlias tests).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5ffb1bb0-a715-4dc2-ac65-2ce7466070af
📒 Files selected for processing (4)
docs/design-decisions.mddocs/embedding.mdunits/Goccia.ModuleResolver.Test.pasunits/ModuleResolver.pas
Benchmark Results263 benchmarks Interpreted: 🟢 179 improved · 🔴 21 regressed · 63 unchanged · avg +5.0% arraybuffer.js — Interp: 🟢 13, 🔴 1 · avg +11.2% · Bytecode: 🟢 1, 🔴 12, 1 unch. · avg -6.4%
arrays.js — Interp: 🟢 19 · avg +7.5% · Bytecode: 🟢 1, 🔴 18 · avg -5.9%
async-await.js — Interp: 🟢 6 · avg +10.9% · Bytecode: 🔴 6 · avg -8.5%
classes.js — Interp: 🟢 31 · avg +11.6% · Bytecode: 🟢 6, 🔴 9, 16 unch. · avg +0.8%
closures.js — Interp: 🟢 11 · avg +8.3% · Bytecode: 🟢 1, 🔴 4, 6 unch. · avg -2.3%
collections.js — Interp: 🟢 10, 2 unch. · avg +5.0% · Bytecode: 🟢 2, 🔴 10 · avg -5.9%
destructuring.js — Interp: 🟢 21, 1 unch. · avg +5.6% · Bytecode: 🟢 8, 🔴 10, 4 unch. · avg -1.3%
fibonacci.js — Interp: 🟢 5, 3 unch. · avg +3.4% · Bytecode: 🟢 1, 🔴 5, 2 unch. · avg -3.9%
for-of.js — Interp: 🟢 5, 2 unch. · avg +3.6% · Bytecode: 🟢 3, 🔴 1, 3 unch. · avg +1.5%
helpers/bench-module.js — Interp: 0 · Bytecode: 0
iterators.js — Interp: 🟢 1, 🔴 1, 18 unch. · avg +1.0% · Bytecode: 🔴 11, 9 unch. · avg -3.3%
json.js — Interp: 🟢 14, 6 unch. · avg +4.9% · Bytecode: 🔴 16, 4 unch. · avg -3.8%
jsx.jsx — Interp: 🟢 14, 🔴 2, 5 unch. · avg +1.5% · Bytecode: 🟢 4, 🔴 9, 8 unch. · avg -1.1%
modules.js — Interp: 🔴 5, 4 unch. · avg -2.4% · Bytecode: 🟢 1, 🔴 2, 6 unch. · avg -0.7%
numbers.js — Interp: 🟢 10, 🔴 1 · avg +5.3% · Bytecode: 🟢 1, 🔴 9, 1 unch. · avg -4.6%
objects.js — Interp: 🔴 2, 5 unch. · avg -0.8% · Bytecode: 🔴 5, 2 unch. · avg -2.7%
promises.js — Interp: 🟢 2, 🔴 2, 8 unch. · avg -0.9% · Bytecode: 🔴 11, 1 unch. · avg -3.4%
strings.js — Interp: 🟢 2, 🔴 3, 6 unch. · avg -1.0% · Bytecode: 🔴 9, 2 unch. · avg -4.8%
typed-arrays.js — Interp: 🟢 15, 🔴 4, 3 unch. · avg +4.7% · Bytecode: 🟢 7, 🔴 7, 8 unch. · avg -0.1%
Measured on ubuntu-latest x64. Benchmark ranges compare cached main-branch min/max ops/sec with the PR run; overlapping ranges are treated as unchanged noise. Percentage deltas are secondary context. |
Suite Timing
Measured on ubuntu-latest x64. |
Summary
HasAliasandApplyAliasesboth require an exact match or a/segment boundaryCloses #113
Verification
Summary by CodeRabbit
Release Notes
Documentation
Tests