zcodeTimelineRuntime.test.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { describe, expect, it } from "vitest";
  2. import type { TaskChatMessage } from "@/lib/taskChatMessageTypes.js";
  3. import {
  4. hasRunningGoalContinuationMessage,
  5. hasRunningGoalRuntimeSignal,
  6. } from "@/lib/zcodeTimelineRuntime.js";
  7. describe("hasRunningGoalRuntimeSignal", () => {
  8. it("detects running goal verification timelines", () => {
  9. const message = {
  10. id: "goal-verification-started",
  11. role: "assistant",
  12. content: "",
  13. timestamp: 1,
  14. syntheticTimeline: {
  15. version: 1,
  16. kind: "synthetic",
  17. type: "goal_verification",
  18. display: "separator",
  19. targetId: "target-1",
  20. verificationId: "verification-1",
  21. status: "started",
  22. updatedAt: 1,
  23. },
  24. } satisfies TaskChatMessage;
  25. expect(hasRunningGoalRuntimeSignal([message])).toBe(true);
  26. });
  27. it("does not treat a started goal verification with a result as running", () => {
  28. const message = {
  29. id: "goal-verification-settled-started",
  30. role: "assistant",
  31. content: "",
  32. timestamp: 1,
  33. syntheticTimeline: {
  34. version: 1,
  35. kind: "synthetic",
  36. type: "goal_verification",
  37. display: "separator",
  38. targetId: "target-1",
  39. verificationId: "verification-1",
  40. status: "started",
  41. verification: {
  42. passed: true,
  43. reason: "目标已完成。",
  44. },
  45. updatedAt: 1,
  46. },
  47. } satisfies TaskChatMessage;
  48. expect(hasRunningGoalRuntimeSignal([message])).toBe(false);
  49. });
  50. it("detects goal continuation streaming boundaries without goalIteration", () => {
  51. const message = {
  52. id: "goal-continuation-stream",
  53. role: "assistant",
  54. content: "checkpoint 2",
  55. timestamp: 2,
  56. streaming: true,
  57. streamGroupId: "turn-goal-2",
  58. } satisfies TaskChatMessage;
  59. expect(hasRunningGoalContinuationMessage([message])).toBe(true);
  60. expect(hasRunningGoalRuntimeSignal([message])).toBe(true);
  61. });
  62. it("does not treat a normal streaming assistant as active goal runtime", () => {
  63. const message = {
  64. id: "normal-stream",
  65. role: "assistant",
  66. content: "正常回答",
  67. timestamp: 3,
  68. streaming: true,
  69. } satisfies TaskChatMessage;
  70. expect(hasRunningGoalRuntimeSignal([message])).toBe(false);
  71. });
  72. });