import { describe, expect, it } from "bun:test"; import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings"; import type { ToolSession } from "@oh-my-pi/pi-coding-agent/sdk"; import { BrowserTool } from "@oh-my-pi/pi-coding-agent/tools/browser"; function makeSession(): ToolSession { return { cwd: "/tmp/test", hasUI: false, getSessionFile: () => null, getSessionSpawns: () => "*", settings: Settings.isolated({ "browser.headless": true }), }; } describe("browser tab evaluation", () => { it("runs tab.evaluate in the page's main JavaScript world", async () => { const tool = new BrowserTool(makeSession()); const name = `main-world-${process.pid}`; try { await tool.execute("open", { action: "open", name, url: "data:text/html,", }); const result = await tool.execute("run", { action: "run", name, code: "return await tab.evaluate(() => globalThis.__ompMainWorld);", }); expect(result.content).toEqual([{ type: "text", text: "42" }]); } finally { await tool.execute("close", { action: "close", name, kill: true }); } }); });