// @vitest-environment node import { describe, expect, it, vi } from "vitest"; import { pauseForOperatorCheckpoint } from "../tests/e2e/utils/operator-checkpoint"; function checkpointContext(headless?: boolean) { return { project: { use: { headless } }, annotations: [] as Array<{ type: string; description?: string }>, }; } describe("P26c operator checkpoint", () => { it("is a no-op unless explicitly enabled", async () => { const page = { pause: vi.fn() }; const testInfo = checkpointContext(); await expect(pauseForOperatorCheckpoint(page, testInfo, "domain-ownership-txt", {})).resolves.toBe(false); await expect(pauseForOperatorCheckpoint(page, testInfo, "domain-ownership-txt", { E2E_OPERATOR_CHECKPOINTS: "0" })).resolves.toBe(false); expect(page.pause).not.toHaveBeenCalled(); expect(testInfo.annotations).toEqual([]); }); it("pauses only in an explicitly enabled local headed run", async () => { const page = { pause: vi.fn().mockResolvedValue(undefined) }; const testInfo = checkpointContext(false); await expect(pauseForOperatorCheckpoint(page, testInfo, "starter-addon-checkout", { E2E_OPERATOR_CHECKPOINTS: "1" })).resolves.toBe(true); expect(page.pause).toHaveBeenCalledOnce(); expect(testInfo.annotations).toEqual([{ type: "operator-checkpoint", description: "starter-addon-checkout" }]); }); it("fails closed for CI, headless runs, and invalid values", async () => { const page = { pause: vi.fn() }; await expect( pauseForOperatorCheckpoint(page, checkpointContext(false), "domain-setup-checkout", { E2E_OPERATOR_CHECKPOINTS: "1", CI: "1", }) ).rejects.toThrow("forbidden in CI"); await expect(pauseForOperatorCheckpoint(page, checkpointContext(true), "domain-setup-checkout", { E2E_OPERATOR_CHECKPOINTS: "1" })).rejects.toThrow( "requires a headed Playwright run" ); await expect(pauseForOperatorCheckpoint(page, checkpointContext(undefined), "domain-setup-checkout", { E2E_OPERATOR_CHECKPOINTS: "1" })).rejects.toThrow( "requires a headed Playwright run" ); await expect(pauseForOperatorCheckpoint(page, checkpointContext(false), "domain-setup-checkout", { E2E_OPERATOR_CHECKPOINTS: "yes" })).rejects.toThrow( "must be unset, 0, or 1" ); expect(page.pause).not.toHaveBeenCalled(); }); });