e2ecase-regression.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. import {
  2. TID_CHAT_INPUT,
  3. TID_CHAT_MESSAGES,
  4. TID_CHAT_REASONING_CONTENT,
  5. TID_CHAT_REASONING_TRIGGER,
  6. TID_CHAT_SEND_BUTTON,
  7. TID_LOGIN_TRIGGER,
  8. TID_SETTINGS_BACK_BUTTON,
  9. TID_SETTINGS_PAGE,
  10. TID_SETTINGS_SECTION_NAV,
  11. TID_SIDEBAR_CODING_PLAN_USAGE_BUTTON,
  12. TID_TASK_SETTINGS_BUTTON,
  13. testId,
  14. } from "@zcode/shared/test-ids";
  15. import AppPage from "#e2e/pages/app.page";
  16. import {
  17. DEFAULT_WORKSPACE,
  18. clearAppData,
  19. clickTestIdByDom,
  20. waitForDefaultWorkspaceReady,
  21. waitForWorkspaceApp,
  22. } from "#e2e/helpers/desktop-app";
  23. import {
  24. UPSTREAM_MODEL,
  25. UPSTREAM_THOUGHT_LEVEL,
  26. ensureUpstreamProviderForE2E,
  27. } from "#e2e/helpers/upstream-provider";
  28. import {
  29. assertUpstreamRequestCapture,
  30. assertUpstreamThoughtLevelCapture,
  31. waitForUpstreamNetworkCapture,
  32. } from "#e2e/helpers/upstream-capture";
  33. import { sel } from "#e2e/helpers/selectors";
  34. const PROMPT_RUNNING_ERROR = "a prompt is already running in session";
  35. const MODEL_REQUEST_FAILED_ERROR = "Model request failed";
  36. describe("e2ecase.md 回归", () => {
  37. after(async () => {
  38. await browser.electron.restoreAllMocks();
  39. await clearAppData();
  40. });
  41. it("设置页再次进入时应自动打开上一次打开的分区", async () => {
  42. await waitForDefaultWorkspaceReady(30000);
  43. await openSettingsPage();
  44. await selectSettingsSection("mcp");
  45. await expectSettingsSectionActive("mcp");
  46. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  47. timeout: 15000,
  48. timeoutMsg: "设置页返回按钮没有出现",
  49. });
  50. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 30000);
  51. await openSettingsPage();
  52. await expectSettingsSectionActive("mcp");
  53. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  54. timeout: 15000,
  55. timeoutMsg: "设置页返回按钮没有出现",
  56. });
  57. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 30000);
  58. });
  59. it("工作区头像菜单点击使用统计应打开设置页用量分区", async () => {
  60. await waitForDefaultWorkspaceReady(30000);
  61. await openUsageStatsFromProfileMenu();
  62. await $(sel(TID_SETTINGS_PAGE)).waitForDisplayed({ timeout: 15000 });
  63. await expectSettingsSectionActive("usage");
  64. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  65. timeout: 15000,
  66. timeoutMsg: "设置页返回按钮没有出现",
  67. });
  68. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 30000);
  69. });
  70. it("设置页头像菜单点击使用统计应停留设置页用量分区", async () => {
  71. await waitForDefaultWorkspaceReady(30000);
  72. await openSettingsPage();
  73. await selectSettingsSection("general");
  74. await expectSettingsSectionActive("general");
  75. await openUsageStatsFromProfileMenu();
  76. await $(sel(TID_SETTINGS_PAGE)).waitForDisplayed({ timeout: 15000 });
  77. await expect($(sel(TID_SETTINGS_PAGE))).toBeDisplayed();
  78. await expectSettingsSectionActive("usage");
  79. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON, {
  80. timeout: 15000,
  81. timeoutMsg: "设置页返回按钮没有出现",
  82. });
  83. await waitForWorkspaceApp(DEFAULT_WORKSPACE, 30000);
  84. });
  85. it.skip("任务运行中应允许快速发送下一条并保留输入框草稿", async function () {
  86. this.timeout(120000);
  87. await ensureUpstreamProviderForE2E();
  88. await waitForDefaultWorkspaceReady(30000);
  89. const runId = Date.now();
  90. const firstPrompt =
  91. `e2e running first prompt ${runId}. Use brief private reasoning if needed. ` +
  92. "Reply with ten short numbered lines and end with QUEUE_FIRST_DONE.";
  93. const draftPrompt = `e2e draft should stay while running ${runId}`;
  94. await typeChatPrompt(firstPrompt);
  95. await clickChatSend();
  96. await waitForComposerText("", "第一条消息发送后输入框没有清空");
  97. await waitForUserMessageContaining(firstPrompt);
  98. const workingStatus = await waitForWorkingZeroStatus();
  99. await assertWorkingStatusPositionStable(workingStatus.top);
  100. await typeChatPrompt(draftPrompt);
  101. await waitForComposerText(draftPrompt, "运行中输入的草稿没有进入输入框");
  102. await browser.pause(800);
  103. await waitForComposerText(draftPrompt, "运行中输入框草稿被意外清空");
  104. await waitForQueueSendButtonReady();
  105. await clickChatSend();
  106. await waitForComposerText("", "队列消息发送后输入框没有清空");
  107. await waitForBodyTextContaining(draftPrompt, "第二条消息没有进入待发送队列或消息列表");
  108. await assertBodyTextNotContaining(PROMPT_RUNNING_ERROR);
  109. await assertBodyTextNotContaining(MODEL_REQUEST_FAILED_ERROR);
  110. await waitForUserMessageContaining(draftPrompt);
  111. await browser.waitUntil(async () => (await getAssistantMessageCount()) >= 2, {
  112. timeout: 60000,
  113. timeoutMsg: "队列消息没有在第一轮结束后继续生成 assistant 回复",
  114. });
  115. await assertBodyTextNotContaining(PROMPT_RUNNING_ERROR);
  116. await assertBodyTextNotContaining(MODEL_REQUEST_FAILED_ERROR);
  117. });
  118. it.skip("思考内容收起时应先播放高度动画再卸载 DOM", async function () {
  119. this.timeout(90000);
  120. await ensureUpstreamProviderForE2E();
  121. await waitForDefaultWorkspaceReady(30000);
  122. await startNewTask();
  123. const runId = Date.now();
  124. const prompt =
  125. `e2e reasoning collapse ${runId}. Use the configured high thinking depth. ` +
  126. "After reasoning, reply with exactly REASONING_COLLAPSE_DONE.";
  127. await typeChatPrompt(prompt);
  128. await clickChatSend();
  129. const captureRecord = await waitForUpstreamNetworkCapture(prompt);
  130. assertUpstreamRequestCapture(captureRecord, {
  131. expectedText: prompt,
  132. model: UPSTREAM_MODEL,
  133. });
  134. assertUpstreamThoughtLevelCapture(captureRecord, UPSTREAM_THOUGHT_LEVEL);
  135. await $(sel(TID_CHAT_REASONING_TRIGGER)).waitForClickable({
  136. timeout: 45000,
  137. timeoutMsg: "没有渲染思考块触发器",
  138. });
  139. await $(sel(TID_CHAT_REASONING_TRIGGER)).click();
  140. await waitForReasoningContentOpen();
  141. const samples = await monitorReasoningCollapseDuringClick();
  142. const firstExisting = samples.find((sample) => sample.exists && sample.height !== null);
  143. const closedSamples = samples.filter((sample) => sample.exists && sample.state === "closed");
  144. const firstClosed = closedSamples.find((sample) => sample.height !== null);
  145. if (!firstExisting || !firstClosed) {
  146. throw new Error(`思考块收起时没有捕获到 closed 动画帧\n${JSON.stringify(samples, null, 2)}`);
  147. }
  148. expect(firstExisting.text.trim().length).toBeGreaterThan(0);
  149. expect(firstClosed.text.trim().length).toBeGreaterThan(0);
  150. expect(firstExisting.height ?? 0).toBeGreaterThan(0);
  151. expect(firstClosed.height ?? 0).toBeGreaterThan(0);
  152. expect(firstClosed.height ?? 0).toBeLessThanOrEqual((firstExisting.height ?? 0) + 2);
  153. await waitForReasoningContentUnmounted();
  154. });
  155. it.skip("goal 首发 query 保留命令,标题不包含命令,续跑 system reminder 不显示为用户消息", async function () {
  156. this.timeout(120000);
  157. await ensureUpstreamProviderForE2E();
  158. await waitForDefaultWorkspaceReady(30000);
  159. await startNewTask();
  160. const runId = Date.now();
  161. const objective = `e2e target objective ${runId}`;
  162. await typeChatPrompt(`/goal ${objective}`);
  163. await clickChatSend();
  164. await waitForWorkspaceTitleContaining("target objective");
  165. await assertWorkspaceTitleNotContaining("/goal");
  166. await assertVisibleUserMessagesContaining(`/goal ${objective}`);
  167. await assertVisibleUserMessagesNotContaining("goal-continuation");
  168. await waitForAssistantMessageCountAtLeast(1);
  169. await typeChatPrompt("/goal pause");
  170. await clickChatSend();
  171. await waitForComposerText("", "goal pause 后输入框没有清空");
  172. await typeChatPrompt("/goal resume");
  173. await clickChatSend();
  174. await waitForAssistantMessageCountAtLeast(2);
  175. await assertVisibleUserMessagesNotContaining("/goal resume");
  176. await assertVisibleUserMessagesNotContaining("system-reminder");
  177. await assertVisibleUserMessagesNotContaining("goal-continuation");
  178. });
  179. });
  180. async function openSettingsPage() {
  181. await clickTestIdByDom(TID_TASK_SETTINGS_BUTTON, {
  182. timeout: 15000,
  183. timeoutMsg: "没有找到设置入口按钮",
  184. });
  185. await $(sel(TID_SETTINGS_PAGE)).waitForDisplayed({ timeout: 15000 });
  186. }
  187. async function openUsageStatsFromProfileMenu() {
  188. await clickVisibleTestIdByDom(TID_LOGIN_TRIGGER, {
  189. timeout: 15000,
  190. timeoutMsg: "没有找到可见的头像菜单入口",
  191. });
  192. await clickVisibleTestIdByDom(TID_SIDEBAR_CODING_PLAN_USAGE_BUTTON, {
  193. timeout: 15000,
  194. timeoutMsg: "头像菜单没有出现可见的使用统计入口",
  195. });
  196. }
  197. async function selectSettingsSection(section: string) {
  198. await clickTestIdByDom(testId(TID_SETTINGS_SECTION_NAV, section), {
  199. timeout: 15000,
  200. timeoutMsg: `设置页没有出现 ${section} 分区入口`,
  201. });
  202. }
  203. async function clickVisibleTestIdByDom(
  204. targetTestId: string,
  205. {
  206. timeout = 10000,
  207. timeoutMsg = `页面没有可见可点击的 test id: ${targetTestId}`,
  208. }: { timeout?: number; timeoutMsg?: string } = {},
  209. ) {
  210. // 修复原因:设置页打开时 workspace DOM 仍保留但不可见,头像菜单和设置页 footer 共享同一 test id。
  211. // E2E 必须点击当前可见入口,否则会误点隐藏 workspace footer,掩盖“设置页菜单返回工作区”的回归。
  212. let latestReason = "not-started";
  213. await browser.waitUntil(
  214. async () => {
  215. const result = (await browser.execute((testIdValue) => {
  216. function isVisible(element: HTMLElement) {
  217. const style = window.getComputedStyle(element);
  218. if (
  219. style.display === "none" ||
  220. style.visibility === "hidden" ||
  221. Number(style.opacity) === 0
  222. ) {
  223. return false;
  224. }
  225. if (element.getClientRects().length === 0) {
  226. return false;
  227. }
  228. return !element.closest('[aria-hidden="true"], [hidden]');
  229. }
  230. const element = Array.from(document.querySelectorAll<HTMLElement>("[data-testid]")).find(
  231. (item) => item.dataset.testid === testIdValue && isVisible(item),
  232. );
  233. if (!element) {
  234. return { clicked: false, reason: "missing-visible" };
  235. }
  236. const disabled =
  237. (element instanceof HTMLButtonElement ||
  238. element instanceof HTMLInputElement ||
  239. element instanceof HTMLSelectElement ||
  240. element instanceof HTMLTextAreaElement) &&
  241. element.disabled;
  242. if (disabled) {
  243. return { clicked: false, reason: "disabled" };
  244. }
  245. // 修复原因:Radix 菜单触发器依赖 pointerdown 激活,单发 element.click() 会让菜单不展开。
  246. function dispatchE2EActivation(target: HTMLElement) {
  247. target.focus();
  248. const pointerEventCtor = window.PointerEvent ?? MouseEvent;
  249. for (const type of ["pointerdown", "mousedown", "pointerup", "mouseup", "click"]) {
  250. const event =
  251. type.startsWith("pointer") && pointerEventCtor === window.PointerEvent
  252. ? new PointerEvent(type, {
  253. bubbles: true,
  254. cancelable: true,
  255. pointerId: 1,
  256. pointerType: "mouse",
  257. isPrimary: true,
  258. })
  259. : new MouseEvent(type, {
  260. bubbles: true,
  261. cancelable: true,
  262. view: window,
  263. });
  264. target.dispatchEvent(event);
  265. }
  266. }
  267. dispatchE2EActivation(element);
  268. return { clicked: true };
  269. }, targetTestId)) as { clicked: boolean; reason?: string };
  270. latestReason = result.reason ?? "clicked";
  271. return result.clicked;
  272. },
  273. {
  274. timeout,
  275. timeoutMsg: `${timeoutMsg}: ${latestReason}`,
  276. },
  277. );
  278. }
  279. async function expectSettingsSectionActive(section: string) {
  280. const navItem = $(sel(testId(TID_SETTINGS_SECTION_NAV, section)));
  281. await browser.waitUntil(async () => (await navItem.getAttribute("aria-current")) === "page", {
  282. timeout: 15000,
  283. timeoutMsg: `设置页没有自动打开上一次的 ${section} 分区`,
  284. });
  285. }
  286. async function typeChatPrompt(prompt: string) {
  287. await AppPage.chatInput.waitForDisplayed({ timeout: 15000 });
  288. await AppPage.chatInput.click();
  289. const result = (await browser.executeAsync(
  290. (inputTestId, text, done) => {
  291. const input = document.querySelector<HTMLElement>(`[data-testid="${inputTestId}"]`);
  292. if (!input) {
  293. done({ actual: "", inserted: false, ok: false, reason: "input-missing" });
  294. return;
  295. }
  296. input.focus();
  297. const selection = window.getSelection();
  298. const range = document.createRange();
  299. range.selectNodeContents(input);
  300. selection?.removeAllRanges();
  301. selection?.addRange(range);
  302. document.execCommand("delete");
  303. // 修复原因:browser.keys() 遇到多行 prompt 会把换行当成 Enter,
  304. // 在 Lexical 输入框里提前触发送信,真实请求只带第一行。逐行插入并显式
  305. // insertLineBreak,才能让 contenteditable 和 Lexical 都保留真实换行。
  306. let inserted = true;
  307. const lines = text.split("\n");
  308. for (const [lineIndex, line] of lines.entries()) {
  309. inserted = document.execCommand("insertText", false, line) && inserted;
  310. if (lineIndex < lines.length - 1) {
  311. inserted = document.execCommand("insertLineBreak") && inserted;
  312. }
  313. }
  314. requestAnimationFrame(() => {
  315. const actual = (input.innerText || input.textContent || "").replace(/\u00a0/g, " ").trim();
  316. done({
  317. actual,
  318. inserted,
  319. ok: actual === text.trim(),
  320. });
  321. });
  322. },
  323. TID_CHAT_INPUT,
  324. prompt,
  325. )) as { actual: string; inserted: boolean; ok: boolean; reason?: string };
  326. if (!result.ok) {
  327. throw new Error(`聊天输入框没有写入完整 prompt: ${JSON.stringify(result)}`);
  328. }
  329. }
  330. async function clickChatSend() {
  331. await AppPage.chatSendButton.waitForClickable({ timeout: 30000 });
  332. await AppPage.chatSendButton.click();
  333. }
  334. async function startNewTask() {
  335. await AppPage.taskNewButton.waitForClickable({ timeout: 15000 });
  336. await AppPage.taskNewButton.click();
  337. await AppPage.chatInput.waitForDisplayed({ timeout: 15000 });
  338. }
  339. async function waitForQueueSendButtonReady() {
  340. await browser.waitUntil(
  341. async () =>
  342. browser.execute((sendButtonTestId) => {
  343. const button = document.querySelector<HTMLButtonElement>(
  344. `[data-testid="${sendButtonTestId}"]`,
  345. );
  346. return Boolean(button && !button.disabled);
  347. }, TID_CHAT_SEND_BUTTON),
  348. {
  349. timeout: 30000,
  350. timeoutMsg: "任务 streaming 时没有出现可用的队列发送按钮",
  351. },
  352. );
  353. }
  354. async function waitForComposerText(expected: string, timeoutMsg: string) {
  355. await browser.waitUntil(async () => (await getComposerText()) === expected, {
  356. timeout: 10000,
  357. timeoutMsg,
  358. });
  359. }
  360. async function getComposerText() {
  361. return browser.execute((inputTestId) => {
  362. const input = document.querySelector<HTMLElement>(`[data-testid="${inputTestId}"]`);
  363. return (input?.innerText || input?.textContent || "").replace(/\u00a0/g, " ").trim();
  364. }, TID_CHAT_INPUT);
  365. }
  366. async function waitForUserMessageContaining(text: string) {
  367. await browser.waitUntil(
  368. async () => {
  369. const messages = await browser.execute((messagesTestId) => {
  370. const root = document.querySelector<HTMLElement>(`[data-testid="${messagesTestId}"]`);
  371. return Array.from(root?.querySelectorAll<HTMLElement>(".is-user") ?? [])
  372. .map((element) => element.innerText)
  373. .join("\n");
  374. }, TID_CHAT_MESSAGES);
  375. return messages.includes(text);
  376. },
  377. {
  378. timeout: 60000,
  379. timeoutMsg: `聊天记录中没有出现用户消息: ${text}`,
  380. },
  381. );
  382. }
  383. async function getAssistantMessageCount() {
  384. return AppPage.assistantMessages.length;
  385. }
  386. async function waitForAssistantMessageCountAtLeast(expectedCount: number) {
  387. await browser.waitUntil(async () => (await getAssistantMessageCount()) >= expectedCount, {
  388. timeout: 60000,
  389. timeoutMsg: `assistant 回复数量没有达到 ${expectedCount}`,
  390. });
  391. }
  392. async function waitForWorkingZeroStatus() {
  393. let lastBodyText = "";
  394. await browser.waitUntil(
  395. async () => {
  396. const snapshot = await getWorkingStatusSnapshot();
  397. if (snapshot) {
  398. return true;
  399. }
  400. lastBodyText = await getBodyText();
  401. return false;
  402. },
  403. {
  404. timeout: 15000,
  405. timeoutMsg: `发送消息后没有出现“工作中 0 秒”状态,body=${lastBodyText.slice(0, 1000)}`,
  406. },
  407. );
  408. const snapshot = await getWorkingStatusSnapshot();
  409. if (!snapshot) {
  410. throw new Error("发送消息后没有出现“工作中 0 秒”状态");
  411. }
  412. return snapshot;
  413. }
  414. async function getWorkingStatusSnapshot() {
  415. return browser.execute(() => {
  416. const workingZeroPattern = /工作中\s*0\s*秒|Working for\s*0\s*(s|sec|second)/i;
  417. const candidates = Array.from(document.querySelectorAll<HTMLElement>(".history-message"));
  418. const target = candidates.find((element) => workingZeroPattern.test(element.innerText));
  419. if (!target) {
  420. return null;
  421. }
  422. const rect = target.getBoundingClientRect();
  423. return {
  424. text: target.innerText,
  425. top: rect.top,
  426. };
  427. });
  428. }
  429. async function assertWorkingStatusPositionStable(initialTop: number) {
  430. await browser.pause(350);
  431. const snapshot = await browser.execute(() => {
  432. const workingPattern = /工作中\s*\d+\s*秒|Working for\s*\d+\s*(s|sec|second)/i;
  433. const target = Array.from(document.querySelectorAll<HTMLElement>(".history-message")).find(
  434. (element) => workingPattern.test(element.innerText),
  435. );
  436. if (!target) {
  437. return null;
  438. }
  439. return {
  440. text: target.innerText,
  441. top: target.getBoundingClientRect().top,
  442. };
  443. });
  444. if (!snapshot) {
  445. throw new Error("工作中状态在稳定性检查期间消失");
  446. }
  447. expect(Math.abs(snapshot.top - initialTop)).toBeLessThanOrEqual(2);
  448. }
  449. async function waitForBodyTextContaining(text: string, timeoutMsg: string) {
  450. await browser.waitUntil(async () => (await getBodyText()).includes(text), {
  451. timeout: 10000,
  452. timeoutMsg,
  453. });
  454. }
  455. async function assertBodyTextNotContaining(text: string) {
  456. expect(await getBodyText()).not.toContain(text);
  457. }
  458. async function getBodyText() {
  459. return browser.execute(() => document.body?.innerText ?? "");
  460. }
  461. async function waitForReasoningContentOpen() {
  462. await browser.waitUntil(
  463. async () =>
  464. browser.execute((contentTestId) => {
  465. const content = document.querySelector<HTMLElement>(`[data-testid="${contentTestId}"]`);
  466. return (
  467. content?.getAttribute("data-state") === "open" && content.innerText.trim().length > 0
  468. );
  469. }, TID_CHAT_REASONING_CONTENT),
  470. {
  471. timeout: 15000,
  472. timeoutMsg: "思考内容展开后没有保持 open 状态",
  473. },
  474. );
  475. }
  476. type CollapseSample = {
  477. elapsedMs: number;
  478. exists: boolean;
  479. height: number | null;
  480. state: string | null;
  481. text: string;
  482. };
  483. async function monitorReasoningCollapseDuringClick(): Promise<CollapseSample[]> {
  484. return browser.executeAsync(
  485. (triggerTestId, contentTestId, done) => {
  486. const trigger = document.querySelector<HTMLElement>(`[data-testid="${triggerTestId}"]`);
  487. if (!trigger) {
  488. done([]);
  489. return;
  490. }
  491. const samples: CollapseSample[] = [];
  492. const startedAt = performance.now();
  493. const sample = () => {
  494. const content = document.querySelector<HTMLElement>(`[data-testid="${contentTestId}"]`);
  495. const rect = content?.getBoundingClientRect();
  496. samples.push({
  497. elapsedMs: Math.round(performance.now() - startedAt),
  498. exists: Boolean(content),
  499. height: rect ? rect.height : null,
  500. state: content?.getAttribute("data-state") ?? null,
  501. text: content?.innerText ?? "",
  502. });
  503. if (performance.now() - startedAt < 420) {
  504. requestAnimationFrame(sample);
  505. return;
  506. }
  507. done(samples);
  508. };
  509. trigger.click();
  510. requestAnimationFrame(sample);
  511. },
  512. TID_CHAT_REASONING_TRIGGER,
  513. TID_CHAT_REASONING_CONTENT,
  514. );
  515. }
  516. async function waitForReasoningContentUnmounted() {
  517. await browser.waitUntil(
  518. async () =>
  519. browser.execute((contentTestId) => {
  520. return !document.querySelector(`[data-testid="${contentTestId}"]`);
  521. }, TID_CHAT_REASONING_CONTENT),
  522. {
  523. timeout: 5000,
  524. timeoutMsg: "思考内容收起动画结束后仍未卸载 DOM",
  525. },
  526. );
  527. }
  528. async function waitForWorkspaceTitleContaining(text: string) {
  529. await browser.waitUntil(async () => (await AppPage.workspaceTitle.getText()).includes(text), {
  530. timeout: 30000,
  531. timeoutMsg: `任务标题没有包含预期文本: ${text}`,
  532. });
  533. }
  534. async function assertWorkspaceTitleNotContaining(text: string) {
  535. expect(await AppPage.workspaceTitle.getText()).not.toContain(text);
  536. }
  537. async function assertVisibleUserMessagesNotContaining(text: string) {
  538. expect(await getVisibleUserMessagesText()).not.toContain(text);
  539. }
  540. async function assertVisibleUserMessagesContaining(text: string) {
  541. expect(await getVisibleUserMessagesText()).toContain(text);
  542. }
  543. async function getVisibleUserMessagesText() {
  544. return browser.execute((messagesTestId) => {
  545. const root = document.querySelector<HTMLElement>(`[data-testid="${messagesTestId}"]`);
  546. return Array.from(root?.querySelectorAll<HTMLElement>(".is-user") ?? [])
  547. .map((element) => element.innerText)
  548. .join("\n");
  549. }, TID_CHAT_MESSAGES);
  550. }