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

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