diff --git a/src/browser/control-auth.auto-token.test.ts b/src/browser/control-auth.auto-token.test.ts index 41107b2cbf..3fa03df89d 100644 --- a/src/browser/control-auth.auto-token.test.ts +++ b/src/browser/control-auth.auto-token.test.ts @@ -18,6 +18,22 @@ vi.mock("../config/config.js", async (importOriginal) => { import { ensureBrowserControlAuth } from "./control-auth.js"; describe("ensureBrowserControlAuth", () => { + const expectExplicitModeSkipsAutoAuth = async (mode: "password" | "none") => { + const cfg: OpenClawConfig = { + gateway: { + auth: { mode }, + }, + browser: { + enabled: true, + }, + }; + + const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv }); + expect(result).toEqual({ auth: {} }); + expect(mocks.loadConfig).not.toHaveBeenCalled(); + expect(mocks.writeConfigFile).not.toHaveBeenCalled(); + }; + beforeEach(() => { vi.restoreAllMocks(); mocks.loadConfig.mockReset(); @@ -80,41 +96,11 @@ describe("ensureBrowserControlAuth", () => { }); it("respects explicit password mode", async () => { - const cfg: OpenClawConfig = { - gateway: { - auth: { - mode: "password", - }, - }, - browser: { - enabled: true, - }, - }; - - const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv }); - - expect(result).toEqual({ auth: {} }); - expect(mocks.loadConfig).not.toHaveBeenCalled(); - expect(mocks.writeConfigFile).not.toHaveBeenCalled(); + await expectExplicitModeSkipsAutoAuth("password"); }); it("respects explicit none mode", async () => { - const cfg: OpenClawConfig = { - gateway: { - auth: { - mode: "none", - }, - }, - browser: { - enabled: true, - }, - }; - - const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv }); - - expect(result).toEqual({ auth: {} }); - expect(mocks.loadConfig).not.toHaveBeenCalled(); - expect(mocks.writeConfigFile).not.toHaveBeenCalled(); + await expectExplicitModeSkipsAutoAuth("none"); }); it("reuses auth from latest config snapshot", async () => {