mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(proxy): ignore legacy singleton session file
This commit is contained in:
@@ -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']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user