The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { classifyEndpointResponse, classifyTransportFailure } from "./endpointFailure.ts"; |
| 4 | |
| 5 | describe("classifyEndpointResponse", () => { |
| 6 | it.each([ |
| 7 | [530, "error code: 1033", "tunnel_down"], |
| 8 | [530, "", "tunnel_down"], |
| 9 | [530, "error code: 1016", "dns"], |
| 10 | [502, "Bad Gateway", "origin_unreachable"], |
| 11 | [503, "", "origin_unreachable"], |
| 12 | [521, "error code: 521", "refused"], |
| 13 | [524, "", "timeout"], |
| 14 | [526, "", "tls"], |
| 15 | [404, "Not Found", "invalid_response"], |
| 16 | [200, "<html>", "invalid_response"], |
| 17 | ] as const)("maps HTTP %i with body %j to %s", (status, body, expected) => { |
| 18 | expect(classifyEndpointResponse(status, body)).toBe(expected); |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | describe("classifyTransportFailure", () => { |
| 23 | const nested = (code: string) => |
| 24 | new TypeError("fetch failed", { cause: Object.assign(new Error(code), { code }) }); |
| 25 | |
| 26 | it.each([ |
| 27 | ["ENOTFOUND", "dns"], |
| 28 | ["ECONNREFUSED", "refused"], |
| 29 | ["UNABLE_TO_VERIFY_LEAF_SIGNATURE: certificate", "tls"], |
| 30 | ["UND_ERR_CONNECT_TIMEOUT", "timeout"], |
| 31 | ["ECONNRESET", "unknown"], |
| 32 | ] as const)("reads %s from the cause chain", (code, expected) => { |
| 33 | expect(classifyTransportFailure(nested(code))).toBe(expected); |
| 34 | }); |
| 35 | }); |