e2eRuntimePaths.test.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
  2. import { tmpdir } from "node:os";
  3. import { join, resolve } from "node:path";
  4. import { describe, expect, it } from "vitest";
  5. import {
  6. findE2EBashOutputPath,
  7. E2E_RUNTIME_RELATIVE_ROOT,
  8. E2E_RUNTIME_ROOT_REPLAY_TOKEN,
  9. createE2EReplayFixtureVariables,
  10. resolveE2EHomeDir,
  11. resolveE2EStorageRoot,
  12. resolveE2ERuntimePath,
  13. resolveE2ERuntimeRoot,
  14. resolveE2EShellPath,
  15. resolveE2EToolPath,
  16. } from "./e2e/helpers/e2e-runtime-paths.js";
  17. describe("Desktop E2E runtime paths", () => {
  18. it("keeps runtime files below the isolated Agent execution workspace", () => {
  19. const e2eHomeDir = resolve("root", "isolated-e2e-home");
  20. expect(resolveE2ERuntimeRoot(e2eHomeDir)).toBe(join(e2eHomeDir, "ZCodeProject", ".zcode-e2e"));
  21. expect(resolveE2ERuntimePath("bg25", "release-child-bash")).toBe(
  22. join(resolveE2ERuntimeRoot(), "bg25", "release-child-bash"),
  23. );
  24. });
  25. it("uses portable absolute tool paths and workspace-relative shell paths", () => {
  26. expect(resolveE2EToolPath("bg25", "continued-work.txt")).toBe(
  27. resolveE2ERuntimePath("bg25", "continued-work.txt").replaceAll("\\", "/"),
  28. );
  29. expect(resolveE2EShellPath("bg25", "release-child-bash")).toBe(
  30. ".zcode-e2e/bg25/release-child-bash",
  31. );
  32. expect(E2E_RUNTIME_RELATIVE_ROOT).toBe(".zcode-e2e");
  33. expect(E2E_RUNTIME_ROOT_REPLAY_TOKEN).toBe("{{e2eRuntimeRoot}}");
  34. expect(createE2EReplayFixtureVariables(resolve("root", "fixture-home"))).toEqual({
  35. e2eRuntimeRoot: resolveE2ERuntimeRoot(resolve("root", "fixture-home")).replaceAll("\\", "/"),
  36. });
  37. });
  38. it("uses the existing E2E HOME precedence", () => {
  39. expect(
  40. resolveE2EHomeDir({
  41. cwd: resolve("root", "desktop"),
  42. env: { ZCODE_DATA_BASE_DIR: resolve("root", "data-base") },
  43. }),
  44. ).toBe(resolve("root", "data-base"));
  45. expect(
  46. resolveE2EHomeDir({
  47. cwd: resolve("root", "desktop"),
  48. env: {
  49. ZCODE_DATA_BASE_DIR: resolve("root", "data-base"),
  50. ZCODE_E2E_HOME_DIR: resolve("root", "explicit-home"),
  51. },
  52. }),
  53. ).toBe(resolve("root", "explicit-home"));
  54. });
  55. it("keeps the E2E CLI storage under the legacy .zcode directory", () => {
  56. const homeDir = resolve("root", "isolated-e2e-home");
  57. expect(resolveE2EStorageRoot(homeDir)).toBe(join(homeDir, ".zcode"));
  58. });
  59. });
  60. it("Bash 输出查找按 session/tool 隔离,区分清理完成与多个实际文件", async () => {
  61. const root = await mkdtemp(join(tmpdir(), "e2e-output-path-"));
  62. const storageRoot = join(root, "storage");
  63. const sessionId = "session_current";
  64. const toolCallId = "tool_current";
  65. const create = async (dir: string, session = sessionId) => {
  66. const path = join(root, dir, session, `${toolCallId}-stdout.log`);
  67. await mkdir(join(root, dir, session), { recursive: true });
  68. await writeFile(path, "output");
  69. return path;
  70. };
  71. try {
  72. await create("zcode-bash-other", "session_other");
  73. const options = { tempRoot: root, storageRoot };
  74. expect(await findE2EBashOutputPath(sessionId, toolCallId, options)).toBeNull();
  75. const path = await create("zcode-bash-current");
  76. expect(await findE2EBashOutputPath(sessionId, toolCallId, options)).toBe(path);
  77. await create("zcode-bash-duplicate");
  78. await expect(findE2EBashOutputPath(sessionId, toolCallId, options)).rejects.toThrow("没有唯一");
  79. } finally {
  80. await rm(root, { recursive: true, force: true });
  81. }
  82. });