test: tighten auth profile runtime assertions

This commit is contained in:
Peter Steinberger
2026-05-09 18:03:11 +01:00
parent 5d452e8179
commit 5ffb936873

View File

@@ -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,
);
});
});