fix: show account identity for Codex OAuth provider cards (#9300)

Co-authored-by: Jason <farion1231@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Allen Xu
2026-11-11 07:42:58 -08:00
committed by GitHub
parent d4647fbbf5
commit 2abcaa6ee0
2 changed files with 94 additions and 17 deletions
+10 -10
View File
@@ -231,6 +231,11 @@ export function ProviderCard({
}: ProviderCardProps) {
const { t } = useTranslation();
const codexOfficialIdentity = resolveCodexOfficialIdentity(appId, provider);
const isBoundCodexOfficial = codexOfficialIdentity === "managed_account";
const isCodexOauth =
appId === "codex"
? isBoundCodexOfficial
: provider.meta?.providerType === PROVIDER_TYPES.CODEX_OAUTH;
const managedCodexAccountId = resolveManagedAccountId(
provider.meta,
"codex_oauth",
@@ -242,13 +247,13 @@ export function ProviderCard({
} = useQuery({
queryKey: ["managed-auth-status", "codex_oauth"],
queryFn: () => authApi.authGetStatus("codex_oauth"),
enabled:
codexOfficialIdentity === "managed_account" &&
Boolean(managedCodexAccountId),
enabled: isCodexOauth,
staleTime: 30_000,
});
const managedCodexAccount = codexAuthStatus?.accounts.find(
(account) => account.id === managedCodexAccountId,
(account) =>
account.id ===
(managedCodexAccountId ?? codexAuthStatus?.default_account_id),
);
const manualNote = provider.notes?.trim() || undefined;
const providerNameIncludesAccountLogin = Boolean(
@@ -292,7 +297,6 @@ export function ProviderCard({
return true;
}, [provider.notes, displayUrl, fallbackUrlText]);
const isBoundCodexOfficial = codexOfficialIdentity === "managed_account";
const isOfficial = isOfficialProvider(provider, appId);
// Claude 官方卡绑了 Claude 官方账号:副标题写账号,额度按这个号查
const claudeBoundAccountId =
@@ -340,10 +344,6 @@ export function ProviderCard({
appId !== "copilot" &&
(provider.meta?.providerType === PROVIDER_TYPES.GITHUB_COPILOT ||
provider.meta?.usage_script?.templateType === "github_copilot");
const isCodexOauth =
appId === "codex"
? isBoundCodexOfficial
: provider.meta?.providerType === PROVIDER_TYPES.CODEX_OAUTH;
// xAI OAuth (SuperGrok 反代):额度经自管 OAuth token 自动显示,与 codex_oauth 同构
const isXaiOauth = provider.meta?.providerType === PROVIDER_TYPES.XAI_OAUTH;
// Antigravity 官方卡绑了授权中心的账号:额度查绑定的号(只有 macOS 能切号,其他平台忽略绑定)
@@ -496,7 +496,7 @@ export function ProviderCard({
)}
</div>
{codexOfficialIdentity && codexOfficialIdentity !== "api_key" ? (
{codexOfficialIdentity === "native_login" || isCodexOauth ? (
<div className="mt-0.5 flex min-w-0 items-center gap-2 text-caption text-fg-2">
{codexOfficialIdentity === "native_login" ? (
<>
@@ -3,7 +3,9 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { ProviderCard } from "@/components/providers/ProviderCard";
import type { ManagedAuthStatus } from "@/lib/api";
import { http, HttpResponse } from "msw";
import type { AppId, ManagedAuthStatus } from "@/lib/api";
import { server } from "../msw/server";
import type { Provider } from "@/types";
import { createTestQueryClient } from "../utils/testQueryClient";
@@ -90,6 +92,7 @@ const authStatus = (login: string): ManagedAuthStatus => ({
function renderCard(
provider: Provider,
options: {
appId?: AppId;
status?: ManagedAuthStatus;
isCurrent?: boolean;
onEdit?: (provider: Provider) => void;
@@ -99,11 +102,14 @@ function renderCard(
) {
const queryClient = createTestQueryClient();
if (options.planName) {
queryClient.setQueryData(["codex_oauth", "quota", "account-long"], {
success: true,
tiers: [],
planName: options.planName,
});
queryClient.setQueryData(
[
"codex_oauth",
"quota",
provider.meta?.authBinding?.accountId ?? "default",
],
{ success: true, tiers: [], planName: options.planName },
);
}
if (options.status) {
queryClient.setQueryData(
@@ -116,7 +122,7 @@ function renderCard(
<QueryClientProvider client={queryClient}>
<ProviderCard
provider={provider}
appId="codex"
appId={options.appId ?? "codex"}
isCurrent={options.isCurrent ?? false}
presentation={{ chips: [], buttons: [] }}
onEdit={options.onEdit ?? vi.fn()}
@@ -130,6 +136,77 @@ function renderCard(
}
describe("ProviderCard Codex Official account identity", () => {
const proxyProvider = (): Provider => ({
...managedProvider("Codex"),
category: "third_party",
websiteUrl: "https://openai.com/chatgpt/pricing",
settingsConfig: {
env: { ANTHROPIC_BASE_URL: "https://chatgpt.com/backend-api/codex" },
},
});
it.each(["claude", "claude-desktop"] as const)(
"shows the bound Codex account and plan instead of the website in %s",
async (appId) => {
server.use(
http.post("http://tauri.local/auth_get_status", () =>
HttpResponse.json(authStatus("me@example.com")),
),
);
renderCard(proxyProvider(), { appId, planName: "Plus" });
expect(await screen.findByText("me@example.com")).toHaveClass("truncate");
expect(screen.getByText("· Plus")).toBeInTheDocument();
expect(
screen.queryByText("https://openai.com/chatgpt/pricing"),
).not.toBeInTheDocument();
},
);
it("shows the default Codex account when the proxy has no explicit binding", () => {
const provider = proxyProvider();
delete provider.meta!.authBinding;
const status = authStatus("default@example.com");
status.accounts.unshift({
...status.accounts[0],
id: "another-account",
login: "another@example.com",
is_default: false,
});
renderCard(provider, { appId: "claude", status, planName: "Plus" });
expect(screen.getByText("default@example.com")).toBeInTheDocument();
expect(screen.getByText("· Plus")).toBeInTheDocument();
expect(screen.queryByText("another@example.com")).not.toBeInTheDocument();
});
it("preserves manual notes on Codex proxy cards", () => {
renderCard(
{ ...proxyProvider(), notes: "Work account" },
{
appId: "claude",
status: authStatus("me@example.com"),
planName: "Plus",
},
);
expect(screen.getByText("Work account")).toBeInTheDocument();
expect(screen.getByText("· Plus")).toBeInTheDocument();
expect(screen.queryByText("me@example.com")).not.toBeInTheDocument();
});
it("does not replace a missing bound proxy account with the default account", () => {
const provider = proxyProvider();
provider.meta!.authBinding!.accountId = "deleted-account";
renderCard(provider, {
appId: "claude",
status: authStatus("default@example.com"),
});
expect(screen.getByText("绑定的账号不可用")).toBeInTheDocument();
expect(screen.queryByText("default@example.com")).not.toBeInTheDocument();
});
it("puts the bound account's plan after the login once its quota is in", () => {
renderCard(managedProvider("OpenAI Official"), {
status: authStatus("me@example.com"),