offPeakCreateTaskCard.test.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. describeOffPeakCardStatus,
  4. readOffPeakCreateTaskOutputSummary,
  5. } from "@/ToolCallBlocks/renderers/offpeak-create.js";
  6. import { resolveOffPeakDetailNavigation } from "@/settings/AutomationsSection.js";
  7. import type { ZCodeOffPeakTask } from "@zcode/shared";
  8. const intl = {
  9. formatMessage: (
  10. { id }: { id: string },
  11. values?: Record<string, string | number>,
  12. ) => (id === "offPeak.chatCreated.queuedAt" ? `排队第 ${values?.["position"]} 位` : id),
  13. };
  14. describe("OffPeakCreateTaskCard output(D49-6 静态轮尾卡)", () => {
  15. it("从工具输出解析最小任务快照(含 JSON 字符串候选)", () => {
  16. const task = readOffPeakCreateTaskOutputSummary(
  17. JSON.stringify({
  18. task: {
  19. offPeakTaskId: "offpeak-abc",
  20. title: "重构 utils",
  21. status: "queued",
  22. queuePosition: 3,
  23. createdAt: 1_700_000_000_000,
  24. },
  25. message: "Created idle-time task offpeak-abc (#3 in queue).",
  26. }),
  27. );
  28. expect(task).toMatchObject({
  29. offPeakTaskId: "offpeak-abc",
  30. title: "重构 utils",
  31. status: "queued",
  32. queuePosition: 3,
  33. });
  34. });
  35. it("缺 offPeakTaskId 视为无效输出(卡片必须能定位任务)", () => {
  36. expect(
  37. readOffPeakCreateTaskOutputSummary({ task: { title: "无 id", status: "queued" } }),
  38. ).toBeNull();
  39. });
  40. it("状态行:有位次显示创建时快照,无位次回退排队文案", () => {
  41. expect(
  42. describeOffPeakCardStatus({ offPeakTaskId: "offpeak-1", queuePosition: 3 }, intl),
  43. ).toBe("排队第 3 位");
  44. expect(describeOffPeakCardStatus({ offPeakTaskId: "offpeak-1" }, intl)).toBe(
  45. "offPeak.chatCreated.queued",
  46. );
  47. });
  48. });
  49. describe("resolveOffPeakDetailNavigation(卡片跳转 idle tab 编辑视图)", () => {
  50. const task = { offPeakTaskId: "offpeak-abc", title: "t" } as ZCodeOffPeakTask;
  51. it("store 加载中保持 pending(不消费导航、不误报 targetNotFound)", () => {
  52. expect(resolveOffPeakDetailNavigation([task], "offpeak-abc", false)).toEqual({
  53. status: "pending",
  54. });
  55. });
  56. it("命中返回 found 目标", () => {
  57. expect(resolveOffPeakDetailNavigation([task], "offpeak-abc", true)).toEqual({
  58. status: "found",
  59. target: task,
  60. });
  61. });
  62. it("任务已删除返回 missing", () => {
  63. expect(resolveOffPeakDetailNavigation([task], "offpeak-gone", true)).toEqual({
  64. status: "missing",
  65. });
  66. });
  67. it("刷新失败(store.error 非空)时返回 unavailable,不做 found/missing 终审(review CR-01)", () => {
  68. expect(resolveOffPeakDetailNavigation([], "offpeak-abc", true, "list failed")).toEqual({
  69. status: "unavailable",
  70. });
  71. // 就绪信号未到时仍 pending,error 不提前终审。
  72. expect(resolveOffPeakDetailNavigation([], "offpeak-abc", false, "list failed")).toEqual({
  73. status: "pending",
  74. });
  75. });
  76. });