subagent-refresh-conversation.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {
  2. waitForV4AssistantMessageContaining,
  3. waitForV4ConversationState,
  4. waitForV4UserMessageContaining,
  5. getV4Messages,
  6. } from "./v4-conversation.js";
  7. import { TID_CHAT_ERROR_BANNER } from "@zcode/shared/test-ids";
  8. import { readSubagentCapture } from "./subagent-refresh-capture.js";
  9. export async function assertSubagentTurnFailed(marker: string, error: string) {
  10. await browser.waitUntil(
  11. async () =>
  12. (
  13. await browser.execute(
  14. (id) =>
  15. Array.from(document.querySelectorAll<HTMLElement>(`[data-testid="${id}"]`))
  16. .map((element) => element.textContent ?? "")
  17. .join("\n"),
  18. TID_CHAT_ERROR_BANNER,
  19. )
  20. ).includes(error),
  21. { timeout: 15000, timeoutMsg: `父轮未显示配置读取错误:${error}` },
  22. );
  23. await waitForSubagentIdle(15000);
  24. await waitForV4UserMessageContaining(marker);
  25. expect(
  26. (await getV4Messages("user")).filter((message) => message.text.includes(marker)),
  27. ).toHaveLength(1);
  28. expect(
  29. (await readSubagentCapture()).filter((record) =>
  30. JSON.stringify(record.requestJson).includes(marker),
  31. ),
  32. ).toHaveLength(0);
  33. }
  34. /** Settings 选择器使用英文文案;只调用仓库已有的测试 UI 入口。 */
  35. export async function useEnglishSubagentSettings() {
  36. await browser.execute(() => {
  37. const actions = (
  38. window as typeof window & {
  39. __testActions?: { setLocale?: (locale: string) => void };
  40. }
  41. ).__testActions;
  42. if (!actions?.setLocale) throw new Error("Missing locale action");
  43. actions.setLocale("en-US");
  44. });
  45. }
  46. export async function waitForSubagentIdle(timeout: number) {
  47. await waitForV4ConversationState(
  48. (state) => state.state === "idle" && state.queueCount === 0,
  49. "父轮未结束",
  50. timeout,
  51. );
  52. }
  53. export async function finishSubagentTurn(token: string, timeout: number) {
  54. await waitForV4AssistantMessageContaining(token, timeout);
  55. await waitForSubagentIdle(timeout);
  56. }