TypeScript
fix(server): the Codex plan badge updates after a ChatGPT downgrade (#24978)
Victor Vogel300baf8ebe61
diff --git a/apps/server/src/provider/CodexProvider.ts b/apps/server/src/provider/CodexProvider.tsindex 65127e6e430..ed9e3d0cde6 100644--- a/apps/server/src/provider/CodexProvider.ts+++ b/apps/server/src/provider/CodexProvider.ts@@ -117,12 +117,17 @@ function reasoningEffortLabel(reasoningEffort: string): string {return REASONING_EFFORT_LABELS[reasoningEffort] ?? reasoningEffort;}-function codexAccountAuthLabel(account: CodexSchema.V2GetAccountResponse["account"]) {+function codexAccountAuthLabel(+ account: CodexSchema.V2GetAccountResponse["account"],+ usagePlanType: string | null | undefined,+) {if (!account) return undefined;if (account.type === "apiKey") return "OpenAI API Key";if (account.type === "amazonBedrock") return "Amazon Bedrock";if (account.type !== "chatgpt") return undefined;- return codexPlanLabel(account.planType);+ // account/read takes the plan from the cached login token; the usage read asks the backend.+ const usageLabel = usagePlanType === "unknown" ? undefined : codexPlanLabel(usagePlanType);+ return usageLabel ?? codexPlanLabel(account.planType);}export function codexPlanLabel(planType: string | null | undefined): string | undefined {@@ -698,7 +703,10 @@ function accountProbeStatus({ account, rateLimits }: CodexAppServerProviderSnapsreadonly auth: ServerProvider["auth"];readonly message?: string;} {- const authLabel = codexAccountAuthLabel(account.account);+ const authLabel = codexAccountAuthLabel(+ account.account,+ rateLimits && "snapshot" in rateLimits ? rateLimits.snapshot.planType : undefined,+ );const authEmail = codexAccountEmail(account.account);const workspaceId =rateLimits && "accountId" in rateLimits ? rateLimits.accountId?.trim() : undefined;diff --git a/apps/server/src/provider/ProviderRegistry.test.ts b/apps/server/src/provider/ProviderRegistry.test.tsindex 60aad9c5997..5e1bc9e962b 100644--- a/apps/server/src/provider/ProviderRegistry.test.ts+++ b/apps/server/src/provider/ProviderRegistry.test.ts@@ -410,6 +410,28 @@ it.layer(}),);+ it.effect("labels the plan the usage read reports over the cached login plan", () =>+ Effect.gen(function* () {+ const statusWithUsagePlan = (planType: string | null) =>+ checkCodexProviderStatus(defaultCodexSettings, () =>+ Effect.succeed(+ makeCodexProbeSnapshot({+ rateLimits: { snapshot: { planType }, resetCredits: null },+ }),+ ),+ );++ const downgraded = yield* statusWithUsagePlan("free");+ assert.strictEqual(downgraded.auth.label, "ChatGPT Free Subscription");++ const unreported = yield* statusWithUsagePlan(null);+ assert.strictEqual(unreported.auth.label, "ChatGPT Pro 200 Subscription");++ const unknown = yield* statusWithUsagePlan("unknown");+ assert.strictEqual(unknown.auth.label, "ChatGPT Pro 200 Subscription");+ }),+ );+it.effect("returns unauthenticated when app-server requires OpenAI auth", () =>Effect.gen(function* () {const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>