test: cover unsafe qa missing-key providers

This commit is contained in:
Shakker
2026-04-08 21:27:26 +01:00
committed by Shakker
parent 705d2dd03e
commit 48c4003f22

View File

@@ -1089,6 +1089,44 @@ describe("runAgentTurnWithFallback", () => {
}
});
it("falls back to a generic provider message for unsafe missing-key provider ids", async () => {
state.runEmbeddedPiAgentMock.mockRejectedValueOnce(
new Error('No API key found for provider "openai`\nrm -rf /".'),
);
const runAgentTurnWithFallback = await getRunAgentTurnWithFallback();
const result = await runAgentTurnWithFallback({
commandBody: "hello",
followupRun: createFollowupRun(),
sessionCtx: {
Provider: "whatsapp",
MessageSid: "msg",
} as unknown as TemplateContext,
opts: {},
typingSignals: createMockTypingSignaler(),
blockReplyPipeline: null,
blockStreamingEnabled: false,
resolvedBlockStreamingBreak: "message_end",
applyReplyToMode: (payload) => payload,
shouldEmitToolResult: () => true,
shouldEmitToolOutput: () => false,
pendingToolTasks: new Set(),
resetSessionAfterCompactionFailure: async () => false,
resetSessionAfterRoleOrderingConflict: async () => false,
isHeartbeat: false,
sessionKey: "main",
getActiveSessionEntry: () => undefined,
resolvedVerboseLevel: "off",
});
expect(result.kind).toBe("final");
if (result.kind === "final") {
expect(result.payload.text).toBe(
"⚠️ Missing API key for the selected provider on the gateway. Configure provider auth, then try again.",
);
}
});
it("falls back to a generic reauth command when the provider in the OAuth error is unsafe", async () => {
state.runEmbeddedPiAgentMock.mockRejectedValueOnce(
new Error(