mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 00:18:05 +00:00
fix(cliproxy): remap codex haiku fallback on free plans
This commit is contained in:
@@ -66,7 +66,9 @@ export async function reconcileCodexModelForActivePlan(options: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (quota.planType === 'free') {
|
if (quota.planType === 'free') {
|
||||||
updateSettingsModel(settingsPath, fallbackModel, 'codex');
|
updateSettingsModel(settingsPath, fallbackModel, 'codex', {
|
||||||
|
rewriteHaikuModel: (haikuModel) => getFreePlanFallbackCodexModel(haikuModel) ?? haikuModel,
|
||||||
|
});
|
||||||
console.error(
|
console.error(
|
||||||
info(
|
info(
|
||||||
`Codex free plan detected. Switched unsupported model "${normalizeCodexModelId(currentModel)}" ` +
|
`Codex free plan detected. Switched unsupported model "${normalizeCodexModelId(currentModel)}" ` +
|
||||||
|
|||||||
@@ -290,7 +290,10 @@ export function deleteSettingsFile(settingsPath: string): boolean {
|
|||||||
export function updateSettingsModel(
|
export function updateSettingsModel(
|
||||||
settingsPath: string,
|
settingsPath: string,
|
||||||
model: string,
|
model: string,
|
||||||
provider?: CLIProxyProfileName
|
provider?: CLIProxyProfileName,
|
||||||
|
options?: {
|
||||||
|
rewriteHaikuModel?: (model: string) => string;
|
||||||
|
}
|
||||||
): void {
|
): void {
|
||||||
const fileName = path.basename(settingsPath);
|
const fileName = path.basename(settingsPath);
|
||||||
if (fileName.startsWith('composite-')) {
|
if (fileName.startsWith('composite-')) {
|
||||||
@@ -316,10 +319,13 @@ export function updateSettingsModel(
|
|||||||
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = normalizedModel;
|
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = normalizedModel;
|
||||||
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = normalizedModel;
|
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = normalizedModel;
|
||||||
if (provider === 'codex' && settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL) {
|
if (provider === 'codex' && settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL) {
|
||||||
settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL = canonicalizeModelForProvider(
|
const normalizedHaikuModel = canonicalizeModelForProvider(
|
||||||
provider,
|
provider,
|
||||||
settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL
|
settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL
|
||||||
);
|
);
|
||||||
|
settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL = options?.rewriteHaikuModel
|
||||||
|
? options.rewriteHaikuModel(normalizedHaikuModel)
|
||||||
|
: normalizedHaikuModel;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Clear model settings to use defaults
|
// Clear model settings to use defaults
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ afterEach(() => {
|
|||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
function createCodexSettingsFixture(): { tmpDir: string; settingsPath: string } {
|
function createCodexSettingsFixture(haikuModel: string = 'gpt-5-codex-mini'): {
|
||||||
|
tmpDir: string;
|
||||||
|
settingsPath: string;
|
||||||
|
} {
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-codex-plan-compat-'));
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-codex-plan-compat-'));
|
||||||
const settingsPath = path.join(tmpDir, 'codex.settings.json');
|
const settingsPath = path.join(tmpDir, 'codex.settings.json');
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ function createCodexSettingsFixture(): { tmpDir: string; settingsPath: string }
|
|||||||
ANTHROPIC_MODEL: 'gpt-5.3-codex',
|
ANTHROPIC_MODEL: 'gpt-5.3-codex',
|
||||||
ANTHROPIC_DEFAULT_OPUS_MODEL: 'gpt-5.3-codex',
|
ANTHROPIC_DEFAULT_OPUS_MODEL: 'gpt-5.3-codex',
|
||||||
ANTHROPIC_DEFAULT_SONNET_MODEL: 'gpt-5.3-codex',
|
ANTHROPIC_DEFAULT_SONNET_MODEL: 'gpt-5.3-codex',
|
||||||
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'gpt-5-codex-mini',
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: haikuModel,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
@@ -39,7 +42,7 @@ async function importCompatibilityModule(cacheTag: string) {
|
|||||||
|
|
||||||
describe('codex plan compatibility reconcile', () => {
|
describe('codex plan compatibility reconcile', () => {
|
||||||
it('repairs stale paid-only Codex settings for free-plan accounts before launch', async () => {
|
it('repairs stale paid-only Codex settings for free-plan accounts before launch', async () => {
|
||||||
const { tmpDir, settingsPath } = createCodexSettingsFixture();
|
const { tmpDir, settingsPath } = createCodexSettingsFixture('gpt-5.3-codex-spark');
|
||||||
|
|
||||||
mock.module('../../../src/cliproxy/account-manager', () => ({
|
mock.module('../../../src/cliproxy/account-manager', () => ({
|
||||||
getDefaultAccount: () => ({ id: 'free@example.com' }),
|
getDefaultAccount: () => ({ id: 'free@example.com' }),
|
||||||
@@ -230,4 +233,54 @@ describe('codex plan compatibility reconcile', () => {
|
|||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('warns and keeps settings unchanged when quota succeeds without a plan type', async () => {
|
||||||
|
const { tmpDir, settingsPath } = createCodexSettingsFixture();
|
||||||
|
|
||||||
|
mock.module('../../../src/cliproxy/account-manager', () => ({
|
||||||
|
getDefaultAccount: () => ({ id: 'missing-plan@example.com' }),
|
||||||
|
}));
|
||||||
|
mock.module('../../../src/cliproxy/quota-fetcher-codex', () => ({
|
||||||
|
fetchCodexQuota: async () => ({
|
||||||
|
success: true,
|
||||||
|
windows: [],
|
||||||
|
coreUsage: { fiveHour: null, weekly: null },
|
||||||
|
planType: null,
|
||||||
|
lastUpdated: Date.now(),
|
||||||
|
accountId: 'missing-plan@example.com',
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
mock.module('../../../src/cliproxy/quota-response-cache', () => ({
|
||||||
|
getCachedQuota: () => null,
|
||||||
|
setCachedQuota: () => {},
|
||||||
|
}));
|
||||||
|
mock.module('../../../src/utils/ui', () => ({
|
||||||
|
info: (message: string) => message,
|
||||||
|
warn: (message: string) => message,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const errorSpy = spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { reconcileCodexModelForActivePlan } =
|
||||||
|
await importCompatibilityModule('missing-plan-type');
|
||||||
|
|
||||||
|
await reconcileCodexModelForActivePlan({
|
||||||
|
settingsPath,
|
||||||
|
currentModel: 'gpt-5.3-codex',
|
||||||
|
verbose: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as {
|
||||||
|
env: Record<string, string>;
|
||||||
|
};
|
||||||
|
expect(settings.env.ANTHROPIC_MODEL).toBe('gpt-5.3-codex');
|
||||||
|
expect(settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe('gpt-5-codex-mini');
|
||||||
|
expect(errorSpy).toHaveBeenCalledWith(
|
||||||
|
'Could not verify Codex plan for model "gpt-5.3-codex". If startup fails with model_not_supported, switch to "gpt-5-codex" via "ccs codex --config".'
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user