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

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