conversation-session-v4-goal.test.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // M4 门禁:sendGoalCommand(v4 composer slash `/goal <目标>`)。
  2. // 证据层 L3:建立 session → composer `/goal E2E_V4_GOAL_OBJECTIVE …` → handleSlashCommand →
  3. // dispatchCommand("sendGoalCommand") → v4-bridge goalSession(set) → TargetChanged 事件 →
  4. // reducer 更新 goal 状态 → unified status-panel shell 投影 objective + active。
  5. // 证明 goal slash 入口 + goal 状态投影 + 摘要 timer/pause/resume UI 全链路。
  6. import { TID_CHAT_SUMMARY_PANEL, TID_V4_COMPOSER_INPUT } from "@zcode/shared";
  7. import {
  8. clearAppData,
  9. setInputValueByTestIdDom,
  10. } from "../helpers/desktop-app.js";
  11. import { selectUpstreamThoughtLevelValue } from "../helpers/upstream-provider.js";
  12. import {
  13. assertUpstreamThoughtLevelCapture,
  14. waitForUpstreamNetworkRequestStarted,
  15. } from "../helpers/upstream-capture.js";
  16. import {
  17. clickV4Send,
  18. getV4GoalProjection,
  19. prepareV4ConversationE2E,
  20. sendV4Prompt,
  21. waitForV4Pane,
  22. waitForV4TimelineContaining,
  23. } from "../helpers/v4-conversation.js";
  24. describe("v4 M4 门禁:sendGoalCommand(/goal slash)", () => {
  25. after(async () => {
  26. await browser.electron.restoreAllMocks();
  27. await clearAppData();
  28. });
  29. it("建立 session → /goal → status panel 投影 → 独立 pause/resume", async () => {
  30. await prepareV4ConversationE2E();
  31. await sendV4Prompt("E2E_V4_GOAL_SEED 建立会话");
  32. await waitForV4TimelineContaining("V4_GOAL_SEED_OK", 45000);
  33. await waitForV4Pane(
  34. (s) => s.sessionId !== "draft" && s.sessionId !== null,
  35. "会话没有建立",
  36. 45000,
  37. );
  38. // composer 设目标(objective 含 fixture 匹配 sentinel)
  39. // 合并恢复:/goal 和普通发送应消费同一份提交档位,而不是重新读取或使用旧会话档位。
  40. await selectUpstreamThoughtLevelValue("low");
  41. await setInputValueByTestIdDom(
  42. TID_V4_COMPOSER_INPUT,
  43. "/goal E2E_V4_GOAL_OBJECTIVE 完成竖切目标",
  44. { timeout: 15000, timeoutMsg: "composer 输入框没有出现" },
  45. );
  46. await clickV4Send();
  47. // goal 横幅出现,objective 含 sentinel,状态为 active(continuation 慢流保持窗口)
  48. await browser.waitUntil(
  49. async () => {
  50. const banner = await getV4GoalProjection();
  51. return (
  52. banner !== null &&
  53. (banner.objective ?? "").includes("E2E_V4_GOAL_OBJECTIVE")
  54. );
  55. },
  56. {
  57. timeout: 45000,
  58. timeoutMsg: "goal 状态面板投影没有出现或 objective 不含 sentinel",
  59. },
  60. );
  61. const banner = await getV4GoalProjection();
  62. expect(banner?.objective).toContain("E2E_V4_GOAL_OBJECTIVE");
  63. expect(["active", "verifying"]).toContain(banner?.status);
  64. const goalRequest = await waitForUpstreamNetworkRequestStarted("E2E_V4_GOAL_OBJECTIVE");
  65. assertUpstreamThoughtLevelCapture(goalRequest, "low");
  66. // Bug 原因:状态面板在窄窗口会自动收成 mini 胶囊,折叠态只提供展开入口,
  67. // 不渲染 pause/resume。旧用例直接找 pause,把合法的响应式布局误报成投影失败。
  68. await browser.waitUntil(
  69. async () =>
  70. browser.execute((panelTestId) => {
  71. const panel = document.querySelector<HTMLElement>(
  72. `[data-testid="${panelTestId}"]`,
  73. );
  74. if (!panel) return false;
  75. if (panel.dataset.state === "collapsed") {
  76. panel.querySelector<HTMLButtonElement>("button")?.click();
  77. return false;
  78. }
  79. return panel.dataset.state === "expanded";
  80. }, TID_CHAT_SUMMARY_PANEL),
  81. { timeout: 15000, timeoutMsg: "goal 状态面板没有展开" },
  82. );
  83. await browser.waitUntil(
  84. async () =>
  85. browser.execute(() => {
  86. const button = document.querySelector<HTMLButtonElement>(
  87. '[data-goal-action="pause"]',
  88. );
  89. return Boolean(button && !button.disabled);
  90. }),
  91. { timeout: 15000, timeoutMsg: "active goal 没有可用的 pauseGoal 按钮" },
  92. );
  93. const activeElapsed = await browser.execute(() => {
  94. const metric = document.querySelector<HTMLElement>(
  95. "[data-goal-elapsed-seconds]",
  96. );
  97. return Number(metric?.getAttribute("data-goal-elapsed-seconds") ?? -1);
  98. });
  99. expect(activeElapsed).toBeGreaterThanOrEqual(0);
  100. const paused = await browser.execute(() => {
  101. const button = document.querySelector<HTMLButtonElement>(
  102. '[data-goal-action="pause"]',
  103. );
  104. if (!button || button.disabled) return false;
  105. button.click();
  106. return true;
  107. });
  108. expect(paused).toBe(true);
  109. await browser.waitUntil(
  110. async () => (await getV4GoalProjection())?.status === "paused",
  111. { timeout: 15000, timeoutMsg: "pauseGoal 后目标没有进入 paused" },
  112. );
  113. await browser.waitUntil(
  114. async () =>
  115. browser.execute(() => {
  116. const button = document.querySelector<HTMLButtonElement>(
  117. '[data-goal-action="resume"]',
  118. );
  119. return Boolean(button && !button.disabled);
  120. }),
  121. {
  122. timeout: 15000,
  123. timeoutMsg: "paused goal 没有可用的三角 resumeGoal 按钮",
  124. },
  125. );
  126. const resumed = await browser.execute(() => {
  127. const button = document.querySelector<HTMLButtonElement>(
  128. '[data-goal-action="resume"]',
  129. );
  130. if (!button || button.disabled) return false;
  131. button.click();
  132. return true;
  133. });
  134. expect(resumed).toBe(true);
  135. await browser.waitUntil(
  136. async () => {
  137. const status = (await getV4GoalProjection())?.status;
  138. return (
  139. status === "active" || status === "verifying" || status === "verified"
  140. );
  141. },
  142. { timeout: 45000, timeoutMsg: "resumeGoal 后目标没有恢复或完成" },
  143. );
  144. });
  145. });