workflowRunSpine.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. // @vitest-environment jsdom
  2. // 并行阶段在脊线上(docs/dynamic-workflow/presentation.md「The spine」):卡上横着的带,在运行
  3. // 详情页竖着读,像提交图——左边是轨道、右边是文字,两者不共用一列。分叉与汇合各占两节之间的一行
  4. // 16px 的接头,只在前驱 / 汇合站存在时才有;没有它们时 strand 在自己的灯上起止。排布在
  5. // `workflowRunSpine.ts` 里是纯函数,这里既钉它,也钉它真的接到了 DOM 上。
  6. import { createElement } from "react";
  7. import { cleanup, render, within } from "@testing-library/react";
  8. import { beforeEach, describe, expect, it } from "vitest";
  9. import type { WorkflowRunState } from "@zcode/shared/zcode-protocol-v4";
  10. import type { WorkflowCausalityGraphData } from "@/components/workflow-graph/types.js";
  11. import { buildWorkflowTimeline } from "@/components/workflow-timeline/timeline-model.js";
  12. import { spineLayout } from "@/app-shell/workflowRunSpine.js";
  13. import { WorkflowRunPhaseList } from "@/app-shell/WorkflowRunPhaseList.js";
  14. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  15. /** 一站一个 ask 成员的骨架图:`near[i]` 是第 i 站的 `alongside`,边按下标给。 */
  16. function bandGraph(
  17. near: (number[] | undefined)[],
  18. edges: [number, number][],
  19. ): WorkflowCausalityGraphData {
  20. const steps: WorkflowCausalityGraphData["steps"] = near.map((_, i) => ({
  21. id: `ask#${i}`,
  22. kind: "ask",
  23. label: `step ${i}`,
  24. lane: `actor#${i}`,
  25. phase: `phase#${i}`,
  26. }));
  27. return {
  28. steps,
  29. lanes: near.map((_, i) => ({ id: `actor#${i}`, name: `agent ${i}` })),
  30. participants: near.map((_, i) => ({
  31. id: `phase#${i}:actor#${i}`,
  32. lane: `actor#${i}`,
  33. phase: `phase#${i}`,
  34. steps: [`ask#${i}`],
  35. })),
  36. handoffs: [],
  37. phases: near.map((alongside, i) => ({
  38. id: `phase#${i}`,
  39. name: `P${i}`,
  40. ...(alongside === undefined ? {} : { alongside: alongside.map((j) => `phase#${j}`) }),
  41. })),
  42. phaseEdges: edges.map(([from, to]) => ({ from: `phase#${from}`, to: `phase#${to}` })),
  43. exits: [`phase#${near.length - 1}`],
  44. };
  45. }
  46. type Node = WorkflowRunState["nodes"][number];
  47. function run(nodes: Node[]): WorkflowRunState {
  48. return {
  49. runId: "dwfrun-1",
  50. toolCallId: "tool-wf-1",
  51. status: "running",
  52. usage: { spentTokens: 0, nodesUsed: 0 },
  53. actors: [],
  54. nodes,
  55. lastEventSequence: 0,
  56. };
  57. }
  58. const settled = (siteId: string): Node =>
  59. ({ siteId, ordinal: 1, phase: "settled", outcome: "ok" }) as Node;
  60. const executing = (siteId: string): Node => ({ siteId, ordinal: 1, phase: "executing" }) as Node;
  61. // A ∥ B → C:有界层报的是约简后的边 A → B、B → C。
  62. const TESTFIELD = bandGraph(
  63. [undefined, [0], undefined],
  64. [
  65. [0, 1],
  66. [1, 2],
  67. ],
  68. );
  69. // 同一条带,前面多一站 P:P → A 让带有了前驱,B → C 让它有了汇合站。
  70. const WITH_PRED = bandGraph(
  71. [undefined, undefined, [1], undefined],
  72. [
  73. [0, 1],
  74. [1, 2],
  75. [2, 3],
  76. ],
  77. );
  78. function renderSpine(graph: WorkflowCausalityGraphData, state?: WorkflowRunState) {
  79. const model = buildWorkflowTimeline(graph, state);
  80. return render(
  81. createElement(
  82. ZCodeIntlProvider,
  83. { initialLocale: "en-US" },
  84. createElement(WorkflowRunPhaseList, { graph, model, pendingQuestions: [], run: state }),
  85. ),
  86. );
  87. }
  88. // plan → {A ∥ B},带后面没有站:有前驱、没有汇合站(LOOP_B 的形状)。
  89. const OPEN_END = bandGraph(
  90. [undefined, undefined, [1]],
  91. [
  92. [0, 1],
  93. [0, 2],
  94. [2, 0],
  95. ],
  96. );
  97. /** 容器的直接子元素序列:节是 `phase:<下标>`,接头是 `fork` / `merge`。 */
  98. const sequenceOf = (view: ReturnType<typeof render>) =>
  99. [...view.getByTestId("workflow-run-phases").children].map((child) =>
  100. child.getAttribute("data-testid") === "workflow-run-spine-joint"
  101. ? child.getAttribute("data-joint-kind")
  102. : `phase:${child.getAttribute("data-phase-id")?.replace("phase#", "")}`,
  103. );
  104. const railsOf = (element: HTMLElement) =>
  105. within(element)
  106. .queryAllByTestId("workflow-run-spine-rail")
  107. .map((rail) => ({
  108. ink: rail.getAttribute("data-rail-ink"),
  109. position: rail.getAttribute("data-rail-position"),
  110. track: rail.getAttribute("data-rail-track"),
  111. }));
  112. beforeEach(() => {
  113. cleanup();
  114. });
  115. describe("spineLayout", () => {
  116. it("没有带时与从前一样:轨距 12、没有让位、每一节只有主轨的上下两截、没有接头", () => {
  117. const line = bandGraph(
  118. [undefined, undefined, undefined],
  119. [
  120. [0, 1],
  121. [1, 2],
  122. ],
  123. );
  124. const layout = spineLayout(buildWorkflowTimeline(line, undefined));
  125. expect(layout).toMatchObject({ gutter: 0, pitch: 12 });
  126. expect(layout.sections.map((section) => section.rails)).toEqual([
  127. [{ ink: "faint", position: "below", track: 0 }],
  128. [
  129. { ink: "faint", position: "above", track: 0 },
  130. { ink: "faint", position: "below", track: 0 },
  131. ],
  132. [{ ink: "faint", position: "above", track: 0 }],
  133. ]);
  134. expect(layout.sections.some((section) => section.fork ?? section.merge)).toBe(false);
  135. });
  136. it("带有前驱也有汇合站:分叉行在带首节之前、汇合行在带末节之后,主轨与分支各就各位", () => {
  137. const layout = spineLayout(buildWorkflowTimeline(WITH_PRED, undefined));
  138. expect(layout).toMatchObject({ gutter: 12, pitch: 12 });
  139. const [p, a, b, c] = layout.sections;
  140. expect(a!.fork).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint" });
  141. expect(b!.merge).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint" });
  142. expect([p, c].some((section) => section!.fork ?? section!.merge)).toBe(false);
  143. expect(p!.rails).toEqual([{ ink: "faint", position: "below", track: 0 }]);
  144. // A:主轨从分叉行下来到灯,再往下接汇合行;分支轨从分叉行一路穿过去找 B 的灯。
  145. expect(a!.rails).toEqual([
  146. { ink: "faint", position: "above", track: 0 },
  147. { ink: "faint", position: "below", track: 0 },
  148. { ink: "faint", position: "full", track: 1 },
  149. ]);
  150. // B:自己那条分支轨上下两截,主轨整节穿过。
  151. expect(b!.rails).toEqual([
  152. { ink: "faint", position: "full", track: 0 },
  153. { ink: "faint", position: "above", track: 1 },
  154. { ink: "faint", position: "below", track: 1 },
  155. ]);
  156. expect(c!.rails).toEqual([{ ink: "faint", position: "above", track: 0 }]);
  157. });
  158. it("带从第一站起:分叉行是开口的根,两条 strand 从它下来", () => {
  159. const layout = spineLayout(buildWorkflowTimeline(TESTFIELD, undefined));
  160. const [a, b, c] = layout.sections;
  161. expect(a!.fork).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint", open: true });
  162. expect(b!.merge).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint" });
  163. // A 在主线上:主轨从根下来到灯,再往下穿过 B 去接汇合行;分支轨从根一路穿过 A 去找 B。
  164. expect(a!.rails).toEqual([
  165. { ink: "faint", position: "above", track: 0 },
  166. { ink: "faint", position: "below", track: 0 },
  167. { ink: "faint", position: "full", track: 1 },
  168. ]);
  169. expect(b!.rails).toEqual([
  170. { ink: "faint", position: "full", track: 0 },
  171. { ink: "faint", position: "above", track: 1 },
  172. { ink: "faint", position: "below", track: 1 },
  173. ]);
  174. expect(c!.rails).toEqual([{ ink: "faint", position: "above", track: 0 }]);
  175. });
  176. it("带到最后一站:汇合行是开口的汇点,分支与主线在最后一节之下相遇", () => {
  177. const layout = spineLayout(buildWorkflowTimeline(OPEN_END, undefined));
  178. const [, a, b] = layout.sections;
  179. expect(a!.fork).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint" });
  180. expect(b!.merge).toEqual({ branches: [{ ink: "faint", track: 1 }], main: "faint", open: true });
  181. expect(a!.rails).toEqual([
  182. { ink: "faint", position: "above", track: 0 },
  183. { ink: "faint", position: "below", track: 0 },
  184. { ink: "faint", position: "full", track: 1 },
  185. ]);
  186. // B:自己那条分支轨上下两截;主线在 A 之后没有成员,照样整节穿过去接汇合行。
  187. expect(b!.rails).toEqual([
  188. { ink: "faint", position: "full", track: 0 },
  189. { ink: "faint", position: "above", track: 1 },
  190. { ink: "faint", position: "below", track: 1 },
  191. ]);
  192. });
  193. it("整个工作流就是一条带、每条 strand 只有一站:仍然画出根、每站一条线、汇点", () => {
  194. // 回归(2026-09-24 实机):四阶段两两并行、前后都没有站——此前按「在灯上起止」的规则,每条
  195. // strand 长度为零,脊线上只剩四枚悬空的灯。
  196. const whole = bandGraph(
  197. [undefined, [0], [0, 1], [0, 1, 2]],
  198. [
  199. [0, 1],
  200. [1, 2],
  201. [2, 3],
  202. ],
  203. );
  204. const model = buildWorkflowTimeline(whole, undefined);
  205. expect(model.bands).toHaveLength(1);
  206. expect(model.bands[0]).toMatchObject({ from: 0, to: 3 });
  207. expect(model.bands[0]!.pred).toBeUndefined();
  208. expect(model.bands[0]!.join).toBeUndefined();
  209. const { sections } = spineLayout(model);
  210. expect(sections[0]!.fork).toMatchObject({ open: true });
  211. expect(sections[3]!.merge).toMatchObject({ open: true });
  212. expect(sections[0]!.fork!.branches.map((branch) => branch.track)).toEqual([1, 2, 3]);
  213. // 每一节里四条轨道都在:自己那条是上下两截,别人的整节穿过。
  214. for (const [i, section] of sections.entries()) {
  215. expect(section.rails.map((rail) => [rail.track, rail.position])).toEqual(
  216. [0, 1, 2, 3].flatMap((t) =>
  217. t === i
  218. ? [
  219. [t, "above"],
  220. [t, "below"],
  221. ]
  222. : [[t, "full"]],
  223. ),
  224. );
  225. }
  226. });
  227. it("分支轨道穿过别人的节:只在 strand 活着的那几节整节穿过", () => {
  228. // 带 {1,4}:轨道 0 是 1、3、4,轨道 1 只有 2;前驱 0、汇合站 5。
  229. const wide = bandGraph(
  230. [undefined, undefined, [1], undefined, [2], undefined],
  231. [
  232. [0, 1],
  233. [1, 2],
  234. [2, 5],
  235. [3, 4],
  236. [4, 5],
  237. ],
  238. );
  239. const model = buildWorkflowTimeline(wide, undefined);
  240. expect(model.bands[0]).toMatchObject({ from: 1, join: 5, pred: 0, to: 4 });
  241. expect(model.bands[0]!.tracks.map((track) => track.stations)).toEqual([[1, 3, 4], [2]]);
  242. const { sections } = spineLayout(model);
  243. expect(sections[1]!.fork).toBeDefined();
  244. expect(sections[4]!.merge).toBeDefined();
  245. const track1 = (i: number) => sections[i]!.rails.filter((rail) => rail.track === 1);
  246. // 分叉行之下、第一枚灯之前:整节穿过;过了最后一枚灯、汇合行之前:也整节穿过。
  247. expect(track1(1)).toEqual([{ ink: "faint", position: "full", track: 1 }]);
  248. expect(track1(3)).toEqual([{ ink: "faint", position: "full", track: 1 }]);
  249. expect(track1(4)).toEqual([{ ink: "faint", position: "full", track: 1 }]);
  250. // 主轨穿过分支站 2(前后都有主线成员)。
  251. expect(sections[2]!.rails.filter((rail) => rail.track === 0)).toEqual([
  252. { ink: "faint", position: "full", track: 0 },
  253. ]);
  254. // 汇合站那一节只有主轨的上半截:汇合在它上面的那一行里,不在它的节头里。
  255. expect(sections[5]!.rails).toEqual([{ ink: "faint", position: "above", track: 0 }]);
  256. });
  257. it("轨距:最多四条分支轨时 12,多于四条收到 8;文字列让开整个轨道区", () => {
  258. const fan = (branches: number) => {
  259. const n = branches + 1;
  260. const near = [
  261. undefined,
  262. ...Array.from({ length: n }, (_, k) =>
  263. k === 0 ? undefined : Array.from({ length: k }, (_, j) => j + 1),
  264. ),
  265. undefined,
  266. ];
  267. const edges: [number, number][] = near.slice(1).map((_, k) => [k, k + 1]);
  268. return spineLayout(buildWorkflowTimeline(bandGraph(near, edges), undefined));
  269. };
  270. expect(fan(4)).toMatchObject({ gutter: 48, pitch: 12 });
  271. expect(fan(5)).toMatchObject({ gutter: 40, pitch: 8 });
  272. });
  273. it("并排的两条带:前一条的开口汇合行紧接后一条的开口分叉行", () => {
  274. // P → [A, B ∥ A, C ∥ B] → [D, E ∥ D] → J
  275. const adjacent = bandGraph(
  276. [undefined, undefined, [1], [2], undefined, [4], undefined],
  277. [
  278. [0, 1],
  279. [1, 2],
  280. [2, 3],
  281. [3, 4],
  282. [4, 5],
  283. [5, 6],
  284. ],
  285. );
  286. const model = buildWorkflowTimeline(adjacent, undefined);
  287. expect(model.bands.map((band) => [band.from, band.to, band.pred, band.join])).toEqual([
  288. [1, 3, 0, undefined],
  289. [4, 5, undefined, 6],
  290. ]);
  291. const { sections } = spineLayout(model);
  292. expect(
  293. sections.flatMap((section, i) =>
  294. [
  295. section.fork ? `fork:${i}${section.fork.open ? ":open" : ""}` : [],
  296. section.merge ? `merge:${i}${section.merge.open ? ":open" : ""}` : [],
  297. ].flat(),
  298. ),
  299. ).toEqual(["fork:1", "merge:3:open", "fork:4:open", "merge:5"]);
  300. // C 的主轨往下接开口的汇合行,D 的主轨从开口的分叉行下来。
  301. expect(sections[3]!.rails.find((rail) => rail.position === "below")).toEqual({
  302. ink: "faint",
  303. position: "below",
  304. track: 0,
  305. });
  306. expect(sections[4]!.rails.find((rail) => rail.position === "above")).toEqual({
  307. ink: "faint",
  308. position: "above",
  309. track: 0,
  310. });
  311. });
  312. });
  313. describe("WorkflowRunPhaseList · 带", () => {
  314. it("文字列让开整个轨道区:每一节的节头都从同一列起,灯留在自己的轨道上", () => {
  315. const view = renderSpine(TESTFIELD);
  316. const phases = view.getAllByTestId("workflow-run-phase");
  317. expect(phases.map((section) => section.getAttribute("data-phase-track"))).toEqual([
  318. "0",
  319. "1",
  320. "0",
  321. ]);
  322. for (const phase of phases) {
  323. expect(within(phase).getByTestId("workflow-run-phase-toggle").style.paddingLeft).toBe("51px");
  324. }
  325. const lamps = phases.map((phase) => within(phase).getByTestId("workflow-run-phase-lamp"));
  326. expect(lamps.map((lamp) => lamp.style.left)).toEqual(["", "28px", ""]);
  327. });
  328. it("接头行插在两节之间:每条带都有分叉行与汇合行,没有前驱 / 汇合站时是开口的", () => {
  329. expect(sequenceOf(renderSpine(WITH_PRED))).toEqual([
  330. "phase:0",
  331. "fork",
  332. "phase:1",
  333. "phase:2",
  334. "merge",
  335. "phase:3",
  336. ]);
  337. cleanup();
  338. expect(sequenceOf(renderSpine(TESTFIELD))).toEqual([
  339. "fork",
  340. "phase:0",
  341. "phase:1",
  342. "merge",
  343. "phase:2",
  344. ]);
  345. cleanup();
  346. expect(sequenceOf(renderSpine(OPEN_END))).toEqual([
  347. "phase:0",
  348. "fork",
  349. "phase:1",
  350. "phase:2",
  351. "merge",
  352. ]);
  353. });
  354. it("接头行:主轨直穿,每条分支一条曲线,带轨道号与墨", () => {
  355. const view = renderSpine(WITH_PRED);
  356. const fork = view
  357. .getAllByTestId("workflow-run-spine-joint")
  358. .find((joint) => joint.getAttribute("data-joint-kind") === "fork")!;
  359. expect(railsOf(fork)).toEqual([{ ink: "faint", position: "full", track: "0" }]);
  360. expect(fork.getAttribute("data-joint-open")).toBeNull();
  361. expect(within(fork).getByTestId("workflow-run-spine-rail").style.top).toBe("");
  362. const curves = within(fork).getAllByTestId("workflow-run-spine-fork");
  363. expect(
  364. curves.map((curve) => [
  365. curve.getAttribute("data-curve-track"),
  366. curve.getAttribute("data-curve-ink"),
  367. ]),
  368. ).toEqual([["1", "faint"]]);
  369. expect(fork.getAttribute("aria-hidden")).toBe("true");
  370. });
  371. it("开口的接头:主轨在行外 4px 起(根)/ 止(汇点),不从上一节或下一节借位", () => {
  372. const view = renderSpine(OPEN_END);
  373. const joints = view.getAllByTestId("workflow-run-spine-joint");
  374. const fork = joints.find((joint) => joint.getAttribute("data-joint-kind") === "fork")!;
  375. const merge = joints.find((joint) => joint.getAttribute("data-joint-kind") === "merge")!;
  376. expect(fork.getAttribute("data-joint-open")).toBeNull();
  377. expect(merge.getAttribute("data-joint-open")).toBe("true");
  378. const stub = within(merge).getByTestId("workflow-run-spine-rail");
  379. expect(stub.style.top).toBe("0px");
  380. expect(stub.style.bottom).toBe("-4px");
  381. cleanup();
  382. const root = renderSpine(TESTFIELD).getAllByTestId("workflow-run-spine-joint")[0]!;
  383. expect(root.getAttribute("data-joint-open")).toBe("true");
  384. expect(within(root).getByTestId("workflow-run-spine-rail").style.top).toBe("-4px");
  385. });
  386. it("汇合站在跑、两条轨道都到过:汇合行的主轨与分支曲线一起行进", () => {
  387. const view = renderSpine(
  388. TESTFIELD,
  389. run([settled("ask#0"), settled("ask#1"), executing("ask#2")]),
  390. );
  391. const [a, b, c] = view.getAllByTestId("workflow-run-phase");
  392. const merge = view
  393. .getAllByTestId("workflow-run-spine-joint")
  394. .find((joint) => joint.getAttribute("data-joint-kind") === "merge")!;
  395. expect(railsOf(merge)).toEqual([{ ink: "march", position: "full", track: "0" }]);
  396. const curve = within(merge).getByTestId("workflow-run-spine-merge");
  397. expect(curve.getAttribute("data-curve-ink")).toBe("march");
  398. // 合流曲线上叠的是一条亮着的光:渐变描边(`url(#…)`),渐变本身就在这张 SVG 里;光画在全部底墨
  399. // 之上,所以它是曲线的兄弟而不是孩子。
  400. expect(curve.querySelector("path.wf-lit")).toBeNull();
  401. const light = within(merge)
  402. .getByTestId("workflow-run-spine-merge-lit")
  403. .querySelector("path.wf-lit");
  404. expect(light?.getAttribute("data-testid")).toBe("workflow-march-light");
  405. expect(light?.getAttribute("stroke")).toMatch(/^url\(#.+\)$/);
  406. expect(merge.querySelector("linearGradient")).toBeTruthy();
  407. // 主线那一段(A 的下半截、B 里穿过的主轨、C 的上半截)行进;B 的分支轨下半截接着合流曲线。
  408. // 根下来的那几段是到过的站的进入墨:浓。
  409. expect(railsOf(a!)).toEqual([
  410. { ink: "strong", position: "above", track: "0" },
  411. { ink: "march", position: "below", track: "0" },
  412. { ink: "strong", position: "full", track: "1" },
  413. ]);
  414. expect(railsOf(b!)).toEqual([
  415. { ink: "march", position: "full", track: "0" },
  416. { ink: "strong", position: "above", track: "1" },
  417. { ink: "march", position: "below", track: "1" },
  418. ]);
  419. expect(railsOf(c!)).toEqual([{ ink: "march", position: "above", track: "0" }]);
  420. });
  421. it("带里两条轨道同时在跑:两节都自己展开,不只最右那个", () => {
  422. const view = renderSpine(TESTFIELD, run([executing("ask#0"), executing("ask#1")]));
  423. const phases = view.getAllByTestId("workflow-run-phase");
  424. expect(phases.map((phase) => phase.getAttribute("data-phase-status"))).toEqual([
  425. "running",
  426. "running",
  427. "pending",
  428. ]);
  429. expect(phases.map((phase) => phase.getAttribute("data-phase-open"))).toEqual([
  430. "true",
  431. "true",
  432. "false",
  433. ]);
  434. // 展开的药丸列也在文字列上。
  435. for (const phase of phases.slice(0, 2)) {
  436. expect(within(phase).getByTestId("workflow-run-phase-body").style.paddingLeft).toBe("51px");
  437. }
  438. });
  439. it("没有 alongside 的图:没有接头、没有让位,DOM 与从前一样", () => {
  440. const line = bandGraph(
  441. [undefined, undefined, undefined],
  442. [
  443. [0, 1],
  444. [1, 2],
  445. ],
  446. );
  447. const view = renderSpine(line, run([settled("ask#0"), executing("ask#1")]));
  448. expect(view.queryAllByTestId("workflow-run-spine-joint")).toHaveLength(0);
  449. const phases = view.getAllByTestId("workflow-run-phase");
  450. expect(phases.map((phase) => phase.getAttribute("data-phase-track"))).toEqual(["0", "0", "0"]);
  451. for (const phase of phases) {
  452. expect(within(phase).getByTestId("workflow-run-phase-toggle").style.paddingLeft).toBe("");
  453. for (const rail of within(phase).queryAllByTestId("workflow-run-spine-rail")) {
  454. expect(rail.getAttribute("data-rail-track")).toBe("0");
  455. expect(rail.style.left).toBe("");
  456. }
  457. }
  458. // 行进段仍落在进入运行站的那一段上。
  459. expect(railsOf(phases[0]!)).toEqual([{ ink: "march", position: "below", track: "0" }]);
  460. expect(railsOf(phases[1]!)).toEqual([
  461. { ink: "march", position: "above", track: "0" },
  462. { ink: "faint", position: "below", track: "0" },
  463. ]);
  464. });
  465. });
  466. // 子代理自己的模型(presentation.md「The spine」):persona 点名了模型的子代理,行尾计数后面跟模型名,
  467. // tooltip 多一行规范串;跑在 run 模型上的子代理什么都不说。
  468. describe("WorkflowRunPhaseList · 子代理的模型", () => {
  469. it("点名了模型的那一行带模型名(不带 providerId),tooltip 带规范串;其余行不带", () => {
  470. const state: WorkflowRunState = {
  471. ...run([
  472. { ...executing("ask#0"), actorSiteId: "actor#0", actorOrdinal: 1, kind: "ask" } as Node,
  473. { ...executing("ask#1"), actorSiteId: "actor#1", actorOrdinal: 1, kind: "ask" } as Node,
  474. ]),
  475. actors: [
  476. {
  477. siteId: "actor#0",
  478. ordinal: 1,
  479. name: "judge",
  480. status: "running",
  481. model: "4fc7f541-2382-4c32-be11-f021b8d7ed1d/GLM-5.3-Flash$high",
  482. },
  483. { siteId: "actor#1", ordinal: 1, name: "writer", status: "running" },
  484. ],
  485. };
  486. const view = renderSpine(TESTFIELD, state);
  487. const models = view.getAllByTestId("workflow-run-agent-model");
  488. expect(models).toHaveLength(1);
  489. expect(models[0]?.textContent).toMatch(/GLM-5\.3-Flash$/);
  490. expect(models[0]?.textContent).not.toContain("4fc7f541");
  491. const row = models[0]!.closest<HTMLElement>('[data-testid="workflow-agent-pill"]');
  492. expect(row?.getAttribute("title")).toBe(
  493. "judge\n4fc7f541-2382-4c32-be11-f021b8d7ed1d/GLM-5.3-Flash$high",
  494. );
  495. const pills = view.getAllByTestId("workflow-agent-pill");
  496. const writer = pills.find((pill) => pill.textContent?.includes("writer"));
  497. expect(writer?.getAttribute("title")).toBe("writer");
  498. });
  499. });