off-peak-tool-policy.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import { updateOffPeakToolPolicy } from "../src/zcode-protocol/off-peak-tool-policy.js";
  3. import type { ZCodeProtocolAgentServerContext } from "../src/zcode-protocol/server-types.js";
  4. function makeContext() {
  5. return {
  6. appRuntimePreferences: {
  7. askUserQuestionAutoResolutionEnabled: true,
  8. modelIoFullRetentionEnabled: false,
  9. offPeakToolEnabled: false,
  10. },
  11. } as unknown as ZCodeProtocolAgentServerContext;
  12. }
  13. describe("workspace/updateOffPeakToolPolicy(D49 workspace 级工具面门禁)", () => {
  14. it("缓存 host 判定的门禁供后续 create/resume/v4 冷恢复读取,并回显结果", async () => {
  15. const context = makeContext();
  16. const workspace = { workspaceKey: "/w", workspacePath: "/w" };
  17. const result = await updateOffPeakToolPolicy(context, { workspace, enabled: true });
  18. expect(context.appRuntimePreferences.offPeakToolEnabled).toBe(true);
  19. expect(result).toEqual({ workspace, enabled: true });
  20. await updateOffPeakToolPolicy(context, { workspace, enabled: false });
  21. expect(context.appRuntimePreferences.offPeakToolEnabled).toBe(false);
  22. });
  23. it("strict schema 拒绝未知键(不让 host 误传 per-session 字段)", async () => {
  24. await expect(
  25. updateOffPeakToolPolicy(makeContext(), {
  26. workspace: { workspaceKey: "/w", workspacePath: "/w" },
  27. enabled: true,
  28. sessionId: "s1",
  29. }),
  30. ).rejects.toThrow();
  31. });
  32. });