Identified failing test due to missing API keys.
UnderstandAdded helpers and skip logic for missing API keys.
EditConfirmed tests skip correctly without API keys.
VerifyCommitted and pushed the fix.
Cleanuphttps://github.com/badlogic/pi-mono/actions/runs/21142602255 build fails, figure it out and fix. no api keys on the ci, tests that require api keys should not run
The user wants me to investigate a failed GitHub Actions build. Let me first check the build logs to understand what's failing.
>gh run view 21142602255 --log-failed 2>&1 | head -200The issue is in test/cross-provider-handoff.test.ts in packages/ai. It's throwing an error "Missing auth for anthropic" because there's no API key available on CI. The test should skip when no API keys are available, not throw an error.
Let me look at that test file to understand how it's structured.
The failure is in packages/ai/test/cross-provider-handoff.test.ts - it throws Error: Missing auth for anthropic instead of skipping when no API keys are available. Let me look at the test:
The issue is in the beforeAll block. At line 273-275:
const apiKey = await getApiKey(pair.provider);if (!apiKey) { throw new Error(`Missing auth for ${pair.provider}`);}This throws an error when no API key is available instead of skipping. For CI without API keys, the test should skip entirely if no providers have keys available.
Looking at other tests in the same package that require API keys, they typically skip when keys aren't available. Let me check how other tests handle this:
The problem is in the beforeAll block (lines 273-275). It throws an error when no API key is found instead of skipping. Let me check how other tests handle this:
>grep -n "skipIf\|skip.*api\|runIf\|getEnvApiKey" packages/ai/test/*.ts | head -40I see. The pattern is to use describe.skipIf(!) or it.skipIf(!) to skip tests when API keys aren't available.
The cross-provider-handoff test needs to be fixed to skip when no API keys are available, rather than throwing an error in beforeAll.
The fix should:
Looking at the test structure, the cleanest approach would be:
Let me rewrite this properly.
The pattern is to use describe.skipIf() or it.skipIf() to skip tests when API keys aren't available. The cross-provider-handoff test needs to be fixed to filter providers without keys and skip if none are available:
Now I need to:
describe.skipIf(!hasAnyApiKey())Now I need to change the beforeAll to skip providers without API keys instead of throwing an error.
Now let me also update the test assertions to handle the case where there are fewer than 2 fixtures available. Currently it throws an error if there are less than 2 fixtures.
Now let me also fix the second test to skip properly and not throw when there are fewer than 2 fixtures.
Now let me run npm run check to verify everything is correct.
Now let me run the check to verify:
>cd packages/ai && npm run check 2>&1Need to run from root or check what scripts are available.
>cd /Users/badlogic/workspaces/pi-mono && npm run check 2>&1The check passes. Let me also run just the cross-provider-handoff test to make sure it skips properly without API keys. Actually, since I'm on a machine that may have API keys set, let me verify by checking if the tests pass in a way that will also work on CI.
Let me verify the test file looks correct by reading the relevant parts.
Check passes. Let me verify the test will skip correctly without API keys by temporarily testing it:
>cd packages/ai && ANTHROPIC_API_KEY= OPENAI_API_KEY= GEMINI_API_KEY= npm test -- --run test/cross-provider-handoff.test.ts 2>&1 | tail -30Oops, duplicated --run. Let me fix that.
>cd packages/ai && ANTHROPIC_API_KEY= OPENAI_API_KEY= GEMINI_API_KEY= npx vitest --run test/cross-provider-handoff.test.ts 2>&1 | tail -20Hmm, the test is not skipping because I have API keys in my environment (likely oauth tokens or other env vars). Let me unset more environment variables to simulate CI:
>cd packages/ai && env -i HOME="$HOME" PATH="$PATH" NODE_PATH="$NODE_PATH" npx vitest --run test/cross-provider-handoff.test.ts 2>&1 | tail -20The tests are properly skipped when no API keys are available. Let me now commit these changes.
Tests properly skip when no API keys are available. Let me commit:
>cd /Users/badlogic/workspaces/pi-mono && git add packages/ai/test/cross-provider-handoff.test.ts && git commit -m "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." && git pushDone. The fix has been committed and pushed. The changes:
hasApiKey() helper for synchronous API key checking (env vars only)hasAnyApiKey() to check if any provider has keys availabledescribe() to describe.skipIf(!hasAnyApiKey()) to skip the entire suite when no API keys existbeforeAll to log and continue instead of throw when a provider lacks authit.skipIf() and return early instead of throwingNow the tests will skip cleanly on CI where no API keys are configured.
Fixed and pushed. The changes:
hasApiKey() and hasAnyApiKey() helpers for synchronous API key checkingdescribe() to describe.skipIf(!hasAnyApiKey()) to skip the entire suite when no API keys are availablebeforeAll to skip providers without auth (using continue) instead of throwing errorsit.skipIf() patternThe tests now skip cleanly on CI without API keys, consistent with other tests in the package.
const apiKey = await getApiKey(pair.provider);if (!apiKey) { throw new Error(`Missing auth for ${pair.provider}`);}