input-intent-persistence.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, expect, it } from "vitest";
  2. import type { TurnInputIntentMetadata } from "@zcode/contracts";
  3. import { buildPersistedConversationInputIntent } from "../src/runtime/methods/input-intent-persistence.js";
  4. describe("persisted conversation input intent", () => {
  5. it.each(["build", "guarded", "yolo"] as const)(
  6. "persists %s with canonical goal text and queue intent",
  7. (mode) => {
  8. const intent: TurnInputIntentMetadata = {
  9. sourceCommandId: "command-goal",
  10. queueItemId: "queue-goal",
  11. clientId: "desktop-goal",
  12. kind: "sendGoalCommand",
  13. text: "X",
  14. admissionSeq: 3,
  15. admittedAt: 999,
  16. requestedDelivery: "queue",
  17. admittedDelivery: "queue",
  18. modelSelection: {
  19. providerId: "account:bigmodel-team-coding-plan",
  20. modelId: "GLM-5.3",
  21. options: { reasoningLevel: "high" },
  22. },
  23. mode,
  24. sharedContextRefs: [{ kind: "shared_context_import", context_id: "context-1" }],
  25. };
  26. expect(
  27. buildPersistedConversationInputIntent("/GoAl replace X", intent, "queued"),
  28. ).toMatchObject({
  29. kind: "sendGoalCommand",
  30. text: "X",
  31. modelSelection: intent.modelSelection,
  32. mode,
  33. sharedContextRefs: intent.sharedContextRefs,
  34. });
  35. },
  36. );
  37. it("persists retry provenance with the rebuilt command intent", () => {
  38. const intent: TurnInputIntentMetadata = {
  39. sourceCommandId: "command-retry",
  40. queueItemId: "queue-retry",
  41. clientId: "desktop-new",
  42. kind: "sendText",
  43. text: "original text",
  44. admissionSeq: 4,
  45. admittedAt: 1000,
  46. requestedDelivery: "guide",
  47. admittedDelivery: "queue",
  48. provenance: {
  49. sourceCommandId: "command-original",
  50. queueItemId: "queue-original",
  51. clientId: "desktop-original",
  52. },
  53. };
  54. expect(buildPersistedConversationInputIntent("original text", intent, "drained")).toMatchObject(
  55. {
  56. sourceCommandId: "command-retry",
  57. provenance: {
  58. sourceCommandId: "command-original",
  59. queueItemId: "queue-original",
  60. clientId: "desktop-original",
  61. },
  62. },
  63. );
  64. });
  65. });