The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { EdgeSessionError } from "@alchemy.run/cloudflare/EdgeSession"; |
| 2 | import { isTransientEdgeSessionError } from "@alchemy.run/cloudflare/StateStore/State"; |
| 3 | import { describe, expect, it } from "@alchemy.run/test"; |
| 4 | |
| 5 | /** |
| 6 | * Predicate coverage for the edge-preview secret-read retry policy, added in |
| 7 | * response to production failures (Axiom `prod-traces`): reads failing with |
| 8 | * Cloudflare HTML error pages ("Secret probe returned 400/502: |
| 9 | * <!DOCTYPE html>..."), session creation flakes and transport errors |
| 10 | * ("fetch failed"). |
| 11 | */ |
| 12 | describe( |
| 13 | "isTransientEdgeSessionError", |
| 14 | { tags: ["unit", "provider:cloudflare", "provider:cloudflare:statestore", "local"] }, |
| 15 | () => { |
| 16 | it("retries non-200 secret-probe responses (Cloudflare HTML error pages)", () => { |
| 17 | const error = new EdgeSessionError({ |
| 18 | message: 'Secret probe returned 400: <!DOCTYPE html>\n<html class="no-', |
| 19 | }); |
| 20 | expect(isTransientEdgeSessionError(error)).toBe(true); |
| 21 | }); |
| 22 | |
| 23 | it("retries session-creation failures with transient causes", () => { |
| 24 | const error = new EdgeSessionError({ |
| 25 | message: "Failed to create edge preview session", |
| 26 | cause: new TypeError("fetch failed"), |
| 27 | }); |
| 28 | expect(isTransientEdgeSessionError(error)).toBe(true); |
| 29 | }); |
| 30 | |
| 31 | it("does not retry permanent auth causes", () => { |
| 32 | for (const tag of ["Unauthorized", "Forbidden", "InvalidRoute"]) { |
| 33 | const cause = Object.assign(new Error("denied"), { _tag: tag }); |
| 34 | const error = new EdgeSessionError({ |
| 35 | message: "Failed to create edge preview session", |
| 36 | cause, |
| 37 | }); |
| 38 | expect(isTransientEdgeSessionError(error)).toBe(false); |
| 39 | } |
| 40 | }); |
| 41 | |
| 42 | it("ignores non-EdgeSessionError values", () => { |
| 43 | expect(isTransientEdgeSessionError(new Error("boom"))).toBe(false); |
| 44 | }); |
| 45 | }, |
| 46 | ); |