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 { 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: "",
},
],
};
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,
/",
},
],
},
"tok",
);
const fragmentMarkup = html.slice(
html.indexOf('/,
);
assert.doesNotMatch(fragmentMarkup, /