import { createServer } from "node:http";
import { expect, test, type APIRequestContext } from "@playwright/test";
import { confirmContinuationPlan, type ContinuationApproval } from "./continuation-approval.js";
import type { ContinuationCheckpoint } from "./continuation-scoring.js";
async function fixture(request: APIRequestContext) {
const card: ContinuationApproval = { id: "current", issueId: "parent", kind: "request_confirmation", status: "pending",
resolverPolicy: "human_only", effectiveResolverPolicy: "human_only", continuationPolicy: "wake_assignee_on_accept",
payload: { acceptLabel: "Confirm", target: { type: "issue_document", issueId: "parent", key: "plan", revisionId: "revision-2" } } };
const documents = [{ key: "plan", body: "Revised plan", latestRevisionId: "revision-2" }];
const checkpoint: ContinuationCheckpoint = { phase: "revised", issue: { id: "parent", status: "in_review" },
children: [], comments: [], attachments: [], runs: [], documents: structuredClone(documents), interactions: [structuredClone(card)] };
const acceptedIds: string[] = [];
const server = createServer((req, res) => {
if (req.method === "GET" && req.url === "/api/issues/parent/interactions") {
res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify([card]));
} else if (req.method === "GET" && req.url === "/api/issues/parent/documents") {
res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(documents));
} else if (req.method === "POST" && req.url?.endsWith("/accept")) {
const id = req.url.split("/").at(-2)!;
acceptedIds.push(id);
if (id === card.id) Object.assign(card, { status: "accepted", result: { outcome: "accepted" },
resolvedByUserId: "fixture-user", resolvedByAgentId: null, resolvedAt: new Date().toISOString() });
res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(card));
} else {
res.writeHead(200, { "content-type": "text/html" });
res.end(` Approve revised plan