mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:27:40 +00:00
fix(auth/session): preserve override reset behavior and repair oauth profile-id drift (openclaw#18820) thanks @Glucksberg
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: Glucksberg <80581902+Glucksberg@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs/promises";
|
||||
import type { OAuthCredentials } from "@mariozechner/pi-ai";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { applyAuthChoice, resolvePreferredProviderForAuthChoice } from "./auth-choice.js";
|
||||
@@ -22,7 +23,9 @@ vi.mock("../providers/github-copilot-auth.js", () => ({
|
||||
githubCopilotLoginCommand: vi.fn(async () => {}),
|
||||
}));
|
||||
|
||||
const loginOpenAICodexOAuth = vi.hoisted(() => vi.fn(async () => null));
|
||||
const loginOpenAICodexOAuth = vi.hoisted(() =>
|
||||
vi.fn<() => Promise<OAuthCredentials | null>>(async () => null),
|
||||
);
|
||||
vi.mock("./openai-codex-oauth.js", () => ({
|
||||
loginOpenAICodexOAuth,
|
||||
}));
|
||||
@@ -123,6 +126,41 @@ describe("applyAuthChoice", () => {
|
||||
).resolves.toEqual({ config: {} });
|
||||
});
|
||||
|
||||
it("stores openai-codex OAuth with email profile id", async () => {
|
||||
await setupTempState();
|
||||
|
||||
loginOpenAICodexOAuth.mockResolvedValueOnce({
|
||||
email: "user@example.com",
|
||||
refresh: "refresh-token",
|
||||
access: "access-token",
|
||||
expires: Date.now() + 60_000,
|
||||
});
|
||||
|
||||
const prompter = createPrompter({});
|
||||
const runtime = createExitThrowingRuntime();
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "openai-codex",
|
||||
config: {},
|
||||
prompter,
|
||||
runtime,
|
||||
setDefaultModel: false,
|
||||
});
|
||||
|
||||
expect(result.config.auth?.profiles?.["openai-codex:user@example.com"]).toMatchObject({
|
||||
provider: "openai-codex",
|
||||
mode: "oauth",
|
||||
});
|
||||
expect(result.config.auth?.profiles?.["openai-codex:default"]).toBeUndefined();
|
||||
expect(await readAuthProfile("openai-codex:user@example.com")).toMatchObject({
|
||||
type: "oauth",
|
||||
provider: "openai-codex",
|
||||
refresh: "refresh-token",
|
||||
access: "access-token",
|
||||
email: "user@example.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("prompts and writes MiniMax API key when selecting minimax-api", async () => {
|
||||
await setupTempState();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user