v4ConversationGoalSummaryModel.test.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, expect, it } from "vitest";
  2. import type { GoalState } from "@zcode/shared/zcode-protocol-v4";
  3. import {
  4. buildConversationGoalIterationSummaries,
  5. getConversationGoalElapsedSeconds,
  6. } from "@/v4/conversationGoalSummaryModel.js";
  7. function goal(overrides: Partial<GoalState> = {}): GoalState {
  8. return {
  9. targetId: "goal-1",
  10. objective: "完成摘要",
  11. summaryTitle: "第一轮 action",
  12. timeUsedSeconds: 5,
  13. activeRunStartedAtMs: null,
  14. status: "active",
  15. iteration: 1,
  16. verifications: [],
  17. iterations: [],
  18. ...overrides,
  19. };
  20. }
  21. describe("conversationGoalSummaryModel", () => {
  22. it("uses verifier nextAction for the next round and sorts completed rounds first", () => {
  23. const rows = buildConversationGoalIterationSummaries(
  24. goal({
  25. verifications: [
  26. {
  27. iteration: 1,
  28. outcome: "notSatisfied",
  29. at: 100,
  30. anchorRowId: null,
  31. nextAction: "第二轮 action",
  32. },
  33. ],
  34. iterations: [
  35. {
  36. iteration: 1,
  37. updatedAt: 100,
  38. items: [{ id: "1", content: "完成", status: "completed" }],
  39. },
  40. {
  41. iteration: 2,
  42. updatedAt: 200,
  43. items: [{ id: "2", content: "继续", status: "inProgress" }],
  44. },
  45. ],
  46. }),
  47. );
  48. expect(rows.map((row) => row.iteration)).toEqual([1, 2]);
  49. expect(rows[0]).toMatchObject({ title: "第一轮 action", completed: true });
  50. expect(rows[1]).toMatchObject({ title: "第二轮 action", completed: false });
  51. });
  52. it("keeps no-todo rounds visible and hides the internal verifier fallback action", () => {
  53. const rows = buildConversationGoalIterationSummaries(
  54. goal({
  55. verifications: [
  56. {
  57. iteration: 1,
  58. outcome: "notSatisfied",
  59. at: 100,
  60. anchorRowId: null,
  61. nextAction: "Continue verifying and completing the goal.",
  62. },
  63. ],
  64. }),
  65. );
  66. expect(rows).toHaveLength(2);
  67. expect(rows[1]).toMatchObject({ iteration: 2, title: null, totalCount: 0, completed: false });
  68. });
  69. it("adds only the active run delta and freezes paused/verified elapsed", () => {
  70. expect(
  71. getConversationGoalElapsedSeconds(
  72. goal({ activeRunStartedAtMs: 10_000, status: "active", timeUsedSeconds: 5 }),
  73. 13_900,
  74. ),
  75. ).toBe(8);
  76. expect(
  77. getConversationGoalElapsedSeconds(
  78. goal({ activeRunStartedAtMs: 10_000, status: "paused", timeUsedSeconds: 5 }),
  79. 99_000,
  80. ),
  81. ).toBe(5);
  82. expect(
  83. getConversationGoalElapsedSeconds(
  84. goal({ activeRunStartedAtMs: 20_000, status: "active", timeUsedSeconds: 5 }),
  85. 10_000,
  86. ),
  87. ).toBe(5);
  88. });
  89. });