refactor(ui): centralize default ports and add parity test

- add ui default port constants for cliproxy and cursor

- wire preset utils to shared ui default port constants

- add backend/ui sync test to prevent port drift
This commit is contained in:
Tam Nhu Tran
2026-02-18 03:10:09 +07:00
parent 688f3e3889
commit 63f422179e
3 changed files with 36 additions and 2 deletions
@@ -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);
});
});
+9
View File
@@ -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;
+4 -2
View File
@@ -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}`,