Files
oh-my-pi/packages/coding-agent/test/tools/browser-aria-snapshot.test.ts
T
can1357 e649017322 feat(coding-agent): added ARIA snapshot support for browser tools
- Implemented `tab.ariaSnapshot()` to capture and represent page structures as ARIA-tree YAML.
- Introduced `tab.ref()` and ref-based selector parsing to enable precise element interaction via unique ARIA identifiers.
- Integrated automated script bundling for cross-environment evaluation of ARIA snapshot logic.
- Updated browser action methods to resolve and target elements using ARIA-ref handles.
2026-06-21 06:39:14 +02:00

49 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { buildAriaSnapshotScript, parseAriaRefSelector } from "@oh-my-pi/pi-coding-agent/tools/browser";
describe("parseAriaRefSelector", () => {
it("accepts the explicit aria-ref prefixes and returns the bare id", () => {
expect(parseAriaRefSelector("aria-ref=e5")).toBe("e5");
expect(parseAriaRefSelector("aria-ref/e12")).toBe("e12");
expect(parseAriaRefSelector("ariaref/e0")).toBe("e0");
expect(parseAriaRefSelector(" aria-ref=e7 ")).toBe("e7");
});
it("rejects a bare eN id so action selectors mean the same on both backends", () => {
// cmux already uses bare `eN`/`@eN` for its native observe refs; requiring
// the prefix keeps `tab.click("e5")` from meaning different things per backend.
expect(parseAriaRefSelector("e5")).toBeNull();
expect(parseAriaRefSelector("@e5")).toBeNull();
});
it("rejects css and other selectors", () => {
expect(parseAriaRefSelector("button#go")).toBeNull();
expect(parseAriaRefSelector("text/Submit")).toBeNull();
expect(parseAriaRefSelector("aria-ref=button")).toBeNull(); // not an eN id
expect(parseAriaRefSelector("aria-ref=")).toBeNull();
});
});
describe("buildAriaSnapshotScript", () => {
it("resolves a CSS root selector in-page and throws on miss", () => {
const script = buildAriaSnapshotScript("main .post");
expect(script).toContain('var __sel="main .post"');
expect(script).toContain("document.querySelector(__sel)");
expect(script).toContain("matched no element");
// The vendored bundle's entry is invoked against the resolved root.
expect(script).toContain("module.exports.ariaSnapshot(__root,");
});
it("defaults the root to the whole document when no selector is given", () => {
const script = buildAriaSnapshotScript(undefined);
expect(script).toContain("var __sel=null");
expect(script).toContain("module.exports.ariaSnapshot(__root,");
});
it("threads depth and boxes options into the request payload", () => {
const script = buildAriaSnapshotScript(undefined, { depth: 3, boxes: true });
expect(script).toContain('"depth":3');
expect(script).toContain('"boxes":true');
});
});