runtime-config-plan-mode.test.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import { createRuntimeSessionModePort } from "../src/runtime/session-mode-port.js";
  3. import { updateConfig } from "../src/runtime/methods/config.js";
  4. import type { AgentRuntimeInternal } from "../src/runtime/internal.js";
  5. // 旧 mode=plan 只在兼容入口拆分;新输入的权限与 Plan 可以分别变化。
  6. describe("updateConfig independent Plan", () => {
  7. it.each(["build", "edit", "guarded", "yolo"] as const)("进入/退出 Plan 保留 %s 权限", (mode) => {
  8. const fixture = { config: { mode, planEnabled: false }, needsPlanModeExitReminder: false };
  9. const runtime = fixture as unknown as AgentRuntimeInternal;
  10. updateConfig.call(runtime, { mode: "plan" });
  11. expect(fixture.config).toEqual({ mode, planEnabled: true });
  12. updateConfig.call(runtime, { mode: "plan" });
  13. expect(fixture.config).toEqual({ mode, planEnabled: true });
  14. updateConfig.call(runtime, { planEnabled: false });
  15. expect(fixture.config).toEqual({ mode, planEnabled: false });
  16. expect(fixture.needsPlanModeExitReminder).toBe(true);
  17. });
  18. it("Guarded 的 Enter/Exit 工具只切换 Plan 标记", async () => {
  19. const runtime = {
  20. config: { mode: "guarded", planEnabled: false },
  21. createEvent: (type: unknown, payload: unknown) => ({ type, payload }),
  22. appendEvent: async () => undefined,
  23. } as unknown as AgentRuntimeInternal;
  24. const port = createRuntimeSessionModePort(runtime);
  25. expect(await port.enterPlanMode()).toMatchObject({ mode: "guarded", planEnabled: true });
  26. expect(await port.exitPlanMode()).toMatchObject({ mode: "guarded", planEnabled: false });
  27. });
  28. it("新提交明确携带 true,改变权限不退出规划", () => {
  29. const runtime = { config: { mode: "build", planEnabled: true } } as AgentRuntimeInternal;
  30. updateConfig.call(runtime, { mode: "yolo", planEnabled: true });
  31. expect(runtime.config).toMatchObject({ mode: "yolo", planEnabled: true });
  32. updateConfig.call(runtime, { mode: "edit" });
  33. expect(runtime.config).toMatchObject({ mode: "edit", planEnabled: false });
  34. });
  35. });