automations-workflows-hub.test.ts 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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. // 3) composer 徽标:恰好一条 workflow、没有终端与子代理,且自述落点是 workflow-run。
  932. await browser.waitUntil(
  933. async () => {
  934. const counts = await getV4ComposerBackgroundWorkCounts();
  935. return (
  936. counts?.workflowCount === 1 &&
  937. counts.bashCount === 0 &&
  938. counts.subagentCount === 0 &&
  939. counts.totalCount === 1 &&
  940. counts.openTarget === "workflow-run"
  941. );
  942. },
  943. { timeout: 60000, timeoutMsg: "composer 徽标没有以 workflow-run 落点显示唯一在跑的工作流" },
  944. );
  945. const panelModeBefore = await browser.execute(
  946. (panelTestId) =>
  947. document.querySelector<HTMLElement>(`[data-testid="${panelTestId}"]`)?.dataset
  948. .displayMode ?? null,
  949. TID_CHAT_SUMMARY_PANEL,
  950. );
  951. expect(panelModeBefore).not.toBe("panel");
  952. // 4) 点徽标 → 侧板出现该 run 的 workflow-run tab(结构化 id 前缀),胶囊没有被置成 panel。
  953. await clickTestIdByDom(TID_V4_COMPOSER_BACKGROUND_WORK_TRIGGER, {
  954. timeoutMsg: "composer 后台任务入口不可点击",
  955. });
  956. await browser.waitUntil(
  957. async () =>
  958. browser.execute(() =>
  959. Boolean(document.querySelector('[data-side-pane-tab-id^="workflow-run:"]')),
  960. ),
  961. { timeout: 30000, timeoutMsg: "点徽标后侧板没有打开 workflow-run tab" },
  962. );
  963. const panelModeAfter = await browser.execute(
  964. (panelTestId) =>
  965. document.querySelector<HTMLElement>(`[data-testid="${panelTestId}"]`)?.dataset
  966. .displayMode ?? null,
  967. TID_CHAT_SUMMARY_PANEL,
  968. );
  969. expect(panelModeAfter).not.toBe("panel");
  970. // 5) 点胶囊展开:「工作流」分区随之打开,不用再点分区头——展开后看到的不能比胶囊还少
  971. // (docs/dynamic-workflow/presentation.md「Other places a run appears」)。run 行两行定高:第一行
  972. // 名字 + 时长,第二行灯 + 词(sleep 脚本没有 phase() 标记,所以是一盏运行灯 + 步数)。悬停这一行
  973. // 时 Stop 叠在时长上出现。
  974. await browser.execute((panelTestId) => {
  975. const panel = document.querySelector<HTMLElement>(`[data-testid="${panelTestId}"]`);
  976. panel?.querySelector<HTMLElement>("[data-workflow-pill]")?.closest("button")?.click();
  977. }, TID_CHAT_SUMMARY_PANEL);
  978. const rowSelector = 'li[data-background-task-kind="workflow"]';
  979. await browser.waitUntil(
  980. async () =>
  981. browser.execute((selector) => {
  982. const row = document.querySelector<HTMLElement>(selector);
  983. return (
  984. row !== null &&
  985. row.querySelector('[data-workflow-island-line="name"] [data-workflow-run-elapsed]') !==
  986. null &&
  987. row.querySelector(
  988. '[data-workflow-island-line="phase"] [data-workflow-run-lamp="running"]',
  989. ) !== null
  990. );
  991. }, rowSelector),
  992. {
  993. timeout: 15000,
  994. timeoutMsg: "点开胶囊后「工作流」分区没有直接显示 run 行(名字 + 时长 / 灯 + 词两行)",
  995. },
  996. );
  997. // 面板展开会移动 run 行;按当前布局重新悬停,并确认真实 hover 后再检查 Stop。
  998. await browser.waitUntil(
  999. async () => {
  1000. await $(rowSelector).moveTo();
  1001. return browser.execute((selector) => {
  1002. const row = document.querySelector<HTMLElement>(selector);
  1003. const stop = row?.querySelector<HTMLElement>(
  1004. '[data-testid^="v4-background-work-cancel-"]',
  1005. );
  1006. return Boolean(row?.matches(":hover") && stop && getComputedStyle(stop).opacity === "1");
  1007. }, rowSelector);
  1008. },
  1009. { timeout: 5000, timeoutMsg: "悬停 run 行时 Stop 没有出现" },
  1010. );
  1011. });
  1012. // 并发芯片(docs/dynamic-workflow/concurrency.md「What the user sees」):芯片的数是一条界,字是
  1013. // 「最大并发数」;它与 Configure 同进同退——run 在跑时就地调小界,芯片出现;run 完成后芯片离开,
  1014. // 不再把一条已经没有东西在它下面跑的界挂成实时读数。
  1015. it("并发芯片:在跑的 run 就地调小界后显示「最大并发数 N」,run 完成后芯片离开", async function () {
  1016. this.timeout(180000);
  1017. await prepareConversationE2E({ skipProvider: true });
  1018. // 1) 跑那条停留 running 的常量工作流(world.run sleep 40s),打开它的 run 侧板。
  1019. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1020. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1021. timeoutMsg: "自动化页标题没有「工作流」切换",
  1022. });
  1023. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_SLEEP_NAME), {
  1024. timeout: 20000,
  1025. timeoutMsg: "工作流列表没有出现停留 running 的常量工作流卡片",
  1026. });
  1027. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_SLEEP_NAME), {
  1028. timeoutMsg: "常量工作流卡片没有「运行」按钮",
  1029. });
  1030. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "running", {
  1031. timeout: 60000,
  1032. timeoutMsg: "run 卡没有进入 running",
  1033. });
  1034. await clickTestIdByDom("workflow-card-open-details", {
  1035. timeoutMsg: "run 卡上没有「打开运行详情」",
  1036. });
  1037. await waitForTestIdByDom("workflow-run-configure", {
  1038. timeout: 30000,
  1039. timeoutMsg: "在跑的 run 侧板上没有 Configure",
  1040. });
  1041. // 2) 跑在默认并发 D 上(没有自己的界):没有芯片。
  1042. expect(await readTestIdText("workflow-run-concurrency")).toBeNull();
  1043. // 3) Configure → 步进器减一 → 应用:只改界、run 在跑,就地生效(不另起 run)。
  1044. await clickRunSidePaneControl("workflow-run-configure");
  1045. await waitForTestIdByDom("workflow-run-settings-popover", {
  1046. timeoutMsg: "点 Configure 后没有设置弹层",
  1047. });
  1048. // 步进器停在默认并发 D = max(4, min(16, 核数 − 2)) 上,减一总有可调小的余地。
  1049. // 控件已改成 input;textContent 恒为空,Number("") 会把默认界误读为 0。
  1050. const boundInput = $('[data-testid="workflow-run-settings-bound-value"]');
  1051. const defaultBound = Number(await boundInput.getValue());
  1052. expect(defaultBound).toBeGreaterThan(1);
  1053. // 还没改:没有后果句(改动之前念哪一句都可能说错)。
  1054. expect(await readTestIdText("workflow-run-settings-consequence")).toBe("");
  1055. await clickTestIdByDom("workflow-run-settings-bound-decrease", {
  1056. timeoutMsg: "设置弹层没有「降低最大并发数」",
  1057. });
  1058. await expect(boundInput).toHaveValue(String(defaultBound - 1));
  1059. // 只改界、run 在跑:后果句是「就地生效」,不是「将停止当前运行」。
  1060. expect(await readTestIdText("workflow-run-settings-consequence")).toMatch(
  1061. /^(立即应用到当前运行,不会新起一次运行。|Applies to this run right away; no new run is started\.)$/,
  1062. );
  1063. await clickTestIdByDom("workflow-run-settings-apply", { timeoutMsg: "设置弹层没有「应用」" });
  1064. // 4) 芯片出现,字是界的字,数是调小后的界。
  1065. await browser.waitUntil(
  1066. async () => {
  1067. const text = await readTestIdText("workflow-run-concurrency");
  1068. return (
  1069. text !== null &&
  1070. new RegExp(`^(最大并发数|Max concurrency) ${defaultBound - 1}\\b`).test(text)
  1071. );
  1072. },
  1073. { timeout: 30000, timeoutMsg: "就地调小界后 run 侧板没有出现「最大并发数 N」芯片" },
  1074. );
  1075. // 5) run 跑完(sleep 结束):Configure 与芯片一起离开。
  1076. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1077. timeout: 90000,
  1078. timeoutMsg: "run 卡的状态没有跑到 completed",
  1079. });
  1080. await browser.waitUntil(
  1081. async () =>
  1082. (await readTestIdText("workflow-run-concurrency")) === null &&
  1083. (await readTestIdText("workflow-run-configure")) === null,
  1084. { timeout: 20000, timeoutMsg: "run 完成后侧板上仍有并发芯片或 Configure" },
  1085. );
  1086. });
  1087. it("完成的 run:侧板有「已保存」与「再次运行」,芯片直达中枢;删掉后「保存」按原样写回同一份脚本", async function () {
  1088. this.timeout(240000);
  1089. await prepareConversationE2E({ skipProvider: true });
  1090. // 1) 中枢「运行」无实参的项目档:点即跑,新会话顶部的 run 卡跑到 completed。
  1091. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1092. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1093. timeoutMsg: "自动化页标题没有「工作流」切换",
  1094. });
  1095. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_SAVE_NAME), {
  1096. timeout: 20000,
  1097. timeoutMsg: "工作流列表没有出现保存用例的工作流卡片",
  1098. });
  1099. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_SAVE_NAME), {
  1100. timeoutMsg: "保存用例的工作流卡片没有「运行」按钮",
  1101. });
  1102. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1103. timeout: 90000,
  1104. timeoutMsg: "run 卡的状态没有跑到 completed",
  1105. });
  1106. // 2) ⤢ 打开 run 侧板:从中枢启动的 run 按名字规则天然「已保存」——芯片在状态行,动词是「再次运行」。
  1107. await clickTestIdByDom("workflow-card-open-details", {
  1108. timeoutMsg: "run 卡上没有「打开运行详情」",
  1109. });
  1110. await waitForTestIdByDom("workflow-saved-chip", {
  1111. timeout: 30000,
  1112. timeoutMsg: "run 侧板状态行没有出现「已保存」芯片",
  1113. });
  1114. await waitForTestIdByDom("workflow-save-run-again", {
  1115. timeout: 10000,
  1116. timeoutMsg: "run 侧板没有「再次运行」",
  1117. });
  1118. // 3) 芯片直达中枢里那个工作流的详情页。
  1119. await clickRunSidePaneControl("workflow-saved-chip");
  1120. await waitForTestIdByDom(TID_WORKFLOW_DETAIL, {
  1121. timeout: 20000,
  1122. timeoutMsg: "点芯片后没有进入工作流详情页",
  1123. });
  1124. expect((await readTestIdText(TID_WORKFLOW_DETAIL)) ?? "").toContain(LAUNCH_SAVE_NAME);
  1125. // 4) 在中枢把它删掉:中枢刷新会作废卡片的读缓存,这次 run 不再「已保存」。
  1126. await clickTestIdByWebDriver(TID_WORKFLOW_DETAIL_MENU, {
  1127. timeoutMsg: "详情页没有「更多操作」菜单",
  1128. });
  1129. await clickTestIdByDom(testId(TID_WORKFLOW_ACTION_DELETE, LAUNCH_SAVE_NAME), {
  1130. timeoutMsg: "详情页菜单没有「删除工作流」项",
  1131. });
  1132. await clickTestIdByDom(TID_CONFIRM_DIALOG_CONFIRM, {
  1133. timeoutMsg: "删除二次确认弹窗没有出现",
  1134. });
  1135. await browser.waitUntil(async () => !(await fileExists(LAUNCH_SAVE_FILE)), {
  1136. timeout: 10000,
  1137. timeoutMsg: "删除后磁盘文件仍然存在",
  1138. });
  1139. // 5) 回到发起它的会话,侧板上的动词翻回「保存」。
  1140. const sessionTaskTestId = await browser.execute(
  1141. (prefix, name) =>
  1142. Array.from(document.querySelectorAll<HTMLElement>(`[data-testid^="${prefix}"]`)).find(
  1143. (item) => item.textContent?.includes(name),
  1144. )?.dataset.testid ?? null,
  1145. testId(TID_TASK_ITEM, ""),
  1146. LAUNCH_SAVE_NAME,
  1147. );
  1148. expect(sessionTaskTestId).not.toBeNull();
  1149. await clickTestIdByDom(sessionTaskTestId!, { timeoutMsg: "侧栏里点不到发起它的会话" });
  1150. await clickTestIdByDom("workflow-card-open-details", {
  1151. timeout: 20000,
  1152. timeoutMsg: "回到会话后 run 卡上没有「打开运行详情」",
  1153. });
  1154. await waitForTestIdByDom("workflow-save-open", {
  1155. timeout: 30000,
  1156. timeoutMsg: "删掉工作流之后 run 侧板没有翻回「保存」",
  1157. });
  1158. // 6) 「保存」→ 弹层 → 按原样直接保存:不经模型回合,写下的是这次 run 实际执行的那一份脚本。
  1159. await clickRunSidePaneControl("workflow-save-open");
  1160. await waitForTestIdByDom("workflow-save-popover", { timeoutMsg: "点「保存」后没有弹层" });
  1161. await setInputValueByTestIdDom("workflow-save-name", LAUNCH_SAVE_NAME, {
  1162. timeoutMsg: "保存弹层没有名称输入框",
  1163. });
  1164. await clickTestIdByDom("workflow-save-submit", { timeoutMsg: "保存弹层没有「直接保存」" });
  1165. await browser.waitUntil(async () => fileExists(LAUNCH_SAVE_FILE), {
  1166. timeout: 20000,
  1167. timeoutMsg: "直接保存后磁盘上没有出现工作流文件",
  1168. });
  1169. const written = await readFile(LAUNCH_SAVE_FILE, "utf-8");
  1170. expect(written.startsWith("/* zcode-workflow")).toBe(true);
  1171. expect(written.endsWith(`*/\n${LAUNCH_SAVE_SCRIPT}`)).toBe(true);
  1172. // 7) 卡片立刻翻面:芯片回来,动词又是「再次运行」。
  1173. await waitForTestIdByDom("workflow-saved-chip", {
  1174. timeout: 20000,
  1175. timeoutMsg: "直接保存后 run 侧板没有出现「已保存」芯片",
  1176. });
  1177. await waitForTestIdByDom("workflow-save-run-again", {
  1178. timeout: 10000,
  1179. timeoutMsg: "直接保存后 run 侧板没有翻成「再次运行」",
  1180. });
  1181. });
  1182. it("产物 tab「作为文件打开」:把这一版的 markdown 落成本机副本,交给系统默认 App", async function () {
  1183. this.timeout(240000);
  1184. await prepareConversationE2E({ skipProvider: true });
  1185. // 1) 中枢「运行」无实参的项目档:点即跑,run 发布一份 markdown 产物后 completed。
  1186. await clickTestIdByDom(TID_AUTOMATIONS_OPEN, { timeoutMsg: "侧栏没有出现自动化入口" });
  1187. await clickTestIdByDom(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"), {
  1188. timeoutMsg: "自动化页标题没有「工作流」切换",
  1189. });
  1190. await waitForTestIdByDom(testId(TID_WORKFLOW_CARD, LAUNCH_ARTIFACT_NAME), {
  1191. timeout: 20000,
  1192. timeoutMsg: "工作流列表没有出现产物用例的工作流卡片",
  1193. });
  1194. await clickTestIdByDom(testId(TID_WORKFLOW_CARD_RUN, LAUNCH_ARTIFACT_NAME), {
  1195. timeoutMsg: "产物用例的工作流卡片没有「运行」按钮",
  1196. });
  1197. await browser.waitUntil(async () => (await readLaunchCardStatus()) === "completed", {
  1198. timeout: 90000,
  1199. timeoutMsg: "run 卡的状态没有跑到 completed",
  1200. });
  1201. // 2) ⤢ 打开 run 侧板 → 唯一的产物即主产物行 → 产物 tab,正文是 markdown。
  1202. await clickTestIdByDom("workflow-card-open-details", {
  1203. timeoutMsg: "run 卡上没有「打开运行详情」",
  1204. });
  1205. await clickTestIdByDom(TID_WORKFLOW_ARTIFACT_CARD, {
  1206. timeout: 30000,
  1207. timeoutMsg: "run 侧板没有出现产物行",
  1208. });
  1209. await waitForTestIdByDom(TID_WORKFLOW_ARTIFACT_PANE, {
  1210. timeout: 20000,
  1211. timeoutMsg: "点产物行后没有打开产物 tab",
  1212. });
  1213. await browser.waitUntil(
  1214. async () =>
  1215. browser.execute(() => Boolean(document.querySelector('[data-artifact-body="markdown"]'))),
  1216. { timeout: 20000, timeoutMsg: "产物 tab 没有画出 markdown 正文" },
  1217. );
  1218. // 3) 点「作为文件打开」:main 落副本,再经 shell.openPath 交给系统默认 App(这里被 mock 接住)。
  1219. const openPath = await browser.electron.mock("shell", "openPath");
  1220. await openPath.mockResolvedValue("");
  1221. try {
  1222. const readOpenedPaths = async (): Promise<string[]> => {
  1223. await openPath.update();
  1224. return openPath.mock.calls.map(([path]) => String(path));
  1225. };
  1226. await clickTestIdByDom("workflow-artifact-open-as-file", {
  1227. timeoutMsg: "产物 tab 头部没有「作为文件打开」",
  1228. });
  1229. await browser.waitUntil(async () => (await readOpenedPaths()).length === 1, {
  1230. timeout: 15000,
  1231. timeoutMsg: "「作为文件打开」没有经 shell.openPath 打开文件",
  1232. });
  1233. const [openedPath] = await readOpenedPaths();
  1234. expect(openedPath).toContain(join("tmp", "workflow-artifacts"));
  1235. expect(openedPath!.endsWith(join("v1", `${LAUNCH_ARTIFACT_ID}.md`))).toBe(true);
  1236. expect(await readFile(openedPath!, "utf-8")).toBe(LAUNCH_ARTIFACT_MARKDOWN);
  1237. // 4) 再点一次:同一版开的是同一个副本。
  1238. await clickTestIdByDom("workflow-artifact-open-as-file", {
  1239. timeoutMsg: "产物 tab 头部没有「作为文件打开」",
  1240. });
  1241. await browser.waitUntil(async () => (await readOpenedPaths()).length === 2, {
  1242. timeout: 15000,
  1243. timeoutMsg: "第二次「作为文件打开」没有打开文件",
  1244. });
  1245. expect((await readOpenedPaths())[1]).toBe(openedPath);
  1246. } finally {
  1247. await browser.electron.restoreAllMocks();
  1248. }
  1249. });
  1250. });