fix: keep CLI auth fallback scoped

This commit is contained in:
Shakker
2026-06-15 19:17:30 +01:00
committed by Shakker
parent e834249db3
commit defaffbb93
2 changed files with 65 additions and 19 deletions

View File

@@ -737,26 +737,22 @@ describe("CLI attempt execution", () => {
};
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
await fs.writeFile(
path.join(tmpDir, "auth-profiles.json"),
JSON.stringify(
{
version: 1,
profiles: {
"google-gemini-cli:user@example.test": {
type: "oauth",
provider: "google-gemini-cli",
access: "access-token",
refresh: "refresh-token",
expires: Date.now() + 3_600_000,
email: "user@example.test",
},
saveAuthProfileStore(
{
version: 1,
profiles: {
"google-gemini-cli:user@example.test": {
type: "oauth",
provider: "google-gemini-cli",
access: "access-token",
refresh: "refresh-token",
expires: Date.now() + 3_600_000,
email: "user@example.test",
},
},
null,
2,
),
"utf-8",
},
tmpDir,
{ filterExternalAuthProfiles: false, syncExternalCli: false },
);
runCliAgentMock.mockResolvedValueOnce(makeCliResult("gemini cli response"));
@@ -1319,6 +1315,56 @@ describe("CLI attempt execution", () => {
});
});
it("does not pass auth-order profiles to CLI backends that do not stage them", async () => {
const sessionKey = "agent:main:direct:claude-auth-order";
const sessionEntry: SessionEntry = {
sessionId: "openclaw-session-claude-auth-order",
updatedAt: Date.now(),
};
const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };
await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");
runCliAgentMock.mockResolvedValueOnce(makeCliResult("ambient claude cli"));
await runAgentAttempt({
providerOverride: "claude-cli",
originalProvider: "claude-cli",
modelOverride: "opus",
cfg: {
auth: {
order: {
"claude-cli": ["claude-cli:work"],
},
},
} as OpenClawConfig,
sessionEntry,
sessionId: sessionEntry.sessionId,
sessionKey,
sessionAgentId: "main",
sessionFile: path.join(tmpDir, "session.jsonl"),
workspaceDir: tmpDir,
body: "use ambient cli auth",
isFallbackRetry: false,
resolvedThinkLevel: "medium",
timeoutMs: 1_000,
runId: "run-claude-auth-order",
opts: {} as Parameters<typeof runAgentAttempt>[0]["opts"],
runContext: {} as Parameters<typeof runAgentAttempt>[0]["runContext"],
spawnedBy: undefined,
messageChannel: undefined,
skillsSnapshot: undefined,
resolvedVerboseLevel: undefined,
agentDir: tmpDir,
onAgentEvent: vi.fn(),
authProfileProvider: "claude-cli",
sessionStore,
storePath,
sessionHasHistory: false,
});
expect(runCliAgentMock).toHaveBeenCalledTimes(1);
expect(firstRunCliAgentArg().authProfileId).toBeUndefined();
});
it("forwards runtime toolsAllow into CLI attempts so the CLI harness can fail closed", async () => {
const sessionKey = "agent:main:direct:claude-tools-allow";
const sessionEntry: SessionEntry = {

View File

@@ -642,7 +642,7 @@ export function runAgentAttempt(params: {
nextCliSessionId === activeCliSessionBinding?.sessionId
? activeCliSessionBinding
: undefined,
authProfileId: authProfileId ?? params.cfg.auth?.order?.[cliExecutionProvider]?.[0],
authProfileId,
bootstrapPromptWarningSignaturesSeen,
bootstrapPromptWarningSignature,
images: params.isFallbackRetry ? undefined : params.opts.images,