Skip to content

Commit adbb09d

Browse files
authored
fix(anthropic): prevent retired Claude CLI profile from breaking setup (#130225)
* fix(anthropic): ignore retired Claude CLI auth profile * test(system-agent): expect native Claude CLI ownership
1 parent bbd66c4 commit adbb09d

4 files changed

Lines changed: 134 additions & 10 deletions

File tree

‎src/agents/cli-execution-auth.test.ts‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22
import type { AuthProfileCredential } from "./auth-profiles/types.js";
33

44
const mocks = vi.hoisted(() => ({
5+
order: [] as string[],
56
profiles: {} as Record<string, AuthProfileCredential>,
67
}));
78

@@ -10,18 +11,67 @@ vi.mock("./auth-profiles/store.js", () => ({
1011
}));
1112

1213
vi.mock("./auth-profiles/order.js", () => ({
13-
resolveAuthProfileOrder: () => [],
14+
resolveAuthProfileOrder: () => mocks.order,
1415
}));
1516

1617
import { resolveCliExecutionAuthProfileId } from "./cli-execution-auth.js";
1718

1819
describe("resolveCliExecutionAuthProfileId", () => {
1920
beforeEach(() => {
21+
mocks.order.length = 0;
2022
for (const profileId of Object.keys(mocks.profiles)) {
2123
delete mocks.profiles[profileId];
2224
}
2325
});
2426

27+
it.each(["auto", "user"] as const)(
28+
"ignores a retired native Claude profile selected by %s",
29+
(authProfileIdSource) => {
30+
const authProfileId = "anthropic:claude-cli";
31+
mocks.profiles[authProfileId] = {
32+
type: "oauth",
33+
provider: "claude-cli",
34+
access: "retired-access",
35+
refresh: "retired-refresh",
36+
expires: Date.now() - 60_000,
37+
};
38+
mocks.order.push(authProfileId);
39+
40+
expect(
41+
resolveCliExecutionAuthProfileId({
42+
cliExecutionProvider: "claude-cli",
43+
authProfileProvider: "claude-cli",
44+
config: {},
45+
agentDir: "/tmp/unused-agent",
46+
...(authProfileIdSource === "user"
47+
? { selected: { authProfileId, authProfileIdSource } }
48+
: {}),
49+
}),
50+
).toBeUndefined();
51+
},
52+
);
53+
54+
it("keeps forwarding a non-retired Claude profile", () => {
55+
const authProfileId = "claude-cli:work";
56+
mocks.profiles[authProfileId] = {
57+
type: "oauth",
58+
provider: "claude-cli",
59+
access: "test-access",
60+
refresh: "test-refresh",
61+
expires: Date.now() + 60_000,
62+
};
63+
64+
expect(
65+
resolveCliExecutionAuthProfileId({
66+
cliExecutionProvider: "claude-cli",
67+
authProfileProvider: "claude-cli",
68+
config: {},
69+
agentDir: "/tmp/unused-agent",
70+
selected: { authProfileId, authProfileIdSource: "user" },
71+
}),
72+
).toBe(authProfileId);
73+
});
74+
2575
it("rejects an explicitly selected profile from another provider", () => {
2676
mocks.profiles["openai:work"] = {
2777
type: "api_key",

‎src/agents/cli-execution-auth.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
55
import { resolveAuthProfileOrder } from "./auth-profiles/order.js";
66
import { loadAuthProfileStoreForRuntime } from "./auth-profiles/store.js";
77
import { resolveCliBackendConfig } from "./cli-backends.js";
8+
import { resolveBundledCliBackendAuthPolicy } from "./cli-runner/cli-backend-auth-policy.js";
89

910
const GOOGLE_GEMINI_CLI_PROVIDER_ID = "google-gemini-cli";
1011
const GOOGLE_PROVIDER_ID = "google";
@@ -50,7 +51,13 @@ export function resolveCliExecutionAuthProfileId(params: {
5051
allowKeychainPrompt: false,
5152
externalCliProviderIds: [params.cliExecutionProvider],
5253
});
54+
const nativeAuthProfileIds = resolveBundledCliBackendAuthPolicy(
55+
params.cliExecutionProvider,
56+
)?.nativeAuthProfileIds;
5357
const selectedAuthProfileId = params.selected?.authProfileId?.trim();
58+
if (selectedAuthProfileId && nativeAuthProfileIds?.includes(selectedAuthProfileId)) {
59+
return undefined;
60+
}
5461
if (selectedAuthProfileId) {
5562
const credential = store.profiles[selectedAuthProfileId];
5663
if (credential?.provider === params.cliExecutionProvider) {
@@ -82,7 +89,7 @@ export function resolveCliExecutionAuthProfileId(params: {
8289
provider: params.cliExecutionProvider,
8390
})[0];
8491
if (cliProfileId) {
85-
return cliProfileId;
92+
return nativeAuthProfileIds?.includes(cliProfileId) ? undefined : cliProfileId;
8693
}
8794

8895
if (

‎src/system-agent/agent-turn.test.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,13 @@ describe("runSystemAgentTurn", () => {
494494
},
495495
);
496496

497-
expect(runCliAgent).toHaveBeenCalledWith(
498-
expect.objectContaining({
499-
provider: "claude-cli",
500-
model: "claude-opus-4-8",
501-
agentDir,
502-
authProfileId: "anthropic:claude-cli",
503-
}),
504-
);
497+
expect(runCliAgent).toHaveBeenCalledOnce();
498+
expect(runCliAgent.mock.calls[0]?.[0]).toMatchObject({
499+
provider: "claude-cli",
500+
model: "claude-opus-4-8",
501+
agentDir,
502+
});
503+
expect(runCliAgent.mock.calls[0]?.[0].authProfileId).toBeUndefined();
505504
});
506505

507506
it("reuses the guarded CLI binding when a denied proposal becomes approved", async () => {

‎src/system-agent/setup-inference.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5719,6 +5719,74 @@ describe("verifySetupInference", () => {
57195719
});
57205720
});
57215721

5722+
it("binds Claude native login when a retired profile remains in the store", async () => {
5723+
const authProfileId = "anthropic:claude-cli";
5724+
const config = {
5725+
agents: { defaults: { model: "claude-cli/claude-opus-5" } },
5726+
} satisfies OpenClawConfig;
5727+
const profiles = {
5728+
[authProfileId]: {
5729+
type: "oauth" as const,
5730+
provider: "claude-cli",
5731+
access: "retired-access",
5732+
refresh: "retired-refresh",
5733+
expires: Date.now() - 60_000,
5734+
},
5735+
};
5736+
const nativeRuntimeOwner = "native-claude-runtime-owner";
5737+
const resolveCliRuntimeOwnerFingerprint = vi.fn(async (params: { authProfileId?: string }) =>
5738+
params.authProfileId ? "retired-profile-owner" : nativeRuntimeOwner,
5739+
);
5740+
const runCliAgent = vi.fn(
5741+
async (params: {
5742+
authProfileId?: string;
5743+
onSuccessfulAuthBinding?: (binding: AgentExecutionAuthBinding) => void;
5744+
}) => {
5745+
params.onSuccessfulAuthBinding?.({
5746+
runtimeOwnerFingerprint: nativeRuntimeOwner,
5747+
runtimeOwnerKind: "cli-runtime",
5748+
runtimeOwnerId: "claude-cli",
5749+
runtimeArtifactFingerprint: testCliRuntimeArtifactFingerprint,
5750+
runtimeArtifactId: "claude-cli",
5751+
});
5752+
return {
5753+
meta: {
5754+
finalAssistantVisibleText: "OK",
5755+
executionTrace: {
5756+
winnerProvider: "claude-cli",
5757+
winnerModel: "claude-opus-5",
5758+
},
5759+
},
5760+
};
5761+
},
5762+
);
5763+
5764+
const result = await verifySetupInference({
5765+
bindSession: true,
5766+
deps: {
5767+
readConfigFileSnapshot: vi.fn(async () => ({ exists: true, valid: true, config })) as never,
5768+
loadAuthProfileStoreForRuntime: vi.fn(() => ({ version: 1, profiles })) as never,
5769+
ensureAuthProfileStore: vi.fn(() => ({ version: 1, profiles })) as never,
5770+
createSystemAgentVerifiedInferenceBinding,
5771+
resolveCliRuntimeArtifactFingerprint: vi.fn(async () => testCliRuntimeArtifactFingerprint),
5772+
resolveCliRuntimeOwnerFingerprint: resolveCliRuntimeOwnerFingerprint as never,
5773+
runCliAgent: runCliAgent as never,
5774+
},
5775+
});
5776+
5777+
expect(result).toMatchObject({
5778+
ok: true,
5779+
binding: {
5780+
auth: { authFingerprint: nativeRuntimeOwner, proofKind: "runtime-owner" },
5781+
execution: { provider: "claude-cli", model: "claude-opus-5" },
5782+
},
5783+
});
5784+
expect(runCliAgent).toHaveBeenCalledOnce();
5785+
expect(runCliAgent.mock.calls[0]?.[0].authProfileId).toBeUndefined();
5786+
expect(resolveCliRuntimeOwnerFingerprint).toHaveBeenCalledOnce();
5787+
expect(resolveCliRuntimeOwnerFingerprint.mock.calls[0]?.[0].authProfileId).toBeUndefined();
5788+
});
5789+
57225790
it("rejects an owner plugin replacement during the live inference turn", async () => {
57235791
const profileId = "openai:verified";
57245792
const credential = {

0 commit comments

Comments
 (0)