conversation-session-preinstalled-tools-env.test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { cp, mkdir, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { getLatestUpstreamToolResultByToolCallId } from "#e2e/helpers/conversation-session-network";
  4. import { resolveE2ERuntimePath, resolveE2EStorageRoot } from "#e2e/helpers/e2e-runtime-paths";
  5. import {
  6. getV4PaneSnapshot,
  7. prepareV4ConversationE2E,
  8. sendV4Prompt,
  9. switchV4Mode,
  10. waitForV4AssistantMessageContaining,
  11. waitForV4ConversationState,
  12. } from "#e2e/helpers/v4-conversation";
  13. const FIRST = "E2E_LOP_ENV_BEFORE";
  14. const NEXT = "E2E_LOP_ENV_CONTINUE";
  15. describe("预装工具无发布目标的环境(待审核)", () => {
  16. it("LOP-17/30: 无目标仍注入固定入口目录,既有会话提供桌面引导", async function () {
  17. this.timeout(120000);
  18. const directory = resolveE2ERuntimePath("conversation-session-preinstalled-tools-env");
  19. await mkdir(directory, { recursive: true });
  20. await cp(
  21. new URL(
  22. "../../../fixtures/fs/conversation-session/conversation-session-preinstalled-tools-env/probe.mjs",
  23. import.meta.url,
  24. ),
  25. join(directory, "probe.mjs"),
  26. );
  27. await writeFile(
  28. join(directory, "config.json"),
  29. JSON.stringify({
  30. storageRoot: resolveE2EStorageRoot(),
  31. python: process.env.ZCODE_E2E_DOCUMENT_PYTHON || "python3",
  32. }),
  33. );
  34. await prepareV4ConversationE2E();
  35. await switchV4Mode("yolo");
  36. const observations = [];
  37. let sessionId: string | null = null;
  38. for (const [marker, tool] of [
  39. [FIRST, "toolu_lop_env_before"],
  40. [NEXT, "toolu_lop_env_continue"],
  41. ]) {
  42. await sendV4Prompt(
  43. `${marker}: Run the exact read-only preinstalled-tools environment probe.`,
  44. );
  45. try {
  46. await waitForV4AssistantMessageContaining(`${marker}_DONE`, 90000);
  47. } catch (error) {
  48. await writeFile(
  49. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "lop-env-failure-state.json"),
  50. JSON.stringify({ snapshot: await getV4PaneSnapshot(), text: await $("body").getText() }),
  51. );
  52. await browser.saveScreenshot(`${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-env-failure.png`);
  53. throw error;
  54. }
  55. await waitForV4ConversationState((state) => state.state === "idle", "环境探测未结束");
  56. const result = await getLatestUpstreamToolResultByToolCallId(tool!);
  57. expect(result?.isError).toBe(false);
  58. const observed = JSON.parse(result!.content);
  59. expect(observed.available).toBe("1");
  60. expect(observed.pathFirst).toBe(observed.binDir);
  61. expect([0, 69]).toContain(observed.exitCode);
  62. if (observed.exitCode !== 0) expect(observed.stdout + observed.stderr).toContain("预装工具");
  63. if (observed.exitCode === 0) expect(JSON.parse(observed.stdout).source).toBe("system");
  64. else expect(observed.stdout + observed.stderr).toContain("env_setup/setup.md");
  65. const current = (await getV4PaneSnapshot()).sessionId;
  66. if (sessionId) expect(current).toBe(sessionId);
  67. sessionId = current;
  68. observations.push(observed);
  69. }
  70. await writeFile(
  71. join(process.env.ZCODE_E2E_ARTIFACT_DIR!, "lop-no-target-environment.json"),
  72. JSON.stringify(observations),
  73. );
  74. await browser.saveScreenshot(`${process.env.ZCODE_E2E_ARTIFACT_DIR}/lop-env-continued.png`);
  75. });
  76. });