activity-history-cases.mjs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. import { join } from "node:path";
  4. export function registerActivityHistoryCases({ getBrowser, getOrigin, artifacts }) {
  5. for (const width of [390, 1200]) {
  6. for (const theme of ["light", "dark"]) {
  7. test(`unknown total preserves observed result states ${width}/${theme}`, async () => {
  8. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  9. try {
  10. for (const [mix, label, secondary] of [
  11. ["resultPending,cancelled", "Completed", null],
  12. ["cancelled", "Activity", "Stopped"],
  13. ["failed,resultPending,cancelled", "Failed", "1"],
  14. ]) {
  15. await page.goto(
  16. getOrigin() +
  17. `fixture?real=1&endedOnly=1&theme=${theme}&locale=en-US&completedTotal=unknown&resultMix=${mix}`,
  18. );
  19. const capsule = page.locator('[data-status-capsule="activity"]');
  20. await capsule.waitFor();
  21. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), label);
  22. const count = capsule.locator("[data-status-capsule-secondary]");
  23. if (secondary === null) assert.equal(await count.count(), 0);
  24. else assert.equal(await count.textContent(), secondary);
  25. }
  26. } finally {
  27. await page.close();
  28. }
  29. });
  30. test(`unknown completed count is not a preview total ${width}/${theme}`, async () => {
  31. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  32. try {
  33. await page.goto(
  34. getOrigin() +
  35. `fixture?real=1&endedOnly=1&theme=${theme}&locale=en-US&completedTotal=unknown`,
  36. );
  37. const capsule = page.locator('[data-status-capsule="activity"]');
  38. await capsule.waitFor();
  39. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Completed");
  40. assert.equal(await capsule.locator("[data-status-capsule-secondary]").count(), 0);
  41. await capsule.click();
  42. assert.ok((await page.locator("[data-activity-id]").count()) > 0);
  43. } finally {
  44. await page.close();
  45. }
  46. });
  47. test(`complete history count exceeds preview ${width}/${theme}`, async () => {
  48. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  49. try {
  50. for (const total of [9, 105, 114]) {
  51. await page.goto(
  52. getOrigin() +
  53. `fixture?real=1&endedOnly=1&theme=${theme}&locale=en-US&completedTotal=${total}`,
  54. );
  55. const capsule = page.locator('[data-status-capsule="activity"]');
  56. await capsule.waitFor();
  57. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Completed");
  58. assert.equal(
  59. await capsule.locator("[data-status-capsule-secondary]").innerText(),
  60. String(total),
  61. );
  62. // 总数大于预览;不靠扩充头像/明细来凑出总数。
  63. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 1);
  64. }
  65. } finally {
  66. await page.close();
  67. }
  68. });
  69. test(`ended activity hides duplicate descriptions ${width}/${theme}`, async () => {
  70. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  71. try {
  72. for (const summary of [
  73. "Inspect files",
  74. " Inspect files ",
  75. " ",
  76. "Inspection complete",
  77. ]) {
  78. await page.goto(
  79. getOrigin() +
  80. `fixture?real=1&endedOnly=1&theme=${theme}&locale=en-US&agentSummary=${encodeURIComponent(summary)}`,
  81. );
  82. await page.locator('[data-status-capsule="activity"]').click();
  83. const row = page.locator('[data-activity-result="completed"]');
  84. const description = row.locator("span.line-clamp-2.text-ui-sm");
  85. assert.equal(await description.count(), summary === "Inspection complete" ? 1 : 0);
  86. assert.equal(await row.getByText("Inspect files", { exact: true }).count(), 1);
  87. assert.match(await row.innerText(), /Completed/);
  88. if (summary === "Inspection complete")
  89. assert.equal(await description.innerText(), summary);
  90. if (summary === "Inspect files")
  91. await page.screenshot({
  92. path: join(artifacts, `activity-description-${width}-${theme}.png`),
  93. });
  94. }
  95. } finally {
  96. await page.close();
  97. }
  98. });
  99. }
  100. }
  101. for (const width of [390, 1200]) {
  102. for (const theme of ["light", "dark"]) {
  103. test(`completed actors survive parent stop and running avatars outrank waiting ${width}/${theme}`, async () => {
  104. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  105. try {
  106. const capsule = page.locator('[data-status-capsule="activity"]');
  107. for (const runStatus of ["stopped", "errored"]) {
  108. await page.goto(
  109. getOrigin() +
  110. `fixture?real=1&endedOnly=1&workflow=1&mixedActors=1&allActorsDone=1&actorParentEnd=1&runStatus=${runStatus}&theme=${theme}&locale=en-US`,
  111. );
  112. await capsule.waitFor();
  113. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Active");
  114. assert.equal(await capsule.locator('[data-agent-result-badge="completed"]').count(), 3);
  115. await page.getByTestId("settle-workflow").click();
  116. assert.equal(
  117. await capsule.locator("[data-capsule-label]").textContent(),
  118. runStatus === "stopped" ? "Activity" : "Failed",
  119. );
  120. assert.equal(
  121. await capsule.locator("[data-status-capsule-secondary]").textContent(),
  122. runStatus === "stopped" ? "Stopped" : "1",
  123. );
  124. assert.equal(
  125. await capsule
  126. .locator('[data-subagent-avatar] [data-agent-result-badge="completed"]')
  127. .count(),
  128. 3,
  129. );
  130. await page.screenshot({
  131. path: join(artifacts, `completed-actors-${runStatus}-${width}-${theme}.png`),
  132. });
  133. await page.getByTestId("dismiss-activity").click();
  134. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 0);
  135. }
  136. await page.goto(
  137. getOrigin() +
  138. `fixture?real=1&workflow=1&waitingActors=1&mixedAgents=1&theme=${theme}&locale=en-US`,
  139. );
  140. await capsule.waitFor();
  141. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 3);
  142. assert.equal(
  143. await capsule.locator('[data-subagent-avatar][data-face-state="scanning"]').count(),
  144. 1,
  145. );
  146. assert.equal(
  147. await capsule.locator('[data-subagent-avatar][data-face-state="waiting"]').count(),
  148. 2,
  149. );
  150. await page.screenshot({
  151. path: join(artifacts, `running-before-waiting-${width}-${theme}.png`),
  152. });
  153. } finally {
  154. await page.close();
  155. }
  156. });
  157. test(`capsule keeps running and completed avatars with configured identity ${width}/${theme}`, async () => {
  158. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  159. try {
  160. const capsule = page.locator('[data-status-capsule="activity"]');
  161. await page.goto(
  162. getOrigin() +
  163. `fixture?theme=${theme}&locale=en-US&real=1&endedOnly=1&mixedAgents=1&configuredColor=1`,
  164. );
  165. await capsule.waitFor();
  166. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 2);
  167. assert.equal(await capsule.locator('[data-agent-result-badge="completed"]').count(), 1);
  168. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Active");
  169. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  170. assert.equal(
  171. await capsule.locator("[data-subagent-avatar]").last().getAttribute("data-face-state"),
  172. "scanning",
  173. );
  174. assert.equal(
  175. await capsule.locator("[data-subagent-avatar]").first().getAttribute("data-face-state"),
  176. "content",
  177. );
  178. const faceColor = () =>
  179. capsule
  180. .locator("[data-subagent-avatar]")
  181. .first()
  182. .evaluate((el) => getComputedStyle(el).getPropertyValue("--wf-face-body").trim());
  183. assert.equal(await faceColor(), "#3C82F6");
  184. assert.equal(
  185. await page
  186. .locator('[data-testid="message-agent"] [data-subagent-avatar]')
  187. .evaluate((el) => getComputedStyle(el).getPropertyValue("--wf-face-body").trim()),
  188. await faceColor(),
  189. );
  190. await capsule.click();
  191. const detail = page.locator(
  192. '[data-testid="v4-running-subagent-item"] [data-subagent-avatar]',
  193. );
  194. assert.equal(
  195. await detail.evaluate((el) =>
  196. getComputedStyle(el).getPropertyValue("--wf-face-body").trim(),
  197. ),
  198. await faceColor(),
  199. );
  200. await page.getByTestId("outside").click();
  201. await page.screenshot({
  202. path: join(artifacts, `activity-avatar-identity-${width}-${theme}.png`),
  203. });
  204. await page.goto(
  205. getOrigin() +
  206. `fixture?theme=${theme}&locale=en-US&real=1&endedOnly=1&mixedAgents=1&workflow=1&mixedActors=1&allActorsDone=1`,
  207. );
  208. await capsule.waitFor();
  209. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 3);
  210. assert.equal(
  211. await capsule.locator("[data-subagent-avatar]").last().getAttribute("data-face-state"),
  212. "scanning",
  213. );
  214. assert.equal(await capsule.locator('[data-agent-result-badge="completed"]').count(), 2);
  215. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  216. for (const runningCount of [2, 3, 4]) {
  217. await page.goto(
  218. getOrigin() +
  219. `fixture?theme=${theme}&locale=en-US&real=1&endedOnly=1&mixedAgents=1&runningCount=${runningCount}`,
  220. );
  221. await capsule.waitFor();
  222. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 3);
  223. assert.equal(
  224. await capsule.locator("[data-agent-result-badge]").count(),
  225. runningCount === 2 ? 1 : 0,
  226. );
  227. assert.deepEqual(
  228. await capsule
  229. .locator("[data-subagent-avatar]")
  230. .evaluateAll((els) => els.map((el) => el.getAttribute("data-face-state"))),
  231. runningCount === 2
  232. ? ["content", "scanning", "scanning"]
  233. : ["scanning", "scanning", "scanning"],
  234. );
  235. assert.equal(
  236. await capsule.locator("[data-status-capsule-secondary]").innerText(),
  237. String(runningCount),
  238. );
  239. }
  240. for (const status of ["success", "failed"]) {
  241. await page.goto(
  242. getOrigin() +
  243. `fixture?theme=${theme}&locale=en-US&real=1&endedOnly=1&agentStatus=${status}&configuredColor=1`,
  244. );
  245. await capsule.waitFor();
  246. assert.equal(await capsule.locator("[data-subagent-avatar]").count(), 1);
  247. assert.equal(await faceColor(), "#3C82F6");
  248. assert.equal(
  249. await capsule
  250. .locator("[data-agent-result-badge]")
  251. .getAttribute("data-agent-result-badge"),
  252. status === "success" ? "completed" : "failed",
  253. );
  254. }
  255. } finally {
  256. await page.close();
  257. }
  258. });
  259. }
  260. }
  261. for (const width of [390, 1200]) {
  262. for (const theme of ["light", "dark"]) {
  263. test(`workflow completion survives while bash clears on next input ${width}/${theme}`, async () => {
  264. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  265. try {
  266. await page.goto(
  267. getOrigin() + `fixture?theme=${theme}&locale=en-US&real=1&workflow=1&endedOnly=1`,
  268. );
  269. const capsule = page.locator('[data-status-capsule="activity"]');
  270. await capsule.waitFor();
  271. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "2");
  272. await page.getByTestId("dismiss-activity").click();
  273. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Completed");
  274. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  275. await capsule.click();
  276. assert.equal(await page.locator("[data-activity-result]").count(), 0);
  277. await page.getByTestId("outside").click();
  278. await page.screenshot({
  279. path: join(artifacts, `activity-completed-retained-${width}-${theme}.png`),
  280. });
  281. } finally {
  282. await page.close();
  283. }
  284. });
  285. }
  286. }
  287. for (const width of [390, 1200]) {
  288. for (const theme of ["light", "dark"]) {
  289. test(`activity failure count resets on accepted input ${width}/${theme}`, async () => {
  290. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  291. try {
  292. await page.goto(
  293. getOrigin() + `fixture?theme=${theme}&locale=en-US&real=1&agentStatus=failed`,
  294. );
  295. const capsule = page.locator('[data-status-capsule="activity"]');
  296. await capsule.waitFor();
  297. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Active");
  298. await page.getByTestId("end-activity").click();
  299. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Failed");
  300. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  301. await page.screenshot({ path: join(artifacts, `activity-failed-${width}-${theme}.png`) });
  302. await page.getByTestId("start-terminal").click();
  303. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Active");
  304. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  305. await page.getByTestId("new-terminal").click();
  306. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Failed");
  307. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  308. await page.getByTestId("dismiss-activity").click();
  309. assert.equal(await capsule.locator("[data-capsule-label]").textContent(), "Completed");
  310. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  311. await capsule.click();
  312. assert.equal(await page.locator('[data-activity-result="failed"]').count(), 0);
  313. } finally {
  314. await page.close();
  315. }
  316. });
  317. }
  318. }
  319. for (const theme of ["light", "dark"]) {
  320. test(`all completed actor badges remain unobscured ${theme}`, async () => {
  321. const page = await getBrowser().newPage();
  322. try {
  323. await page.goto(
  324. `${getOrigin()}fixture?real=1&workflow=1&endedOnly=1&mixedActors=1&allActorsDone=1&theme=${theme}&locale=en-US`,
  325. );
  326. const capsule = page.locator('[data-status-capsule="activity"]');
  327. const badges = capsule.locator(
  328. '[data-subagent-avatar] [data-agent-result-badge="completed"]',
  329. );
  330. assert.equal(await badges.count(), 3);
  331. assert.equal(await capsule.locator("[data-agent-result-badge]").count(), 3);
  332. for (const badge of await badges.all()) {
  333. assert.equal(
  334. await badge.evaluate((node) => {
  335. // Button 默认关闭 SVG 命中;仅为遮挡检测打开,不改变视觉或层级。
  336. node.ownerSVGElement.style.pointerEvents = "all";
  337. for (const child of node.querySelectorAll("*")) child.style.pointerEvents = "all";
  338. const r = node.getBoundingClientRect();
  339. return node.contains(
  340. document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2),
  341. );
  342. }),
  343. true,
  344. );
  345. }
  346. await page.screenshot({ path: join(artifacts, `all-actor-badges-${theme}.png`) });
  347. } finally {
  348. await page.close();
  349. }
  350. });
  351. }
  352. for (const theme of ["light", "dark"]) {
  353. test(`Workflow capsule preserves each actor state ${theme}`, async () => {
  354. const page = await getBrowser().newPage({ viewport: { width: 390, height: 900 } });
  355. try {
  356. await page.goto(
  357. `${getOrigin()}fixture?real=1&workflow=1&mixedActors=1&theme=${theme}&locale=en-US`,
  358. );
  359. const capsule = page.locator('[data-status-capsule="activity"]');
  360. const avatars = capsule.locator("[data-subagent-avatar]");
  361. assert.equal(await avatars.count(), 3);
  362. assert.equal(await capsule.locator('[data-agent-result-badge="completed"]').count(), 1);
  363. assert.equal(await avatars.nth(0).getAttribute("data-face-state"), "content");
  364. assert.equal(await avatars.nth(1).getAttribute("data-face-state"), "scanning");
  365. assert.equal(await avatars.nth(2).getAttribute("data-face-state"), "waiting");
  366. await page.screenshot({ path: join(artifacts, `individual-actor-${theme}.png`) });
  367. } finally {
  368. await page.close();
  369. }
  370. });
  371. }
  372. for (const width of [390, 1200]) {
  373. for (const theme of ["light", "dark"]) {
  374. test(`Chinese Activity capsule uses active label ${width}/${theme}`, async () => {
  375. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  376. try {
  377. await page.goto(`${getOrigin()}fixture?real=1&theme=${theme}&locale=zh-CN`);
  378. const capsule = page.locator('[data-status-capsule="activity"]');
  379. // 窄屏按既有响应式规则收起文字,仍用同一中文无障碍名称。
  380. if (width === 390) assert.equal(await capsule.getAttribute("aria-label"), "活跃中");
  381. else assert.match(await capsule.innerText(), /活跃/);
  382. } finally {
  383. await page.close();
  384. }
  385. });
  386. }
  387. }
  388. for (const status of ["success", "failed", "cancelled"]) {
  389. for (const endedAt of [4, 14]) {
  390. test(`cold seeded ${status} result respects input boundary ${endedAt}`, async () => {
  391. const page = await getBrowser().newPage();
  392. try {
  393. await page.goto(
  394. `${getOrigin()}fixture?real=1&theme=dark&locale=en-US&endedOnly=1&onlySubagentHistory=1&agentStatus=${status}&childEndedAt=${endedAt}`,
  395. );
  396. await page.getByTestId("dismiss-activity").click();
  397. const capsule = page.locator('[data-status-capsule="activity"]');
  398. await capsule.click();
  399. await page.getByTestId("activity-subagent-directory").waitFor();
  400. assert.equal(await page.locator("[data-activity-result]").count(), endedAt > 10 ? 1 : 0);
  401. if (endedAt <= 10) {
  402. assert.equal(
  403. (await capsule.innerText()).replace(/\s+/g, " "),
  404. `Completed ${status === "success" ? 1 : 0}`,
  405. );
  406. assert.equal(
  407. await page.locator("[data-agent-result-badge]").count(),
  408. status === "success" ? 1 : 0,
  409. );
  410. } else {
  411. const result = { success: "completed", failed: "failed", cancelled: "stopped" }[status];
  412. assert.equal(
  413. await page.locator("[data-activity-result]").getAttribute("data-activity-result"),
  414. result,
  415. );
  416. assert.equal(
  417. await capsule
  418. .locator("[data-agent-result-badge]")
  419. .getAttribute("data-agent-result-badge"),
  420. result,
  421. );
  422. assert.equal(
  423. await page
  424. .locator(`[data-activity-result] [data-agent-result-badge="${result}"]`)
  425. .count(),
  426. 1,
  427. );
  428. }
  429. } finally {
  430. await page.close();
  431. }
  432. });
  433. }
  434. }
  435. test("accepted input keeps running activity alongside history", async () => {
  436. const page = await getBrowser().newPage();
  437. try {
  438. await page.goto(`${getOrigin()}fixture?real=1&theme=light&locale=en-US`);
  439. await page.getByTestId("dismiss-activity").click();
  440. const capsule = page.locator('[data-status-capsule="activity"]');
  441. assert.equal(await capsule.locator("[data-status-capsule-secondary]").innerText(), "1");
  442. await capsule.click();
  443. await page.getByTestId("activity-subagent-directory").waitFor();
  444. await page.getByTestId("v4-running-subagent-stop").waitFor();
  445. } finally {
  446. await page.close();
  447. }
  448. });
  449. for (const width of [390, 1200]) {
  450. for (const theme of ["light", "dark"]) {
  451. test(`previous directories coexist with current completed terminal ${width}/${theme}`, async () => {
  452. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  453. try {
  454. await page.goto(`${getOrigin()}fixture?real=1&theme=${theme}&locale=en-US&endedOnly=1`);
  455. await page.getByTestId("dismiss-activity").click();
  456. await page.getByTestId("new-terminal").click();
  457. await page.locator('[data-status-capsule="activity"]').click();
  458. await page.getByText("Current round terminal", { exact: true }).waitFor();
  459. for (const kind of ["subagent", "workflow"]) {
  460. if (kind === "workflow") await page.locator('[data-status-capsule="activity"]').click();
  461. const entry = page.getByTestId(`activity-${kind}-directory`);
  462. assert.equal(await entry.count(), 1, "本轮结果不能隐藏上一轮目录");
  463. await entry.click();
  464. assert.equal(
  465. await page.locator("output").textContent(),
  466. `${kind === "subagent" ? "agent" : "workflow"}-history:parent`,
  467. );
  468. }
  469. await page.screenshot({
  470. path: join(artifacts, `activity-history-current-${width}-${theme}.png`),
  471. });
  472. } finally {
  473. await page.close();
  474. }
  475. });
  476. }
  477. }
  478. test("directory visibility follows each archived kind independently", async () => {
  479. const page = await getBrowser().newPage();
  480. try {
  481. await page.goto(
  482. `${getOrigin()}fixture?real=1&theme=light&locale=en-US&endedOnly=1&onlySubagentHistory=1`,
  483. );
  484. await page.locator('[data-status-capsule="activity"]').click();
  485. assert.equal(await page.getByTestId("activity-subagent-directory").count(), 0);
  486. assert.equal(await page.getByTestId("activity-workflow-directory").count(), 0);
  487. await page.getByTestId("dismiss-activity").click();
  488. await page.getByTestId("new-terminal").click();
  489. await page.locator('[data-status-capsule="activity"]').click();
  490. await page.getByTestId("activity-subagent-directory").waitFor();
  491. assert.equal(await page.getByTestId("activity-workflow-directory").count(), 0);
  492. } finally {
  493. await page.close();
  494. }
  495. });
  496. for (const width of [390, 1280])
  497. for (const theme of ["light", "dark"]) {
  498. test(`capsule navigation closes portal ${width}/${theme}`, async () => {
  499. const page = await getBrowser().newPage({ viewport: { width, height: 900 } });
  500. try {
  501. for (const item of [
  502. {
  503. capsule: "activity",
  504. query: "",
  505. selector: "[data-running-subagent-session-trigger]",
  506. result: "agent-details",
  507. },
  508. {
  509. capsule: "activity",
  510. query: "&workflow=1",
  511. selector: '[data-testid="background-bash-open"]',
  512. result: "bash-details",
  513. },
  514. {
  515. capsule: "git",
  516. query: "",
  517. selector: '[data-testid="status-git-files"] button',
  518. result: "unstaged:shared.txt",
  519. },
  520. {
  521. capsule: "git",
  522. query: "",
  523. selector: '[data-testid="status-git-view-all"]',
  524. result: "git-details",
  525. },
  526. ]) {
  527. await page.goto(
  528. getOrigin() + `fixture?real=1&theme=${theme}&locale=en-US` + item.query,
  529. );
  530. await page.locator(`[data-status-capsule="${item.capsule}"]`).click();
  531. await page.locator(item.selector).first().click();
  532. assert.equal(await page.locator("output").innerText(), item.result);
  533. await page.locator("[data-status-capsule-content]").waitFor({ state: "hidden" });
  534. }
  535. } finally {
  536. await page.close();
  537. }
  538. });
  539. }
  540. test("workflow journal distinguishes pending, empty and unavailable; ignores stale response", async () => {
  541. const page = await getBrowser().newPage();
  542. try {
  543. await page.goto(getOrigin() + "fixture?journalQuery=1");
  544. await page.getByTestId("query-state").waitFor();
  545. assert.equal(await page.getByTestId("query-state").innerText(), "loading");
  546. await page.waitForFunction(() => window.workflowRequests.length === 1);
  547. await page.getByRole("button", { name: "Switch query" }).click();
  548. await page.waitForFunction(() => window.workflowRequests.length === 2);
  549. await page.evaluate(() => window.workflowRequests[0].resolve({ runs: [{ runId: "old" }] }));
  550. assert.equal(await page.getByTestId("query-state").innerText(), "loading");
  551. await page.evaluate(() => window.workflowRequests[1].resolve({ runs: [] }));
  552. await page.waitForFunction(
  553. () => document.querySelector('[data-testid="query-state"]').textContent === "[]",
  554. );
  555. await page.reload();
  556. await page.waitForFunction(() => window.workflowRequests.length === 1);
  557. assert.equal(await page.getByTestId("query-state").innerText(), "loading");
  558. await page.evaluate(() =>
  559. window.workflowRequests[0].reject(new Error("capabilityUnsupported")),
  560. );
  561. await page.waitForFunction(
  562. () => document.querySelector('[data-testid="query-state"]').textContent === "unavailable",
  563. );
  564. } finally {
  565. await page.close();
  566. }
  567. });
  568. test("workflow actors are counted once alongside terminal tasks", async () => {
  569. const page = await getBrowser().newPage();
  570. try {
  571. await page.goto(getOrigin() + "fixture?theme=light&locale=en-US&real=1&workflow=1");
  572. const activity = page.locator('[data-status-capsule="activity"]');
  573. await activity.waitFor();
  574. assert.equal((await activity.innerText()).replace(/\s+/g, " "), "Active 2");
  575. assert.equal(await activity.locator("[data-status-capsule-secondary]").innerText(), "2");
  576. const secondarySizes = await page
  577. .locator("[data-status-capsule-secondary]")
  578. .evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).fontSize));
  579. assert.ok(secondarySizes.length >= 4);
  580. assert.ok(secondarySizes.every((size) => size === "12px"));
  581. await activity.click();
  582. assert.equal(await page.getByTestId("v4-running-subagent-item").count(), 0);
  583. assert.deepEqual(
  584. await page
  585. .locator("[data-activity-id]")
  586. .evaluateAll((nodes) => nodes.map((n) => n.dataset.activityId)),
  587. ["workflow:run", "bash:shell"],
  588. );
  589. await page.locator("[data-workflow-run-details-trigger]").click();
  590. assert.equal(await page.locator("output").innerText(), "workflow-details");
  591. await page.locator('[data-status-capsule-content="activity"]').waitFor({ state: "hidden" });
  592. } finally {
  593. await page.close();
  594. }
  595. });
  596. }
  597. export const workflowQueryFixture = `const requests=[];
  598. window.workflowRequests=requests;
  599. const queryContext={workflowRuns:()=>new Promise((resolve,reject)=>requests.push({resolve,reject}))};
  600. function QueryProbe(){
  601. const [session,setSession]=useState("a");
  602. const data=useWorkflowRunJournalSummaries({sessionId:session,live:true});
  603. return <><button onClick={()=>setSession("b")}>Switch query</button><output data-testid="query-state">{data===undefined?"loading":data===null?"unavailable":JSON.stringify(data)}</output></>;
  604. }
  605. `;