import assert from "node:assert/strict"; import { existsSync, readFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { ROOT } from "../lib/common.ts"; import { runScene, type Scene } from "./runner.ts"; const scene = JSON.parse( readFileSync(join(ROOT, "extensions/clipboard/demo/scene.json"), "utf8"), ) as Scene; const negative = structuredClone(scene); negative.args = ["-e", "./missing-fixture.ts"]; // Even a broken preflight must have no route to the real desktop clipboard. negative.env = { PATH: "", WAYLAND_DISPLAY: "", DISPLAY: "", XDG_SESSION_TYPE: "", SSH_CONNECTION: "", SSH_CLIENT: "", MOSH_CONNECTION: "", PI_CLIPBOARD_OSC52: "0", }; let rejected = false; try { await runScene("clipboard", { assertOnly: true, scene: negative }); } catch { rejected = true; } assert(rejected, "missing clipboard fixture was accepted"); const sandbox = join(tmpdir(), "pi-demo-sandbox", "clipboard"); const transcript = readFileSync(join(sandbox, "transcript.txt"), "utf8"); assert( transcript.includes("missing-fixture.ts"), "failure did not identify the missing fixture", ); const reportPath = join(sandbox, "provider-report.json"); const report = existsSync(reportPath) ? (JSON.parse(readFileSync(reportPath, "utf8")) as { calls: number }) : { calls: 0 }; assert.equal( report.calls, 0, "fixture failure allowed model-driven clipboard execution", ); console.log( "OK clipboard: fixture-load failure rejected before model/tool input; desktop backend disabled in negative control", ); await runScene("clipboard", { assertOnly: true }); console.log( "OK clipboard: isolated fixture copied and read back the exact command", );