fix(init): normalize custom base URL#115
Conversation
404-Page-Found
left a comment
There was a problem hiding this comment.
PR Review: fix(init): normalize custom base URL
Overview
| Criterion | Assessment |
|---|---|
| Purpose | ✅ Clear — trims trailing slashes from custom base URLs before saving to config, closing #109 |
| Scope | ✅ Focused — one small normalization fix + regression test |
| Size | ✅ Minimal (21 lines changed) |
Correctness & Logic
The new normalizeBaseUrl function strips one or more trailing slashes from user-supplied URLs before they're persisted to config — correct and well-targeted.
All three provider adapters already strip trailing slashes at request time (openai-compatible.ts:8, anthropic.ts:8, cohere.ts:8), so this doesn't change runtime behavior — but it does normalize the saved config, which is the right thing to do. Users shouldn't see a trailing-slash URL in their persisted config when it will always be used without one.
Edge cases are fine: the URL validate callback rejects empty/invalid URLs before normalizeBaseUrl is reached, and the regex \/+ correctly handles one or more trailing slashes.
Code Quality & Maintainability
- Readability: ✅ Clean, self-explanatory function name and implementation.
- Exports: ✅ Exported for testability, consistent with how
buildApiKeyPromptis exported. - Conventions: ✅ Matches project style (minimal, no unnecessary comments).
Security
✅ No concerns. Simple regex replacement, no new dependencies, no secrets exposed.
Testing
The new tests/init-base-url.test.mjs follows project conventions (node:assert/strict + node:test, imports from ../dist/). Coverage is reasonable with trimming and passthrough cases.
However, two issues need attention before merge:
-
Tests were not run by the author. The PR description states "Not run locally; GitHub clone/test access timed out." Please confirm CI passes or run
npm run build && node --test tests/init-base-url.test.mjslocally before merge. -
Missing edge case: The tests cover multi-trailing-slash (
v1///) and no trailing slash (v1), but don't explicitly test the most common scenario — a single trailing slash (v1/). While the regex handles it, this is the exact case the PR claims to fix and should have explicit coverage:
test('handles single trailing slash', () => {
assert.equal(normalizeBaseUrl('https://api.example.com/v1/'), 'https://api.example.com/v1');
});Breaking Changes
✅ None.
Documentation
The PR description could mention this is a config-level normalization (not a behavior change), since the providers already handled trailing slashes at request time.
Verdict: Request changes
The implementation is correct and clean, but the single-trailing-slash edge case (the exact scenario from #109) is not explicitly tested, and the tests haven't been verified to pass. Please add the missing test case and confirm tests pass.
Closes #109
Summary
Testing