import { readFileSync } from "node:fs"; import { runInNewContext } from "node:vm"; import { describe, expect, it } from "vitest"; import { openScreenCapability, SCREEN_PROXY_TTL_MS, sealScreenCapability, } from "./screen-capability.js"; const scope = { botId: "bot", computerId: "computer", botGeneration: 2, computerGeneration: 3, controlLeaseId: null, }; const path = (url: string, interactive = false) => new URL( sealScreenCapability( `${url}?token=fake-provider-token&view_only=${!interactive}`, "fake-secret", "https://app.example", scope, 100, ), ).pathname; describe("sealed screen capabilities", () => { it.each([false, true])( "connects the shipped embed through one capability prefix (control=%s)", (interactive) => { const provider = new URL("http://127.0.0.1:49152/embed.html"); provider.searchParams.set("view_only", String(!interactive)); provider.searchParams.set("path", "websockify?token=fake-socket-token"); const url = new URL( sealScreenCapability(provider.toString(), "fake-secret", "https://app.example", scope, 100), ); const html = readFileSync( new URL("../../../../infra/sandboxes/computer/embed.html", import.meta.url), "utf8", ); const script = html .match(/