From 5ffb9368737a14cb136ec861a080f78ec98b1ac7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 18:03:11 +0100 Subject: [PATCH] test: tighten auth profile runtime assertions --- .../auth-profile-runtime-contract.test.ts | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/agents/auth-profile-runtime-contract.test.ts b/src/agents/auth-profile-runtime-contract.test.ts index ad0b6b9b6d4..2ea42a0a06a 100644 --- a/src/agents/auth-profile-runtime-contract.test.ts +++ b/src/agents/auth-profile-runtime-contract.test.ts @@ -11,6 +11,7 @@ import type { SessionEntry } from "../config/sessions.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import type * as ManifestRegistryModule from "../plugins/manifest-registry.js"; import { runAgentAttempt } from "./command/attempt-execution.js"; +import type { RunEmbeddedPiAgentParams } from "./pi-embedded-runner/run/params.js"; import type { EmbeddedPiRunResult } from "./pi-embedded.js"; import { resolveProviderIdForAuth } from "./provider-auth-aliases.js"; @@ -68,6 +69,15 @@ vi.mock("./pi-embedded.js", () => ({ runEmbeddedPiAgent: runEmbeddedPiAgentMock, })); +function capturedEmbeddedRunParams(): RunEmbeddedPiAgentParams { + expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); + const call = runEmbeddedPiAgentMock.mock.calls[0]; + if (!call) { + throw new Error("expected runEmbeddedPiAgent to be called"); + } + return call[0] as RunEmbeddedPiAgentParams; +} + function makeCliResult(text: string): EmbeddedPiRunResult { return { payloads: [{ text }], @@ -377,10 +387,9 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - provider: AUTH_PROFILE_RUNTIME_CONTRACT.openAiProvider, - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiProfileId, - }); + const params = capturedEmbeddedRunParams(); + expect(params.provider).toBe(AUTH_PROFILE_RUNTIME_CONTRACT.openAiProvider); + expect(params.authProfileId).toBe(AUTH_PROFILE_RUNTIME_CONTRACT.openAiProfileId); }); it("forwards an OpenAI Codex auth profile through the default OpenAI Codex harness path", async () => { @@ -393,9 +402,9 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, - }); + expect(capturedEmbeddedRunParams().authProfileId).toBe( + AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, + ); }); it("routes explicit OpenAI PI runs with Codex OAuth through OpenAI Codex transport", async () => { @@ -409,10 +418,9 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - provider: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProvider, - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, - }); + const params = capturedEmbeddedRunParams(); + expect(params.provider).toBe(AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProvider); + expect(params.authProfileId).toBe(AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId); }); it("preserves OpenAI Codex auth profiles through the real codex/* harness startup path", async () => { @@ -426,9 +434,9 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, - }); + expect(capturedEmbeddedRunParams().authProfileId).toBe( + AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, + ); }); it("validates openai/* forced through the Codex harness can use OpenAI Codex OAuth profiles", async () => { @@ -442,9 +450,9 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, - }); + expect(capturedEmbeddedRunParams().authProfileId).toBe( + AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, + ); }); it("preserves configured Codex harness when a skeleton session entry is considered history", async () => { @@ -459,8 +467,8 @@ describe("Auth profile runtime contract - Pi and CLI adapter", () => { }); expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1); - expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]).toMatchObject({ - authProfileId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, - }); + expect(capturedEmbeddedRunParams().authProfileId).toBe( + AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProfileId, + ); }); });