import { chromium } from "@playwright/test"; const baseUrl = process.argv[2] || "http://localhost:5173/?mode=mock&device=wasm"; const executablePath = process.env.CHROMIUM_PATH || "/snap/bin/chromium"; const browser = await chromium.launch({ executablePath, headless: true, args: ["--no-sandbox", "--disable-dev-shm-usage"], }); try { const page = await browser.newPage(); page.setDefaultTimeout(90000); const consoleLines = []; page.on("console", (message) => { consoleLines.push(`${message.type()}: ${message.text()}`); }); page.on("pageerror", (error) => { consoleLines.push(`pageerror: ${error.stack || error.message}`); }); await page.goto(baseUrl, { waitUntil: "domcontentloaded" }); const isolated = await page.evaluate(() => globalThis.crossOriginIsolated); if (!isolated) { throw new Error("Page is not cross-origin isolated."); } await page.click("#boot-sandbox"); await page.waitForFunction(() => document.querySelector("#sandbox-status")?.textContent === "Sandbox ready"); await page.waitForFunction(() => document.querySelector("#files")?.textContent?.includes("hello.js")); await page.click("#run"); await page.waitForFunction(() => document.querySelector("#status")?.textContent === "Ready", null, { timeout: 120000, }); const transcript = await page.textContent("#transcript"); const files = await page.textContent("#files"); const events = await page.textContent("#event-log"); if (!transcript?.includes("pi sandbox result: 42")) { throw new Error(`Expected command output in transcript.\n\nTranscript:\n${transcript}\n\nEvents:\n${events}`); } if (!files?.includes("hello.js")) { throw new Error(`Expected hello.js in file listing.\n\nFiles:\n${files}`); } if (!events?.includes("run_command finished")) { throw new Error(`Expected pi tool execution events.\n\nEvents:\n${events}`); } console.log(JSON.stringify({ ok: true, isolated, transcript, files }, null, 2)); } catch (error) { console.error(error instanceof Error ? error.stack || error.message : String(error)); throw error; } finally { await browser.close(); }