test(vercel-gateway): pin every retryable status and the refused-credential case

This commit is contained in:
Resham Joshi 2026-11-06 06:02:08 -08:00
parent dbb90d6e61
commit 1692778bb5

View file

@ -186,6 +186,38 @@ describe('vercel-gateway end-to-end (parseAllSessions network path)', () => {
expect(entry?.retryableFailures).toBe(3)
})
it.each([408, 409, 425, 429, 500, 503])('keeps the cached report on HTTP %i', async (status) => {
const day = new Date(Date.now() - 15 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)
globalThis.fetch = vi.fn(async () => ({
ok: true,
json: async () => ({ results: [{ day, model: 'openai/gpt-4o', total_cost: 12.34, input_tokens: 1000, output_tokens: 500 }] }),
})) as typeof fetch
const range = getDashboardScanRange('week', null, null)
const total = async () => {
clearSessionCache()
return (await parseAllSessions(range, 'vercel-gateway')).reduce((sum, p) => sum + p.totalCostUSD, 0)
}
expect(await total()).toBeCloseTo(12.34, 2)
vi.spyOn(process.stderr, 'write').mockImplementation(() => true)
globalThis.fetch = vi.fn(async () => ({ ok: false, status, text: async () => '' })) as unknown as typeof fetch
expect(await total()).toBeCloseTo(12.34, 2)
})
it('reads a refused credential (HTTP 403) as no report', async () => {
const day = new Date(Date.now() - 15 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)
globalThis.fetch = vi.fn(async () => ({
ok: true,
json: async () => ({ results: [{ day, model: 'openai/gpt-4o', total_cost: 12.34, input_tokens: 1000, output_tokens: 500 }] }),
})) as typeof fetch
const range = getDashboardScanRange('week', null, null)
clearSessionCache()
await parseAllSessions(range, 'vercel-gateway')
vi.spyOn(process.stderr, 'write').mockImplementation(() => true)
globalThis.fetch = vi.fn(async () => ({ ok: false, status: 403, text: async () => '' })) as unknown as typeof fetch
clearSessionCache()
expect((await parseAllSessions(range, 'vercel-gateway')).reduce((sum, p) => sum + p.totalCostUSD, 0)).toBe(0)
})
it('emits no gateway rows at all without a credential', async () => {
delete process.env.AI_GATEWAY_API_KEY
delete process.env.VERCEL_OIDC_TOKEN