automations-workflows-hub.test.ts 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. import { openStatusCapsule } from "#e2e/helpers/status-capsule";
  2. import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
  3. import { dirname, join } from "node:path";
  4. import {
  5. TID_AUTOMATIONS_PAGE_TAB,
  6. TID_CHAT_WORKFLOW_RUN_DIGEST,
  7. TID_WORKFLOW_ACTION_DELETE,
  8. TID_WORKFLOW_ACTION_MOVE,
  9. TID_WORKFLOW_ARTIFACT_CARD,
  10. TID_WORKFLOW_ARTIFACT_PANE,
  11. TID_WORKFLOW_CARD,
  12. TID_WORKFLOW_CARD_MENU,
  13. TID_WORKFLOW_CARD_RUN,
  14. TID_WORKFLOW_DETAIL,
  15. TID_WORKFLOW_DETAIL_DESCRIPTION,
  16. TID_WORKFLOW_DETAIL_MENU,
  17. TID_WORKFLOW_DETAIL_PROJECT,
  18. TID_WORKFLOW_GLOBAL_GROUP,
  19. TID_WORKFLOW_LAUNCH_ARG,
  20. TID_WORKFLOW_LAUNCH_DIALOG,
  21. TID_WORKFLOW_LAUNCH_ERROR,
  22. TID_WORKFLOW_LAUNCH_FIELDS,
  23. TID_WORKFLOW_LAUNCH_SUBMIT,
  24. TID_WORKFLOW_META_SAVE,
  25. TID_WORKFLOW_MOVE_DIALOG,
  26. TID_WORKFLOW_MOVE_DIALOG_SUBMIT,
  27. TID_WORKFLOW_PROJECT_GROUP,
  28. TID_WORKFLOWS_CREATE_VIA_CHAT,
  29. TID_WORKFLOWS_EMPTY,
  30. } from "@zcode/shared";
  31. import {
  32. TID_AUTOMATIONS_OPEN,
  33. TID_CONFIRM_DIALOG_CONFIRM,
  34. TID_TASK_ITEM,
  35. TID_V4_TIMELINE,
  36. testId,
  37. } from "@zcode/shared/test-ids";
  38. import {
  39. DEFAULT_WORKSPACE,
  40. clearAppData,
  41. clickTestIdByDom,
  42. clickTestIdByWebDriver,
  43. pinE2ELocale,
  44. setInputValueByTestIdDom,
  45. waitForTestIdByDom,
  46. } from "#e2e/helpers/desktop-app";
  47. import {
  48. getMessages,
  49. prepareConversationE2E,
  50. waitForUserMessageContaining,
  51. } from "#e2e/helpers/conversation-session";
  52. import { getV4ComposerBackgroundWorkCounts } from "#e2e/helpers/v4-conversation";
  53. import { readDynamicWorkflowGrayMockStatus } from "#e2e/helpers/dynamic-workflow-gray";
  54. import { startDraftFromProject } from "#e2e/helpers/project-sidebar";
  55. const WORKFLOW_NAME = "release-check";
  56. const WORKFLOWS_DIR = join(DEFAULT_WORKSPACE, ".zcode", "workflows");
  57. const WORKFLOW_FILE = join(WORKFLOWS_DIR, `${WORKFLOW_NAME}.dwf.ts`);
  58. const EDITED_DESCRIPTION = "发布前检查(E2E 已编辑)";
  59. // 脚本正文:元数据编辑只改文件顶部的 frontmatter,这一段必须逐字节保留(不变式 4)。
  60. const SCRIPT = [
  61. "export default async ({ agent }) => {",
  62. ' await agent("跑测试并整理发布说明");',
  63. "};",
  64. "",
  65. ].join("\n");
  66. const SEED = [
  67. "/* zcode-workflow",
  68. "description: 发布前检查",
  69. "whenToUse: 准备发版时",
  70. "args:",
  71. " branch:",
  72. " type: string",
  73. " required: true",
  74. "*/",
  75. SCRIPT,
  76. ].join("\n");
  77. interface GroupHeaderInfo {
  78. groupTestId: string | null;
  79. text: string;
  80. createTestId: string | null;
  81. }
  82. beforeEach(async () => {
  83. // Bug 原因:worker 延后统一清理,前一条 case 的自动化页和编译失败弹窗仍在。
  84. // 先关闭弹窗并从默认项目新建任务;全局新建入口会进入无项目草稿,无法满足准备流程。
  85. const launchDialog = $(`[data-testid="${TID_WORKFLOW_LAUNCH_DIALOG}"]`);
  86. if (await launchDialog.isDisplayed()) {
  87. await browser.keys("Escape");
  88. await launchDialog.waitForDisplayed({ reverse: true });
  89. }
  90. const automationsOpen = await browser.execute(() =>
  91. Boolean(document.querySelector("[data-automations-content]")),
  92. );
  93. if (automationsOpen) {
  94. await startDraftFromProject(DEFAULT_WORKSPACE);
  95. }
  96. });
  97. /**
  98. * 每条 case 的准备:只要 workspace 就绪,不需要账号或模型 provider。
  99. * 断言中文文案,所以紧接着固定界面语言,不跟随宿主系统语言(容器里默认英文);
  100. * 必须在 workspace 就绪之后调(此前 renderer 还没注册 __testActions),且每条 case 都调:
  101. * 各 describe 的 after 会 clearAppData,把语言设置一起清掉。
  102. */
  103. async function prepareHubCase(): Promise<void> {
  104. await prepareConversationE2E({ skipProvider: true });
  105. await pinE2ELocale("zh-CN");
  106. }
  107. async function fileExists(path: string): Promise<boolean> {
  108. try {
  109. await access(path);
  110. return true;
  111. } catch {
  112. return false;
  113. }
  114. }
  115. async function readTestIdText(currentTestId: string): Promise<string | null> {
  116. return browser.execute((tid) => {
  117. const element = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  118. (item) => item.dataset.testid === tid && item.checkVisibility(),
  119. );
  120. return element?.textContent?.trim() ?? null;
  121. }, currentTestId);
  122. }
  123. async function clickRunSidePaneControl(currentTestId: string): Promise<void> {
  124. // Bug 原因:非活动侧栏页仍挂载;全局按 test id 取首项会操作前一条 case 的 run。
  125. // 限定活动 tab,并通过真实指针点击,避免隐藏控件造成假通过或污染其他 run。
  126. const control = $(`[role="tabpanel"][data-state="active"] [data-testid="${currentTestId}"]`);
  127. await control.waitForClickable();
  128. await control.click();
  129. }
  130. /**
  131. * 已保存工作流中枢「列表 → 详情 → 改元数据 → 删除」端到端(docs/dynamic-workflow/launch.md)。
  132. *
  133. * 只碰 UI + 项目目录里的 `.zcode/workflows/`:不发送 prompt、不依赖模型回放,因此是确定性的。
  134. * 「运行」走对话的用例在 conversation-session/ 下单独立案(需要回放 provider)。
  135. */
  136. describe("已保存工作流中枢 E2E", () => {
  137. before(async () => {
  138. await mkdir(WORKFLOWS_DIR, { recursive: true });
  139. await writeFile(WORKFLOW_FILE, SEED, "utf-8");
  140. });
  141. after(async () => {
  142. await browser.electron.restoreAllMocks();
  143. await rm(WORKFLOWS_DIR, { recursive: true, force: true });
  144. await clearAppData();
  145. });
  146. it("预置的工作流可见,改说明只重写 frontmatter,删除后回到空态", async function () {
  147. this.timeout(150000);
  148. // 只需要 workspace 就绪即可进入自动化页,不需要账号或配置模型 provider。
  149. await prepareHubCase();
  150. const configStatus = await readDynamicWorkflowGrayMockStatus();
  151. expect(configStatus.mode).toBe("alwaysOn");
  152. expect(configStatus.configRequests).toBeGreaterThan(0);
  153. // 1) 打开自动化页,页标题切到「工作流」。
  154. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, {
  155. timeoutMsg: "侧栏没有出现自动化入口",
  156. });
  157. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  158. timeoutMsg: "自动化页标题没有「工作流」切换",
  159. });
  160. // 2) 全局视图按项目分组:默认工作区(folder 名 ZCodeProject)自成一组,组头带名字,
  161. // 组内「通过对话创建」按钮带以 workspaceKey 收尾的 test id。
  162. // group / create 的 test id 后缀是 workspaceKey(本地通常 = workspacePath),但
  163. // resolveWorkspaceKey 若对本地路径做归一化(大小写 / 去尾斜杠 / realpath)后缀就不等于
  164. // DEFAULT_WORKSPACE——所以只按前缀等待与断言,不钉死整串。
  165. const readGroupInfo = () =>
  166. browser.execute(
  167. (groupPrefix: string, createPrefix: string) => {
  168. const group = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  169. (item) => item.dataset.testid?.startsWith(groupPrefix),
  170. );
  171. if (!group) return null;
  172. const createButton = group.querySelector<HTMLElement>(`[data-testid^="${createPrefix}"]`);
  173. return {
  174. groupTestId: group.dataset.testid ?? null,
  175. text: group.textContent ?? "",
  176. createTestId: createButton?.dataset.testid ?? null,
  177. };
  178. },
  179. TID_WORKFLOW_PROJECT_GROUP,
  180. // testId(base, "") = `${base}-`:create 按钮 test id 的前缀。
  181. testId(TID_WORKFLOWS_CREATE_VIA_CHAT, ""),
  182. ) as Promise<GroupHeaderInfo | null>;
  183. let groupInfo: GroupHeaderInfo | null = null;
  184. await browser.waitUntil(
  185. async () => {
  186. groupInfo = await readGroupInfo();
  187. return Boolean(groupInfo && groupInfo.createTestId);
  188. },
  189. { timeout: 20000, timeoutMsg: "工作流页没有出现默认工作区的项目组" },
  190. );
  191. const seen = groupInfo as GroupHeaderInfo | null;
  192. expect(seen?.groupTestId?.startsWith(TID_WORKFLOW_PROJECT_GROUP)).toBe(true);
  193. expect(seen?.text).toContain("ZCodeProject");
  194. expect(seen?.createTestId?.startsWith(testId(TID_WORKFLOWS_CREATE_VIA_CHAT, ""))).toBe(true);
  195. expect(seen?.createTestId).toContain("ZCodeProject");
  196. // 3) 预置文件以卡片出现:名字 + frontmatter 里的说明。
  197. const cardTestId = testId(TID_WORKFLOW_CARD, WORKFLOW_NAME);
  198. await waitForTestIdByDom(cardTestId, {
  199. timeout: 20000,
  200. timeoutMsg: "工作流列表没有出现预置的 release-check 卡片",
  201. });
  202. expect(await readTestIdText(cardTestId)).toContain("发布前检查");
  203. // 4) 点卡片进详情,改说明并保存。
  204. await clickTestIdByDom(cardTestId, { timeoutMsg: "无法点击工作流卡片进入详情" });
  205. await waitForTestIdByDom(TID_WORKFLOW_DETAIL, { timeoutMsg: "没有进入工作流详情页" });
  206. // 4a) 面包屑只有「自动化 › 工作流名」两级:项目不是一页,不该占一级点不动的面包屑;
  207. // 项目归属写在标题旁的小标上。
  208. await waitForTestIdByDom(TID_WORKFLOW_DETAIL_PROJECT, {
  209. timeoutMsg: "详情页标题旁没有项目归属小标",
  210. });
  211. expect(await readTestIdText(TID_WORKFLOW_DETAIL_PROJECT)).toBe("ZCodeProject");
  212. const crumbs = (await browser.execute(() => {
  213. const nav = document.querySelector('[data-testid="automations-main-drag-region"] nav');
  214. return nav
  215. ? Array.from(nav.querySelectorAll("li")).map((item) => ({
  216. text: item.textContent?.trim() ?? "",
  217. clickable: item.querySelector("button") !== null,
  218. }))
  219. : null;
  220. })) as { text: string; clickable: boolean }[] | null;
  221. expect(crumbs).toHaveLength(2);
  222. expect(crumbs?.[1]?.text).toBe(WORKFLOW_NAME);
  223. expect(crumbs?.map((crumb) => crumb.clickable)).toEqual([true, false]);
  224. // 4b) 一级面包屑回到列表,卡片还在;再点卡片回到详情。
  225. await clickTestIdByDom("settings-breadcrumb-section", {
  226. timeoutMsg: "详情页没有可点的一级面包屑",
  227. });
  228. await waitForTestIdByDom(cardTestId, { timeoutMsg: "点一级面包屑后没有回到工作流列表" });
  229. await clickTestIdByDom(cardTestId, { timeoutMsg: "无法再次点击工作流卡片进入详情" });
  230. await waitForTestIdByDom(TID_WORKFLOW_DETAIL, { timeoutMsg: "没有再次进入工作流详情页" });
  231. await setInputValueByTestIdDom(TID_WORKFLOW_DETAIL_DESCRIPTION, EDITED_DESCRIPTION, {
  232. timeoutMsg: "详情页没有出现说明输入框",
  233. });
  234. await clickTestIdByDom(TID_WORKFLOW_META_SAVE, {
  235. timeoutMsg: "改说明后没有出现「保存元数据」",
  236. });
  237. // 5) 磁盘:frontmatter 更新、脚本正文逐字节不变。
  238. await browser.waitUntil(
  239. async () => (await readFile(WORKFLOW_FILE, "utf-8")).includes(EDITED_DESCRIPTION),
  240. { timeout: 15000, timeoutMsg: "保存后磁盘文件的说明没有更新" },
  241. );
  242. const saved = await readFile(WORKFLOW_FILE, "utf-8");
  243. expect(saved.startsWith("/* zcode-workflow\n")).toBe(true);
  244. expect(saved.endsWith(`*/\n${SCRIPT}`)).toBe(true);
  245. expect(saved).toContain("whenToUse: 准备发版时");
  246. expect(saved).toContain("required: true");
  247. // 6) 详情页 ⋯ 菜单 → 删除 → 二次确认 → 回到列表空态,文件消失。
  248. await clickTestIdByWebDriver(TID_WORKFLOW_DETAIL_MENU, {
  249. timeoutMsg: "详情页没有「更多操作」菜单",
  250. });
  251. await clickTestIdByDom(testId(TID_WORKFLOW_ACTION_DELETE, WORKFLOW_NAME), {
  252. timeoutMsg: "详情页菜单没有「删除工作流」项",
  253. });
  254. await clickTestIdByDom(TID_CONFIRM_DIALOG_CONFIRM, {
  255. timeoutMsg: "删除二次确认弹窗没有出现",
  256. });
  257. await waitForTestIdByDom(TID_WORKFLOWS_EMPTY, {
  258. timeout: 15000,
  259. timeoutMsg: "删除后没有回到工作流空态",
  260. });
  261. await browser.waitUntil(async () => !(await fileExists(WORKFLOW_FILE)), {
  262. timeout: 10000,
  263. timeoutMsg: "删除后磁盘文件仍然存在",
  264. });
  265. });
  266. });
  267. // ── 全局工作流:置顶「全局」组 + 全局→项目搬文件 + 项目→全局 AI 概括(docs/dynamic-workflow/launch.md)──
  268. // E2E_HOME_DIR 由 wdio 配置设为隔离目录并写进 HOME(wdio.conf.ts:520),app / agent 进程都继承它,
  269. // 因此 agent 的 os.homedir() 解析到这里,全局根 = `<E2E_HOME>/.zcode/workflows/`。
  270. const E2E_HOME = dirname(DEFAULT_WORKSPACE);
  271. const GLOBAL_WORKFLOW_NAME = "global-note";
  272. const GLOBAL_WORKFLOWS_DIR = join(E2E_HOME, ".zcode", "workflows");
  273. const GLOBAL_WORKFLOW_FILE = join(GLOBAL_WORKFLOWS_DIR, `${GLOBAL_WORKFLOW_NAME}.dwf.ts`);
  274. const GLOBAL_PROJECT_WORKFLOWS_DIR = join(DEFAULT_WORKSPACE, ".zcode", "workflows");
  275. const GLOBAL_PROJECT_WORKFLOW_FILE = join(
  276. GLOBAL_PROJECT_WORKFLOWS_DIR,
  277. `${GLOBAL_WORKFLOW_NAME}.dwf.ts`,
  278. );
  279. // 无实参的全局工作流:「移到项目…」是逐字节搬文件,脚本正文两端必须完全一致。
  280. const GLOBAL_SCRIPT = [
  281. "export default async ({ agent }) => {",
  282. ' await agent("做一次深度调研");',
  283. "};",
  284. "",
  285. ].join("\n");
  286. const GLOBAL_SEED = [
  287. "/* zcode-workflow",
  288. "description: 深度调研(全局)",
  289. "*/",
  290. GLOBAL_SCRIPT,
  291. ].join("\n");
  292. describe("全局工作流中枢 E2E", () => {
  293. before(async () => {
  294. await mkdir(GLOBAL_WORKFLOWS_DIR, { recursive: true });
  295. await writeFile(GLOBAL_WORKFLOW_FILE, GLOBAL_SEED, "utf-8");
  296. });
  297. after(async () => {
  298. await browser.electron.restoreAllMocks();
  299. await rm(GLOBAL_WORKFLOW_FILE, { force: true });
  300. await rm(GLOBAL_PROJECT_WORKFLOW_FILE, { force: true });
  301. await clearAppData();
  302. });
  303. it("全局组置顶;全局→项目搬文件;项目→全局开新会话发概括提示、文件不动", async function () {
  304. this.timeout(150000);
  305. await prepareHubCase();
  306. // 1) 自动化页 →「工作流」标签。
  307. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  308. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  309. timeoutMsg: "自动化页标题没有「工作流」切换",
  310. });
  311. // 2) 顶部「全局」组出现,且含预置的 global-note 卡片。
  312. await waitForTestIdByDom(TID_WORKFLOW_GLOBAL_GROUP, {
  313. timeout: 20000,
  314. timeoutMsg: "工作流页没有出现「全局」组",
  315. });
  316. const globalCardTestId = testId(TID_WORKFLOW_CARD, GLOBAL_WORKFLOW_NAME);
  317. await waitForTestIdByDom(globalCardTestId, {
  318. timeout: 20000,
  319. timeoutMsg: "「全局」组里没有出现预置的 global-note 卡片",
  320. });
  321. // 3) 卡片 ⋯ →「移到项目…」→ 移动窗 → 提交。
  322. await clickTestIdByWebDriver(testId(TID_WORKFLOW_CARD_MENU, GLOBAL_WORKFLOW_NAME), {
  323. timeoutMsg: "全局卡片没有「更多操作」菜单",
  324. });
  325. await clickTestIdByDom(testId(TID_WORKFLOW_ACTION_MOVE, GLOBAL_WORKFLOW_NAME), {
  326. timeoutMsg: "全局卡片菜单没有「移到项目…」项",
  327. });
  328. await waitForTestIdByDom(TID_WORKFLOW_MOVE_DIALOG, { timeoutMsg: "没有出现「移到项目」窗" });
  329. await clickTestIdByDom(TID_WORKFLOW_MOVE_DIALOG_SUBMIT, {
  330. timeoutMsg: "「移到项目」窗没有提交按钮",
  331. });
  332. // 4) 磁盘:文件已搬到项目目录,从 HOME 消失。
  333. await browser.waitUntil(async () => fileExists(GLOBAL_PROJECT_WORKFLOW_FILE), {
  334. timeout: 15000,
  335. timeoutMsg: "移到项目后文件没有出现在项目目录",
  336. });
  337. await browser.waitUntil(async () => !(await fileExists(GLOBAL_WORKFLOW_FILE)), {
  338. timeout: 10000,
  339. timeoutMsg: "移到项目后 HOME 里的文件仍然存在",
  340. });
  341. // 5) 卡片现在落在项目组里,且「全局」组仍在项目组之上(比较 DOM 顺序)。
  342. const projectGroupTestId = await browser.waitUntil(
  343. async () => {
  344. const tid = await browser.execute((prefix: string) => {
  345. const group = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  346. (item) => item.dataset.testid?.startsWith(prefix),
  347. );
  348. return group?.dataset.testid ?? null;
  349. }, TID_WORKFLOW_PROJECT_GROUP);
  350. return tid ?? false;
  351. },
  352. { timeout: 15000, timeoutMsg: "移到项目后没有出现项目组" },
  353. );
  354. const order = await browser.execute(
  355. (globalTid: string, projectTid: string) => {
  356. const globalEl = document.querySelector<HTMLElement>(`[data-testid="${globalTid}"]`);
  357. const projectEl = document.querySelector<HTMLElement>(`[data-testid="${projectTid}"]`);
  358. if (!globalEl || !projectEl) return null;
  359. // Node.DOCUMENT_POSITION_FOLLOWING = 4:project 在 global 之后。
  360. return (globalEl.compareDocumentPosition(projectEl) & 4) !== 0
  361. ? "global-first"
  362. : "project-first";
  363. },
  364. TID_WORKFLOW_GLOBAL_GROUP,
  365. projectGroupTestId as string,
  366. );
  367. expect(order).toBe("global-first");
  368. // 卡片仍可见(此刻在项目组里)。
  369. await waitForTestIdByDom(globalCardTestId, { timeoutMsg: "移到项目后卡片消失了" });
  370. // 6) 项目卡片 ⋯ →「提升为全局」(2026-09-04 追记):不搬文件,而是在本项目开新会话、自动发送
  371. // 概括提示(createSession.firstInput)。断言:切到新会话,首条用户消息含工作流名、路径与
  372. // scope: "global" 指令;两处文件都不动(不变式 9:提升不搬、不删)。模型回合本身不断言
  373. // (skipProvider 下没有 provider,那一跳失败与否与本特性无关)。
  374. await clickTestIdByWebDriver(testId(TID_WORKFLOW_CARD_MENU, GLOBAL_WORKFLOW_NAME), {
  375. timeoutMsg: "项目卡片没有「更多操作」菜单",
  376. });
  377. await clickTestIdByDom(testId(TID_WORKFLOW_ACTION_MOVE, GLOBAL_WORKFLOW_NAME), {
  378. timeoutMsg: "项目卡片菜单没有「提升为全局」项",
  379. });
  380. await waitForUserMessageContaining(GLOBAL_WORKFLOW_NAME);
  381. const promoteMessage = (await getMessages("user")).find((message) =>
  382. message.text.includes(GLOBAL_WORKFLOW_NAME),
  383. );
  384. expect(promoteMessage?.text ?? "").toContain(GLOBAL_PROJECT_WORKFLOW_FILE);
  385. expect(promoteMessage?.text ?? "").toContain('scope: "global"');
  386. // 文件不动:项目档还在,HOME 里没有被搬回去的同名文件。
  387. expect(await fileExists(GLOBAL_PROJECT_WORKFLOW_FILE)).toBe(true);
  388. expect(await fileExists(GLOBAL_WORKFLOW_FILE)).toBe(false);
  389. });
  390. });
  391. // ── 直接启动:中枢「运行」→ 新会话顶部启动卡(docs/dynamic-workflow/launch.md)─────────
  392. // 与前两组一样只碰 UI + 项目目录里的 `.zcode/workflows/`,且刻意用**无 agent()/模型调用**的
  393. // 常量工作流:run 的子代理一个都不起,因此整条路(建会话 → startSavedWorkflow → run 结算)
  394. // 都不需要 provider 回放,skipProvider 下即可跑到 completed。run 终态之后会触发既有的完成
  395. // 通知回合(那一跳才第一次要模型),本组**刻意断言到启动卡 completed 为止**,不依赖模型——
  396. // 与 spec 测试地图「完成通知回合按既有 replay 惯例处理或断言到通知行为止」一致。
  397. const LAUNCH_OK_NAME = "direct-launch-ok";
  398. const LAUNCH_OK_ARG = "topic";
  399. const LAUNCH_OK_ARG_VALUE = "adaptive concurrency in agent runtimes";
  400. const LAUNCH_OK_FILE = join(WORKFLOWS_DIR, `${LAUNCH_OK_NAME}.dwf.ts`);
  401. // 脚本体:无 agent()、立即返回常量。声明一个必填实参 `topic`,好让「运行」弹出实参窗
  402. // (无实参的项目档点击即跑、不弹窗,见 spec)。编译干净(`return <字面量>` 是合法脚本体)。
  403. const LAUNCH_OK_SEED = [
  404. "/* zcode-workflow",
  405. "description: 常量工作流(直接启动 E2E)",
  406. "args:",
  407. " topic:",
  408. " type: string",
  409. " required: true",
  410. "*/",
  411. "return { ok: true };",
  412. "",
  413. ].join("\n");
  414. // 在跑一段时间的常量工作流(composer 徽标直达 E2E,docs/dynamic-workflow/presentation.md):
  415. // 零 agent、零 provider,靠 `world.run("sleep", …)` 停留在 running——这是沙箱里唯一不需要模型
  416. // 又能让 run 停住的手段(沙箱 realm 只有 ES intrinsics,没有 setTimeout)。cmd 是编译期字面量,
  417. // 直接启动把它编进 declaredRunCommands,不需要确认窗。无实参的项目档点「运行」即跑、不弹实参窗。
  418. // 注:`sleep` 依赖 POSIX 环境;桌面 e2e 只在 macOS / Linux 容器里跑。
  419. const LAUNCH_SLEEP_NAME = "direct-launch-sleeping";
  420. const LAUNCH_SLEEP_FILE = join(WORKFLOWS_DIR, `${LAUNCH_SLEEP_NAME}.dwf.ts`);
  421. const LAUNCH_SLEEP_SEED = [
  422. "/* zcode-workflow",
  423. "description: 停留 running 的常量工作流(composer 徽标直达 E2E)",
  424. "*/",
  425. 'await world.run("sleep", ["40"]);',
  426. "return { ok: true };",
  427. "",
  428. ].join("\n");
  429. // 保存 / 再次运行(docs/dynamic-workflow/transcript-and-notifications.md「Saving the run, and running
  430. // it again」):无实参的项目档,点「运行」即跑。脚本体与本组其他常量工作流逐字不同——「按 run 跑的
  431. // 那一份认出已保存」这条规则必须只能命中它自己。
  432. const LAUNCH_SAVE_NAME = "direct-launch-save";
  433. const LAUNCH_SAVE_FILE = join(WORKFLOWS_DIR, `${LAUNCH_SAVE_NAME}.dwf.ts`);
  434. const LAUNCH_SAVE_SCRIPT = "return { ok: true, savedFromRun: 1 };\n";
  435. const LAUNCH_SAVE_SEED = [
  436. "/* zcode-workflow",
  437. "description: 保存与再次运行(直接启动 E2E)",
  438. "*/",
  439. LAUNCH_SAVE_SCRIPT,
  440. ].join("\n");
  441. // 「作为文件打开」(docs/dynamic-workflow/authoring.md「How the user sees them」):零 agent 的常量工作流
  442. // 发布一份 markdown 产物,run 完成后从侧板打开产物 tab,点「作为文件打开」。系统默认 App 那一跳由
  443. // shell.openPath 的 mock 接住——断言的是它收到的路径,以及那个路径上真的落了这一版的字节。
  444. const LAUNCH_ARTIFACT_NAME = "direct-launch-artifact";
  445. const LAUNCH_ARTIFACT_FILE = join(WORKFLOWS_DIR, `${LAUNCH_ARTIFACT_NAME}.dwf.ts`);
  446. const LAUNCH_ARTIFACT_ID = "e2e-report";
  447. const LAUNCH_ARTIFACT_MARKDOWN = "# E2E 报告\n\n作为文件打开。\n";
  448. const LAUNCH_ARTIFACT_SEED = [
  449. "/* zcode-workflow",
  450. "description: 发布 markdown 产物(作为文件打开 E2E)",
  451. "*/",
  452. `await artifact.markdown(${JSON.stringify(LAUNCH_ARTIFACT_ID)}, ${JSON.stringify(
  453. LAUNCH_ARTIFACT_MARKDOWN,
  454. )}, { title: "E2E 报告" });`,
  455. "return { ok: true };",
  456. "",
  457. ].join("\n");
  458. const LAUNCH_FAIL_NAME = "direct-launch-broken";
  459. const LAUNCH_FAIL_FILE = join(WORKFLOWS_DIR, `${LAUNCH_FAIL_NAME}.dwf.ts`);
  460. // frontmatter 仍然合法(卡片照常出现、实参窗照常弹),脚本体带一个类型错误(TS2322:把字符串
  461. // 赋给 number)。编译只在启动的 ② 阶段发生,因此错误在 startSavedWorkflow 的 ACK 里以
  462. // compile_failed 回来,被实参窗行内错误区接住——会话在此之前不存在(不变式 2)。
  463. const LAUNCH_FAIL_SEED = [
  464. "/* zcode-workflow",
  465. "description: 编译失败工作流(直接启动 E2E)",
  466. "args:",
  467. " topic:",
  468. " type: string",
  469. " required: true",
  470. "*/",
  471. 'const answer: number = "not a number";',
  472. "return answer;",
  473. "",
  474. ].join("\n");
  475. // 脚本点名了一个本机目录里没有的模型(docs/dynamic-workflow/launch.md「Models the script names」):
  476. // 编译本身干净,解不出来的名字按 9011 与编译诊断同一条路拒绝(compile_failed)。脚本里只**声明**
  477. // 这个子代理、从不 ask 它,所以即使解析意外放行也不会碰 provider。
  478. const LAUNCH_MODEL_NAME = "direct-launch-unknown-model";
  479. const LAUNCH_MODEL_FILE = join(WORKFLOWS_DIR, `${LAUNCH_MODEL_NAME}.dwf.ts`);
  480. const LAUNCH_MODEL_UNKNOWN = "no-such-model-e2e";
  481. const LAUNCH_MODEL_SEED = [
  482. "/* zcode-workflow",
  483. "description: 点名未知模型的工作流(直接启动 E2E)",
  484. "args:",
  485. " topic:",
  486. " type: string",
  487. " required: true",
  488. "*/",
  489. `agent("judge", { model: "${LAUNCH_MODEL_UNKNOWN}" });`,
  490. "return 1;",
  491. "",
  492. ].join("\n");
  493. // 实参很多的工作流(docs/dynamic-workflow/launch.md「The launch dialog」的三段式布局):40 个声明
  494. // 的实参远高于视口,其中靠中间的一个是无默认值的必填项——既断言窗口不溢出、按钮够得着,也断言
  495. // 校验失败时那个字段被带进视野。每三个里有一个 boolean:开关在 form 里带一个绝对定位的隐藏原生
  496. // 控件,它曾经逃出实参滚动区、把窗口自身也撑出一条滚动条。脚本体是常量,本用例也从不真正启动它。
  497. const LAUNCH_MANY_NAME = "direct-launch-many-args";
  498. const LAUNCH_MANY_FILE = join(WORKFLOWS_DIR, `${LAUNCH_MANY_NAME}.dwf.ts`);
  499. const LAUNCH_MANY_COUNT = 40;
  500. const LAUNCH_MANY_REQUIRED = "arg20";
  501. const LAUNCH_MANY_SEED = [
  502. "/* zcode-workflow",
  503. "description: 实参很多的常量工作流(实参窗限高 E2E)",
  504. "args:",
  505. ...Array.from({ length: LAUNCH_MANY_COUNT }, (_, index) => {
  506. const name = `arg${String(index).padStart(2, "0")}`;
  507. if (name === LAUNCH_MANY_REQUIRED) {
  508. return [` ${name}:`, " type: string", " required: true"];
  509. }
  510. return index % 3 === 0
  511. ? [` ${name}:`, " type: boolean", " default: true"]
  512. : [` ${name}:`, " type: string", ` default: v${index}`];
  513. }).flat(),
  514. "*/",
  515. "return { ok: true };",
  516. "",
  517. ].join("\n");
  518. interface LaunchDialogGeometry {
  519. viewportHeight: number;
  520. dialogTop: number;
  521. dialogBottom: number;
  522. /** 提交按钮中心点上最上层的元素就是它自己(没被裁掉、没被盖住、在视口内)。 */
  523. submitHit: boolean;
  524. /** 窗口自身是否可滚:实参区之外不该再有第二条滚动条。 */
  525. dialogScrolls: boolean;
  526. fieldsClientHeight: number;
  527. fieldsScrollHeight: number;
  528. /** 指定实参控件是否完整落在滚动区的可视范围内。 */
  529. argVisible: boolean;
  530. argFocused: boolean;
  531. }
  532. /** 量实参窗:窗口与视口的关系、提交按钮是否点得到、滚动区的高度,以及某个实参控件的可见性。 */
  533. async function readLaunchDialogGeometry(argName: string): Promise<LaunchDialogGeometry | null> {
  534. return browser.execute(
  535. (dialogTid, fieldsTid, submitTid, argTid) => {
  536. const byTestId = (tid: string) =>
  537. Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  538. (item) => item.dataset.testid === tid,
  539. );
  540. const dialog = byTestId(dialogTid);
  541. const fields = byTestId(fieldsTid);
  542. const submit = byTestId(submitTid);
  543. const arg = byTestId(argTid);
  544. if (!dialog || !fields || !submit || !arg) return null;
  545. const dialogRect = dialog.getBoundingClientRect();
  546. const submitRect = submit.getBoundingClientRect();
  547. const fieldsRect = fields.getBoundingClientRect();
  548. const argRect = arg.getBoundingClientRect();
  549. const top = document.elementFromPoint(
  550. submitRect.left + submitRect.width / 2,
  551. submitRect.top + submitRect.height / 2,
  552. );
  553. return {
  554. viewportHeight: window.innerHeight,
  555. dialogTop: dialogRect.top,
  556. dialogBottom: dialogRect.bottom,
  557. submitHit: top !== null && submit.contains(top),
  558. dialogScrolls: dialog.scrollHeight > dialog.clientHeight,
  559. fieldsClientHeight: fields.clientHeight,
  560. fieldsScrollHeight: fields.scrollHeight,
  561. argVisible: argRect.top >= fieldsRect.top && argRect.bottom <= fieldsRect.bottom,
  562. argFocused: document.activeElement === arg,
  563. };
  564. },
  565. TID_WORKFLOW_LAUNCH_DIALOG,
  566. TID_WORKFLOW_LAUNCH_FIELDS,
  567. TID_WORKFLOW_LAUNCH_SUBMIT,
  568. testId(TID_WORKFLOW_LAUNCH_ARG, argName),
  569. );
  570. }
  571. /** 按前缀读某个 testid 元素的可见文本(启动卡 / 任务项的 testid 后缀是运行期才知道的 key)。 */
  572. async function readTestIdPrefixText(prefix: string): Promise<string | null> {
  573. return browser.execute((currentPrefix) => {
  574. const element = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  575. (item) => item.dataset.testid?.startsWith(currentPrefix),
  576. );
  577. return element?.textContent?.replace(/ /g, " ").trim() ?? null;
  578. }, prefix);
  579. }
  580. /**
  581. * 启动轮 run 卡当前的 run 状态(`data-workflow-run-status`);卡不在时为 null。直接启动的会话顶部长出的
  582. * 就是普通的轮尾 run 卡(docs/dynamic-workflow/presentation.md「The run card」),不是别的卡。
  583. */
  584. async function readLaunchCardStatus(): Promise<string | null> {
  585. return browser.execute(
  586. (prefix) => {
  587. const card = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  588. (item) => item.dataset.testid?.startsWith(prefix),
  589. );
  590. return card?.getAttribute("data-workflow-run-status") ?? null;
  591. },
  592. testId(TID_CHAT_WORKFLOW_RUN_DIGEST, ""),
  593. );
  594. }
  595. /** 读 run 详情侧板来龙去脉节的可见文本(docs/dynamic-workflow/launch.md「The launch turn」)。 */
  596. async function readLaunchProvenanceText(): Promise<string | null> {
  597. return browser.execute(() => {
  598. const element = document.querySelector<HTMLElement>('[data-testid="workflow-run-provenance"]');
  599. return element?.textContent?.replace(/ /g, " ").trim() ?? null;
  600. });
  601. }
  602. /** 侧栏任务项数量(compile_failed 用例比较提交前后不变)。 */
  603. async function countTaskItems(): Promise<number> {
  604. return browser.execute(
  605. (prefix) => document.querySelectorAll(`[data-testid^="${prefix}"]`).length,
  606. testId(TID_TASK_ITEM, ""),
  607. );
  608. }
  609. /** 侧栏所有任务项的文本拼接(断言会话标题里出现工作流名)。 */
  610. async function readTaskItemsText(): Promise<string> {
  611. return browser.execute(
  612. (prefix) =>
  613. Array.from(document.querySelectorAll<HTMLElement>(`[data-testid^="${prefix}"]`))
  614. .map((item) => item.textContent?.replace(/ /g, " ") ?? "")
  615. .join("\n"),
  616. testId(TID_TASK_ITEM, ""),
  617. );
  618. }
  619. /** 会话转写(v4 timeline)的全文(断言没有旧的合成 prompt 文案)。 */
  620. async function readTimelineText(): Promise<string> {
  621. return browser.execute((timelineTestId) => {
  622. const element = document.querySelector<HTMLElement>(`[data-testid="${timelineTestId}"]`);
  623. return element?.textContent?.replace(/ /g, " ") ?? "";
  624. }, TID_V4_TIMELINE);
  625. }
  626. describe("直接启动 E2E", () => {
  627. before(async () => {
  628. await mkdir(WORKFLOWS_DIR, { recursive: true });
  629. await writeFile(LAUNCH_OK_FILE, LAUNCH_OK_SEED, "utf-8");
  630. await writeFile(LAUNCH_FAIL_FILE, LAUNCH_FAIL_SEED, "utf-8");
  631. await writeFile(LAUNCH_MANY_FILE, LAUNCH_MANY_SEED, "utf-8");
  632. await writeFile(LAUNCH_MODEL_FILE, LAUNCH_MODEL_SEED, "utf-8");
  633. await writeFile(LAUNCH_SLEEP_FILE, LAUNCH_SLEEP_SEED, "utf-8");
  634. await writeFile(LAUNCH_SAVE_FILE, LAUNCH_SAVE_SEED, "utf-8");
  635. await writeFile(LAUNCH_ARTIFACT_FILE, LAUNCH_ARTIFACT_SEED, "utf-8");
  636. });
  637. after(async () => {
  638. await browser.electron.restoreAllMocks();
  639. await rm(WORKFLOWS_DIR, { recursive: true, force: true });
  640. await clearAppData();
  641. });
  642. it("中枢「运行」常量工作流:新会话顶部启动卡跑到 completed,无用户气泡、无确认窗", async function () {
  643. this.timeout(180000);
  644. // 只需要登录 + workspace,就绪即可;常量工作流不碰 provider(见组注释)。
  645. await prepareHubCase();
  646. // 1) 自动化页 →「工作流」标签 → 常量工作流的卡片。
  647. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  648. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  649. timeoutMsg: "自动化页标题没有「工作流」切换",
  650. });
  651. const okCardTestId = testId(TID_WORKFLOW_CARD, LAUNCH_OK_NAME);
  652. await waitForTestIdByDom(okCardTestId, {
  653. timeout: 20000,
  654. timeoutMsg: "工作流列表没有出现常量工作流卡片",
  655. });
  656. // 2) 点卡片的「运行」→ 有实参的项目档弹出实参窗:头部 = 名字 + 作用域徽标,且带「新会话」说明。
  657. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_OK_NAME), {
  658. timeoutMsg: "常量工作流卡片没有「运行」按钮",
  659. });
  660. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  661. timeout: 15000,
  662. timeoutMsg: "点「运行」后没有弹出实参窗",
  663. });
  664. const dialogText = (await readTestIdPrefixText(TID_WORKFLOW_LAUNCH_DIALOG)) ?? "";
  665. expect(dialogText).toContain(LAUNCH_OK_NAME); // 名字(mono)
  666. expect(dialogText).toContain("项目"); // 作用域徽标(scope.project)
  667. expect(dialogText).toContain("的新会话中运行"); // 「将立即在 X 的新会话中运行」说明
  668. // 3) 填实参并提交。提交前记下任务数,稍后新会话应比它多一个。
  669. const tasksBeforeLaunch = await countTaskItems();
  670. await setInputValueByTestIdDom(
  671. testId(TID_WORKFLOW_LAUNCH_ARG, LAUNCH_OK_ARG),
  672. LAUNCH_OK_ARG_VALUE,
  673. {
  674. timeoutMsg: "实参窗没有出现 topic 输入框",
  675. },
  676. );
  677. await clickTestIdByDom(TID_WORKFLOW_LAUNCH_SUBMIT, {
  678. timeoutMsg: "实参窗没有「运行」提交按钮",
  679. });
  680. // 4) 应用切到新会话,转写顶部长出 run 卡(不是用户气泡、不是 CreateWorkflow 工具行),
  681. // 卡上带工作流名;实参值不在卡上,而在 run 详情侧板的来龙去脉节里。
  682. const launchCardPrefix = testId(TID_CHAT_WORKFLOW_RUN_DIGEST, "");
  683. await browser.waitUntil(
  684. async () =>
  685. (await readLaunchCardStatus()) !== null ||
  686. Boolean(await readTestIdPrefixText(launchCardPrefix)),
  687. {
  688. timeout: 60000,
  689. timeoutMsg: "新会话顶部没有出现 run 卡",
  690. },
  691. );
  692. const cardText = (await readTestIdPrefixText(launchCardPrefix)) ?? "";
  693. expect(cardText).toContain(LAUNCH_OK_NAME);
  694. expect(cardText).not.toContain(LAUNCH_OK_ARG_VALUE);
  695. // 4b) 卡上的 ⤢ 开 run 详情侧板:来龙去脉节写着「由你从工作流中枢启动」、作用域与刚填的实参值。
  696. await clickTestIdByDom("workflow-card-open-details", {
  697. timeoutMsg: "run 卡上没有「打开运行详情」",
  698. });
  699. await browser.waitUntil(async () => (await readLaunchProvenanceText()) !== null, {
  700. timeout: 30000,
  701. timeoutMsg: "run 详情侧板没有出现来龙去脉节",
  702. });
  703. const provenanceText = (await readLaunchProvenanceText()) ?? "";
  704. expect(provenanceText).toContain(LAUNCH_OK_ARG_VALUE);
  705. // 5) 无用户气泡、无旧的合成 prompt 文案:转写里不出现「Run the saved workflow」这类
  706. // 被本 spec 删除的 composer 文案。
  707. expect(await readTimelineText()).not.toContain("Run the saved workflow");
  708. // 6) 无确认窗:直接启动是记录在案的确认旁路,通用二次确认窗不应出现。
  709. const hasConfirmDialog = await browser.execute(
  710. (confirmTestId) => Boolean(document.querySelector(`[data-testid="${confirmTestId}"]`)),
  711. TID_CONFIRM_DIALOG_CONFIRM,
  712. );
  713. expect(hasConfirmDialog).toBe(false);
  714. // 7) run 卡的状态跑到 completed(常量工作流零 agent,立即结算)。宽超时:
  715. // run-started → run-settled 走真实 dwf 运行时的子进程。
  716. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  717. timeout: 90000,
  718. timeoutMsg: "run 卡的状态没有跑到 completed",
  719. });
  720. // 8) 侧栏会话标题 = 工作流名(titleSource: first_input,不用消息全文、不等 LLM);
  721. // 且确实新开了一个会话。
  722. await browser.waitUntil(async () => (await countTaskItems()) === tasksBeforeLaunch + 1, {
  723. timeout: 20000,
  724. timeoutMsg: "直接启动后没有新增一个会话",
  725. });
  726. expect(await readTaskItemsText()).toContain(LAUNCH_OK_NAME);
  727. });
  728. it("编译失败的工作流:实参窗行内错误显示 compile_failed,会话列表不新增", async function () {
  729. this.timeout(150000);
  730. await prepareHubCase();
  731. // 1) 自动化页 →「工作流」标签 → 编译失败工作流的卡片(frontmatter 合法,卡片照常出现)。
  732. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  733. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  734. timeoutMsg: "自动化页标题没有「工作流」切换",
  735. });
  736. const failCardTestId = testId(TID_WORKFLOW_CARD, LAUNCH_FAIL_NAME);
  737. await waitForTestIdByDom(failCardTestId, {
  738. timeout: 20000,
  739. timeoutMsg: "工作流列表没有出现编译失败工作流卡片",
  740. });
  741. // 2) 「运行」→ 实参窗 → 填实参并提交。记下提交前的任务数。
  742. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_FAIL_NAME), {
  743. timeoutMsg: "编译失败工作流卡片没有「运行」按钮",
  744. });
  745. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  746. timeout: 15000,
  747. timeoutMsg: "点「运行」后没有弹出实参窗",
  748. });
  749. const tasksBeforeReject = await countTaskItems();
  750. await setInputValueByTestIdDom(testId(TID_WORKFLOW_LAUNCH_ARG, LAUNCH_OK_ARG), "x", {
  751. timeoutMsg: "实参窗没有出现 topic 输入框",
  752. });
  753. await clickTestIdByDom(TID_WORKFLOW_LAUNCH_SUBMIT, {
  754. timeoutMsg: "实参窗没有「运行」提交按钮",
  755. });
  756. // 3) 行内错误区出现,标题是 compile_failed 的文案;实参窗留着(不导航、不留会话)。
  757. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_ERROR, {
  758. timeout: 30000,
  759. timeoutMsg: "编译失败没有在实参窗行内错误区显示",
  760. });
  761. const errorText = (await readTestIdPrefixText(TID_WORKFLOW_LAUNCH_ERROR)) ?? "";
  762. expect(errorText).toContain("工作流脚本编译失败");
  763. // 实参窗仍在(失败不关窗)。
  764. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  765. timeoutMsg: "编译失败后实参窗被意外关闭",
  766. });
  767. // 4) 会话列表没有新增:agent 侧 ① ② 阶段失败前不建任何行,GUI 侧随即 deleteSession
  768. // 收回刚建的空会话(不变式 2)。
  769. await browser.waitUntil(async () => (await countTaskItems()) === tasksBeforeReject, {
  770. timeout: 15000,
  771. timeoutMsg: "编译失败却新增了一个会话",
  772. });
  773. });
  774. it("实参很多的工作流:实参窗不溢出视口,实参区自己滚动,校验失败把出错字段带进视野", async function () {
  775. this.timeout(150000);
  776. await prepareHubCase();
  777. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  778. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  779. timeoutMsg: "自动化页标题没有「工作流」切换",
  780. });
  781. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_MANY_NAME), {
  782. timeout: 20000,
  783. timeoutMsg: "工作流列表没有出现实参很多的工作流卡片",
  784. });
  785. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_MANY_NAME), {
  786. timeoutMsg: "实参很多的工作流卡片没有「运行」按钮",
  787. });
  788. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  789. timeout: 15000,
  790. timeoutMsg: "点「运行」后没有弹出实参窗",
  791. });
  792. const tasksBefore = await countTaskItems();
  793. // 1) 窗口整个在视口内,提交按钮点得到;实参区的内容比它的可视高度长,靠它自己滚动。
  794. // 必填项在列表中段,此刻还在可视区之外。等开窗动画(缩放)结束后再量。
  795. await browser.waitUntil(
  796. async () => {
  797. const geometry = await readLaunchDialogGeometry(LAUNCH_MANY_REQUIRED);
  798. return (
  799. geometry !== null &&
  800. geometry.dialogTop >= 0 &&
  801. geometry.dialogBottom <= geometry.viewportHeight &&
  802. geometry.submitHit
  803. );
  804. },
  805. { timeout: 15000, timeoutMsg: "实参很多时实参窗溢出了视口,或提交按钮点不到" },
  806. );
  807. const opened = await readLaunchDialogGeometry(LAUNCH_MANY_REQUIRED);
  808. expect(opened?.fieldsScrollHeight ?? 0).toBeGreaterThan(opened?.fieldsClientHeight ?? 0);
  809. expect(opened?.argVisible).toBe(false);
  810. // 只有实参区这一条滚动条:窗口自身不可滚。
  811. expect(opened?.dialogScrolls).toBe(false);
  812. // 2) 必填项留空直接提交:校验失败,那个字段被滚进可视区并拿到焦点;按钮仍然点得到。
  813. await clickTestIdByDom(TID_WORKFLOW_LAUNCH_SUBMIT, {
  814. timeoutMsg: "实参窗没有「运行」提交按钮",
  815. });
  816. await browser.waitUntil(
  817. async () => {
  818. const geometry = await readLaunchDialogGeometry(LAUNCH_MANY_REQUIRED);
  819. return geometry !== null && geometry.argVisible && geometry.argFocused;
  820. },
  821. { timeout: 15000, timeoutMsg: "校验失败后出错的必填字段没有被带进视野并聚焦" },
  822. );
  823. const revealed = await readLaunchDialogGeometry(LAUNCH_MANY_REQUIRED);
  824. expect(revealed?.submitHit).toBe(true);
  825. expect(revealed?.dialogScrolls).toBe(false);
  826. expect(revealed?.dialogTop ?? -1).toBeGreaterThanOrEqual(0);
  827. // 3) 校验失败不启动:实参窗留着,会话列表不新增。
  828. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  829. timeoutMsg: "校验失败后实参窗被意外关闭",
  830. });
  831. expect(await countTaskItems()).toBe(tasksBefore);
  832. });
  833. it("脚本点名的模型解不出来:实参窗行内显示 compile_failed 与那个名字的 9011,会话列表不新增", async function () {
  834. this.timeout(150000);
  835. await prepareHubCase();
  836. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  837. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  838. timeoutMsg: "自动化页标题没有「工作流」切换",
  839. });
  840. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_MODEL_NAME), {
  841. timeout: 20000,
  842. timeoutMsg: "工作流列表没有出现点名未知模型的工作流卡片",
  843. });
  844. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_MODEL_NAME), {
  845. timeoutMsg: "点名未知模型的工作流卡片没有「运行」按钮",
  846. });
  847. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  848. timeout: 15000,
  849. timeoutMsg: "点「运行」后没有弹出实参窗",
  850. });
  851. const tasksBefore = await countTaskItems();
  852. await setInputValueByTestIdDom(testId(TID_WORKFLOW_LAUNCH_ARG, LAUNCH_OK_ARG), "x", {
  853. timeoutMsg: "实参窗没有出现 topic 输入框",
  854. });
  855. await clickTestIdByDom(TID_WORKFLOW_LAUNCH_SUBMIT, {
  856. timeoutMsg: "实参窗没有「运行」提交按钮",
  857. });
  858. // 与脚本编不过同一个出口:标题是 compile_failed 的文案,细节是一条带位置的诊断。
  859. // 宿主有目录时细节点出名字;没有目录时说「这台宿主选不了模型」——两种都是脚本侧的改法。
  860. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_ERROR, {
  861. timeout: 30000,
  862. timeoutMsg: "解不出来的模型没有在实参窗行内错误区显示",
  863. });
  864. const errorText = (await readTestIdPrefixText(TID_WORKFLOW_LAUNCH_ERROR)) ?? "";
  865. expect(errorText).toContain("工作流脚本编译失败");
  866. expect(errorText).toMatch(/L\d+:C\d+/);
  867. expect(
  868. errorText.includes(LAUNCH_MODEL_UNKNOWN) || errorText.includes("cannot choose models"),
  869. ).toBe(true);
  870. await waitForTestIdByDom(TID_WORKFLOW_LAUNCH_DIALOG, {
  871. timeoutMsg: "解不出来的模型让实参窗被意外关闭",
  872. });
  873. await browser.waitUntil(async () => (await countTaskItems()) === tasksBefore, {
  874. timeout: 15000,
  875. timeoutMsg: "解不出来的模型却新增了一个会话",
  876. });
  877. });
  878. // composer 徽标直达(docs/dynamic-workflow/presentation.md「Other places a run appears」):
  879. // 会话里唯一在跑的是一条工作流时,点徽标不展开状态胶囊,直接打开该 run 的详情 side tab。
  880. it("唯一在跑的工作流:Activity 胶囊展开后从运行行打开详情 side tab", async function () {
  881. this.timeout(180000);
  882. await prepareHubCase();
  883. // 1) 自动化页 →「工作流」标签 → 无实参的项目档点「运行」即跑(不弹实参窗、不弹确认窗)。
  884. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  885. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  886. timeoutMsg: "自动化页标题没有「工作流」切换",
  887. });
  888. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_SLEEP_NAME), {
  889. timeout: 20000,
  890. timeoutMsg: "工作流列表没有出现停留 running 的常量工作流卡片",
  891. });
  892. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_SLEEP_NAME), {
  893. timeoutMsg: "常量工作流卡片没有「运行」按钮",
  894. });
  895. // 2) 新会话顶部长出 run 卡,run 进入 running(world.run 的 sleep 让它停在这里)。
  896. const launchCardPrefix = testId(TID_CHAT_WORKFLOW_RUN_DIGEST, "");
  897. await browser.waitUntil(async () => Boolean(await readTestIdPrefixText(launchCardPrefix)), {
  898. timeout: 60000,
  899. timeoutMsg: "新会话顶部没有出现 run 卡",
  900. });
  901. // 2b) 侧栏运行行(docs/dynamic-workflow/presentation.md「The sidebar run line」):发起它的会话行在标题下
  902. // 长出一条 running 的运行行;sleep 脚本没有 phase() 标记,所以轨道是一个隐含站点。
  903. await browser.waitUntil(
  904. async () =>
  905. browser.execute(
  906. (prefix) => {
  907. const rows = Array.from(
  908. document.querySelectorAll<HTMLElement>(`[data-testid^="${prefix}"]`),
  909. );
  910. return rows.some((row) => {
  911. const line = row.querySelector<HTMLElement>(
  912. '[data-workflow-run-line][data-run-status="running"]',
  913. );
  914. return (
  915. line !== null &&
  916. line.querySelector('[data-workflow-run-rail][data-implicit="true"]') !== null
  917. );
  918. });
  919. },
  920. testId(TID_TASK_ITEM, ""),
  921. ),
  922. { timeout: 60000, timeoutMsg: "侧栏里发起工作流的会话行没有长出 running 的运行行" },
  923. );
  924. // Activity 统一计数入口代替旧工作流名称胶囊。
  925. await $('[data-status-capsule="activity"]').waitForDisplayed({ timeout: 30000 });
  926. // 2d) 胶囊不盖住启动卡(docs/dynamic-workflow/presentation.md「The run card」,转写顶部 inset):
  927. // 启动轮是会话首轮且没有气泡,卡头部的配置 / 停止 / ⤢ 曾落在胶囊下面。clickTestIdByDom 走 DOM
  928. // click 不做命中测试,所以这里按按钮中心点 elementFromPoint,命中的必须是按钮自己。
  929. const coveredHeaderButtons = await browser.execute(() => {
  930. const header = document.querySelector<HTMLElement>('[data-testid="workflow-card-header"]');
  931. const buttons = Array.from(header?.querySelectorAll<HTMLElement>("button") ?? []);
  932. if (buttons.length === 0) return ["<no header buttons>"];
  933. return buttons
  934. .filter((button) => {
  935. const rect = button.getBoundingClientRect();
  936. const hit = document.elementFromPoint(
  937. rect.left + rect.width / 2,
  938. rect.top + rect.height / 2,
  939. );
  940. return !button.contains(hit);
  941. })
  942. .map((button) => button.getAttribute("aria-label") ?? button.outerHTML.slice(0, 80));
  943. });
  944. expect(coveredHeaderButtons).toEqual([]);
  945. // 3) Activity 计数:恰好一条 workflow、没有终端与独立子代理。
  946. await browser.waitUntil(
  947. async () => {
  948. const counts = await getV4ComposerBackgroundWorkCounts();
  949. return (
  950. counts?.workflowCount === 1 &&
  951. counts.bashCount === 0 &&
  952. counts.subagentCount === 0 &&
  953. counts.totalCount === 1
  954. );
  955. },
  956. { timeout: 60000, timeoutMsg: "Activity 没有显示唯一在跑的工作流" },
  957. );
  958. // 点 Activity 打开浮层,再点工作流行进入详情;不再从胶囊直接跳转。
  959. await openStatusCapsule("activity");
  960. await $('[data-workflow-run-details-trigger="true"]').click();
  961. await $('[data-side-pane-tab-id^="workflow-run:"]').waitForDisplayed({ timeout: 30000 });
  962. await openStatusCapsule("activity");
  963. const rowSelector = 'li[data-background-task-kind="workflow"]';
  964. await browser.waitUntil(
  965. async () =>
  966. browser.execute((selector) => {
  967. const row = document.querySelector<HTMLElement>(selector);
  968. return Boolean(
  969. row &&
  970. row.querySelector('[data-workflow-run-lamp="running"]') &&
  971. /\d/.test(row.querySelector(".tabular-nums")?.textContent ?? "") &&
  972. row.querySelector('[data-testid^="v4-background-work-cancel-"]'),
  973. );
  974. }, rowSelector),
  975. {
  976. timeout: 15000,
  977. timeoutMsg: "点开 Activity 后没有运行灯和单项停止控件",
  978. },
  979. );
  980. // 面板展开会移动 run 行;按当前布局重新悬停,并确认真实 hover 后再检查 Stop。
  981. await browser.waitUntil(
  982. async () => {
  983. await $(rowSelector).moveTo();
  984. return browser.execute((selector) => {
  985. const row = document.querySelector<HTMLElement>(selector);
  986. const stop = row?.querySelector<HTMLElement>(
  987. '[data-testid^="v4-background-work-cancel-"]',
  988. );
  989. return Boolean(row?.matches(":hover") && stop && getComputedStyle(stop).opacity === "1");
  990. }, rowSelector);
  991. },
  992. { timeout: 5000, timeoutMsg: "悬停 run 行时 Stop 没有出现" },
  993. );
  994. });
  995. // 并发芯片(docs/dynamic-workflow/concurrency.md「What the user sees」):芯片的数是一条界,字是
  996. // 「最大并发数」;它与 Configure 同进同退——run 在跑时就地调小界,芯片出现;run 完成后芯片离开,
  997. // 不再把一条已经没有东西在它下面跑的界挂成实时读数。
  998. it("并发芯片:在跑的 run 就地调小界后显示「最大并发数 N」,run 完成后芯片离开", async function () {
  999. this.timeout(180000);
  1000. await prepareHubCase();
  1001. // 1) 跑那条停留 running 的常量工作流(world.run sleep 40s),打开它的 run 侧板。
  1002. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1003. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1004. timeoutMsg: "自动化页标题没有「工作流」切换",
  1005. });
  1006. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_SLEEP_NAME), {
  1007. timeout: 20000,
  1008. timeoutMsg: "工作流列表没有出现停留 running 的常量工作流卡片",
  1009. });
  1010. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_SLEEP_NAME), {
  1011. timeoutMsg: "常量工作流卡片没有「运行」按钮",
  1012. });
  1013. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "running", {
  1014. timeout: 60000,
  1015. timeoutMsg: "run 卡没有进入 running",
  1016. });
  1017. await clickTestIdByDom("workflow-card-open-details", {
  1018. timeoutMsg: "run 卡上没有「打开运行详情」",
  1019. });
  1020. await waitForTestIdByDom("workflow-run-configure", {
  1021. timeout: 30000,
  1022. timeoutMsg: "在跑的 run 侧板上没有 Configure",
  1023. });
  1024. // 2) 跑在默认并发 D 上(没有自己的界):没有芯片。
  1025. expect(await readTestIdText("workflow-run-concurrency")).toBeNull();
  1026. // 3) Configure → 步进器减一 → 应用:只改界、run 在跑,就地生效(不另起 run)。
  1027. await clickRunSidePaneControl("workflow-run-configure");
  1028. await waitForTestIdByDom("workflow-run-settings-popover", {
  1029. timeoutMsg: "点 Configure 后没有设置弹层",
  1030. });
  1031. // 步进器停在默认并发 D = max(4, min(16, 核数 − 2)) 上,减一总有可调小的余地。
  1032. // 控件已改成 input;textContent 恒为空,Number("") 会把默认界误读为 0。
  1033. const boundInput = $('[data-testid="workflow-run-settings-bound-value"]');
  1034. const defaultBound = Number(await boundInput.getValue());
  1035. expect(defaultBound).toBeGreaterThan(1);
  1036. // 还没改:没有后果句(改动之前念哪一句都可能说错)。
  1037. expect(await readTestIdText("workflow-run-settings-consequence")).toBe("");
  1038. await clickTestIdByDom("workflow-run-settings-bound-decrease", {
  1039. timeoutMsg: "设置弹层没有「降低最大并发数」",
  1040. });
  1041. await expect(boundInput).toHaveValue(String(defaultBound - 1));
  1042. // 只改界、run 在跑:后果句是「就地生效」,不是「将停止当前运行」。
  1043. expect(await readTestIdText("workflow-run-settings-consequence")).toMatch(
  1044. /^(立即应用到当前运行,不会新起一次运行。|Applies to this run right away; no new run is started\.)$/,
  1045. );
  1046. await clickTestIdByDom("workflow-run-settings-apply", { timeoutMsg: "设置弹层没有「应用」" });
  1047. // 4) 芯片出现,字是界的字,数是调小后的界。
  1048. await browser.waitUntil(
  1049. async () => {
  1050. const text = await readTestIdText("workflow-run-concurrency");
  1051. return (
  1052. text !== null &&
  1053. new RegExp(`^(最大并发数|Max concurrency) ${defaultBound - 1}\\b`).test(text)
  1054. );
  1055. },
  1056. { timeout: 30000, timeoutMsg: "就地调小界后 run 侧板没有出现「最大并发数 N」芯片" },
  1057. );
  1058. // 5) run 跑完(sleep 结束):Configure 与芯片一起离开。
  1059. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1060. timeout: 90000,
  1061. timeoutMsg: "run 卡的状态没有跑到 completed",
  1062. });
  1063. await browser.waitUntil(
  1064. async () =>
  1065. (await readTestIdText("workflow-run-concurrency")) === null &&
  1066. (await readTestIdText("workflow-run-configure")) === null,
  1067. { timeout: 20000, timeoutMsg: "run 完成后侧板上仍有并发芯片或 Configure" },
  1068. );
  1069. });
  1070. it("完成的 run:侧板有「已保存」与「再次运行」,芯片直达中枢;删掉后「保存」按原样写回同一份脚本", async function () {
  1071. this.timeout(240000);
  1072. await prepareHubCase();
  1073. // 1) 中枢「运行」无实参的项目档:点即跑,新会话顶部的 run 卡跑到 completed。
  1074. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1075. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1076. timeoutMsg: "自动化页标题没有「工作流」切换",
  1077. });
  1078. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_SAVE_NAME), {
  1079. timeout: 20000,
  1080. timeoutMsg: "工作流列表没有出现保存用例的工作流卡片",
  1081. });
  1082. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_SAVE_NAME), {
  1083. timeoutMsg: "保存用例的工作流卡片没有「运行」按钮",
  1084. });
  1085. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1086. timeout: 90000,
  1087. timeoutMsg: "run 卡的状态没有跑到 completed",
  1088. });
  1089. // 2) ⤢ 打开 run 侧板:从中枢启动的 run 按名字规则天然「已保存」——芯片在状态行,动词是「再次运行」。
  1090. await clickTestIdByDom("workflow-card-open-details", {
  1091. timeoutMsg: "run 卡上没有「打开运行详情」",
  1092. });
  1093. await waitForTestIdByDom("workflow-saved-chip", {
  1094. timeout: 30000,
  1095. timeoutMsg: "run 侧板状态行没有出现「已保存」芯片",
  1096. });
  1097. await waitForTestIdByDom("workflow-save-run-again", {
  1098. timeout: 10000,
  1099. timeoutMsg: "run 侧板没有「再次运行」",
  1100. });
  1101. // 3) 芯片直达中枢里那个工作流的详情页。
  1102. await clickRunSidePaneControl("workflow-saved-chip");
  1103. await waitForTestIdByDom(TID_WORKFLOW_DETAIL, {
  1104. timeout: 20000,
  1105. timeoutMsg: "点芯片后没有进入工作流详情页",
  1106. });
  1107. expect((await readTestIdText(TID_WORKFLOW_DETAIL)) ?? "").toContain(LAUNCH_SAVE_NAME);
  1108. // 4) 在中枢把它删掉:中枢刷新会作废卡片的读缓存,这次 run 不再「已保存」。
  1109. await clickTestIdByWebDriver(TID_WORKFLOW_DETAIL_MENU, {
  1110. timeoutMsg: "详情页没有「更多操作」菜单",
  1111. });
  1112. await clickTestIdByDom(testId(TID_WORKFLOW_ACTION_DELETE, LAUNCH_SAVE_NAME), {
  1113. timeoutMsg: "详情页菜单没有「删除工作流」项",
  1114. });
  1115. await clickTestIdByDom(TID_CONFIRM_DIALOG_CONFIRM, {
  1116. timeoutMsg: "删除二次确认弹窗没有出现",
  1117. });
  1118. await browser.waitUntil(async () => !(await fileExists(LAUNCH_SAVE_FILE)), {
  1119. timeout: 10000,
  1120. timeoutMsg: "删除后磁盘文件仍然存在",
  1121. });
  1122. // 5) 回到发起它的会话,侧板上的动词翻回「保存」。
  1123. const sessionTaskTestId = await browser.execute(
  1124. (prefix, name) =>
  1125. Array.from(document.querySelectorAll<HTMLElement>(`[data-testid^="${prefix}"]`)).find(
  1126. (item) => item.textContent?.includes(name),
  1127. )?.dataset.testid ?? null,
  1128. testId(TID_TASK_ITEM, ""),
  1129. LAUNCH_SAVE_NAME,
  1130. );
  1131. expect(sessionTaskTestId).not.toBeNull();
  1132. await clickTestIdByDom(sessionTaskTestId!, { timeoutMsg: "侧栏里点不到发起它的会话" });
  1133. await clickTestIdByDom("workflow-card-open-details", {
  1134. timeout: 20000,
  1135. timeoutMsg: "回到会话后 run 卡上没有「打开运行详情」",
  1136. });
  1137. await waitForTestIdByDom("workflow-save-open", {
  1138. timeout: 30000,
  1139. timeoutMsg: "删掉工作流之后 run 侧板没有翻回「保存」",
  1140. });
  1141. // 6) 「保存」→ 弹层 → 按原样直接保存:不经模型回合,写下的是这次 run 实际执行的那一份脚本。
  1142. await clickRunSidePaneControl("workflow-save-open");
  1143. await waitForTestIdByDom("workflow-save-popover", { timeoutMsg: "点「保存」后没有弹层" });
  1144. await setInputValueByTestIdDom("workflow-save-name", LAUNCH_SAVE_NAME, {
  1145. timeoutMsg: "保存弹层没有名称输入框",
  1146. });
  1147. await clickTestIdByDom("workflow-save-submit", { timeoutMsg: "保存弹层没有「直接保存」" });
  1148. await browser.waitUntil(async () => fileExists(LAUNCH_SAVE_FILE), {
  1149. timeout: 20000,
  1150. timeoutMsg: "直接保存后磁盘上没有出现工作流文件",
  1151. });
  1152. const written = await readFile(LAUNCH_SAVE_FILE, "utf-8");
  1153. expect(written.startsWith("/* zcode-workflow")).toBe(true);
  1154. expect(written.endsWith(`*/\n${LAUNCH_SAVE_SCRIPT}`)).toBe(true);
  1155. // 7) 卡片立刻翻面:芯片回来,动词又是「再次运行」。
  1156. await waitForTestIdByDom("workflow-saved-chip", {
  1157. timeout: 20000,
  1158. timeoutMsg: "直接保存后 run 侧板没有出现「已保存」芯片",
  1159. });
  1160. await waitForTestIdByDom("workflow-save-run-again", {
  1161. timeout: 10000,
  1162. timeoutMsg: "直接保存后 run 侧板没有翻成「再次运行」",
  1163. });
  1164. });
  1165. it("产物 tab「作为文件打开」:把这一版的 markdown 落成本机副本,交给系统默认 App", async function () {
  1166. this.timeout(240000);
  1167. await prepareHubCase();
  1168. // 1) 中枢「运行」无实参的项目档:点即跑,run 发布一份 markdown 产物后 completed。
  1169. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1170. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1171. timeoutMsg: "自动化页标题没有「工作流」切换",
  1172. });
  1173. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_ARTIFACT_NAME), {
  1174. timeout: 20000,
  1175. timeoutMsg: "工作流列表没有出现产物用例的工作流卡片",
  1176. });
  1177. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_ARTIFACT_NAME), {
  1178. timeoutMsg: "产物用例的工作流卡片没有「运行」按钮",
  1179. });
  1180. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1181. timeout: 90000,
  1182. timeoutMsg: "run 卡的状态没有跑到 completed",
  1183. });
  1184. // 2) ⤢ 打开 run 侧板 → 唯一的产物即主产物行 → 产物 tab,正文是 markdown。
  1185. await clickTestIdByDom("workflow-card-open-details", {
  1186. timeoutMsg: "run 卡上没有「打开运行详情」",
  1187. });
  1188. await clickTestIdByDom(TID_WORKFLOW_ARTIFACT_CARD, {
  1189. timeout: 30000,
  1190. timeoutMsg: "run 侧板没有出现产物行",
  1191. });
  1192. await waitForTestIdByDom(TID_WORKFLOW_ARTIFACT_PANE, {
  1193. timeout: 20000,
  1194. timeoutMsg: "点产物行后没有打开产物 tab",
  1195. });
  1196. await browser.waitUntil(
  1197. async () =>
  1198. browser.execute(() => Boolean(document.querySelector('[data-artifact-body="markdown"]'))),
  1199. { timeout: 20000, timeoutMsg: "产物 tab 没有画出 markdown 正文" },
  1200. );
  1201. // 3) 点「作为文件打开」:main 落副本,再经 shell.openPath 交给系统默认 App(这里被 mock 接住)。
  1202. const openPath = await browser.electron.mock("shell", "openPath");
  1203. await openPath.mockResolvedValue("");
  1204. try {
  1205. const readOpenedPaths = async (): Promise<string[]> => {
  1206. await openPath.update();
  1207. return openPath.mock.calls.map(([path]) => String(path));
  1208. };
  1209. await clickTestIdByDom("workflow-artifact-open-as-file", {
  1210. timeoutMsg: "产物 tab 头部没有「作为文件打开」",
  1211. });
  1212. await browser.waitUntil(async () => (await readOpenedPaths()).length === 1, {
  1213. timeout: 15000,
  1214. timeoutMsg: "「作为文件打开」没有经 shell.openPath 打开文件",
  1215. });
  1216. const [openedPath] = await readOpenedPaths();
  1217. expect(openedPath).toContain(join("tmp", "workflow-artifacts"));
  1218. expect(openedPath!.endsWith(join("v1", `${LAUNCH_ARTIFACT_ID}.md`))).toBe(true);
  1219. expect(await readFile(openedPath!, "utf-8")).toBe(LAUNCH_ARTIFACT_MARKDOWN);
  1220. // 4) 再点一次:同一版开的是同一个副本。
  1221. await clickTestIdByDom("workflow-artifact-open-as-file", {
  1222. timeoutMsg: "产物 tab 头部没有「作为文件打开」",
  1223. });
  1224. await browser.waitUntil(async () => (await readOpenedPaths()).length === 2, {
  1225. timeout: 15000,
  1226. timeoutMsg: "第二次「作为文件打开」没有打开文件",
  1227. });
  1228. expect((await readOpenedPaths())[1]).toBe(openedPath);
  1229. } finally {
  1230. await browser.electron.restoreAllMocks();
  1231. }
  1232. });
  1233. });