conversation-session-thought-level-session-isolation.test.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { TID_V4_COMPOSER_INPUT } from "@zcode/shared/test-ids";
  2. import { clearAppData, setInputValueByTestIdDom } from "#e2e/helpers/desktop-app";
  3. import {
  4. assertUpstreamRequestCapture,
  5. assertUpstreamThoughtLevelCapture,
  6. waitForUpstreamNetworkCapture,
  7. } from "#e2e/helpers/upstream-capture";
  8. import { UPSTREAM_MODEL, UPSTREAM_PROVIDER_ID } from "#e2e/helpers/upstream-provider";
  9. import {
  10. getV4ModelConfig,
  11. getV4ComposerText,
  12. prepareV4ConversationE2E,
  13. selectV4TaskById,
  14. sendV4Prompt,
  15. startNewV4Draft,
  16. switchV4Model,
  17. waitForV4ComposerSelectionReady,
  18. waitForV4Pane,
  19. } from "#e2e/helpers/v4-conversation";
  20. import { isV4TurnCompleted } from "#e2e/helpers/v4-turn-completion";
  21. // 修复原因:formal admission 禁止依赖整套 legacy conversation-session helper;
  22. // 此 case 只需要稳定回复文本,因此把常量留在 case 内,避免重新引入旧测试栈。
  23. const A_SEED_REPLY = "I55_A_SEED_DONE";
  24. const B_SEED_REPLY = "I55_B_SEED_DONE";
  25. const B_FOLLOW_REPLY = "I55_B_FOLLOW_DONE";
  26. const A_FOLLOW_REPLY = "I55_A_FOLLOW_DONE";
  27. const INITIAL_THOUGHT_LEVEL = "high";
  28. const SESSION_A_THOUGHT_LEVEL = "max";
  29. describe("会话区思考深度 session 隔离 E2E", () => {
  30. after(async () => {
  31. await browser.electron.restoreAllMocks();
  32. await clearAppData();
  33. });
  34. it("I55: 只修改 A 的思考深度后,B 的思考深度不应改变", async function () {
  35. this.timeout(260000);
  36. // 修复原因:V4 竖切已删除 legacy `chat-input` 和 ChatView 状态投影;继续调用
  37. // `prepareConversationE2E()` 会在业务步骤前超时,并在 teardown 阶段产生误导性的 CDP 报错。
  38. await prepareV4ConversationE2E();
  39. // 修复原因:provider 初始化只写入 high 偏好,不能保证 V4 草稿已经吸收该配置;
  40. // 直接首发可能继承上一轮的 max,导致用例在构造 I55 前置状态时误报。
  41. // 这里显式建立 catalog 已确认的 A/B=high 前置状态,待测动作仍只有后续 A→max。
  42. // Bug 根因:draft DOM 会先出现,pane 内 prewarm binding 仍可能在创建;此时立即切配置
  43. // 并点击发送,会撞上 binding 换代,UI 有乐观输入但 Agent 收不到 sendText。
  44. await waitForV4ComposerSelectionReady();
  45. await selectSharedModelAndThought(INITIAL_THOUGHT_LEVEL);
  46. const runId = Date.now();
  47. const promptASeed = buildPrompt(`E2E_THOUGHT_LEVEL_SESSION_ISOLATION_A_SEED_${runId}`);
  48. const sessionA = await sendPromptAndAssertThought(
  49. promptASeed,
  50. INITIAL_THOUGHT_LEVEL,
  51. A_SEED_REPLY,
  52. "A 首轮没有完成",
  53. );
  54. await startNewV4Draft();
  55. await waitForV4ComposerSelectionReady();
  56. await selectSharedModelAndThought(INITIAL_THOUGHT_LEVEL);
  57. const promptBSeed = buildPrompt(`E2E_THOUGHT_LEVEL_SESSION_ISOLATION_B_SEED_${runId}`);
  58. const sessionB = await sendPromptAndAssertThought(
  59. promptBSeed,
  60. INITIAL_THOUGHT_LEVEL,
  61. B_SEED_REPLY,
  62. "B 首轮没有完成",
  63. );
  64. expect(sessionB).not.toBe(sessionA);
  65. await selectV4TaskById(sessionA);
  66. await assertSelectedSharedModelAndThought(INITIAL_THOUGHT_LEVEL);
  67. // 空白 Composer 不持久化改选;隔离场景需保留非空草稿,才能验证 A 的选择恢复。
  68. const promptAFollow = buildPrompt(`E2E_THOUGHT_LEVEL_SESSION_ISOLATION_A_FOLLOW_${runId}`);
  69. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, promptAFollow);
  70. await selectSharedModelAndThought(SESSION_A_THOUGHT_LEVEL);
  71. await selectV4TaskById(sessionB);
  72. await assertSelectedSharedModelAndThought(INITIAL_THOUGHT_LEVEL);
  73. const promptBFollow = buildPrompt(`E2E_THOUGHT_LEVEL_SESSION_ISOLATION_B_FOLLOW_${runId}`);
  74. await sendPromptAndAssertThought(
  75. promptBFollow,
  76. INITIAL_THOUGHT_LEVEL,
  77. B_FOLLOW_REPLY,
  78. "B follow-up 没有完成",
  79. );
  80. await selectV4TaskById(sessionA);
  81. await assertSelectedSharedModelAndThought(SESSION_A_THOUGHT_LEVEL);
  82. expect(await getV4ComposerText()).toBe(promptAFollow);
  83. await sendPromptAndAssertThought(
  84. promptAFollow,
  85. SESSION_A_THOUGHT_LEVEL,
  86. A_FOLLOW_REPLY,
  87. "A follow-up 没有完成",
  88. );
  89. });
  90. });
  91. function buildPrompt(marker: string) {
  92. return `${marker}: Return the deterministic fixture reply for this marker.`;
  93. }
  94. async function selectSharedModelAndThought(thoughtLevel: string) {
  95. await switchV4Model(UPSTREAM_PROVIDER_ID, UPSTREAM_MODEL, thoughtLevel);
  96. await assertSelectedSharedModelAndThought(thoughtLevel);
  97. }
  98. async function sendPromptAndAssertThought(
  99. prompt: string,
  100. thoughtLevel: string,
  101. expectedAssistantReply: string,
  102. timeoutMsg: string,
  103. ) {
  104. const marker = prompt.split(":")[0] ?? prompt;
  105. await sendV4Prompt(prompt);
  106. const record = await waitForUpstreamNetworkCapture(marker);
  107. assertUpstreamRequestCapture(record, {
  108. expectedText: prompt,
  109. model: UPSTREAM_MODEL,
  110. });
  111. assertUpstreamThoughtLevelCapture(record, thoughtLevel);
  112. return waitForCompletedSession(expectedAssistantReply, timeoutMsg);
  113. }
  114. async function assertSelectedSharedModelAndThought(thoughtLevel: string) {
  115. let latest = await getV4ModelConfig();
  116. await browser.waitUntil(
  117. async () => {
  118. latest = await getV4ModelConfig();
  119. return (
  120. latest.provider === UPSTREAM_PROVIDER_ID &&
  121. latest.model === UPSTREAM_MODEL &&
  122. latest.thought === thoughtLevel
  123. );
  124. },
  125. {
  126. timeout: 30000,
  127. timeoutMsg: `v4 模型配置不是期望值: ${JSON.stringify({
  128. expected: {
  129. model: UPSTREAM_MODEL,
  130. provider: UPSTREAM_PROVIDER_ID,
  131. thought: thoughtLevel,
  132. },
  133. latest,
  134. })}`,
  135. },
  136. );
  137. }
  138. async function waitForCompletedSession(expectedAssistantReply: string, timeoutMsg: string) {
  139. const snapshot = await waitForV4Pane(
  140. (candidate) => isV4TurnCompleted(candidate, expectedAssistantReply),
  141. timeoutMsg,
  142. 90000,
  143. );
  144. if (!snapshot.sessionId || snapshot.sessionId === "draft") {
  145. throw new Error(`${timeoutMsg}: sessionId missing`);
  146. }
  147. return snapshot.sessionId;
  148. }