conversation-session-toolsearch-lifecycle.test.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { expandAssistantHistoriesWithContent } from "#e2e/helpers/conversation-session-tool-diagnostics";
  2. import { clearAppData } from "#e2e/helpers/desktop-app";
  3. import { restartIntoWorkspace } from "#e2e/helpers/model-provider-restart";
  4. import {
  5. editFirstV4UserQuery,
  6. getV4PaneSnapshot,
  7. selectV4TaskById,
  8. switchV4Model,
  9. waitForV4Edit,
  10. waitForV4Fork,
  11. waitForV4Pane,
  12. } from "#e2e/helpers/v4-conversation";
  13. import {
  14. readToolSearchRequests,
  15. TOOLSEARCH_TODO_CALL_ID,
  16. TOOLSEARCH_NOTICE,
  17. } from "#e2e/helpers/toolsearch-provider";
  18. import {
  19. compactToolSearchTask,
  20. expectToolResultPair,
  21. expectToolSearchDisabled,
  22. newToolSearchTask,
  23. setupToolSearchDesktop,
  24. TOOLSEARCH_MODEL,
  25. TOOLSEARCH_PLAIN_PROVIDER,
  26. TOOLSEARCH_PLAN_PROVIDER,
  27. toolSearchTurn,
  28. } from "#e2e/helpers/toolsearch-desktop";
  29. describe("ToolSearch provider、续写和历史生命周期", () => {
  30. before(async () => {
  31. await setupToolSearchDesktop();
  32. });
  33. after(async () => {
  34. await browser.electron.restoreAllMocks();
  35. await clearAppData();
  36. });
  37. it("TS03: 同一 session 双向切 provider,默认持续关闭 ToolSearch", async function () {
  38. this.timeout(180_000);
  39. await newToolSearchTask();
  40. await toolSearchTurn("E2E_TOOLSEARCH_INITIAL 搜索 TodoRead 并执行。");
  41. const sessionId = (await getV4PaneSnapshot()).sessionId;
  42. await switchV4Model(TOOLSEARCH_PLAIN_PROVIDER, TOOLSEARCH_MODEL, "");
  43. const [off] = await toolSearchTurn("E2E_TOOLSEARCH_OFF 继续。");
  44. expectToolSearchDisabled(off!);
  45. expectToolResultPair(off!, TOOLSEARCH_TODO_CALL_ID);
  46. expect(JSON.stringify(off!.requestJson.messages)).not.toContain("tool_reference");
  47. await switchV4Model(TOOLSEARCH_PLAN_PROVIDER, TOOLSEARCH_MODEL, "");
  48. const [on] = await toolSearchTurn("E2E_TOOLSEARCH_ON 继续。");
  49. expectToolSearchDisabled(on!);
  50. expectToolResultPair(on!, TOOLSEARCH_TODO_CALL_ID);
  51. expect(JSON.stringify(on!.requestJson.messages)).not.toContain('"type":"tool_reference"');
  52. expect((await getV4PaneSnapshot()).sessionId).toBe(sessionId);
  53. });
  54. it("TS09: 默认关闭时三次 Continue 与冷恢复均不新增工具公告", async function () {
  55. this.timeout(120_000);
  56. await newToolSearchTask();
  57. const requests = await toolSearchTurn("E2E_TOOLSEARCH_CONTINUE 分三次续写后结束。");
  58. expect(requests).toHaveLength(4);
  59. for (const request of requests) expectToolSearchDisabled(request);
  60. const [next] = await toolSearchTurn("E2E_TOOLSEARCH_AFTER_CONTINUE 正常下一轮。");
  61. expectToolSearchDisabled(next!);
  62. const text = JSON.stringify(next!.requestJson.messages);
  63. expect(text).toContain("E2E_TOOLSEARCH_PARTIAL_1");
  64. expect(text).toContain("E2E_TOOLSEARCH_PARTIAL_3");
  65. expect(text).not.toContain("Output token limit hit. Resume directly");
  66. const sessionId = (await getV4PaneSnapshot()).sessionId!;
  67. await restartIntoWorkspace();
  68. await selectV4TaskById(sessionId);
  69. const [cold] = await toolSearchTurn("E2E_TOOLSEARCH_COLD_CONTINUE 检查续写的冷恢复。");
  70. expectToolSearchDisabled(cold!);
  71. const coldText = JSON.stringify(cold!.requestJson.messages);
  72. expect(coldText).toContain("E2E_TOOLSEARCH_PARTIAL_1");
  73. expect(coldText).toContain("E2E_TOOLSEARCH_PARTIAL_3");
  74. expect(coldText).not.toContain("Output token limit hit. Resume directly");
  75. });
  76. for (const disabledDuringCompact of [false, true]) {
  77. it(`TS04: ${disabledDuringCompact ? "普通 provider" : "Coding Plan"} 默认关闭期间 compact 后冷恢复`, async function () {
  78. this.timeout(240_000);
  79. await newToolSearchTask();
  80. await toolSearchTurn("E2E_TOOLSEARCH_INITIAL 搜索并执行后压缩。");
  81. const sessionId = (await getV4PaneSnapshot()).sessionId!;
  82. if (disabledDuringCompact)
  83. await switchV4Model(TOOLSEARCH_PLAIN_PROVIDER, TOOLSEARCH_MODEL, "");
  84. await compactToolSearchTask();
  85. const [after] = await toolSearchTurn("E2E_TOOLSEARCH_AFTER_COMPACT 核对压缩后的请求。");
  86. if (disabledDuringCompact) expectToolSearchDisabled(after!);
  87. else {
  88. expectToolSearchDisabled(after!);
  89. }
  90. // 摘要移走旧调用;默认关闭时仍按当前目录发送完整 schema。
  91. expect(JSON.stringify(after!.requestJson.messages)).not.toContain(TOOLSEARCH_TODO_CALL_ID);
  92. await restartIntoWorkspace();
  93. await selectV4TaskById(sessionId);
  94. await switchV4Model(TOOLSEARCH_PLAN_PROVIDER, TOOLSEARCH_MODEL, "");
  95. const cold = await toolSearchTurn("E2E_TOOLSEARCH_COLD_COMPACT 检查首请求。");
  96. expect(cold).toHaveLength(1);
  97. expectToolSearchDisabled(cold[0]!);
  98. expect(JSON.stringify(cold[0]!.requestJson.messages)).not.toContain(TOOLSEARCH_TODO_CALL_ID);
  99. });
  100. }
  101. it("TS05: 默认关闭时 fork 旧稳定轮不继承未来工具调用", async function () {
  102. this.timeout(180_000);
  103. await newToolSearchTask();
  104. await toolSearchTurn("E2E_TOOLSEARCH_SEED 尚未搜索的稳定轮。");
  105. const parentId = (await getV4PaneSnapshot()).sessionId!;
  106. await waitForV4Fork();
  107. const forkTestId = await browser.$('[data-testid^="v4-fork-"]').getAttribute("data-testid");
  108. await toolSearchTurn("E2E_TOOLSEARCH_INITIAL 现在搜索 TodoRead。");
  109. // 历史轮会折叠;“第一个可见按钮”可能属于最新轮,必须点预先记录的旧稳定轮。
  110. await expandAssistantHistoriesWithContent();
  111. const forkButton = await browser.$(`[data-testid="${forkTestId}"]`);
  112. await forkButton.$("..").moveTo();
  113. await forkButton.click();
  114. await waitForV4Pane(
  115. (s) => !!s.sessionId && s.sessionId !== "draft" && s.sessionId !== parentId,
  116. "fork 未切换到子分支",
  117. 30_000,
  118. );
  119. const [child] = await toolSearchTurn("E2E_TOOLSEARCH_FORK 检查 fork 点工具池。");
  120. expectToolSearchDisabled(child!);
  121. await selectV4TaskById(parentId);
  122. const [parent] = await toolSearchTurn("E2E_TOOLSEARCH_AFTER_FORK 父分支检查。");
  123. expectToolSearchDisabled(parent!);
  124. expectToolResultPair(parent!, TOOLSEARCH_TODO_CALL_ID);
  125. });
  126. it("TS05: 默认关闭时编辑首轮不带回旧工具调用", async function () {
  127. this.timeout(120_000);
  128. await newToolSearchTask();
  129. await toolSearchTurn("E2E_TOOLSEARCH_INITIAL 原始搜索轮。");
  130. const before = (await readToolSearchRequests()).length;
  131. await waitForV4Edit();
  132. await editFirstV4UserQuery("E2E_TOOLSEARCH_EDITED 不搜索的新分支。");
  133. await browser.waitUntil(async () => (await readToolSearchRequests()).length > before, {
  134. timeout: 45_000,
  135. });
  136. await waitForV4Pane((s) => !s.canStop, "编辑重跑未结束", 30_000);
  137. const edited = (await readToolSearchRequests())[before]!;
  138. expectToolSearchDisabled(edited);
  139. expect(JSON.stringify(edited.requestJson.messages)).not.toContain(TOOLSEARCH_TODO_CALL_ID);
  140. expect(JSON.stringify(edited.requestJson.messages)).not.toContain(TOOLSEARCH_NOTICE);
  141. });
  142. });