|
1 | 1 | import { defined } from "../testkit/defined.js"; |
2 | 2 | import { describe, test, expect } from "bun:test"; |
3 | 3 | import { isAbsolute, join } from "node:path"; |
| 4 | +import { configureSync, getConfig, resetSync } from "@intx/log"; |
4 | 5 | import { |
5 | 6 | parseModelsDevContextWindows, |
6 | 7 | parseModelsDevPricing, |
@@ -259,6 +260,43 @@ describe("loadPricing", () => { |
259 | 260 |
|
260 | 261 | expect(result).toBeNull(); |
261 | 262 | }); |
| 263 | + |
| 264 | + test("emits a single debug line when refresh fails", async () => { |
| 265 | + const records: { level: string; text: string }[] = []; |
| 266 | + const previous = getConfig(); |
| 267 | + configureSync({ |
| 268 | + reset: true, |
| 269 | + sinks: { |
| 270 | + test: (record) => { |
| 271 | + records.push({ |
| 272 | + level: record.level, |
| 273 | + text: record.message.map(String).join(""), |
| 274 | + }); |
| 275 | + }, |
| 276 | + }, |
| 277 | + loggers: [{ category: [], lowestLevel: "debug", sinks: ["test"] }], |
| 278 | + }); |
| 279 | + try { |
| 280 | + const failingFetch = (async (): Promise<Response> => { |
| 281 | + throw new Error("network error"); |
| 282 | + }) as unknown as typeof fetch; |
| 283 | + const result = await loadPricing({ |
| 284 | + fetchImpl: failingFetch, |
| 285 | + cachePath: "/tmp/nonexistent-pricing-cache-debug.json", |
| 286 | + }); |
| 287 | + expect(result).toBeNull(); |
| 288 | + const hits = records.filter( |
| 289 | + (record) => |
| 290 | + record.level === "debug" && |
| 291 | + record.text.includes("pricing refresh failed"), |
| 292 | + ); |
| 293 | + expect(hits).toHaveLength(1); |
| 294 | + expect(hits[0]?.text).toContain("network error"); |
| 295 | + } finally { |
| 296 | + if (previous === null) resetSync(); |
| 297 | + else configureSync({ ...previous, reset: true }); |
| 298 | + } |
| 299 | + }); |
262 | 300 | }); |
263 | 301 |
|
264 | 302 | // --------------------------------------------------------------------------- |
|
0 commit comments