composerPlanTransition.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from "vitest";
  2. import { applyComposerPlanTransition } from "@/v4/composer/composerPlanTransition.js";
  3. describe("Plan 工具定向同步", () => {
  4. it("批准只关闭 Plan,权限、正文和模型不变;回放不重复应用", () => {
  5. const draft = { text: "next", mode: "yolo" as const, planEnabled: true, updatedAt: 0 };
  6. const next = applyComposerPlanTransition(draft, { toolCallId: "approve", planEnabled: false });
  7. expect(next).toMatchObject({ text: "next", mode: "yolo", planEnabled: false });
  8. expect(applyComposerPlanTransition(next, { toolCallId: "approve", planEnabled: false })).toBe(
  9. next,
  10. );
  11. });
  12. it.each([true, false])("新工具结果按 %s 设置标记,不保护期间的手动改选", (planEnabled) => {
  13. // 包含未上线初版留下的额外字段,不能再改变最新裁决的结果。
  14. const draft = {
  15. text: "下一条消息",
  16. mode: "yolo" as const,
  17. modelSelection: { providerId: "p", modelId: "m" },
  18. planEnabled: !planEnabled,
  19. ignoredPlanToolCallIds: ["transition"],
  20. updatedAt: 0,
  21. };
  22. expect(
  23. applyComposerPlanTransition(draft, { toolCallId: "transition", planEnabled }),
  24. ).toMatchObject({ ...draft, planEnabled, lastPlanTransitionId: "transition" });
  25. });
  26. it("批准已应用后,用户重新开启 Plan,相同结果的重复快照不再清除", () => {
  27. const transition = { toolCallId: "approve", planEnabled: false };
  28. const approved = applyComposerPlanTransition(
  29. { text: "", planEnabled: true, updatedAt: 0 },
  30. transition,
  31. );
  32. const edited = { ...approved, planEnabled: true };
  33. expect(applyComposerPlanTransition(edited, transition)).toBe(edited);
  34. });
  35. it("没有工具转换时,普通快照、拒绝和反馈不修改草稿", () => {
  36. const draft = { text: "", planEnabled: true, updatedAt: 0 };
  37. expect(applyComposerPlanTransition(draft, undefined)).toBe(draft);
  38. });
  39. });