guardedMode.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. getZCodeAgentAvailableModes,
  4. getZCodeAgentModeSelectOptions,
  5. normalizeAvailableZCodeMode,
  6. } from "../src/zcode-agent-model-state.js";
  7. import { submissionModeSchema } from "../src/zcode-protocol-v4/submission.js";
  8. import { zcodeSessionModeSchema } from "../src/zcode-protocol-legacy-types.js";
  9. import { executionStateSchema, resolveExecutionState } from "../src/execution-state.js";
  10. describe("guarded wire and mode catalog", () => {
  11. it("uses autonomous display copy without renaming the guarded value", () => {
  12. const copy = { name: "Autonomous mode", description: "Ask when there’s risk" };
  13. expect(getZCodeAgentAvailableModes().find((mode) => mode.id === "guarded")).toEqual({
  14. id: "guarded",
  15. ...copy,
  16. });
  17. expect(getZCodeAgentModeSelectOptions().find((option) => option.value === "guarded")).toEqual({
  18. value: "guarded",
  19. ...copy,
  20. });
  21. });
  22. it("preserves guarded across independent Plan transitions and serialization", () => {
  23. const current = resolveExecutionState({ mode: "guarded", planEnabled: true });
  24. expect(executionStateSchema.parse(current)).toEqual({ mode: "guarded", planEnabled: true });
  25. expect(resolveExecutionState({ planEnabled: false }, current)).toEqual({
  26. mode: "guarded",
  27. planEnabled: false,
  28. });
  29. });
  30. it("round trips the opt-in value without changing the default", () => {
  31. expect(submissionModeSchema.parse("guarded")).toBe("guarded");
  32. expect(zcodeSessionModeSchema.parse("guarded")).toBe("guarded");
  33. expect(normalizeAvailableZCodeMode("guarded")).toBe("guarded");
  34. const ids = getZCodeAgentAvailableModes().map((mode) => mode.id);
  35. expect(ids[0]).toBe("build");
  36. expect(ids).toContain("guarded");
  37. expect(ids).toEqual(["build", "guarded", "plan", "yolo"]);
  38. expect(getZCodeAgentModeSelectOptions().map((option) => option.value)).toEqual(ids);
  39. expect(submissionModeSchema.safeParse("unknown").success).toBe(false);
  40. });
  41. it("keeps historical edit valid without advertising it as a new choice", () => {
  42. expect(submissionModeSchema.parse("edit")).toBe("edit");
  43. expect(zcodeSessionModeSchema.parse("edit")).toBe("edit");
  44. expect(normalizeAvailableZCodeMode("edit")).toBe("edit");
  45. expect(getZCodeAgentAvailableModes().some((mode) => mode.id === "edit")).toBe(false);
  46. });
  47. });