interactionAutoResolutionCommand.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, it, vi } from "vitest";
  2. import type { CommandEnvelope } from "@zcode/shared/zcode-protocol-v4";
  3. import { sendInteractionAutoResolutionSnooze } from "../src/v4/interactionAutoResolutionCommand.js";
  4. describe("sendInteractionAutoResolutionSnooze", () => {
  5. it("sends the shared idempotent command and settles the exact command id", async () => {
  6. let sentEnvelope: CommandEnvelope | null = null;
  7. const onCommandSettled = vi.fn();
  8. const accepted = await sendInteractionAutoResolutionSnooze({
  9. sessionId: "sess-ask",
  10. interactionId: "interaction-ask",
  11. source: "taskBadge",
  12. onCommandSettled,
  13. sendCommand: async (envelope) => {
  14. sentEnvelope = envelope;
  15. return {
  16. commandId: envelope.commandId,
  17. status: "accepted",
  18. revisionAtDecision: 12,
  19. };
  20. },
  21. });
  22. expect(accepted).toBe(true);
  23. expect(sentEnvelope).toMatchObject({
  24. sessionId: "sess-ask",
  25. type: "snoozeInteractionAutoResolution",
  26. payload: { interactionId: "interaction-ask" },
  27. });
  28. expect(onCommandSettled).toHaveBeenCalledWith(sentEnvelope?.commandId);
  29. });
  30. it("reports a rejected command as retryable failure", async () => {
  31. const accepted = await sendInteractionAutoResolutionSnooze({
  32. sessionId: "sess-ask",
  33. interactionId: "interaction-ask",
  34. source: "taskBadge",
  35. sendCommand: async (envelope) => ({
  36. commandId: envelope.commandId,
  37. status: "rejected",
  38. reasonCode: "proto.notFound",
  39. revisionAtDecision: 12,
  40. }),
  41. });
  42. expect(accepted).toBe(false);
  43. });
  44. });