import assert from "node:assert/strict"; import test from "node:test"; import { CHROME_TOOL_NAMES, formatActionResultText, formatChromeFindMatches, snapshotStats, } from "../extensions/chrome-profile-bridge/index.ts"; test("formatActionResultText appends the inline snapshot JSON", () => { const snapshot = { elements: [{ uid: "el-1", role: "button", label: "Save" }], matches: [] }; const text = formatActionResultText("Clicked el-1", snapshot); const [summary, json] = text.split("\n\n"); assert.equal(summary, "Clicked el-1"); assert.deepEqual(JSON.parse(json), snapshot); }); test("formatActionResultText returns the summary alone without a snapshot", () => { assert.equal(formatActionResultText("Clicked el-1", undefined), "Clicked el-1"); }); test("snapshotStats stays small: only element and match counts", () => { assert.deepEqual( snapshotStats({ elements: [{ uid: "a" }, { uid: "b" }], matches: [{ uid: "a" }] }), { elementCount: 2, matchCount: 1 }, ); assert.deepEqual(snapshotStats({ elements: "nope" }), { elementCount: 0, matchCount: 0 }); assert.deepEqual(snapshotStats(undefined), { elementCount: 0, matchCount: 0 }); assert.deepEqual(snapshotStats([1, 2, 3]), { elementCount: 0, matchCount: 0 }); }); test("chrome_find formatting is capped and authorization tracks all 21 tools", () => { const matches = Array.from({ length: 25 }, (_, index) => ({ kind: "element", uid: `el-${index}`, role: "button", label: `Button ${index}`, rect: { x: index, y: index, width: 10, height: 10 }, })); const text = formatChromeFindMatches({ query: "button", matches }); assert.match(text, /el-0/); assert.match(text, /el-19/); assert.doesNotMatch(text, /el-20/); assert.equal(CHROME_TOOL_NAMES.length, 21); assert.ok(CHROME_TOOL_NAMES.includes("chrome_find")); assert.ok(CHROME_TOOL_NAMES.includes("chrome_inspect")); });