conversation-session-dynamic-workflow-gray-always-on-run-pane-details.test.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. import {
  2. TID_CHAT_MODEL_SELECT_GROUP,
  3. TID_CHAT_MODEL_SELECT_ITEM,
  4. testId,
  5. } from "@zcode/shared/test-ids";
  6. import type { ChainablePromiseElement } from "webdriverio";
  7. import { clearAppData, pinE2ELocale } from "#e2e/helpers/desktop-app";
  8. import {
  9. approveV4Permission,
  10. prepareV4ConversationE2E,
  11. sendV4Prompt,
  12. waitForV4AssistantMessageContaining,
  13. waitForV4Pane,
  14. } from "#e2e/helpers/v4-conversation";
  15. import {
  16. UPSTREAM_PROVIDER_ID,
  17. UPSTREAM_SECONDARY_MODEL,
  18. ensureUpstreamModelForE2E,
  19. getUpstreamProviderModelValues,
  20. selectUpstreamModel,
  21. selectUpstreamThoughtLevel,
  22. } from "#e2e/helpers/upstream-provider";
  23. import {
  24. countUpstreamRequests,
  25. getLatestUpstreamToolResultByToolCallId,
  26. getUpstreamRequestEvidence,
  27. } from "#e2e/helpers/conversation-session-network";
  28. // run 侧板的细节与「配置」弹层(docs/dynamic-workflow/presentation.md「The run pane」「The run state
  29. // the pane draws」「The settings popover」、docs/dynamic-workflow/launch.md「Changing a run's settings
  30. // from the GUI」「Models the script names」、docs/dynamic-workflow/authoring.md「Choosing a model per
  31. // subagent」):
  32. // 完成的 run 侧板写出结果、用量与每个子代理的模型;出错的 run 写出错误正文;在跑的 run 上用弹层
  33. // 先就地调并发、再换子代理模型——后者是一次保留脚本的修订,侧板跟到新 run,新旧两端各自写出
  34. // 「调整自」与「已被替代」。
  35. //
  36. // 文件名带 `gray-always-on`:配置 mock 网关按文件名下发 alwaysOn,工作流工具才在工具集里。
  37. // case-local 回放只决定模型调用(主代理与子代理);真实 Skill、编译、确认窗、模型解析、run 引擎、
  38. // 子代理会话、GUI 配置命令、设置轮与通知仍走产品链路。长跑子代理的回答用受控流挂起,让 run 在配置
  39. // 期间保持 running;旧 run 被替代时那条请求随之中止,不靠延时抢时序。
  40. const RUN_DIGEST = '[data-workflow-run-digest="true"]';
  41. const digestOf = (runId: string) => $(`${RUN_DIGEST}[data-workflow-run-id="${runId}"]`);
  42. const POPOVER = '[data-testid="workflow-run-settings-popover"]';
  43. const SECONDARY_MODEL = UPSTREAM_SECONDARY_MODEL;
  44. const SESSION_MODEL_WORD = "会话模型";
  45. const LIVE_RUN_NAME = "E2E 长跑";
  46. // 请求里最后一条 user 消息的文字(设置轮与通知并在同一条消息里送达)。
  47. function lastUserMessageText(requestJson: unknown): string {
  48. const messages = (requestJson as { messages?: { role: string; content: unknown }[] } | undefined)
  49. ?.messages;
  50. const last = messages?.findLast((message) => message.role === "user");
  51. if (typeof last?.content === "string") return last.content;
  52. return ((last?.content as { text?: string }[] | undefined) ?? [])
  53. .map((part) => part.text ?? "")
  54. .join("\n");
  55. }
  56. function launchedRunId(content: string | undefined): string {
  57. const launched = /started in the background with ID: (\S+?)\./u.exec(content ?? "");
  58. expect(launched).not.toBeNull();
  59. return launched![1]!;
  60. }
  61. async function waitForToolSuccess(toolCallId: string): Promise<string> {
  62. await browser.waitUntil(
  63. async () => (await getLatestUpstreamToolResultByToolCallId(toolCallId))?.isError === false,
  64. { timeout: 60000, timeoutMsg: `${toolCallId} 未执行成功` },
  65. );
  66. return launchedRunId((await getLatestUpstreamToolResultByToolCallId(toolCallId))?.content);
  67. }
  68. async function waitForTurnEnd(marker: string) {
  69. await waitForV4AssistantMessageContaining(marker, 120000);
  70. await waitForV4Pane((pane) => !pane.canStop, `${marker} 那一轮未结束`, 60000);
  71. }
  72. // 侧板根元素带 run id 与状态;Stop 钮总是画出,用它把侧板与聊天里的卡区分开。侧板可能同时挂着
  73. // 几个 run 标签,只认当前可见的那一个。
  74. async function visiblePaneRunId(): Promise<string | null> {
  75. return browser.execute(() => {
  76. for (const cancel of document.querySelectorAll<HTMLElement>(
  77. '[data-testid="workflow-run-cancel"]',
  78. )) {
  79. if (cancel.getClientRects().length === 0) continue;
  80. const pane = cancel.closest<HTMLElement>("[data-workflow-run-id]");
  81. if (pane) return pane.dataset.workflowRunId ?? null;
  82. }
  83. return null;
  84. });
  85. }
  86. const paneOf = (runId: string) =>
  87. $(`div[data-workflow-run-id="${runId}"]:has([data-testid="workflow-run-cancel"])`);
  88. async function openPaneFromDigest(runId: string) {
  89. const digest = digestOf(runId);
  90. await digest.waitForExist({ timeout: 60000 });
  91. await digest.scrollIntoView({ block: "center" });
  92. await digest.$('[data-testid="workflow-card-open-details"]').click();
  93. await browser.waitUntil(async () => (await visiblePaneRunId()) === runId, {
  94. timeout: 30000,
  95. timeoutMsg: `run ${runId} 的侧板没有打开`,
  96. });
  97. return paneOf(runId);
  98. }
  99. // 折叠展开动画期间 getText 可能读到空串:一律读 textContent。
  100. async function textOf(element: ChainablePromiseElement): Promise<string> {
  101. return String(await element.getProperty("textContent"));
  102. }
  103. async function openPhase(section: WebdriverIO.Element) {
  104. if ((await section.getAttribute("data-phase-open")) !== "true") {
  105. await section.$('[data-testid="workflow-run-phase-toggle"]').click();
  106. }
  107. await section.$('[data-testid="workflow-run-phase-body"]').waitForDisplayed({ timeout: 10000 });
  108. }
  109. // 设置轮在转写里留下一行「已调整设置 · …」(WorkflowSettingsChangeRow,没有 run id 属性):按文字找。
  110. // 已结束一轮的行收在「已处理」折叠里(默认收起):没找到就展开所有收起的折叠,直到它出现。
  111. async function waitForSettingsChangeRow(...needles: string[]) {
  112. await browser.waitUntil(
  113. async () =>
  114. browser.execute((wanted: string[]) => {
  115. const found = Array.from(
  116. document.querySelectorAll<HTMLElement>('[data-testid="workflow-settings-change-row"]'),
  117. ).some((row) => wanted.every((needle) => (row.textContent ?? "").includes(needle)));
  118. if (found) return true;
  119. for (const trigger of document.querySelectorAll<HTMLElement>(
  120. '[data-testid^="chat-assistant-history-trigger-"][data-history-open="false"]',
  121. )) {
  122. trigger.click();
  123. }
  124. return false;
  125. }, needles),
  126. { timeout: 30000, timeoutMsg: `转写里没有设置行:${needles.join(" · ")}` },
  127. );
  128. }
  129. async function consequenceText(): Promise<string> {
  130. return (await textOf($('[data-testid="workflow-run-settings-consequence"]'))).trim();
  131. }
  132. // 弹层的模型菜单与 composer 是同一个 ModelConfigSelect:宽屏下按 provider 分组(二级菜单),
  133. // 也可能直接平铺模型项。两种形态都接得住,找不到时把菜单里出现过的项带进错误信息。
  134. async function pickSettingsModel(modelId: string) {
  135. const itemIds = getUpstreamProviderModelValues(modelId).map((value) =>
  136. testId(TID_CHAT_MODEL_SELECT_ITEM, value),
  137. );
  138. const groupId = testId(TID_CHAT_MODEL_SELECT_GROUP, `registry-provider:${UPSTREAM_PROVIDER_ID}`);
  139. await $('[data-testid="workflow-run-settings-model-trigger"]').click();
  140. try {
  141. await browser.waitUntil(
  142. async () =>
  143. browser.execute(
  144. (items: string[], group: string) => {
  145. const find = (id: string) =>
  146. document.querySelector<HTMLElement>(`[data-testid="${CSS.escape(id)}"]`);
  147. if (items.some((id) => find(id) !== null)) return true;
  148. const groupElement = find(group);
  149. if (groupElement) {
  150. groupElement.focus();
  151. for (const name of ["pointerenter", "mouseenter", "mousemove"]) {
  152. groupElement.dispatchEvent(
  153. new MouseEvent(name, { bubbles: true, cancelable: true, view: window }),
  154. );
  155. }
  156. groupElement.click();
  157. }
  158. return false;
  159. },
  160. itemIds,
  161. groupId,
  162. ),
  163. { timeout: 30000 },
  164. );
  165. } catch (error) {
  166. const seen = await browser.execute(() =>
  167. Array.from(document.querySelectorAll<HTMLElement>("[data-testid]"))
  168. .map((element) => element.dataset.testid ?? "")
  169. .filter((id) => id.startsWith("chat-model-select-")),
  170. );
  171. throw new Error(`配置弹层的模型菜单里没有 ${modelId};菜单项:${JSON.stringify(seen)}`, {
  172. cause: error,
  173. });
  174. }
  175. await browser.execute((items: string[]) => {
  176. for (const id of items) {
  177. const element = document.querySelector<HTMLElement>(`[data-testid="${CSS.escape(id)}"]`);
  178. if (element) {
  179. element.click();
  180. return;
  181. }
  182. }
  183. }, itemIds);
  184. }
  185. describe("动态工作流 · run 侧板细节与配置弹层", () => {
  186. let okRunId = "";
  187. let failRunId = "";
  188. let liveRunId = "";
  189. let amendedRunId = "";
  190. before(async () => {
  191. await prepareV4ConversationE2E();
  192. // 弹层要换到第二个模型:给 E2E provider 加上录制时的第二个模型,再把 composer 选回会话模型。
  193. await ensureUpstreamModelForE2E(SECONDARY_MODEL);
  194. await selectUpstreamModel();
  195. await selectUpstreamThoughtLevel();
  196. // 断言中文文案:固定界面语言,不跟随宿主系统语言(容器里默认英文)。
  197. await pinE2ELocale("zh-CN");
  198. });
  199. after(async () => {
  200. await browser.electron.restoreAllMocks();
  201. await clearAppData();
  202. });
  203. it("DWR-04 完成的 run:侧板写出结果面板、用量行与 run 的子代理模型,点名模型的子代理行带自己的模型;完成的 run 不能配置", async function () {
  204. this.timeout(300000);
  205. await sendV4Prompt("E2E_DWD_OK_START 用工作流核对材料并成文,子代理用 deepseek-v4-pro。");
  206. await approveV4Permission();
  207. okRunId = await waitForToolSuccess("toolu_dwd_create_ok");
  208. // 工具回话说出解析后的规范串:run 的 subagent_model 与脚本点名的模型(launch.md「Models the script names」)。
  209. const created = await getLatestUpstreamToolResultByToolCallId("toolu_dwd_create_ok");
  210. expect(created?.content).toContain(SECONDARY_MODEL);
  211. expect(created?.content).toContain("Models named in the script");
  212. await browser.waitUntil(
  213. async () =>
  214. (await digestOf(okRunId).isExisting()) &&
  215. (await digestOf(okRunId).getAttribute("data-workflow-run-status")) === "completed",
  216. { timeout: 120000, timeoutMsg: "核对成文 run 没有跑到 completed" },
  217. );
  218. await waitForTurnEnd("E2E_DWD_OK_DONE");
  219. // 每个子代理真的跑在它的模型上:点名模型的核对员走自己的模型,撰写员跟随 run 的 subagent_model。
  220. const [checkRequest] = await getUpstreamRequestEvidence({
  221. lastUserMessageIncludes: ["E2E_DWD_TASK_CHECK"],
  222. });
  223. const [writeRequest] = await getUpstreamRequestEvidence({
  224. lastUserMessageIncludes: ["E2E_DWD_TASK_WRITE"],
  225. });
  226. expect((checkRequest?.requestJson as { model?: string } | undefined)?.model).toBe(
  227. "deepseek-v4-flash",
  228. );
  229. expect((writeRequest?.requestJson as { model?: string } | undefined)?.model).toBe(
  230. SECONDARY_MODEL,
  231. );
  232. const pane = await openPaneFromDigest(okRunId);
  233. expect(await pane.getAttribute("data-workflow-run-status")).toBe("completed");
  234. // 结果面板:completed 写「结果」与「结果已作为后台结果送进会话」的提示。
  235. const result = pane.$('[data-testid="workflow-run-result"]');
  236. await result.waitForExist({ timeout: 30000 });
  237. expect(await textOf(result)).toContain("结果");
  238. expect(await textOf(result)).toContain("本实例已完成");
  239. await expect(pane.$('[data-testid="workflow-run-error"]')).not.toBeExisting();
  240. // 摘要行:模型是第一个词「子代理 {model}」,之后是子代理数、步数与 tokens。
  241. const usage = pane.$('[data-testid="workflow-run-usage"]');
  242. await browser.waitUntil(async () => /2\/2/u.test(await textOf(usage)), {
  243. timeout: 30000,
  244. timeoutMsg: "侧板摘要行没有写出 2/2 步",
  245. });
  246. const usageText = await textOf(usage);
  247. expect(usageText).toMatch(new RegExp(`^\\s*子代理 [^·]*${SECONDARY_MODEL}`, "u"));
  248. expect(usageText).toContain("tokens");
  249. // 模型段:屏幕上只有名字,规范串在 tooltip 里;完成的 run 不能配置,所以它只是字、不是按钮,
  250. // 状态头也没有 Configure。
  251. const modelSegment = pane.$('[data-testid="workflow-run-subagent-model"]');
  252. expect(await modelSegment.getTagName()).toBe("span");
  253. expect(await modelSegment.getAttribute("title")).toContain(`/${SECONDARY_MODEL}`);
  254. await expect(pane.$('[data-testid="workflow-run-configure"]')).not.toBeExisting();
  255. // 脊线:人设点名了模型的核对员,行尾跟着它的模型名;撰写员跑在 run 的模型上,行里不再说一遍。
  256. const sections = await pane.$$('[data-testid="workflow-run-phase"]');
  257. expect(sections).toHaveLength(2);
  258. for (const section of sections) await openPhase(section);
  259. const modelsByAgent: Record<string, string | null> = {};
  260. for (const pill of await pane.$$('[data-testid="workflow-agent-pill"]')) {
  261. const text = String(await pill.getProperty("textContent"));
  262. const name = ["核对员", "撰写员"].find((candidate) => text.includes(candidate));
  263. if (name === undefined) continue;
  264. const model = pill.$('[data-testid="workflow-run-agent-model"]');
  265. modelsByAgent[name] = (await model.isExisting())
  266. ? String(await model.getProperty("textContent"))
  267. : null;
  268. }
  269. expect(modelsByAgent["核对员"]).toContain("deepseek-v4-flash");
  270. expect(modelsByAgent["撰写员"]).toBeNull();
  271. });
  272. it("DWR-05 出错的 run:侧板写「实例出错」与脚本抛出的错误正文;出错的 run 可以配置,弹层的后果句是「重试」", async function () {
  273. this.timeout(300000);
  274. await sendV4Prompt("E2E_DWD_FAIL_START 用工作流取证。");
  275. await approveV4Permission();
  276. failRunId = await waitForToolSuccess("toolu_dwd_create_fail");
  277. await browser.waitUntil(
  278. async () =>
  279. (await digestOf(failRunId).isExisting()) &&
  280. (await digestOf(failRunId).getAttribute("data-workflow-run-status")) === "errored",
  281. { timeout: 120000, timeoutMsg: "取证 run 没有到达 errored" },
  282. );
  283. await waitForTurnEnd("E2E_DWD_FAIL_DONE");
  284. const pane = await openPaneFromDigest(failRunId);
  285. expect(await pane.getAttribute("data-workflow-run-status")).toBe("errored");
  286. // 错误面板:标题「实例出错」,正文是脚本抛出的那句话;没有「结果」面板。
  287. const errorPanel = pane.$('[data-testid="workflow-run-error"]');
  288. await errorPanel.waitForExist({ timeout: 30000 });
  289. expect(await textOf(errorPanel)).toContain("实例出错");
  290. expect(await textOf(pane.$('[data-testid="workflow-run-error-message"]'))).toContain(
  291. "E2E_DWD_FAIL_REASON 证据不足,无法继续",
  292. );
  293. await expect(pane.$('[data-testid="workflow-run-result"]')).not.toBeExisting();
  294. // 出错的 run 可以配置(launch.md「Which runs can be configured」):弹层打开时两项都停在 run 的
  295. // 设置上,没有改动就没有后果句;拨一下步进器,后果句是出错状态那一句「重试」。不应用,Esc 关掉。
  296. await pane.$('[data-testid="workflow-run-configure"]').click();
  297. await $(POPOVER).waitForDisplayed({ timeout: 10000 });
  298. expect(await consequenceText()).toBe("");
  299. expect(await $('[data-testid="workflow-run-settings-apply"]').isEnabled()).toBe(false);
  300. await $('[data-testid="workflow-run-settings-bound-decrease"]').click();
  301. expect(await consequenceText()).toBe("将以新设置另起一次运行重试,已完成的步骤会保留。");
  302. await browser.keys("Escape");
  303. await $(POPOVER).waitForExist({ reverse: true, timeout: 10000 });
  304. expect(await pane.getAttribute("data-workflow-run-status")).toBe("errored");
  305. });
  306. it("DWR-06 在跑的 run:弹层只调并发就地生效;换子代理模型是修订,侧板跟到新 run,新旧两端写出「调整自」与「已被替代」", async function () {
  307. this.timeout(300000);
  308. await sendV4Prompt("E2E_DWD_LIVE_START 用工作流准备材料后长跑。");
  309. await approveV4Permission();
  310. liveRunId = await waitForToolSuccess("toolu_dwd_create_live");
  311. // 准备员做完,长跑员的回答被挂起:run 保持 running。
  312. await browser.waitUntil(
  313. async () =>
  314. (await digestOf(liveRunId)
  315. .$('[data-testid="workflow-agent-pill"][data-agent-status="done"]')
  316. .isExisting()) &&
  317. (await digestOf(liveRunId)
  318. .$('[data-testid="workflow-agent-pill"][data-agent-status="running"]')
  319. .isExisting()),
  320. { timeout: 60000, timeoutMsg: "准备员没有做完,或长跑员没有进入运行态" },
  321. );
  322. await waitForTurnEnd("E2E_DWD_LIVE_STARTED");
  323. const pane = await openPaneFromDigest(liveRunId);
  324. expect(await pane.getAttribute("data-workflow-run-status")).toBe("running");
  325. // run 没有自己选模型:摘要行不写模型段。
  326. await expect(pane.$('[data-testid="workflow-run-subagent-model"]')).not.toBeExisting();
  327. // 1) 弹层从 run 的当前设置起步:模型是会话模型(带「会话模型」徽标),步进器停在默认并发 D 上。
  328. await pane.$('[data-testid="workflow-run-configure"]').click();
  329. const popover = $(POPOVER);
  330. await popover.waitForDisplayed({ timeout: 10000 });
  331. expect(await textOf(popover)).toContain("配置工作流");
  332. expect(await textOf($('[data-testid="workflow-run-settings-model-badge"]'))).toBe(
  333. SESSION_MODEL_WORD,
  334. );
  335. const boundInput = $('[data-testid="workflow-run-settings-bound-value"]');
  336. const defaultBound = Number(await boundInput.getValue());
  337. expect(defaultBound).toBeGreaterThan(0);
  338. expect(await textOf($('[data-testid="workflow-run-settings-bound"]'))).toContain("= 默认");
  339. expect(await consequenceText()).toBe("");
  340. expect(await $('[data-testid="workflow-run-settings-apply"]').isEnabled()).toBe(false);
  341. // 2) 只把上限调高一格:run 在跑,就地生效,不另起 run。
  342. await $('[data-testid="workflow-run-settings-bound-increase"]').click();
  343. await expect(boundInput).toHaveValue(String(defaultBound + 1));
  344. expect(await textOf($('[data-testid="workflow-run-settings-bound"]'))).toContain(
  345. `默认 ${defaultBound}`,
  346. );
  347. expect(await consequenceText()).toBe("立即应用到当前运行,不会新起一次运行。");
  348. await $('[data-testid="workflow-run-settings-apply"]').click();
  349. await popover.waitForExist({ reverse: true, timeout: 30000 });
  350. // 就地调并发:侧板仍是同一个 run,芯片读出新的界;设置轮的行点名同一个 run。
  351. const chip = pane.$('[data-testid="workflow-run-concurrency"]');
  352. await browser.waitUntil(
  353. async () =>
  354. (await chip.isExisting()) &&
  355. new RegExp(`^最大并发数 ${defaultBound + 1}\\b`, "u").test((await textOf(chip)).trim()),
  356. { timeout: 30000, timeoutMsg: `侧板没有出现「最大并发数 ${defaultBound + 1}」芯片` },
  357. );
  358. expect(await visiblePaneRunId()).toBe(liveRunId);
  359. // 就地生效的设置轮只有一行、没有卡(presentation.md「The run card」)。
  360. await waitForSettingsChangeRow("已调整设置", `最多 ${defaultBound + 1} 个同时运行`);
  361. expect(await pane.getAttribute("data-workflow-run-status")).toBe("running");
  362. // 3) 再打开:步进器从 run 自己的界起步;换子代理模型 = 停掉当前 run、以新设置另起一次。
  363. await paneOf(liveRunId).$('[data-testid="workflow-run-configure"]').click();
  364. await popover.waitForDisplayed({ timeout: 10000 });
  365. await expect(boundInput).toHaveValue(String(defaultBound + 1));
  366. await pickSettingsModel(SECONDARY_MODEL);
  367. await browser.waitUntil(
  368. async () =>
  369. (await consequenceText()) === "将停止当前运行,以新设置另起一次运行,已完成的步骤会保留。",
  370. { timeout: 10000, timeoutMsg: "换模型后后果句不是「将停止当前运行……」" },
  371. );
  372. expect(await $('[data-testid="workflow-run-settings-model-badge"]').isExisting()).toBe(false);
  373. await $('[data-testid="workflow-run-settings-apply"]').click();
  374. await popover.waitForExist({ reverse: true, timeout: 30000 });
  375. // 4) 侧板跟着工作流走:同一个标签换成新 run(presentation.md「The settings popover」)。
  376. await browser.waitUntil(
  377. async () => {
  378. const visible = await visiblePaneRunId();
  379. return visible !== null && visible !== liveRunId;
  380. },
  381. { timeout: 30000, timeoutMsg: "接受修订后侧板没有换成新 run" },
  382. );
  383. amendedRunId = (await visiblePaneRunId())!;
  384. const amendedPane = paneOf(amendedRunId);
  385. // 修订的设置轮:一行说换了模型,下面挂新 run 的卡;旧卡变「工作流已被替代」。
  386. await waitForSettingsChangeRow("已调整设置", SECONDARY_MODEL);
  387. await digestOf(amendedRunId).waitForExist({ timeout: 30000 });
  388. await browser.waitUntil(
  389. async () => (await digestOf(liveRunId).getAttribute("aria-label")) === "工作流已被替代",
  390. { timeout: 30000, timeoutMsg: "旧 run 卡没有变成「工作流已被替代」" },
  391. );
  392. expect(await textOf(amendedPane.$('[data-testid="workflow-run-amends"]'))).toContain(
  393. `调整自 run${liveRunId}`,
  394. );
  395. const provenance = amendedPane.$('[data-testid="workflow-run-provenance"]');
  396. await provenance.waitForExist({ timeout: 30000 });
  397. expect(await textOf(provenance)).toContain("由你调整设置");
  398. expect(await textOf(provenance)).toContain("子代理模型");
  399. await browser.waitUntil(
  400. async () =>
  401. new RegExp(`子代理 [^·]*${SECONDARY_MODEL}`, "u").test(
  402. await textOf(amendedPane.$('[data-testid="workflow-run-usage"]')),
  403. ),
  404. { timeout: 30000, timeoutMsg: "新 run 的摘要行没有写出新的子代理模型" },
  405. );
  406. // 新 run 重跑长跑员(新模型上的一次真实请求)并完成;准备员那一步作为缓存导入,不再发请求。
  407. await browser.waitUntil(
  408. async () => (await amendedPane.getAttribute("data-workflow-run-status")) === "completed",
  409. { timeout: 120000, timeoutMsg: "修订出来的新 run 没有跑到 completed" },
  410. );
  411. const longRequest = (
  412. await getUpstreamRequestEvidence({ lastUserMessageIncludes: ["E2E_DWD_TASK_LONG"] })
  413. ).find((record) => record.fixtureId === "dwd-agent-long");
  414. expect((longRequest?.requestJson as { model?: string } | undefined)?.model).toBe(
  415. SECONDARY_MODEL,
  416. );
  417. expect(await countUpstreamRequests({ lastUserMessageIncludes: ["E2E_DWD_TASK_PREP"] })).toBe(1);
  418. // 5) 旧 run 的侧板:停在「已被替代」,lineage 行指向后继、可点;被替代的 run 不能再配置。
  419. await openPaneFromDigest(liveRunId);
  420. const oldPane = paneOf(liveRunId);
  421. expect(await oldPane.getAttribute("data-workflow-run-status")).toBe("stopped");
  422. const supersededBy = oldPane.$('[data-testid="workflow-run-superseded-by"]');
  423. await supersededBy.waitForExist({ timeout: 30000 });
  424. expect(await textOf(supersededBy)).toContain(`已被替代,后继 run${amendedRunId}`);
  425. await expect(oldPane.$('[data-testid="workflow-run-configure"]')).not.toBeExisting();
  426. await expect(oldPane.$('[data-testid="workflow-run-amends"]')).not.toBeExisting();
  427. await supersededBy.click();
  428. await browser.waitUntil(async () => (await visiblePaneRunId()) === amendedRunId, {
  429. timeout: 30000,
  430. timeoutMsg: "点「已被替代」没有打开后继 run 的侧板",
  431. });
  432. // 新 run 的完成通知唤醒主代理;被替代的旧 run 不单独通知。
  433. await waitForTurnEnd("E2E_DWD_LIVE_DONE");
  434. expect(
  435. await countUpstreamRequests({
  436. lastUserMessageIncludes: ["<task-notification>", `<task-id>${liveRunId}</task-id>`],
  437. }),
  438. ).toBe(0);
  439. // 设置轮沿用 run 的名字(launch.md「The settings turn」):模型读到的两句设置文字都写
  440. // 「run {A} ("{name}")」,新 run 的通知也以这个名字为题,而不是一串 run id。
  441. const [notified] = await getUpstreamRequestEvidence({
  442. lastUserMessageIncludes: ["<task-notification>", "<tool-use-id>settings-"],
  443. });
  444. expect(notified?.fixtureId).toBe("dwd-live-notified");
  445. const notifiedText = lastUserMessageText(notified?.requestJson);
  446. expect(notifiedText).toContain(
  447. `Changed the settings of workflow run ${liveRunId} ("${LIVE_RUN_NAME}") from the GUI: at most ${defaultBound + 1} of its subagents run at once.`,
  448. );
  449. expect(notifiedText).toContain(
  450. `Changed the settings of workflow run ${liveRunId} ("${LIVE_RUN_NAME}") from the GUI: its subagents now run on`,
  451. );
  452. expect(notifiedText).toContain(`<description>${LIVE_RUN_NAME}</description>`);
  453. });
  454. });