automationsPopulatedListFidelity.test.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. import enUS from "@/i18n/locales/en-US.js";
  4. import zhCN from "@/i18n/locales/zh-CN.js";
  5. /**
  6. * 读取仓库源码用于文本契约断言。
  7. *
  8. * Bugfix:下面断言里有跨行片段(`<AutomationCreateDropdown\n ...`),而仓库只对 *.mjs / *.sh
  9. * 声明了 `eol=lf`,其余源码在 `core.autocrlf=true` 的 Windows 检出里是 CRLF,`toContain`
  10. * 的 `\n` 匹配不到 `\r\n`,用例在 Windows 上必然失败。它想断言的是源码内容契约,
  11. * 与换行字节无关,统一归一成 LF 再比对。
  12. */
  13. const automationsSectionSource = readFileSync(
  14. new URL("../src/settings/AutomationsSection.tsx", import.meta.url),
  15. "utf8",
  16. ).replaceAll("\r\n", "\n");
  17. describe("Automations populated-list Figma contract", () => {
  18. it("removes the All tab and its unified mixed grid", () => {
  19. // 规范出处:docs/off-peak-task/decisions.md D47(2026-07-28)——主视图只保留
  20. // Scheduled / Idle 两个 tab,All 混排总览及其统一 grid 删除;任务区锚点保留供布局断言使用。
  21. expect(automationsSectionSource).not.toContain('"all"');
  22. expect(automationsSectionSource).not.toContain("showUnifiedAllTaskGrid");
  23. expect(automationsSectionSource).toContain("data-automations-task-grid");
  24. expect(automationsSectionSource).toContain(
  25. '"grid grid-cols-1 auto-rows-[132px] gap-x-4 gap-y-4 lg:grid-cols-2"',
  26. );
  27. });
  28. it("keeps the populated banner ahead of tasks with the Figma spacing", () => {
  29. const bannerStart = automationsSectionSource.indexOf("<AutomationKeepAwakeNotice");
  30. const gridStart = automationsSectionSource.indexOf("data-automations-task-grid");
  31. expect(bannerStart).toBeGreaterThanOrEqual(0);
  32. expect(gridStart).toBeGreaterThan(bannerStart);
  33. // D47:keep-awake 是全局开关,Scheduled / Idle 两个 tab 都展示;有任务时提示条与 action row 收紧到 20px。
  34. expect(automationsSectionSource).toMatch(/hasAnyTasks \? "mt-5" : "mt-8"/);
  35. });
  36. it("keeps inactive tabs transparent and shows the scheduled create split action only on its tab", () => {
  37. expect(automationsSectionSource).toContain(
  38. '"text-foreground-subtle hover:bg-hover hover:text-foreground"',
  39. );
  40. expect(automationsSectionSource).not.toContain(
  41. '"bg-surface text-foreground-subtle hover:bg-hover hover:text-foreground"',
  42. );
  43. expect(automationsSectionSource).toContain(
  44. "<AutomationCreateDropdown\n onViaChat={handleCreateViaChat}",
  45. );
  46. expect(automationsSectionSource).not.toContain("appearance={");
  47. });
  48. it("keeps manual refresh immediately before the populated create action", () => {
  49. const refreshAction = automationsSectionSource.indexOf(
  50. 'aria-label={intl.formatMessage({ id: "automations.refresh" })}',
  51. );
  52. const createAction = automationsSectionSource.indexOf(
  53. "<AutomationCreateDropdown\n onViaChat={handleCreateViaChat}",
  54. );
  55. expect(refreshAction).toBeGreaterThanOrEqual(0);
  56. expect(createAction).toBeGreaterThan(refreshAction);
  57. expect(automationsSectionSource).toContain("refresh(zcodeAgentService)");
  58. expect(automationsSectionSource).toContain("offPeakRefresh(offPeakTaskService)");
  59. expect(automationsSectionSource).toMatch(
  60. /variant="outline"\s+size="icon"\s+aria-label=\{intl\.formatMessage\(\{ id: "automations\.refresh" \}\)\}/,
  61. );
  62. });
  63. it("keeps scheduled-task delete confirmation buttons text-only", () => {
  64. expect(automationsSectionSource).toMatch(
  65. /presentation: "automation-confirmation",[\s\S]*?id: "automations\.delete\.title"[\s\S]*?confirmVariant: "destructive",[\s\S]*?showKeyboardHints: false,/,
  66. );
  67. });
  68. it("labels scheduled-task toggle actions as pause and continue", () => {
  69. expect(zhCN["automations.pause"]).toBe("暂停");
  70. expect(zhCN["automations.resume"]).toBe("继续");
  71. expect(enUS["automations.pause"]).toBe("Pause");
  72. expect(enUS["automations.resume"]).toBe("Continue");
  73. });
  74. it("uses the dedicated idle-time delete confirmation action label", () => {
  75. expect(automationsSectionSource).toMatch(
  76. /id: "offPeak\.delete\.title"[\s\S]*?id: "offPeak\.delete\.description"[\s\S]*?id: "offPeak\.delete\.confirm"/,
  77. );
  78. });
  79. it("dims paused schedule time and run count to 40 percent opacity", () => {
  80. expect(automationsSectionSource).toContain("font-normal text-success opacity-40");
  81. expect(automationsSectionSource).toMatch(
  82. /\(hasFailure \|\| status === "paused"\) &&\s+"opacity-40"/,
  83. );
  84. });
  85. it("shows only the cumulative run count without a max-runs denominator", () => {
  86. expect(automationsSectionSource).toContain('{ id: "automations.runCount" }');
  87. expect(automationsSectionSource).not.toContain('{ id: "automations.runCountLimited" }');
  88. });
  89. it("does not expose retry queue details on scheduled task cards", () => {
  90. expect(automationsSectionSource).not.toContain('id: "automations.retryQueued"');
  91. expect(automationsSectionSource).not.toContain("hasAutomationRetryQueueState(automation)");
  92. });
  93. it("shows a cron summary for completed scheduled tasks", () => {
  94. expect(automationsSectionSource).toMatch(
  95. /status === "paused" \|\|\s+status === "completed" \? \(/,
  96. );
  97. });
  98. it("keeps completed cards dimmed without card hover styling", () => {
  99. expect(automationsSectionSource).toMatch(
  100. /status === "completed"\s+\?\s+"opacity-60"\s+:\s+"hover:bg-hover"/,
  101. );
  102. expect(automationsSectionSource).not.toContain("opacity-60 hover:opacity-100");
  103. });
  104. it("appends next-run time only for active non-failing cards", () => {
  105. expect(automationsSectionSource).toContain("`${scheduleText} · ${intl.formatMessage(");
  106. // 列表 grid 已嵌入筛选空态的三目分支,缩进会随结构变化;断言只关心调用形态。
  107. expect(automationsSectionSource).toMatch(
  108. /formatAutomationCardNextRun\(\s*automation\.nextRunAt/,
  109. );
  110. // completed/paused/失败态调度不再推进;有限次任务跑完后 nextRunAt 仍可能指向
  111. // 未来时刻,不能再拼进卡片文案。
  112. expect(automationsSectionSource).toContain(
  113. 'status === "active" && !hasFailure && formattedNextRun',
  114. );
  115. });
  116. });