diff --git a/tests/unit/cliproxy/backend-ui-default-ports-sync.test.ts b/tests/unit/cliproxy/backend-ui-default-ports-sync.test.ts new file mode 100644 index 00000000..751d7624 --- /dev/null +++ b/tests/unit/cliproxy/backend-ui-default-ports-sync.test.ts @@ -0,0 +1,23 @@ +/** + * Default Port Sync Test + * + * Keeps backend and UI default ports in sync while allowing independent modules. + */ + +import { describe, expect, test } from 'bun:test'; +import { CLIPROXY_DEFAULT_PORT as BACKEND_CLIPROXY_DEFAULT_PORT } from '../../../src/cliproxy/config/port-manager'; +import { DEFAULT_CURSOR_PORT as BACKEND_CURSOR_DEFAULT_PORT } from '../../../src/cursor/cursor-models'; +import { + CLIPROXY_DEFAULT_PORT as UI_CLIPROXY_DEFAULT_PORT, + DEFAULT_CURSOR_PORT as UI_CURSOR_DEFAULT_PORT, +} from '../../../ui/src/lib/default-ports'; + +describe('Default Port Sync', () => { + test('CLIProxy default port is synced between backend and UI', () => { + expect(UI_CLIPROXY_DEFAULT_PORT).toBe(BACKEND_CLIPROXY_DEFAULT_PORT); + }); + + test('Cursor default port is synced between backend and UI', () => { + expect(UI_CURSOR_DEFAULT_PORT).toBe(BACKEND_CURSOR_DEFAULT_PORT); + }); +}); diff --git a/ui/src/lib/default-ports.ts b/ui/src/lib/default-ports.ts new file mode 100644 index 00000000..e16a097f --- /dev/null +++ b/ui/src/lib/default-ports.ts @@ -0,0 +1,9 @@ +/** + * UI-side default ports. + * + * Keep UI defaults explicit to preserve frontend decoupling from backend build internals. + * Sync is enforced by backend/UI parity tests in `tests/unit/cliproxy`. + */ + +export const CLIPROXY_DEFAULT_PORT = 8317; +export const DEFAULT_CURSOR_PORT = 20129; diff --git a/ui/src/lib/preset-utils.ts b/ui/src/lib/preset-utils.ts index ebdb724d..bf2de02b 100644 --- a/ui/src/lib/preset-utils.ts +++ b/ui/src/lib/preset-utils.ts @@ -4,9 +4,11 @@ */ import { MODEL_CATALOGS } from './model-catalogs'; +import { CLIPROXY_DEFAULT_PORT } from './default-ports'; +export { CLIPROXY_DEFAULT_PORT } from './default-ports'; /** CLIProxy port - should match the backend configuration */ -export const CLIPROXY_PORT = 8317; +export const CLIPROXY_PORT = CLIPROXY_DEFAULT_PORT; /** Default fallback API key if fetch fails */ const DEFAULT_API_KEY = 'ccs-internal-managed'; @@ -53,7 +55,7 @@ export async function applyDefaultPreset( // Fetch effective API key (respects user customization) const effectiveApiKey = await fetchEffectiveApiKey(); - const effectivePort = port ?? CLIPROXY_PORT; + const effectivePort = port ?? CLIPROXY_DEFAULT_PORT; const settings = { env: { ANTHROPIC_BASE_URL: `http://127.0.0.1:${effectivePort}/api/provider/${provider}`,