mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 16:17:02 +00:00
feat(proxy): add adaptive local port selection for OpenAI-compatible profiles
This commit is contained in:
1 parent
5ddf130223
commit
15751e2db5
11 files changed
+337
-103
No files matched your search
@@ -159,6 +159,34 @@ describe('openai proxy daemon lifecycle', () => {
|
||||
expect(secondHealth.status).toBe(200);
|
||||
});
|
||||
|
||||
it('uses an adaptive implicit port instead of defaulting to 3456 for shared defaults', async () => {
|
||||
const settingsPath = path.join(tempDir, 'adaptive-default.settings.json');
|
||||
fs.writeFileSync(
|
||||
settingsPath,
|
||||
JSON.stringify({
|
||||
env: {
|
||||
ANTHROPIC_BASE_URL: 'https://api.openai.com/v1',
|
||||
ANTHROPIC_AUTH_TOKEN: 'sk-adaptive-default',
|
||||
ANTHROPIC_MODEL: 'gpt-4.1',
|
||||
},
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
const profile = resolveOpenAICompatProfileConfig('adaptive-default', settingsPath, {
|
||||
ANTHROPIC_BASE_URL: 'https://api.openai.com/v1',
|
||||
ANTHROPIC_AUTH_TOKEN: 'sk-adaptive-default',
|
||||
ANTHROPIC_MODEL: 'gpt-4.1',
|
||||
});
|
||||
if (!profile) {
|
||||
throw new Error('Expected adaptive-default OpenAI-compatible profile');
|
||||
}
|
||||
|
||||
const started = await startOpenAICompatProxy(profile);
|
||||
expect(started.success).toBe(true);
|
||||
expect(started.port).not.toBe(3456);
|
||||
});
|
||||
|
||||
it('keeps a legacy singleton daemon visible across upgrade', async () => {
|
||||
const port = await getPort();
|
||||
const settingsPath = path.join(tempDir, 'legacy.settings.json');
|
||||
@@ -416,6 +444,55 @@ describe('openai proxy daemon lifecycle', () => {
|
||||
expect(started.port).toBe(preferredPort);
|
||||
});
|
||||
|
||||
it('does not keep a stopped shared-default profile anchored to legacy port 3456', async () => {
|
||||
const settingsPath = path.join(tempDir, 'legacy-shared-default.settings.json');
|
||||
fs.writeFileSync(
|
||||
settingsPath,
|
||||
JSON.stringify({
|
||||
env: {
|
||||
ANTHROPIC_BASE_URL: 'https://api.openai.com/v1',
|
||||
ANTHROPIC_AUTH_TOKEN: 'sk-legacy-shared-default',
|
||||
ANTHROPIC_MODEL: 'gpt-4.1',
|
||||
},
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
const profile = resolveOpenAICompatProfileConfig('legacy-shared-default', settingsPath, {
|
||||
ANTHROPIC_BASE_URL: 'https://api.openai.com/v1',
|
||||
ANTHROPIC_AUTH_TOKEN: 'sk-legacy-shared-default',
|
||||
ANTHROPIC_MODEL: 'gpt-4.1',
|
||||
});
|
||||
if (!profile) {
|
||||
throw new Error('Expected legacy-shared-default OpenAI-compatible profile');
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(getOpenAICompatProxySessionPath('legacy-shared-default')), {
|
||||
recursive: true,
|
||||
});
|
||||
fs.writeFileSync(
|
||||
getOpenAICompatProxySessionPath('legacy-shared-default'),
|
||||
JSON.stringify(
|
||||
{
|
||||
profileName: profile.profileName,
|
||||
settingsPath: profile.settingsPath,
|
||||
host: '127.0.0.1',
|
||||
port: 3456,
|
||||
baseUrl: profile.baseUrl,
|
||||
authToken: 'stale-token',
|
||||
model: profile.model,
|
||||
},
|
||||
null,
|
||||
2
|
||||
) + '\n',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
const started = await startOpenAICompatProxy(profile);
|
||||
expect(started.success).toBe(true);
|
||||
expect(started.port).not.toBe(3456);
|
||||
});
|
||||
|
||||
it('stops legacy daemons even when the legacy session is missing a profile name', async () => {
|
||||
const port = await getPort();
|
||||
const settingsPath = path.join(tempDir, 'legacy-missing-profile.settings.json');
|
||||
|
||||
Reference in new issue
Block a user