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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { openStatusCapsule } from "#e2e/helpers/status-capsule";
  2. import { waitForControlledReplay } from "#e2e/helpers/controlled-replay";
  3. // M4 门禁:sendGoalCommand(v4 composer slash `/goal <目标>`)。
  4. // 证据层 L3:建立 session → composer `/goal E2E_V4_GOAL_OBJECTIVE …` → handleSlashCommand →
  5. // dispatchCommand("sendGoalCommand") → v4-bridge goalSession(set) → TargetChanged 事件 →
  6. // reducer 更新 goal 状态 → unified status-panel shell 投影 objective + active。
  7. // 证明 goal slash 入口 + goal 状态投影 + 摘要 timer/pause/resume UI 全链路。
  8. import { TID_V4_COMPOSER_INPUT } from "@zcode/shared/test-ids";
  9. import { clearAppData, setInputValueByTestIdDom } from "#e2e/helpers/desktop-app";
  10. import { selectUpstreamThoughtLevelValue } from "#e2e/helpers/upstream-provider";
  11. import {
  12. assertUpstreamThoughtLevelCapture,
  13. waitForUpstreamNetworkRequestStarted,
  14. } from "#e2e/helpers/upstream-capture";
  15. import {
  16. clickV4Send,
  17. getV4GoalProjection,
  18. prepareV4ConversationE2E,
  19. sendV4Prompt,
  20. waitForV4Pane,
  21. waitForV4TimelineContaining,
  22. waitForLatestV4CommandAck,
  23. } from "#e2e/helpers/v4-conversation";
  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 banner !== null && (banner.objective ?? "").includes("E2E_V4_GOAL_OBJECTIVE");
  52. },
  53. {
  54. timeout: 45000,
  55. timeoutMsg: "goal 状态面板投影没有出现或 objective 不含 sentinel",
  56. },
  57. );
  58. const banner = await getV4GoalProjection();
  59. expect(banner?.objective).toContain("E2E_V4_GOAL_OBJECTIVE");
  60. expect(["active", "verifying"]).toContain(banner?.status);
  61. const goalRequest = await waitForUpstreamNetworkRequestStarted("E2E_V4_GOAL_OBJECTIVE");
  62. assertUpstreamThoughtLevelCapture(goalRequest, "low");
  63. // 首个输出会新增消息行并递增 revision;只等请求开始就点击,会偶发收到
  64. // proto.staleRevision。先等真实输出投影,再由关卡保持运行态,不靠固定慢流窗口。
  65. await waitForControlledReplay("v4-goal-continuation-slow");
  66. await waitForV4TimelineContaining("V4_GOAL_STREAMING", 15000);
  67. await openStatusCapsule("goal", 15000);
  68. await browser.waitUntil(
  69. async () =>
  70. browser.execute(() => {
  71. const button = document.querySelector<HTMLButtonElement>('[data-goal-action="pause"]');
  72. return Boolean(button && !button.disabled);
  73. }),
  74. { timeout: 15000, timeoutMsg: "active goal 没有可用的 pauseGoal 按钮" },
  75. );
  76. const activeElapsed = await browser.execute(() => {
  77. const metric = document.querySelector<HTMLElement>("[data-goal-elapsed-seconds]");
  78. return Number(metric?.getAttribute("data-goal-elapsed-seconds") ?? -1);
  79. });
  80. expect(activeElapsed).toBeGreaterThanOrEqual(0);
  81. const paused = await browser.execute(() => {
  82. const button = document.querySelector<HTMLButtonElement>('[data-goal-action="pause"]');
  83. if (!button || button.disabled) return false;
  84. button.click();
  85. return true;
  86. });
  87. expect(paused).toBe(true);
  88. // 点击成功不代表命令已接纳;保留 ACK,区分版本冲突与投影未更新。
  89. expect(await waitForLatestV4CommandAck("pauseGoal")).toMatchObject({ status: "accepted" });
  90. await browser.waitUntil(async () => (await getV4GoalProjection())?.status === "paused", {
  91. timeout: 15000,
  92. timeoutMsg: "pauseGoal 后目标没有进入 paused",
  93. });
  94. await browser.waitUntil(
  95. async () =>
  96. browser.execute(() => {
  97. const button = document.querySelector<HTMLButtonElement>('[data-goal-action="resume"]');
  98. return Boolean(button && !button.disabled);
  99. }),
  100. {
  101. timeout: 15000,
  102. timeoutMsg: "paused goal 没有可用的三角 resumeGoal 按钮",
  103. },
  104. );
  105. const resumed = await browser.execute(() => {
  106. const button = document.querySelector<HTMLButtonElement>('[data-goal-action="resume"]');
  107. if (!button || button.disabled) return false;
  108. button.click();
  109. return true;
  110. });
  111. expect(resumed).toBe(true);
  112. expect(await waitForLatestV4CommandAck("resumeGoal")).toMatchObject({ status: "accepted" });
  113. await browser.waitUntil(
  114. async () => {
  115. const status = (await getV4GoalProjection())?.status;
  116. return status === "active" || status === "verifying" || status === "verified";
  117. },
  118. { timeout: 45000, timeoutMsg: "resumeGoal 后目标没有恢复或完成" },
  119. );
  120. });
  121. });