import assert from "node:assert"; import { request as httpRequest } from "node:http"; import { describe, it } from "vitest"; import { MOCKUP_FULL_DOCUMENT_ERROR, type MockupRequest, renderMockupPage, startMockupServer, validateMockupRequest, } from "../mockup.ts"; import { previewDeviceScaleFactor, renderMockupPreviewPage, thinReplayFrames, } from "../mockup-preview.ts"; import { openerCandidates } from "../src/pi-ext-browser-open.ts"; const client = { userAgent: "mockup-test-browser/1", viewport: { width: 1280, height: 720, devicePixelRatio: 1 }, }; const baseRequest: MockupRequest = { title: "Pick layout", question: "Which option works?", options: [ { id: "a", label: "A", description: "First direction", html: "

A

", }, ], }; describe("mockup validation", () => { it("rejects full HTML documents with an agent-facing fix", () => { for (const html of [ "", "full", ]) { assert.throws( () => validateMockupRequest({ ...baseRequest, options: [{ id: "full", label: "Full", html }], }), (error) => { assert.ok(error instanceof Error); assert.strictEqual( error.message, MOCKUP_FULL_DOCUMENT_ERROR("options[0].html"), ); return true; }, ); } }); it("allows scripts and styles inside HTML fragments", () => { const request = validateMockupRequest({ ...baseRequest, options: [ { ...baseRequest.options[0], html: '
', }, ], }); assert.match( request.options[0].html, /
Card
", }, ], }, "tok", ); const fragmentMarkup = html.slice( html.indexOf('
/, ); assert.doesNotMatch(fragmentMarkup, /