conversation-session-toolsearch.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { BUILTIN_MODEL_PROVIDER_IDS } from "@zcode/shared";
  2. import { clearAppData } from "#e2e/helpers/desktop-app";
  3. import { skipOccupationOnboardingIfPresent } from "#e2e/helpers/occupation-onboarding";
  4. import {
  5. restartIntoWorkspace,
  6. seedBigModelConnectionSelection,
  7. seedBigModelOAuthCredential,
  8. settleBigModelIdentityOnboarding,
  9. } from "#e2e/helpers/model-provider-restart";
  10. import {
  11. prepareV4ConversationE2E,
  12. switchV4Model,
  13. sendV4Prompt,
  14. waitForV4TimelineContaining,
  15. getV4PaneSnapshot,
  16. selectV4TaskById,
  17. waitForV4Pane,
  18. } from "#e2e/helpers/v4-conversation";
  19. import {
  20. readToolSearchRequests,
  21. TOOLSEARCH_DEFERRED_TOOL,
  22. TOOLSEARCH_TODO_CALL_ID,
  23. TOOLSEARCH_DONE,
  24. } from "#e2e/helpers/toolsearch-provider";
  25. import { expectToolSearchDisabled } from "#e2e/helpers/toolsearch-desktop";
  26. describe("ToolSearch Desktop 默认关闭与冷恢复", () => {
  27. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan;
  28. after(async () => {
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. });
  32. it("TS01/TS04: Coding Plan 默认完整目录,直接执行 TodoRead 后冷恢复保持关闭", async function () {
  33. this.timeout(180_000);
  34. // 批量运行时会保留测试账号,但新 renderer profile 仍需完成职业引导。
  35. await skipOccupationOnboardingIfPresent();
  36. await prepareV4ConversationE2E({ skipProvider: true });
  37. await restartIntoWorkspace({
  38. afterElectronProcessExit: async () => {
  39. await seedBigModelConnectionSelection({ kind: "individual-coding-plan" });
  40. await seedBigModelOAuthCredential();
  41. },
  42. });
  43. // 换成 BigModel 身份后引导会按新身份重新判定,先等判定落定再操作主界面。
  44. await settleBigModelIdentityOnboarding();
  45. await switchV4Model(providerId, "GLM-5.3", "");
  46. await sendV4Prompt(
  47. `E2E_TOOLSEARCH_INITIAL 请搜索 ${TOOLSEARCH_DEFERRED_TOOL},然后读取当前待办。`,
  48. );
  49. await waitForV4TimelineContaining(TOOLSEARCH_DONE, 60_000);
  50. const requests = await readToolSearchRequests();
  51. expectToolSearchDisabled(requests[0]!);
  52. assertTodoResult(requests);
  53. await waitForV4Pane((s) => !s.canStop, "搜索轮未结束", 30_000);
  54. const sessionId = (await getV4PaneSnapshot()).sessionId;
  55. expect(sessionId).toBeTruthy();
  56. await restartIntoWorkspace();
  57. await selectV4TaskById(sessionId!);
  58. const before = (await readToolSearchRequests()).length;
  59. await sendV4Prompt("E2E_TOOLSEARCH_COLD 继续验证已加载的工具。");
  60. await waitForV4TimelineContaining(TOOLSEARCH_DONE, 60_000);
  61. await browser.waitUntil(async () => (await readToolSearchRequests()).length > before, {
  62. timeout: 30_000,
  63. });
  64. await waitForV4Pane((s) => !s.canStop, "冷恢复轮未结束", 30_000);
  65. const coldRequests = (await readToolSearchRequests()).slice(before);
  66. expect(coldRequests).toHaveLength(1);
  67. const coldRequest = coldRequests[0]!;
  68. expectToolSearchDisabled(coldRequest);
  69. assertTodoResult([coldRequest]);
  70. });
  71. });
  72. function assertTodoResult(requests: Awaited<ReturnType<typeof readToolSearchRequests>>) {
  73. const result = requests
  74. .flatMap(({ requestJson }) =>
  75. requestJson.messages.flatMap((message) =>
  76. Array.isArray(message.content) ? message.content : [],
  77. ),
  78. )
  79. .find((block) => block.type === "tool_result" && block.tool_use_id === TOOLSEARCH_TODO_CALL_ID);
  80. expect(result).toBeDefined();
  81. expect(result?.is_error).not.toBe(true);
  82. // 新会话没有待办,TodoRead 的真实执行输出是空清单。
  83. expect(JSON.parse(String(result?.content))).toEqual({ todos: [] });
  84. }