fix(proxy): ignore legacy singleton session file

This commit is contained in:
Wooseong Kim
2026-04-20 14:09:50 +09:00
parent 24c24847f7
commit f345cf441e
2 changed files with 47 additions and 2 deletions
+10 -2
View File
@@ -108,10 +108,18 @@ export function listOpenAICompatProxyProfileNames(): string[] {
const entries = fs.readdirSync(getOpenAICompatProxyDir(), { withFileTypes: true });
const profileKeys = new Set<string>();
for (const entry of entries) {
if (!entry.isFile() || !entry.name.endsWith('.session.json')) {
if (
!entry.isFile() ||
entry.name === 'session.json' ||
!entry.name.endsWith('.session.json')
) {
continue;
}
profileKeys.add(entry.name.slice(0, -'.session.json'.length));
const profileKey = entry.name.slice(0, -'.session.json'.length);
if (!profileKey) {
continue;
}
profileKeys.add(profileKey);
}
return [...profileKeys].map((profileKey) => decodeURIComponent(profileKey));
} catch {
@@ -0,0 +1,37 @@
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import {
getLegacyOpenAICompatProxySessionPath,
getOpenAICompatProxySessionPath,
} from '../../../src/proxy/proxy-daemon-paths';
import { listOpenAICompatProxyProfileNames } from '../../../src/proxy/proxy-daemon-state';
let originalCcsHome: string | undefined;
let tempDir: string;
beforeEach(() => {
originalCcsHome = process.env.CCS_HOME;
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-proxy-state-'));
process.env.CCS_HOME = tempDir;
});
afterEach(() => {
if (originalCcsHome !== undefined) {
process.env.CCS_HOME = originalCcsHome;
} else {
delete process.env.CCS_HOME;
}
fs.rmSync(tempDir, { recursive: true, force: true });
});
describe('listOpenAICompatProxyProfileNames', () => {
it('ignores the legacy singleton session file', () => {
fs.mkdirSync(path.dirname(getLegacyOpenAICompatProxySessionPath()), { recursive: true });
fs.writeFileSync(getLegacyOpenAICompatProxySessionPath(), '{}\n', 'utf8');
fs.writeFileSync(getOpenAICompatProxySessionPath('ccg'), '{}\n', 'utf8');
expect(listOpenAICompatProxyProfileNames()).toEqual(['ccg']);
});
});