Files
2026-07-13 12:22:59 +08:00

39 lines
1.1 KiB
TypeScript

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,<script>globalThis.__ompMainWorld = 42</script>",
});
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 });
}
});
});