From c6eefd9f4d591eee71e82d21ba300219d45d9414 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 22:22:48 +0100 Subject: [PATCH] test: guard cron auth profile helper --- ...ted-agent.auth-profile-propagation.test.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cron/isolated-agent.auth-profile-propagation.test.ts b/src/cron/isolated-agent.auth-profile-propagation.test.ts index 200d299c25a..668f77d54d8 100644 --- a/src/cron/isolated-agent.auth-profile-propagation.test.ts +++ b/src/cron/isolated-agent.auth-profile-propagation.test.ts @@ -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"); });