automations-workflows-hub.test.ts 63 KB

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