mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-17 06:14:30 +00:00
feat: make cliproxy provider nicknames optional by default
This commit is contained in:
1 parent
834704938d
commit
4df08f6d99
46 files changed
+2076
-1096
No files matched your search
@@ -1,64 +1,62 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { resolveLifecyclePort } from '../../../src/commands/cliproxy/proxy-lifecycle-subcommand';
|
||||
import { afterEach, describe, expect, it, mock } from 'bun:test';
|
||||
import { CLIPROXY_DEFAULT_PORT } from '../../../src/cliproxy/config/port-manager';
|
||||
import { runWithScopedConfigDir } from '../../../src/utils/config-manager';
|
||||
|
||||
let tempDir: string;
|
||||
type MockUnifiedConfig = {
|
||||
cliproxy_server?: {
|
||||
local?: {
|
||||
port?: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
function writeUnifiedConfig(localPort: number): void {
|
||||
const configPath = path.join(tempDir, 'config.yaml');
|
||||
const yaml = `version: 2
|
||||
accounts: {}
|
||||
profiles: {}
|
||||
preferences:
|
||||
theme: system
|
||||
telemetry: false
|
||||
auto_update: true
|
||||
cliproxy:
|
||||
oauth_accounts: {}
|
||||
providers:
|
||||
- gemini
|
||||
- codex
|
||||
- agy
|
||||
variants: {}
|
||||
cliproxy_server:
|
||||
local:
|
||||
port: ${localPort}
|
||||
`;
|
||||
fs.writeFileSync(configPath, yaml, 'utf8');
|
||||
function mockUnifiedConfig(config: MockUnifiedConfig): void {
|
||||
mock.module('../../../src/config/unified-config-loader', () => ({
|
||||
loadOrCreateUnifiedConfig: () => config,
|
||||
}));
|
||||
}
|
||||
|
||||
async function loadResolveLifecyclePort() {
|
||||
const mod = await import(
|
||||
`../../../src/commands/cliproxy/resolve-lifecycle-port?proxy-lifecycle-port=${Date.now()}-${Math.random()}`
|
||||
);
|
||||
return mod.resolveLifecyclePort;
|
||||
}
|
||||
|
||||
describe('resolveLifecyclePort', () => {
|
||||
beforeEach(() => {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-proxy-lifecycle-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (tempDir && fs.existsSync(tempDir)) {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
mock.restore();
|
||||
});
|
||||
|
||||
it('uses configured cliproxy_server.local.port', async () => {
|
||||
writeUnifiedConfig(9456);
|
||||
await runWithScopedConfigDir(tempDir, () => {
|
||||
expect(resolveLifecyclePort()).toBe(9456);
|
||||
mockUnifiedConfig({
|
||||
cliproxy_server: {
|
||||
local: {
|
||||
port: 9456,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const resolveLifecyclePort = await loadResolveLifecyclePort();
|
||||
expect(resolveLifecyclePort()).toBe(9456);
|
||||
});
|
||||
|
||||
it('falls back to default port when configured local port is invalid', async () => {
|
||||
writeUnifiedConfig(70000);
|
||||
await runWithScopedConfigDir(tempDir, () => {
|
||||
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
|
||||
mockUnifiedConfig({
|
||||
cliproxy_server: {
|
||||
local: {
|
||||
port: 70000,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const resolveLifecyclePort = await loadResolveLifecyclePort();
|
||||
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
|
||||
});
|
||||
|
||||
it('falls back to default port when config file is missing', async () => {
|
||||
await runWithScopedConfigDir(tempDir, () => {
|
||||
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
|
||||
});
|
||||
mockUnifiedConfig({});
|
||||
|
||||
const resolveLifecyclePort = await loadResolveLifecyclePort();
|
||||
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user