Skip to content

Commit defaffb

Browse files
committed
fix: keep CLI auth fallback scoped
1 parent e834249 commit defaffb

2 files changed

Lines changed: 65 additions & 19 deletions

File tree

‎src/agents/command/attempt-execution.cli.test.ts‎

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -737,26 +737,22 @@ describe("CLI attempt execution", () => {
737737
};
738738
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
739739
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
740-
await fs.writeFile(
741-
path.join(tmpDir, "auth-profiles.json"),
742-
JSON.stringify(
743-
{
744-
version: 1,
745-
profiles: {
746-
"google-gemini-cli:[email protected]": {
747-
type: "oauth",
748-
provider: "google-gemini-cli",
749-
access: "access-token",
750-
refresh: "refresh-token",
751-
expires: Date.now() + 3_600_000,
752-
753-
},
740+
saveAuthProfileStore(
741+
{
742+
version: 1,
743+
profiles: {
744+
"google-gemini-cli:[email protected]": {
745+
type: "oauth",
746+
provider: "google-gemini-cli",
747+
access: "access-token",
748+
refresh: "refresh-token",
749+
expires: Date.now() + 3_600_000,
750+
754751
},
755752
},
756-
null,
757-
2,
758-
),
759-
"utf-8",
753+
},
754+
tmpDir,
755+
{ filterExternalAuthProfiles: false, syncExternalCli: false },
760756
);
761757
runCliAgentMock.mockResolvedValueOnce(makeCliResult("gemini cli response"));
762758

@@ -1319,6 +1315,56 @@ describe("CLI attempt execution", () => {
13191315
});
13201316
});
13211317

1318+
it("does not pass auth-order profiles to CLI backends that do not stage them", async () => {
1319+
const sessionKey = "agent:main:direct:claude-auth-order";
1320+
const sessionEntry: SessionEntry = {
1321+
sessionId: "openclaw-session-claude-auth-order",
1322+
updatedAt: Date.now(),
1323+
};
1324+
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
1325+
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
1326+
runCliAgentMock.mockResolvedValueOnce(makeCliResult("ambient claude cli"));
1327+
1328+
await runAgentAttempt({
1329+
providerOverride: "claude-cli",
1330+
originalProvider: "claude-cli",
1331+
modelOverride: "opus",
1332+
cfg: {
1333+
auth: {
1334+
order: {
1335+
"claude-cli": ["claude-cli:work"],
1336+
},
1337+
},
1338+
} as OpenClawConfig,
1339+
sessionEntry,
1340+
sessionId: sessionEntry.sessionId,
1341+
sessionKey,
1342+
sessionAgentId: "main",
1343+
sessionFile: path.join(tmpDir, "session.jsonl"),
1344+
workspaceDir: tmpDir,
1345+
body: "use ambient cli auth",
1346+
isFallbackRetry: false,
1347+
resolvedThinkLevel: "medium",
1348+
timeoutMs: 1_000,
1349+
runId: "run-claude-auth-order",
1350+
opts: {} as Parameters<typeof runAgentAttempt>[0]["opts"],
1351+
runContext: {} as Parameters<typeof runAgentAttempt>[0]["runContext"],
1352+
spawnedBy: undefined,
1353+
messageChannel: undefined,
1354+
skillsSnapshot: undefined,
1355+
resolvedVerboseLevel: undefined,
1356+
agentDir: tmpDir,
1357+
onAgentEvent: vi.fn(),
1358+
authProfileProvider: "claude-cli",
1359+
sessionStore,
1360+
storePath,
1361+
sessionHasHistory: false,
1362+
});
1363+
1364+
expect(runCliAgentMock).toHaveBeenCalledTimes(1);
1365+
expect(firstRunCliAgentArg().authProfileId).toBeUndefined();
1366+
});
1367+
13221368
it("forwards runtime toolsAllow into CLI attempts so the CLI harness can fail closed", async () => {
13231369
const sessionKey = "agent:main:direct:claude-tools-allow";
13241370
const sessionEntry: SessionEntry = {

‎src/agents/command/attempt-execution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ export function runAgentAttempt(params: {
642642
nextCliSessionId === activeCliSessionBinding?.sessionId
643643
? activeCliSessionBinding
644644
: undefined,
645-
authProfileId: authProfileId ?? params.cfg.auth?.order?.[cliExecutionProvider]?.[0],
645+
authProfileId,
646646
bootstrapPromptWarningSignaturesSeen,
647647
bootstrapPromptWarningSignature,
648648
images: params.isFallbackRetry ? undefined : params.opts.images,

0 commit comments

Comments
 (0)