test(3p): pre-warm importFreshBetas in beforeAll to avoid 5s timeout

The first call to importFreshBetas() in this file triggered a 4.3s module
load (growthbook feature-flag init), which exceeded Bun's default 5s test
timeout. On the agent's local Windows machine, that race is close to
deterministic (the openai test, being first in source order, paid the
full cost and reported `(fail) this test timed out after 5000ms`). On CI
(Ubuntu) the import was usually fast enough to pass — but flaky, and
completely unrelated to actual test correctness.

Move the slow import to beforeAll so it happens once before any test
runs and is not charged to the first test's budget. After pre-warming,
every per-test import is sub-second (the 579ms / 8ms timings in the
last run confirm this). All 21 tests in the betas+compact pair now pass
deterministically.

This is the only remaining source-order flake in this file. The actual
test logic (provider-gate assertions, env-var isolation, cache-busting
imports) was already correct.
This commit is contained in:
adityachaudhary99
2026-06-13 02:44:22 +05:30
parent 77389de44b
commit 5095f76985
+11 -1
View File
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, expect, mock, test } from 'bun:test'
import { afterEach, beforeAll, beforeEach, expect, mock, test } from 'bun:test'
import {
acquireSharedMutationLock,
releaseSharedMutationLock,
@@ -92,6 +92,16 @@ async function importFreshBetas() {
return import(`./betas.js?ts=${Date.now()}-${Math.random()}`)
}
// Pre-warm the import in beforeAll so the first test does not pay the full
// module-load cost (growthbook feature-flag init takes ~4s on first import).
// The first importFreshBetas() in any test would otherwise burn the 5s default
// test timeout, and the cache-busting query string ensures every subsequent
// call is a real fresh import. After pre-warming, the per-test import is
// sub-second and well under the 5s budget.
beforeAll(async () => {
await importFreshBetas()
})
const MODEL = 'claude-sonnet-4-5'
// --- getMergedBetas: non-Anthropic providers return [] ---