channel-reply-permission.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, it } from "vitest";
  2. import { PermissionService } from "../src/permission/service.js";
  3. import { replyToChannelToolEntry } from "../src/tool/handlers/reply-to-channel.js";
  4. const capability = {
  5. ...replyToChannelToolEntry.metadata,
  6. permission: replyToChannelToolEntry.permission,
  7. };
  8. const context = {
  9. toolName: "ReplyToChannel",
  10. input: { parts: [{ type: "mention", refId: "m1" }] },
  11. riskLevel: "medium" as const,
  12. mode: "build" as const,
  13. };
  14. describe("channel reply permission", () => {
  15. it.each(["build", "edit", "plan", "yolo"] as const)("does not ask again in %s", (mode) => {
  16. expect(new PermissionService().checkPermission({ ...context, mode }, capability)).toMatchObject(
  17. { decision: "allow", sideEffectScope: "network" },
  18. );
  19. });
  20. it("does not exempt other network tools or an undeclared capability", () => {
  21. const service = new PermissionService();
  22. expect(
  23. service.checkPermission({ ...context, toolName: "OtherSender" }, capability).decision,
  24. ).toBe("ask");
  25. expect(
  26. service.checkPermission(context, { ...capability, permission: undefined }).decision,
  27. ).toBe("ask");
  28. });
  29. it.each(["deny", "ask"] as const)("preserves explicit project %s policy", (decision) => {
  30. expect(
  31. new PermissionService().checkPermission(context, capability, {
  32. version: 1,
  33. [decision]: [{ toolName: "ReplyToChannel" }],
  34. }).decision,
  35. ).toBe(decision);
  36. });
  37. });