// author: simon-pierre boucher import { describe, expect, it } from "vitest"; import { shouldEscalate } from "./escalate.js"; const goodHtml = "Article" + "

Heading

" + "

" + "Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod. ".repeat(20) + "

" + 'next'; describe("shouldEscalate", () => { it("proceeds on a healthy article page", () => { expect(shouldEscalate({ status: 200, contentType: "text/html", body: goodHtml })).toEqual({ action: "proceed", }); }); it("routes non-HTML content to ยง9 without escalating", () => { const d = shouldEscalate({ status: 200, contentType: "application/pdf", body: "%PDF-1.7" }); expect(d.action).toBe("non-html"); }); it("escalates on 403/429/503 (decisive)", () => { for (const status of [403, 429, 503]) { const d = shouldEscalate({ status, contentType: "text/html", body: goodHtml }); expect(d.action).toBe("escalate"); if (d.action === "escalate") expect(d.reason).toContain(`status:${status}`); } }); it("escalates on a Cloudflare challenge title (decisive)", () => { const d = shouldEscalate({ status: 200, contentType: "text/html", body: "Just a moment...", }); expect(d.action).toBe("escalate"); if (d.action === "escalate") expect(d.reason).toContain("challenge-title"); }); it("escalates on known challenge markers (decisive)", () => { const d = shouldEscalate({ status: 200, contentType: "text/html", body: `${goodHtml}`, }); expect(d.action).toBe("escalate"); if (d.action === "escalate") expect(d.reason).toContain("challenge:datadome"); }); it("escalates on an empty SPA root under 2KB (decisive)", () => { const d = shouldEscalate({ status: 200, contentType: "text/html", body: '
', }); expect(d.action).toBe("escalate"); if (d.action === "escalate") expect(d.reason).toContain("empty-spa-root"); }); it("does not escalate on a single strong signal alone", () => { const body = `${goodHtml}`; const d = shouldEscalate({ status: 200, contentType: "text/html", body }); expect(d.action).toBe("proceed"); }); it("escalates on two weak signals together", () => { const filler = "x".repeat(11_000); const body = ``; const d = shouldEscalate({ status: 200, contentType: "text/html", body }); expect(d.action).toBe("escalate"); }); });