evOo-local/packages/adapters/src/approval-ask.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

74 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildApprovalAskBlock } from "./approval-ask.js";
describe("buildApprovalAskBlock", () => {
it("binds the approval to its effect and redacts secrets", () => {
const block = buildApprovalAskBlock(
"effect-1",
"gmail_send_email",
{ to: "person@example.test", body: "token-secret" },
["token-secret"],
);
expect(block).toMatchObject({
kind: "ask",
approvalEffectId: "effect-1",
actions: [
{ id: "allow", label: "Allow once" },
{ id: "always", label: "Always allow this tool" },
{ id: "deny", label: "Deny" },
],
});
expect(JSON.stringify(block)).not.toContain("token-secret");
});
it("bounds model-controlled summaries and details", () => {
const block = buildApprovalAskBlock(
"effect-1",
"destination.write",
{ title: "t".repeat(1_000), body: "b".repeat(10_000) },
[],
);
expect(block.kind).toBe("ask");
if (block.kind !== "ask") throw new Error("expected ask block");
expect(block.text.length).toBeLessThanOrEqual(501);
expect(block.detail?.length).toBeLessThanOrEqual(4_001);
});
it("includes an optional review reason as the first detail line", () => {
const block = buildApprovalAskBlock(
"effect-1",
"gmail_send_email",
{ to: "person@example.test", subject: "Hi" },
[],
{ reviewReason: "Sends email outside the draft-only task." },
);
expect(block.kind).toBe("ask");
if (block.kind !== "ask") throw new Error("expected ask block");
expect(block.detail?.startsWith("Sends email outside the draft-only task.")).toBe(true);
expect(block.detail).toContain("to: person@example.test");
});
it("uses a one-time create or cancel choice for a new security boundary", () => {
const block = buildApprovalAskBlock(
"effect-1",
"create_space",
{ name: "Customer support" },
[],
);
expect(block).toMatchObject({
kind: "ask",
text: "Create space “Customer support”?",
actions: [
{ id: "allow", label: "Create space", outcome: "created" },
{ id: "deny", label: "Cancel", outcome: "cancelled" },
],
});
if (block.kind !== "ask") throw new Error("expected ask block");
expect(block.detail).toContain("stay separate from other spaces");
});
});