diff --git a/src/models.ts b/src/models.ts index 50aa8098..7daa5f1b 100644 --- a/src/models.ts +++ b/src/models.ts @@ -225,21 +225,30 @@ function mergeSnapshotFallbacks(pricing: Map): Map): void { + pricingCache = pricing + sortedPricingKeys = null + lowercasePricingIndex = null + knownNamespaces = null +} + export async function loadPricing(): Promise { const cached = await loadCachedPricing() if (cached) { - pricingCache = mergeSnapshotFallbacks(cached) - sortedPricingKeys = null - lowercasePricingIndex = null - knownNamespaces = null + setPricingCache(mergeSnapshotFallbacks(cached)) + return + } + + // Test-only escape hatch, set for the whole suite in + // tests/setup/env-isolation.ts: skip the live LiteLLM fetch and price purely + // off the bundled snapshot, so an upstream reprice can't turn tests red. + if (process.env['CODEBURN_PRICING_SNAPSHOT_ONLY']) { + setPricingCache(mergeSnapshotFallbacks(new Map())) return } try { - pricingCache = mergeSnapshotFallbacks(await fetchAndCachePricing()) - sortedPricingKeys = null - lowercasePricingIndex = null - knownNamespaces = null + setPricingCache(mergeSnapshotFallbacks(await fetchAndCachePricing())) } catch { // snapshot already loaded at init; nothing more to do } diff --git a/tests/setup/env-isolation.ts b/tests/setup/env-isolation.ts index ea1c32a4..42f2aeba 100644 --- a/tests/setup/env-isolation.ts +++ b/tests/setup/env-isolation.ts @@ -106,6 +106,10 @@ function applyIsolation(): void { if (original === undefined) delete process.env[key] else process.env[key] = original } + // Price off the bundled LiteLLM snapshot only. Without this, loadPricing() + // fetches the live upstream table, so a mid-week reprice by a provider turns + // pricing assertions red with no local change. + process.env['CODEBURN_PRICING_SNAPSHOT_ONLY'] = '1' // Pin the timezone so date grouping is deterministic regardless of the dev's // shell TZ. Clearing it is not enough (Node falls back to the OS zone); a // non-UTC TZ would otherwise shift day buckets versus a clean CI runner. A