mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 10:02:23 +00:00
fix(ai): skip cross-provider-handoff tests when no API keys available
Tests were throwing errors instead of skipping on CI where no API keys are configured. Now uses describe.skipIf() and it.skipIf() patterns consistent with other tests in the package.
This commit is contained in:
parent
2f4b510c12
commit
68352a42cf
1 changed files with 123 additions and 100 deletions
|
|
@ -116,6 +116,20 @@ async function getApiKey(provider: string): Promise<string | undefined> {
|
|||
return getEnvApiKey(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous check for API key availability (env vars only, for skipIf)
|
||||
*/
|
||||
function hasApiKey(provider: string): boolean {
|
||||
return !!getEnvApiKey(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any provider has API keys available (for skipIf at describe level)
|
||||
*/
|
||||
function hasAnyApiKey(): boolean {
|
||||
return PROVIDER_MODEL_PAIRS.some((pair) => hasApiKey(pair.provider));
|
||||
}
|
||||
|
||||
function dumpFailurePayload(params: { label: string; error: string; payload?: unknown; messages: Message[] }): void {
|
||||
const filename = `/tmp/pi-handoff-${params.label}-${Date.now()}.json`;
|
||||
const body = {
|
||||
|
|
@ -259,7 +273,7 @@ async function generateContext(
|
|||
};
|
||||
}
|
||||
|
||||
describe("Cross-Provider Handoff", () => {
|
||||
describe.skipIf(!hasAnyApiKey())("Cross-Provider Handoff", () => {
|
||||
let contexts: Record<string, CachedContext>;
|
||||
let availablePairs: ProviderModelPair[];
|
||||
|
||||
|
|
@ -272,14 +286,16 @@ describe("Cross-Provider Handoff", () => {
|
|||
for (const pair of PROVIDER_MODEL_PAIRS) {
|
||||
const apiKey = await getApiKey(pair.provider);
|
||||
if (!apiKey) {
|
||||
throw new Error(`Missing auth for ${pair.provider}`);
|
||||
console.log(`[${pair.label}] Skipping - no auth for ${pair.provider}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`[${pair.label}] Generating fixture...`);
|
||||
const result = await generateContext(pair, apiKey);
|
||||
|
||||
if (!result || result.messages.length < 4) {
|
||||
throw new Error(`Failed to generate fixture for ${pair.label}`);
|
||||
console.log(`[${pair.label}] Failed to generate fixture, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
contexts[pair.label] = {
|
||||
|
|
@ -297,15 +313,18 @@ describe("Cross-Provider Handoff", () => {
|
|||
console.log(`\n=== ${availablePairs.length}/${PROVIDER_MODEL_PAIRS.length} contexts available ===\n`);
|
||||
}, 300000);
|
||||
|
||||
it("should have at least 2 fixtures to test handoffs", () => {
|
||||
it.skipIf(!hasAnyApiKey())("should have at least 2 fixtures to test handoffs", () => {
|
||||
expect(Object.keys(contexts).length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
it("should handle cross-provider handoffs for each target", async () => {
|
||||
it.skipIf(!hasAnyApiKey())(
|
||||
"should handle cross-provider handoffs for each target",
|
||||
async () => {
|
||||
const contextLabels = Object.keys(contexts);
|
||||
|
||||
if (contextLabels.length < 2) {
|
||||
throw new Error("Not enough fixtures for handoff test");
|
||||
console.log("Not enough fixtures for handoff test, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("\n=== Testing Cross-Provider Handoffs ===\n");
|
||||
|
|
@ -350,7 +369,9 @@ describe("Cross-Provider Handoff", () => {
|
|||
continue;
|
||||
}
|
||||
|
||||
const model: Model<Api> = targetPair.apiOverride ? { ...baseModel, api: targetPair.apiOverride } : baseModel;
|
||||
const model: Model<Api> = targetPair.apiOverride
|
||||
? { ...baseModel, api: targetPair.apiOverride }
|
||||
: baseModel;
|
||||
const supportsReasoning = model.reasoning === true;
|
||||
|
||||
console.log(
|
||||
|
|
@ -419,5 +440,7 @@ describe("Cross-Provider Handoff", () => {
|
|||
}
|
||||
|
||||
expect(failures.length).toBe(0);
|
||||
}, 600000);
|
||||
},
|
||||
600000,
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue