test: guard cron auth profile helper

This commit is contained in:
Peter Steinberger
2026-05-11 22:22:48 +01:00
parent 3f75797de7
commit c6eefd9f4d

View File

@@ -17,6 +17,21 @@ vi.mock("../plugins/provider-runtime.js", () => ({
resolveExternalAuthProfilesWithPlugins: () => [],
}));
function getEmbeddedPiAgentParams(): {
authProfileId?: string;
authProfileIdSource?: string;
} {
const [call] = vi.mocked(runEmbeddedPiAgent).mock.calls;
if (!call) {
throw new Error("Expected embedded PI agent call for auth profile propagation");
}
const [params] = call;
if (typeof params !== "object" || params === null || Array.isArray(params)) {
throw new Error("Expected embedded PI agent params to be an object");
}
return params;
}
describe("runCronIsolatedAgentTurn auth profile propagation (#20624)", () => {
beforeEach(() => {
setupIsolatedAgentTurnMocks({ fast: true });
@@ -84,15 +99,7 @@ describe("runCronIsolatedAgentTurn auth profile propagation (#20624)", () => {
expect(vi.mocked(runEmbeddedPiAgent)).toHaveBeenCalledTimes(1);
// 5. Check that authProfileId was passed
const callArgs = vi.mocked(runEmbeddedPiAgent).mock.calls[0]?.[0] as
| {
authProfileId?: string;
authProfileIdSource?: string;
}
| undefined;
if (!callArgs) {
throw new Error("Expected embedded PI agent call for auth profile propagation");
}
const callArgs = getEmbeddedPiAgentParams();
expect(callArgs.authProfileId).toBe("openrouter:default");
});