mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 08:17:11 +00:00
hotfix(codex): tolerate BOM in Codex TOML config
This commit is contained in:
@@ -9,11 +9,16 @@ function isTomlObject(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function stripUtf8Bom(rawText: string): string {
|
||||
return rawText.charCodeAt(0) === 0xfeff ? rawText.slice(1) : rawText;
|
||||
}
|
||||
|
||||
export function parseTomlObject(rawText: string): Record<string, unknown> {
|
||||
const trimmed = rawText.trim();
|
||||
const parseText = stripUtf8Bom(rawText);
|
||||
const trimmed = parseText.trim();
|
||||
if (!trimmed) return {};
|
||||
|
||||
const parsed = parse(rawText);
|
||||
const parsed = parse(parseText);
|
||||
if (!isTomlObject(parsed)) {
|
||||
throw new Error('TOML root must be a table.');
|
||||
}
|
||||
|
||||
@@ -49,6 +49,19 @@ describe('codex cliproxy provider config repair', () => {
|
||||
expect(rawText).toContain('[model_providers.cliproxy]');
|
||||
});
|
||||
|
||||
it('repairs Codex config files saved with a UTF-8 BOM', async () => {
|
||||
fs.mkdirSync(codexHome, { recursive: true });
|
||||
const rawText = '\ufeffmodel = "gpt-5.4"\n';
|
||||
fs.writeFileSync(configPath, rawText, 'utf8');
|
||||
|
||||
const result = await ensureCodexCliproxyProviderConfig(8317, env);
|
||||
|
||||
expect(result.changed).toBe(true);
|
||||
const repairedText = fs.readFileSync(configPath, 'utf8');
|
||||
expect(repairedText.startsWith('\ufeffmodel = "gpt-5.4"\n\n')).toBe(true);
|
||||
expect(repairedText).toContain('[model_providers.cliproxy]');
|
||||
});
|
||||
|
||||
it('repairs an existing incomplete cliproxy provider', async () => {
|
||||
fs.mkdirSync(codexHome, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
|
||||
Reference in New Issue
Block a user