e2eBashPrefixPermissionShim.test.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { access, mkdtemp, readFile, rm } from "node:fs/promises";
  2. import { constants } from "node:fs";
  3. import { tmpdir } from "node:os";
  4. import { join } from "node:path";
  5. import { afterEach, describe, expect, it } from "vitest";
  6. import { installBashPrefixPermissionPnpmShim } from "./e2e/helpers/bash-prefix-permission-shim.js";
  7. describe("Bash prefix permission E2E pnpm shim", () => {
  8. const roots: string[] = [];
  9. afterEach(async () => {
  10. await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
  11. });
  12. it("prepends a case-owned executable only for the BPR spec", async () => {
  13. const homeDir = await mkdtemp(join(tmpdir(), "zcode-bpr-shim-"));
  14. roots.push(homeDir);
  15. const environment: NodeJS.ProcessEnv = { PATH: "/usr/bin:/bin" };
  16. const shimPath = await installBashPrefixPermissionPnpmShim({
  17. environment,
  18. homeDir,
  19. specs: [
  20. "/repo/packages/desktop/test/e2e/conversation-session/" +
  21. "conversation-session-v4-bash-command-prefix-permission.test.ts",
  22. ],
  23. });
  24. expect(shimPath).toBe(
  25. join(
  26. homeDir,
  27. "ZCodeProject",
  28. ".zcode-e2e",
  29. "conversation-session-v4-bash-command-prefix-permission",
  30. "bin",
  31. "pnpm",
  32. ),
  33. );
  34. expect(environment.PATH?.split(process.platform === "win32" ? ";" : ":")[0]).toBe(
  35. join(
  36. homeDir,
  37. "ZCodeProject",
  38. ".zcode-e2e",
  39. "conversation-session-v4-bash-command-prefix-permission",
  40. "bin",
  41. ),
  42. );
  43. expect(await readFile(shimPath!, "utf8")).toContain('printf "%s\\n" "lint-ok"');
  44. if (process.platform !== "win32") {
  45. await expect(access(shimPath!, constants.X_OK)).resolves.toBeUndefined();
  46. }
  47. });
  48. it("does not change PATH for unrelated specs", async () => {
  49. const homeDir = await mkdtemp(join(tmpdir(), "zcode-bpr-shim-unrelated-"));
  50. roots.push(homeDir);
  51. const environment: NodeJS.ProcessEnv = { PATH: "/usr/bin:/bin" };
  52. await expect(
  53. installBashPrefixPermissionPnpmShim({
  54. environment,
  55. homeDir,
  56. specs: ["/repo/packages/desktop/test/e2e/conversation-session/other.test.ts"],
  57. }),
  58. ).resolves.toBeUndefined();
  59. expect(environment.PATH).toBe("/usr/bin:/bin");
  60. });
  61. it("preserves the Windows-style Path key instead of creating a competing PATH key", async () => {
  62. const homeDir = await mkdtemp(join(tmpdir(), "zcode-bpr-shim-path-key-"));
  63. roots.push(homeDir);
  64. const environment: NodeJS.ProcessEnv = { Path: "/usr/bin:/bin" };
  65. await installBashPrefixPermissionPnpmShim({
  66. environment,
  67. homeDir,
  68. specs: [
  69. "/repo/packages/desktop/test/e2e/conversation-session/" +
  70. "conversation-session-v4-bash-command-prefix-permission.test.ts",
  71. ],
  72. });
  73. expect(environment.Path?.split(process.platform === "win32" ? ";" : ":")[0]).toBe(
  74. join(
  75. homeDir,
  76. "ZCodeProject",
  77. ".zcode-e2e",
  78. "conversation-session-v4-bash-command-prefix-permission",
  79. "bin",
  80. ),
  81. );
  82. expect(environment.PATH).toBeUndefined();
  83. });
  84. });