117 lines
3.6 KiB
JavaScript
117 lines
3.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
buildDialogInterventionResult,
|
|
createDialogSignature,
|
|
evaluateDialogSnapshot,
|
|
normalizeDialogSnapshot,
|
|
readDialogSnapshotFromEnv,
|
|
} from "../local-agent/desktop-dialog-guard.mjs";
|
|
|
|
test("dialog guard auto-handles safe welcome prompts on macOS and Windows", () => {
|
|
for (const platform of ["darwin", "win32"]) {
|
|
const decision = evaluateDialogSnapshot({
|
|
platform,
|
|
appName: platform === "darwin" ? "Google Chrome" : "Microsoft Edge",
|
|
title: "Welcome",
|
|
text: "Welcome. Not now",
|
|
buttons: ["Get started", "Not now"],
|
|
});
|
|
|
|
assert.equal(decision.disposition, "auto_action");
|
|
assert.equal(decision.action, "click_button");
|
|
assert.equal(decision.button, "Not now");
|
|
assert.equal(decision.risk, "low");
|
|
}
|
|
});
|
|
|
|
test("dialog guard pauses for sensitive permission prompts", () => {
|
|
const decision = evaluateDialogSnapshot({
|
|
platform: "darwin",
|
|
appName: "System Settings",
|
|
title: "Screen Recording",
|
|
text: "BossComputerUseHelper would like to record this computer's screen",
|
|
buttons: ["Allow", "Don't Allow"],
|
|
});
|
|
|
|
assert.equal(decision.disposition, "needs_user_action");
|
|
assert.equal(decision.risk, "high");
|
|
assert.equal(decision.kind, "permission_required");
|
|
});
|
|
|
|
test("dialog guard generates stable signatures from normalized content", () => {
|
|
const a = createDialogSignature({
|
|
platform: "darwin",
|
|
deviceId: "macbook-air",
|
|
appBundleId: "com.google.Chrome",
|
|
title: " Welcome ",
|
|
text: "Not now",
|
|
buttons: ["Not now", "OK"],
|
|
});
|
|
const b = createDialogSignature({
|
|
platform: "darwin",
|
|
deviceId: "macbook-air",
|
|
appBundleId: "com.google.Chrome",
|
|
title: "Welcome",
|
|
text: " Not now ",
|
|
buttons: ["Not now", "OK"],
|
|
});
|
|
|
|
assert.equal(a.id, b.id);
|
|
assert.equal(a.scopeKey, "darwin:macbook-air:com.google.Chrome");
|
|
});
|
|
|
|
test("dialog guard emits app-safe intervention payload", () => {
|
|
const snapshot = normalizeDialogSnapshot({
|
|
platform: "win32",
|
|
deviceId: "win-node",
|
|
appName: "Installer",
|
|
title: "User Account Control",
|
|
text: "Do you want to allow this app to make changes to your device?",
|
|
buttons: ["Yes", "No"],
|
|
});
|
|
const decision = evaluateDialogSnapshot(snapshot);
|
|
const result = buildDialogInterventionResult({
|
|
requestId: "desktop-task-1",
|
|
snapshot,
|
|
decision,
|
|
});
|
|
|
|
assert.equal(result.status, "needs_user_action");
|
|
assert.equal(result.kind, "dialog_intervention_required");
|
|
assert.equal(result.risk, "high");
|
|
assert.equal(result.recommendedAction, "handled_on_device");
|
|
assert.deepEqual(result.availableActions, ["handled_on_device", "cancel_task"]);
|
|
assert.match(result.summary, /Installer/);
|
|
});
|
|
|
|
test("dialog guard reads platform-specific macOS and Windows snapshots from env", () => {
|
|
const mac = readDialogSnapshotFromEnv(
|
|
{
|
|
BOSS_MAC_DIALOG_GUARD_SNAPSHOT_JSON: JSON.stringify({
|
|
appName: "System Settings",
|
|
title: "Accessibility",
|
|
text: "Accessibility permission",
|
|
buttons: ["Open Settings"],
|
|
}),
|
|
},
|
|
"darwin",
|
|
);
|
|
const windows = readDialogSnapshotFromEnv(
|
|
{
|
|
BOSS_WINDOWS_DIALOG_GUARD_SNAPSHOT_JSON: JSON.stringify({
|
|
appName: "Windows Security",
|
|
title: "User Account Control",
|
|
text: "Do you want to allow this app to make changes to your device?",
|
|
buttons: ["Yes", "No"],
|
|
}),
|
|
},
|
|
"win32",
|
|
);
|
|
|
|
assert.equal(mac.platform, "darwin");
|
|
assert.equal(mac.appName, "System Settings");
|
|
assert.equal(windows.platform, "win32");
|
|
assert.equal(windows.appName, "Windows Security");
|
|
});
|