offPeakFigmaLayout.test.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. import { existsSync, readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. /**
  4. * 读取仓库源码用于文本契约断言。
  5. *
  6. * Bugfix:本文件的断言里有跨行片段(例如 `const hasPrimaryMenuAction =\n ...`),而仓库
  7. * 只对 *.mjs / *.sh 声明了 `eol=lf`,其余源码在 `core.autocrlf=true` 的 Windows 检出里是
  8. * CRLF。直接 `toContain` 跨行片段时 `\n` 匹配不到 `\r\n`,用例在 Windows 上必然失败,
  9. * 而它想断言的其实是源码内容契约,与换行字节无关。统一归一成 LF 再比对。
  10. */
  11. function readSource(url: URL): string {
  12. return readFileSync(url, "utf8").replaceAll("\r\n", "\n");
  13. }
  14. const automationsSectionSource = readSource(
  15. new URL("../src/settings/AutomationsSection.tsx", import.meta.url),
  16. );
  17. const automationEditViewSource = readSource(
  18. new URL("../src/settings/AutomationEditView.tsx", import.meta.url),
  19. );
  20. const confirmDialogSource = readSource(new URL("../src/ConfirmDialog.tsx", import.meta.url));
  21. const automationConfirmDialogPresentationSource = readSource(
  22. new URL("../src/settings/automationConfirmDialogPresentation.ts", import.meta.url),
  23. );
  24. const buttonSource = readSource(new URL("../src/components/ui/button.tsx", import.meta.url));
  25. const stylesSource = readSource(new URL("../src/styles.css", import.meta.url));
  26. const automationPrimitivesSource = readSource(
  27. new URL("../src/settings/AutomationDesignPrimitives.tsx", import.meta.url),
  28. );
  29. const settingsSegmentedTabsSource = readSource(
  30. new URL("../src/settings/SettingsSegmentedTabs.tsx", import.meta.url),
  31. );
  32. const automationIconsSource = readSource(
  33. new URL("../src/settings/AutomationIcons.tsx", import.meta.url),
  34. );
  35. const instructionsComposerUrl = new URL(
  36. "../src/settings/AutomationInstructionsComposer.tsx",
  37. import.meta.url,
  38. );
  39. const instructionsComposerSource = existsSync(instructionsComposerUrl)
  40. ? readSource(instructionsComposerUrl)
  41. : "";
  42. const editViewSource = readSource(new URL("../src/settings/OffPeakEditView.tsx", import.meta.url));
  43. const automationSwitchSource = readSource(
  44. new URL("../src/settings/AutomationSwitchToggle.tsx", import.meta.url),
  45. );
  46. const historyTabSource = readSource(
  47. new URL("../src/settings/OffPeakHistoryTab.tsx", import.meta.url),
  48. );
  49. const offPeakTaskListSource = readSource(
  50. new URL("../src/settings/OffPeakTaskList.tsx", import.meta.url),
  51. );
  52. const offPeakUiPresentationSource = readSource(
  53. new URL("../src/settings/offPeakUiPresentation.ts", import.meta.url),
  54. );
  55. const offPeakNewTaskEntrySource = readSource(
  56. new URL("../src/v4/OffPeakNewTaskEntry.tsx", import.meta.url),
  57. );
  58. const chatInputDisplaySource = readSource(
  59. new URL("../src/chat-input-toolbar/display.tsx", import.meta.url),
  60. );
  61. const sessionPaneSource = readSource(new URL("../src/v4/SessionPane.tsx", import.meta.url));
  62. describe("idle-time task Figma layout contracts", () => {
  63. it("keeps the footer status badge unshrinkable so a long bound-session title cannot clip it", () => {
  64. // Bug 回归:状态徽章与「运行会话:…」同为 min-w-0 时,长会话标题会把「失败」压到只剩一个字。
  65. expect(offPeakTaskListSource).toContain(
  66. '"flex w-fit shrink-0 items-center gap-0.5 font-normal"',
  67. );
  68. expect(offPeakTaskListSource).not.toContain(
  69. '"flex w-fit min-w-0 items-center gap-0.5 font-normal"',
  70. );
  71. expect(offPeakTaskListSource).toContain(
  72. 'className="ml-auto min-w-0 truncate text-foreground-subtle"',
  73. );
  74. });
  75. it("scrolls the idle-time task grid with the same threshold and classes as scheduled tasks", () => {
  76. expect(offPeakTaskListSource).toContain("export const OFFPEAK_LIST_SCROLL_THRESHOLD = 8;");
  77. expect(offPeakTaskListSource).toContain("sorted.length > OFFPEAK_LIST_SCROLL_THRESHOLD &&");
  78. expect(offPeakTaskListSource).toContain(
  79. '"max-h-[1198px] overflow-y-auto overscroll-contain lg:max-h-[606px]"',
  80. );
  81. expect(automationsSectionSource).toContain(
  82. '"max-h-[1198px] overflow-y-auto overscroll-contain lg:max-h-[606px]"',
  83. );
  84. });
  85. it("keeps the idle-time create and edit page title hierarchy aligned with scheduled tasks", () => {
  86. expect(editViewSource).toContain('data-testid="offpeak-edit-title"');
  87. expect(editViewSource).toContain('className="text-ui-xl font-semibold text-foreground"');
  88. expect(editViewSource).toContain('data-testid="offpeak-edit-subtitle"');
  89. expect(editViewSource).toContain('className="text-ui-base text-foreground-subtle"');
  90. expect(editViewSource).toContain('id: editing ? "offPeak.edit.title" : "offPeak.create.title"');
  91. expect(editViewSource).toContain(
  92. 'id: editing ? "offPeak.edit.subtitle" : "offPeak.create.subtitle"',
  93. );
  94. });
  95. it("keeps the idle-time entry component available without mounting it on the draft homepage", () => {
  96. const dockStart = sessionPaneSource.indexOf(
  97. "const conversationBottomDockContent = readOnly ? null :",
  98. );
  99. const dockEnd = sessionPaneSource.indexOf("\n );\n", dockStart);
  100. const dockSource = sessionPaneSource.slice(dockStart, dockEnd);
  101. expect(dockStart).toBeGreaterThanOrEqual(0);
  102. // 首页入口暂时下线;组件与布局契约继续保留备用。
  103. expect(dockSource).not.toContain("<OffPeakNewTaskEntry");
  104. expect(dockSource).toContain("<ConversationDraftSuggestedPromptsContainer");
  105. expect(sessionPaneSource).not.toContain(
  106. 'import { OffPeakNewTaskEntry } from "@/v4/OffPeakNewTaskEntry.js"',
  107. );
  108. expect(sessionPaneSource).not.toContain("<OffPeakNewTaskEntry");
  109. expect(dockSource).toContain("isWebRemoteControl={compactForRemoteControl}");
  110. expect(offPeakNewTaskEntrySource).toContain("max-w-[780px]");
  111. expect(offPeakNewTaskEntrySource).toContain("pb-[38px]");
  112. expect(offPeakNewTaskEntrySource).toContain("sm:grid-cols-3");
  113. expect(offPeakNewTaskEntrySource).toContain("data-off-peak-template-grid");
  114. expect(offPeakNewTaskEntrySource).not.toContain("data-off-peak-carousel-dot");
  115. expect(offPeakNewTaskEntrySource).not.toContain("CarouselContent");
  116. expect(offPeakNewTaskEntrySource).not.toContain("@min-[820px]/conversation:-mx-[54px]");
  117. });
  118. it("keeps the main tabs 8px apart and trailing actions 12px apart", () => {
  119. const actionRowStart = automationsSectionSource.indexOf("Tab:Scheduled");
  120. const actionRowEnd = automationsSectionSource.indexOf("{loading &&", actionRowStart);
  121. const actionRowSource = automationsSectionSource.slice(actionRowStart, actionRowEnd);
  122. expect(actionRowStart).toBeGreaterThanOrEqual(0);
  123. expect(actionRowSource.match(/className="flex items-center gap-2"/g)).toHaveLength(1);
  124. expect(actionRowSource.match(/className="flex items-center gap-3"/g)).toHaveLength(1);
  125. });
  126. it("keeps inactive main tabs transparent until hover", () => {
  127. const actionRowStart = automationsSectionSource.indexOf("Tab:Scheduled");
  128. const actionRowEnd = automationsSectionSource.indexOf("{loading &&", actionRowStart);
  129. const actionRowSource = automationsSectionSource.slice(actionRowStart, actionRowEnd);
  130. expect(actionRowSource).toContain(
  131. 'tab === key\n ? "bg-selected text-foreground"',
  132. );
  133. expect(actionRowSource).toContain(
  134. '"text-foreground-subtle hover:bg-hover hover:text-foreground"',
  135. );
  136. expect(actionRowSource).not.toContain('"bg-surface text-foreground-subtle');
  137. });
  138. it("keeps action-row labels at 14px and the idle create button text-only", () => {
  139. const actionRowStart = automationsSectionSource.indexOf("Tab:Scheduled");
  140. const actionRowEnd = automationsSectionSource.indexOf("{loading &&", actionRowStart);
  141. const actionRowSource = automationsSectionSource.slice(actionRowStart, actionRowEnd);
  142. const idleButtonStart = automationsSectionSource.indexOf("function OffPeakCreateButton");
  143. const idleButtonEnd = automationsSectionSource.indexOf(
  144. "/** 创建表单的预填草稿",
  145. idleButtonStart,
  146. );
  147. const idleButtonSource = automationsSectionSource.slice(idleButtonStart, idleButtonEnd);
  148. expect(actionRowSource).toContain(
  149. '"rounded-full px-3 py-1 text-ui-base font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-input-border-focused"',
  150. );
  151. expect(settingsSegmentedTabsSource).toContain("px-2.5 text-ui-base font-medium");
  152. expect(idleButtonSource).toContain('variant="default"');
  153. expect(idleButtonSource).toContain('size="default"');
  154. expect(actionRowSource).toContain("font-medium");
  155. expect(idleButtonSource).not.toContain("<Lock");
  156. expect(idleButtonSource).not.toContain("<AutomationIdleTimeIcon");
  157. expect(idleButtonSource).toMatch(
  158. /<Button[\s\S]*?variant="default"[\s\S]*?size="default"[\s\S]*?onClick=\{onCreate\}\s*>/,
  159. );
  160. expect(idleButtonSource).toMatch(/<Button(?:(?!className=)[\s\S])*?onClick=\{onCreate\}\s*>/);
  161. });
  162. it("uses the shared default large button for idle-time detail creation without class overrides", () => {
  163. const createButtonStart = editViewSource.indexOf("const createSubmitButton");
  164. const createButtonEnd = editViewSource.indexOf("return (", createButtonStart);
  165. const createButtonSource = editViewSource.slice(createButtonStart, createButtonEnd);
  166. expect(createButtonSource).toMatch(
  167. /<Button[\s\S]*?variant="default"[\s\S]*?size="lg"[\s\S]*?onClick=\{\(\) => void handleSubmit\(\)\}\s*>/,
  168. );
  169. expect(createButtonSource).not.toContain("className=");
  170. });
  171. it("uses the shared default large button for scheduled detail creation without class overrides", () => {
  172. const createButtonStart = automationEditViewSource.indexOf(") : showCreateSettingsAction ? (");
  173. const createButtonEnd = automationEditViewSource.indexOf(") : null}", createButtonStart);
  174. const createButtonSource = automationEditViewSource.slice(createButtonStart, createButtonEnd);
  175. expect(createButtonSource).toMatch(
  176. /<Button[\s\S]*?variant="default"[\s\S]*?size="lg"[\s\S]*?data-testid=\{TID_AUTOMATION_FORM_SUBMIT\}/,
  177. );
  178. expect(createButtonSource).not.toContain("className=");
  179. });
  180. it("wraps idle create-block reasons within a shared 220px tooltip", () => {
  181. expect(offPeakUiPresentationSource).toContain(
  182. "max-w-[220px] [&>span]:break-words [&>span]:whitespace-normal [&>span]:text-wrap-pretty",
  183. );
  184. expect(automationsSectionSource).toContain("className={OFF_PEAK_CREATE_TOOLTIP_CLASSNAME}");
  185. expect(editViewSource).toContain("className={OFF_PEAK_CREATE_TOOLTIP_CLASSNAME}");
  186. });
  187. it("uses the homepage card border token for automation cards and empty states", () => {
  188. expect(offPeakNewTaskEntrySource).toContain(
  189. "rounded-2xl border border-card-border bg-background",
  190. );
  191. expect(automationsSectionSource).toContain(
  192. "rounded-xl border border-card-border bg-background",
  193. );
  194. expect(automationsSectionSource).toContain(
  195. "rounded-2xl border border-card-border bg-background",
  196. );
  197. expect(offPeakTaskListSource).toContain("rounded-[10px] border border-card-border");
  198. expect(automationsSectionSource).not.toContain(
  199. "rounded-xl border border-surface bg-background",
  200. );
  201. expect(offPeakTaskListSource).not.toContain("shadow-[inset_0_0_0_1px_var(--color-surface)]");
  202. });
  203. it("uses Client Scenes Lucide names with Moon as the homepage fallback", () => {
  204. expect(offPeakNewTaskEntrySource).toContain(
  205. 'import { Megaphone, Moon, X } from "lucide-react"',
  206. );
  207. expect(offPeakNewTaskEntrySource).toContain("<ClientSceneLucideIcon");
  208. expect(offPeakNewTaskEntrySource).toContain("name={template.iconName}");
  209. expect(offPeakNewTaskEntrySource).toContain('data-off-peak-homepage-template-icon="moon"');
  210. expect(offPeakNewTaskEntrySource).toContain("size={16}");
  211. expect(offPeakNewTaskEntrySource).toContain("strokeWidth={2}");
  212. expect(offPeakNewTaskEntrySource).not.toContain("<OffPeakTemplateIcon");
  213. });
  214. it("keeps the keep-awake notice at 10px radius with 12px content insets", () => {
  215. const noticeStart = automationPrimitivesSource.indexOf(
  216. "export function AutomationKeepAwakeNotice",
  217. );
  218. const noticeEnd = automationPrimitivesSource.indexOf(
  219. "export function AutomationCreateDropdown",
  220. noticeStart,
  221. );
  222. const noticeSource = automationPrimitivesSource.slice(noticeStart, noticeEnd);
  223. expect(noticeStart).toBeGreaterThanOrEqual(0);
  224. expect(noticeSource).toContain("rounded-[10px]");
  225. expect(noticeSource).toContain("px-3 py-3");
  226. expect(noticeSource).not.toContain("sm:py-0");
  227. });
  228. it("uses the Changes Summary Open structure for the scheduled create split action", () => {
  229. const createStart = automationPrimitivesSource.indexOf(
  230. "export function AutomationCreateDropdown",
  231. );
  232. const createSource = automationPrimitivesSource.slice(createStart);
  233. expect(createSource).toMatch(
  234. /<DropdownMenu>\s*<div[\s\S]*?<Button[\s\S]*?<DropdownMenuTrigger asChild>/,
  235. );
  236. expect(createSource).toContain('variant="default"');
  237. expect(createSource).toContain('className="inline-flex h-7');
  238. expect(createSource).toContain(
  239. 'className="inline-flex h-7 items-center overflow-hidden rounded-lg"',
  240. );
  241. expect(createSource).not.toContain("border border-transparent bg-primary");
  242. expect(createSource).toContain('size="default"');
  243. expect(createSource).toContain('size="icon-md"');
  244. expect(createSource).not.toContain('className="h-4 w-px"');
  245. expect(createSource).not.toContain("alignOffset={-64}");
  246. expect(createSource).toContain('align="end"');
  247. });
  248. it("keeps the action row and keep-awake notice 20px apart", () => {
  249. const contentStart = automationsSectionSource.indexOf('"flex flex-col gap-8"');
  250. const contentEnd = automationsSectionSource.indexOf(
  251. '<div className="flex w-full flex-col gap-4">',
  252. contentStart,
  253. );
  254. const contentSource = automationsSectionSource.slice(contentStart, contentEnd);
  255. expect(contentStart).toBeGreaterThanOrEqual(0);
  256. expect(contentSource).toContain('? "mt-5"');
  257. expect(contentSource).not.toContain('? "mt-4"');
  258. });
  259. it("separates visible task cards and templates with the Figma divider rhythm", () => {
  260. const separatorStart = automationsSectionSource.indexOf("真实任务卡与模板此前只靠空白分区");
  261. const separatorEnd = automationsSectionSource.indexOf(
  262. "Idle-time task template",
  263. separatorStart,
  264. );
  265. const separatorSource = automationsSectionSource.slice(separatorStart, separatorEnd);
  266. expect(separatorStart).toBeGreaterThanOrEqual(0);
  267. expect(automationsSectionSource).toContain("hasVisibleTaskCards && hasVisibleTemplates");
  268. expect(separatorSource).toContain("{showTaskTemplateSeparator ? (");
  269. expect(separatorSource).toContain("data-automations-task-template-separator");
  270. expect(separatorSource).toContain('className="flex w-full flex-col py-2"');
  271. expect(separatorSource).toContain('className="h-px w-full bg-card-border"');
  272. expect(separatorSource).not.toContain('className="h-px w-full bg-surface"');
  273. });
  274. it("stretches idle-time template cards to the tallest card in each desktop grid row", () => {
  275. const templateStart = automationsSectionSource.indexOf("data-automations-idle-templates");
  276. const templateEnd = automationsSectionSource.indexOf("</section>", templateStart);
  277. const templateSource = automationsSectionSource.slice(templateStart, templateEnd);
  278. expect(templateStart).toBeGreaterThanOrEqual(0);
  279. expect(templateSource).toContain('className="flex h-full min-h-[114px] w-full flex-col');
  280. });
  281. it("keeps the detail breadcrumb and keep-awake control above the tabs", () => {
  282. expect(editViewSource).toContain("<SettingsBreadcrumbReporter");
  283. expect(editViewSource).toContain("flex min-w-0 flex-wrap items-center gap-4 sm:flex-nowrap");
  284. expect(editViewSource).toContain("<AutomationSwitchToggle");
  285. expect(editViewSource.indexOf("<SettingsBreadcrumbReporter")).toBeLessThan(
  286. editViewSource.indexOf("<AutomationSettingsHistoryTabs"),
  287. );
  288. });
  289. it("uses the shared Input border states for the idle-time title field", () => {
  290. expect(editViewSource).toContain(
  291. '"h-9 rounded-lg bg-card px-2 text-foreground hover:bg-surface-hover focus-visible:bg-card"',
  292. );
  293. expect(editViewSource).not.toContain("rounded-lg border-transparent bg-card px-2");
  294. });
  295. it("adds 4px above the idle-time unattended note", () => {
  296. expect(editViewSource).toContain(
  297. 'className="mt-1 flex items-start gap-1.5 text-ui-base leading-5 text-foreground-subtle"',
  298. );
  299. });
  300. it("uses breadcrumb navigation and keeps the switch interactive on hover", () => {
  301. expect(editViewSource).toContain("<SettingsBreadcrumbReporter");
  302. expect(automationEditViewSource).toContain("<SettingsBreadcrumbReporter");
  303. expect(editViewSource).not.toContain("AUTOMATION_BACK_TRIGGER_CLASSNAME");
  304. expect(automationEditViewSource).not.toContain("AUTOMATION_BACK_TRIGGER_CLASSNAME");
  305. expect(automationSwitchSource).toContain("hover:ring-2 hover:ring-border-hover");
  306. });
  307. it("keeps localized idle template descriptions on natural phrase boundaries", () => {
  308. expect(stylesSource).toContain(".text-wrap-phrase");
  309. expect(stylesSource).toContain("line-break: strict");
  310. expect(stylesSource).toContain("text-wrap: pretty");
  311. expect(stylesSource).toContain("@supports (word-break: auto-phrase)");
  312. expect(stylesSource).toContain("word-break: auto-phrase");
  313. expect(automationsSectionSource).toContain("text-wrap-phrase line-clamp-2");
  314. });
  315. it("removes the page-local back icon and keeps the create action text only", () => {
  316. expect(editViewSource).not.toMatch(/import\s+\{[^}]*ArrowLeft[^}]*\}\s+from\s+"lucide-react"/s);
  317. expect(editViewSource).not.toContain("<ArrowLeft");
  318. expect(editViewSource).not.toContain("<Play");
  319. expect(editViewSource).not.toMatch(/import\s+\{[^}]*\bPlay\b[^}]*\}\s+from\s+"lucide-react"/s);
  320. expect(automationEditViewSource).not.toContain("<Play");
  321. expect(automationEditViewSource).not.toMatch(
  322. /import\s+\{[^}]*\bPlay\b[^}]*\}\s+from\s+"lucide-react"/s,
  323. );
  324. expect(editViewSource).not.toContain("<OffPeakFigmaAssetIcon");
  325. expect(editViewSource).not.toContain("@/assets/off-peak-");
  326. expect(editViewSource).not.toContain("maskImage");
  327. });
  328. it("anchors the 160px history menu from the trigger start and preserves its 89px stack", () => {
  329. const menuStart = historyTabSource.indexOf("旧版按触发器右缘对齐");
  330. const menuEnd = historyTabSource.indexOf("</DropdownMenuContent>", menuStart);
  331. const menuSource = historyTabSource.slice(menuStart, menuEnd);
  332. expect(menuStart).toBeGreaterThanOrEqual(0);
  333. expect(menuSource).toContain('align="start"');
  334. expect(menuSource).toContain("alignOffset={-10}");
  335. expect(menuSource).toContain("sideOffset={4}");
  336. expect(menuSource).toContain("collisionPadding={8}");
  337. expect(menuSource).toContain("w-[160px]");
  338. expect(menuSource).toContain("gap-0.5");
  339. expect(menuSource).toContain("py-1.5");
  340. expect(menuSource).toContain("<DropdownMenuSeparator");
  341. expect(menuSource.match(/min-h-9/g)).toHaveLength(2);
  342. });
  343. it("keeps the shared empty history state rounded-xl with a dashed border", () => {
  344. const emptyStart = historyTabSource.indexOf("if (!task?.startedAt");
  345. const emptyEnd = historyTabSource.indexOf(
  346. "const status = resolveOffPeakHistoryStatus",
  347. emptyStart,
  348. );
  349. const emptyStateSource = historyTabSource.slice(emptyStart, emptyEnd);
  350. expect(emptyStart).toBeGreaterThanOrEqual(0);
  351. expect(emptyStateSource).toContain("<AutomationHistoryEmptyState>");
  352. expect(automationEditViewSource).toContain("<AutomationHistoryEmptyState>");
  353. expect(automationPrimitivesSource).toContain("min-h-[226px]");
  354. expect(automationPrimitivesSource).toContain("border-card-border");
  355. expect(automationPrimitivesSource).toContain("rounded-xl");
  356. expect(automationPrimitivesSource).toContain("border-dashed");
  357. expect(automationPrimitivesSource).toContain("bg-background");
  358. expect(automationPrimitivesSource).toContain("text-center text-ui-base text-foreground-subtle");
  359. expect(automationPrimitivesSource).not.toContain(
  360. "min-h-[226px] items-center justify-center rounded-lg border border-card-border bg-card",
  361. );
  362. expect(automationPrimitivesSource).not.toContain(
  363. "min-h-[226px] items-center justify-center rounded-lg border border-card-border bg-surface",
  364. );
  365. });
  366. it("does not repeat the awake-only hint above scheduled history", () => {
  367. expect(automationEditViewSource).not.toContain('id: "automations.runs.awakeHint"');
  368. });
  369. it("omits the separator when an idle task menu only contains delete", () => {
  370. // 修复原因:源码契约只关心状态集合,不能让格式化产生的缩进变化误报产品回归。
  371. expect(offPeakTaskListSource).toMatch(
  372. /const hasPrimaryMenuAction =\s*task\.status === "queued" \|\|\s*task\.status === "paused" \|\|\s*task\.status === "running";/,
  373. );
  374. expect(offPeakTaskListSource).toContain(
  375. "{hasPrimaryMenuAction ? <DropdownMenuSeparator /> : null}",
  376. );
  377. expect(offPeakTaskListSource).not.toContain(
  378. "\n <DropdownMenuSeparator />\n <DropdownMenuItem",
  379. );
  380. });
  381. it("shares a five-to-seven-line auto-sizing Instructions composer across scheduled and idle forms", () => {
  382. expect(instructionsComposerSource).toContain(
  383. "flex min-h-39 flex-col overflow-hidden rounded-xl border-0 bg-surface",
  384. );
  385. expect(instructionsComposerSource).toContain("border border-input-border bg-input");
  386. expect(instructionsComposerSource).toContain("h-29 min-h-29 max-h-39");
  387. expect(instructionsComposerSource).toContain("AUTOMATION_INSTRUCTIONS_MIN_HEIGHT_PX = 116");
  388. expect(instructionsComposerSource).toContain("AUTOMATION_INSTRUCTIONS_MAX_HEIGHT_PX = 156");
  389. expect(instructionsComposerSource).toContain(
  390. "textarea.style.height = `${AUTOMATION_INSTRUCTIONS_MIN_HEIGHT_PX}px`",
  391. );
  392. expect(instructionsComposerSource).toContain(
  393. 'contentHeight > AUTOMATION_INSTRUCTIONS_MAX_HEIGHT_PX ? "auto" : "hidden"',
  394. );
  395. expect(instructionsComposerSource).toContain("max-h-39 shrink-0 resize-none");
  396. expect(instructionsComposerSource).toContain("bg-input p-3 text-foreground");
  397. expect(instructionsComposerSource).toContain("AUTOMATION_FORM_INPUT_TYPOGRAPHY_CLASSNAME");
  398. expect(instructionsComposerSource).toContain(
  399. "flex min-h-10 shrink-0 flex-wrap items-center justify-between gap-0 p-1.5 sm:h-10 sm:flex-nowrap",
  400. );
  401. expect(automationEditViewSource).toContain("<AutomationInstructionsComposer");
  402. expect(editViewSource).toContain("<AutomationInstructionsComposer");
  403. expect(automationEditViewSource).not.toContain("min-h-[116px] max-h-[156px]");
  404. expect(editViewSource).not.toContain("<textarea");
  405. expect(editViewSource).toContain('containerClassName="contents"');
  406. expect(editViewSource).not.toContain("focus-within:bg-hover");
  407. expect(editViewSource).toContain("<ModelConfigSelect");
  408. expect(editViewSource).toContain("showProviderLevel={false}");
  409. expect(editViewSource).toContain("<ThoughtLevelCycleControl");
  410. expect(editViewSource).toContain("focusSelectorOnClose={null}");
  411. expect(editViewSource).toContain("restoreFocusSelector={null}");
  412. // 权限下拉与项目/模型/推理一样以 New Task composer 为唯一实现来源。
  413. expect(editViewSource).toContain("<ConfigSelect");
  414. expect(editViewSource).not.toContain("OffPeakToolbarSelect");
  415. expect(editViewSource).toContain("buildAutomationModeOption(mode)");
  416. expect(editViewSource).toContain("provider={ZCODE_AGENT_PROVIDER}");
  417. expect(editViewSource).not.toContain("offPeak.mode.");
  418. expect(automationEditViewSource).toContain("<ConfigSelect");
  419. expect(editViewSource).toContain(
  420. "flex w-full shrink-0 flex-nowrap items-center justify-end gap-0 sm:w-auto",
  421. );
  422. expect(automationIconsSource).toContain("ChevronDown");
  423. expect(automationIconsSource).toContain("strokeWidth={2}");
  424. expect(automationIconsSource).not.toContain("@/assets/");
  425. expect(automationIconsSource).not.toContain("maskImage");
  426. expect(editViewSource).toContain("triggerIndicator={");
  427. expect(editViewSource).toContain("containerSize={20}");
  428. expect(editViewSource).toContain("<ConfigSelect");
  429. expect(editViewSource).toContain("option={modeOption}");
  430. expect(chatInputDisplaySource).toContain(
  431. "text-warning hover:text-warning aria-expanded:text-warning",
  432. );
  433. expect(chatInputDisplaySource).toContain("min-h-13 items-start gap-3 py-2 pl-2 pr-8");
  434. expect(instructionsComposerSource).toContain("hover:bg-hover hover:text-foreground");
  435. expect(instructionsComposerSource).toContain(
  436. "aria-expanded:bg-hover aria-expanded:text-foreground",
  437. );
  438. });
  439. it("removes the idle-time queue guidance block before the task title", () => {
  440. expect(editViewSource).not.toContain('id: "offPeak.form.idleTimeLabel"');
  441. expect(editViewSource).not.toContain('id: "offPeak.form.scheduleHint"');
  442. expect(editViewSource).not.toContain('id: "offPeak.form.soonestAvailable"');
  443. });
  444. it("shares the remote Automation confirmation presentation for destructive drafts", () => {
  445. const zaiDarkThemeStart = stylesSource.indexOf(".theme-zai-dark {");
  446. const zaiDarkThemeEnd = stylesSource.indexOf("\n}", zaiDarkThemeStart);
  447. const zaiDarkThemeSource = stylesSource.slice(zaiDarkThemeStart, zaiDarkThemeEnd);
  448. expect(automationEditViewSource).toContain("const confirmDialog = useConfirmDialog();");
  449. expect(automationEditViewSource).toContain(
  450. 'title: intl.formatMessage({ id: "automations.unsaved.title" })',
  451. );
  452. expect(automationEditViewSource).toContain('confirmVariant: "destructive"');
  453. expect(automationEditViewSource).toContain("showCloseButton: true");
  454. expect(automationEditViewSource).toContain("showKeyboardHints: false");
  455. expect(automationEditViewSource).toContain('presentation: "automation-confirmation"');
  456. expect(editViewSource).toContain('presentation: "automation-confirmation"');
  457. expect(automationEditViewSource).not.toContain("<Dialog open={unsavedDialogOpen}");
  458. expect(confirmDialogSource).toContain(
  459. 'displayedRequest?.presentation === "automation-confirmation"',
  460. );
  461. expect(automationConfirmDialogPresentationSource).toContain(
  462. "min-h-[180px] w-[min(448px,calc(100vw-2rem))]",
  463. );
  464. expect(automationConfirmDialogPresentationSource).not.toContain(
  465. "gap-5 rounded-2xl border-none bg-popover/98 p-5",
  466. );
  467. expect(automationConfirmDialogPresentationSource).not.toContain(
  468. "text-ui-lg font-semibold text-foreground",
  469. );
  470. expect(automationConfirmDialogPresentationSource).not.toContain(
  471. "text-ui-base leading-6 text-foreground-subtle",
  472. );
  473. expect(confirmDialogSource).toContain(
  474. '<DialogTitle className="text-ui-lg font-semibold text-foreground">',
  475. );
  476. expect(confirmDialogSource).toContain(
  477. "whitespace-pre-line pt-0.5 text-ui-base leading-6 text-foreground-subtle",
  478. );
  479. expect(confirmDialogSource).toContain('isAutomationConfirmation && "mt-auto"');
  480. expect(confirmDialogSource).toContain('"gap-5 rounded-2xl border-none bg-popover/98 p-5');
  481. expect(confirmDialogSource).toContain('"h-9 gap-3 px-4"');
  482. expect(zaiDarkThemeStart).toBeGreaterThanOrEqual(0);
  483. expect(zaiDarkThemeSource).toContain("--color-destructive-foreground: #ffffff;");
  484. expect(buttonSource).toContain(
  485. "bg-destructive text-destructive-foreground hover:bg-destructive/90",
  486. );
  487. expect(confirmDialogSource).not.toContain('"text-white hover:text-white"');
  488. });
  489. });