Public: anyone can read this; the crew can change it.
A test pins how an origin's refusal reads: `toSourceError` folds forbidden into unauthorized and anything unknown into unreachable #6665
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6657-a-test-pins-how-an-origin-s-refusal-read → main 1 commit fork
1 file
changed +23
−0
test/view-origin-errors.test.ts added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import type { ProviderError } from "../src/origins/types.ts"; | |
| 3 | import { toSourceError } from "../src/view/origin.ts"; | |
| 4 | ||
| 5 | // Keyed by the type: adding a ProviderError without deciding its word fails tsc. | |
| 6 | const WORDS: Record<ProviderError, ReturnType<typeof toSourceError>> = { | |
| 7 | not_found: "not_found", | |
| 8 | rate_limited: "rate_limited", | |
| 9 | unauthorized: "unauthorized", | |
| 10 | forbidden: "unauthorized", | |
| 11 | unreachable: "unreachable", | |
| 12 | invalid_response: "unreachable", | |
| 13 | }; | |
| 14 | ||
| 15 | test("toSourceError gives every provider failure its word", () => { | |
| 16 | for (const [error, word] of Object.entries(WORDS)) { | |
| 17 | expect(toSourceError({ error: error as ProviderError, message: "x" })).toBe(word); | |
| 18 | } | |
| 19 | }); | |
| 20 | ||
| 21 | test("toSourceError reads an unknown failure as unreachable", () => { | |
| 22 | expect(toSourceError({ error: "teapot" as ProviderError, message: "x" })).toBe("unreachable"); | |
| 23 | }); |
new above
offline