Spaces:
Configuration error
Configuration error
File size: 2,485 Bytes
059f0de 53f8186 059f0de 53f8186 059f0de 6b71b4b 059f0de 6b71b4b 059f0de 6b71b4b 059f0de 6b71b4b 059f0de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import { chromium } from "@playwright/test";
import { existsSync } from "node:fs";
const baseUrl = process.argv[2] || "http://localhost:5173/?mode=mock&device=wasm";
const executablePath = process.env.CHROMIUM_PATH || (existsSync("/usr/bin/google-chrome") ? "/usr/bin/google-chrome" : "/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.waitForFunction(() => document.querySelector("#status")?.textContent === "Ready");
await page.click("#send");
await page.waitForFunction(() => document.querySelector("#status")?.textContent === "Agent running", null, {
timeout: 120000,
});
await page.waitForFunction(() => window.__piWebAgent?.transcript?.includes("pi sandbox result: 42"), null, {
timeout: 120000,
});
await page.waitForFunction(() => document.querySelector("#status")?.textContent === "Ready");
const transcript = await page.evaluate(() => window.__piWebAgent?.transcript || "");
const chatText = await page.textContent("#chat");
const files = await page.textContent("#files");
const events = await page.textContent("#event-log");
if (!transcript.includes("pi sandbox result: 42") || !chatText?.includes("pi sandbox result: 42")) {
throw new Error(`Expected command output in chat transcript.\n\nTranscript:\n${transcript}\n\nChat:\n${chatText}\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();
}
|