import assert from "node:assert/strict"; import { test } from "node:test"; import { classifyClickRisk, isLowRiskClickable } from "../src/risk.js"; import type { ActionableElement } from "../src/types.js"; function element(overrides: Partial): ActionableElement { return { elementId: "el_test", stateId: "state_test", tag: "button", role: "button", accessibleName: "Open settings", text: "Open settings", label: null, placeholder: null, attributes: {}, bbox: { x: 0, y: 0, width: 100, height: 30 }, framePath: [], shadowPath: [], interactability: { visible: true, enabled: true, editable: false, receivesEvents: true }, locators: [], ...overrides, }; } test("risk classifier blocks destructive and submission terms", () => { assert.equal(classifyClickRisk(element({ accessibleName: "Delete account" })), "high"); assert.equal(classifyClickRisk(element({ accessibleName: "提交订单" })), "high"); assert.equal(classifyClickRisk(element({ attributes: { type: "submit" }, text: "Submit search" })), "high"); }); test("risk classifier treats editable controls as medium", () => { assert.equal(classifyClickRisk(element({ tag: "input", role: "textbox", accessibleName: "Query" })), "medium"); assert.equal(classifyClickRisk(element({ tag: "select", role: "combobox", accessibleName: "Segment" })), "medium"); }); test("default explorer only clicks low-risk visible clickable elements", () => { assert.equal(isLowRiskClickable(element({ accessibleName: "Open settings" })), true); assert.equal(isLowRiskClickable(element({ accessibleName: "Delete account" })), false); assert.equal(isLowRiskClickable(element({ interactability: { visible: true, enabled: false, editable: false, receivesEvents: true } })), false); });