Skip to content

feat: free key endpoint resolution and custom/regional URL support#32

Merged
shirgoldbird merged 11 commits intomainfrom
feat/free-key-endpoint-resolution
Apr 7, 2026
Merged

feat: free key endpoint resolution and custom/regional URL support#32
shirgoldbird merged 11 commits intomainfrom
feat/free-key-endpoint-resolution

Conversation

@shirgoldbird
Copy link
Copy Markdown
Member

Summary

Adds automatic API endpoint resolution based on key suffix (:fxapi-free.deepl.com), while preserving custom/regional endpoint support (e.g. api-jp.deepl.com).

Closes #30

Changes Made

  • New shared endpoint resolver (src/utils/resolve-endpoint.ts) with clear priority chain:

    1. --api-url CLI flag (highest priority)
    2. Custom/regional api.baseUrl from config (non-standard hostname)
    3. API key suffix: :fx → free endpoint, else → pro endpoint
    4. api.usePro === false fallback → free endpoint
    5. Default → pro endpoint
  • Standard DeepL URLs no longer block auto-detection: persisted api.baseUrl values of api.deepl.com or api-free.deepl.com (with any path) are treated as tier defaults, not custom overrides.

  • Auth and init commands resolve from entered key: auth set-key and init now validate against the correct endpoint based on the key being entered, not the saved config.

  • Voice API follows the same resolution: removed hardcoded PRO_API_URL from VoiceClient; endpoint selection is now centralized in the resolver like all other commands.

  • Exported FREE_API_URL / PRO_API_URL from http-client.ts for shared use.

Test Coverage

  • 43 new unit tests for resolveEndpoint(), isStandardDeepLUrl(), isFreeKey()
  • 5 new unit tests for auth/init free key validation with nock
  • 4 new unit tests for voice command endpoint wiring at the service-factory boundary
  • Updated voice integration tests (nock URL changed from pro to free for :fx test keys)
  • Relaxed brittle CLI integration/E2E tests that asserted auth-specific error text instead of testing flag/option acceptance
  • Full suite: 143 suites, 3486 tests, all passing
  • Manually verified with a real free API key against DeepL production

Backward Compatibility

  • api.usePro config key is preserved as a backward-compatible fallback (does not override :fx key detection)
  • Custom/regional endpoints like api-jp.deepl.com remain authoritative
  • --api-url translate flag still takes highest priority
  • No config schema changes

shirgoldbird and others added 2 commits April 5, 2026 00:02
- Rewrite resolve-endpoint tests from 43 to 25 using table-driven it.each()
  (covers all 5 priority branches + edge cases: subdomain spoof, URL parsing)
- Consolidate free-key-auth-init tests from 5 to 3 (drop redundant InitCommand)
- Reduce voice wiring test from 4 to 1 (pin passthrough, not permutations)
- Remove 55 expect(true).toBe(true) anti-pattern across integration/e2e tests
- Add expect.assertions(N) guards to 10 must-fail tests (API key required, etc.)
- Add InitCommand :fx key test to init-command.test.ts (closes coverage gap)

Net: 3486 → 3464 tests, zero branch coverage lost, -466 lines of test code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Six integration tests had no assertions, causing the eslint
jest/expect-expect rule to fail in CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shirgoldbird shirgoldbird merged commit 299e3f5 into main Apr 7, 2026
3 checks passed
@shirgoldbird shirgoldbird deleted the feat/free-key-endpoint-resolution branch April 7, 2026 03:00
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.

Working API keys don't work with CLI

2 participants