composerPermissionGrant.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, it } from "vitest";
  2. import { applyComposerPermissionGrant } from "../src/v4/composer/composerPermissionGrant.js";
  3. import { sortPermissionOptions } from "../src/lib/permissionRequest.js";
  4. describe("审批权限定向同步", () => {
  5. it("保留 Plan、正文和模型,同一授权不覆盖后来手动改选", () => {
  6. const draft = {
  7. text: "draft",
  8. updatedAt: 1,
  9. mode: "edit" as const,
  10. planEnabled: true,
  11. modelSelection: { providerId: "p", modelId: "m" },
  12. };
  13. const granted = applyComposerPermissionGrant(draft, { interactionId: "a" });
  14. expect(granted).toEqual({ ...draft, mode: "yolo", lastPermissionGrantId: "a" });
  15. const edited = { ...granted, mode: "build" as const };
  16. expect(applyComposerPermissionGrant(edited, { interactionId: "a" })).toBe(edited);
  17. expect(applyComposerPermissionGrant(edited, undefined)).toBe(edited);
  18. expect(applyComposerPermissionGrant(edited, { interactionId: "b" }).mode).toBe("yolo");
  19. });
  20. it("完全访问位于始终允许之后、拒绝之前,不靠序号决定 response", () => {
  21. const options = [
  22. { optionId: "deny", kind: "deny" },
  23. { optionId: "fullAccess", kind: "custom" },
  24. { optionId: "allowAlways", kind: "allow_always" },
  25. { optionId: "allowOnce", kind: "allow_once" },
  26. ].map((option) => ({
  27. ...option,
  28. name: option.optionId,
  29. response: { decision: "deny" as const },
  30. }));
  31. expect(sortPermissionOptions(options).map((option) => option.optionId)).toEqual([
  32. "allowOnce",
  33. "allowAlways",
  34. "fullAccess",
  35. "deny",
  36. ]);
  37. });
  38. });