From 4866332b91a446898b5cecc00bb75be7720f3a50 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Fri, 21 Aug 2026 02:21:31 -0700 Subject: [PATCH 1/2] test: price off the bundled snapshot so upstream reprices can't turn tests red loadPricing() fetched the live LiteLLM table during tests and live data wins over the bundled snapshot, so DeepSeek v4 assertions went red when upstream dropped the off-peak discount. CODEBURN_PRICING_SNAPSHOT_ONLY skips the fetch; env-isolation sets it for the whole suite. --- src/models.ts | 25 +++++++++++++++++-------- tests/setup/env-isolation.ts | 4 ++++ 2 files changed, 21 insertions(+), 8 deletions(-) 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 From 577ff0b9eeded4b19b632e5038b7e20a2d80aa88 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Fri, 21 Aug 2026 02:23:41 -0700 Subject: [PATCH 2/2] test: skip the live Frankfurter fetch so FX moves can't shift assertions Mirrors the pricing guard: CODEBURN_FX_NO_FETCH short-circuits getExchangeRate after the cache read and before the fetch, returning the same USD-equivalent rate an unreachable network already yields. Tests that seed their own exchange-rate.json (serve-stdio's EUR case) keep working unchanged. --- src/currency.ts | 5 +++++ tests/setup/env-isolation.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/currency.ts b/src/currency.ts index 1e9fae1d..f084546a 100644 --- a/src/currency.ts +++ b/src/currency.ts @@ -114,6 +114,11 @@ async function getExchangeRate(code: string): Promise { const cached = await loadCachedRate(code) if (cached) return cached + // Test-only escape hatch, set for the whole suite in + // tests/setup/env-isolation.ts: skip the live Frankfurter fetch so a real FX + // move can't shift assertions. Same fallback an unreachable network gets. + if (process.env['CODEBURN_FX_NO_FETCH']) return 1 + let rate: number try { rate = await fetchRate(code) diff --git a/tests/setup/env-isolation.ts b/tests/setup/env-isolation.ts index 42f2aeba..6a3326ec 100644 --- a/tests/setup/env-isolation.ts +++ b/tests/setup/env-isolation.ts @@ -110,6 +110,9 @@ function applyIsolation(): void { // 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' + // Same for FX: skip the live Frankfurter fetch and fall back to the + // USD-equivalent rate unless a test seeds its own exchange-rate.json cache. + process.env['CODEBURN_FX_NO_FETCH'] = '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