Skip to content

fix(init): normalize custom base URL#115

Open
Kushagra963-lab wants to merge 2 commits into
404-PF:mainfrom
Kushagra963-lab:main
Open

fix(init): normalize custom base URL#115
Kushagra963-lab wants to merge 2 commits into
404-PF:mainfrom
Kushagra963-lab:main

Conversation

@Kushagra963-lab
Copy link
Copy Markdown

Closes #109

Summary

  • Trim trailing slashes from custom OpenAI-compatible base URLs before saving config.
  • Keep existing URL validation behavior unchanged.
  • Add regression coverage for normalized and unchanged custom base URLs.

Testing

  • Not run locally; GitHub clone/test access timed out in this environment.

Copy link
Copy Markdown
Contributor

@404-Page-Found 404-Page-Found left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 buildApiKeyPrompt is 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:

  1. 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.mjs locally before merge.

  2. 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.

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.

Normalize custom base URL by trimming trailing slash in init

2 participants