@testmuai/rook 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/rook.cjs CHANGED
@@ -257,9 +257,9 @@ function wireSignalForwarding(
257
257
 
258
258
  function runViaSystemNode(entry) {
259
259
  const major = Number(process.versions.node.split(".")[0]);
260
- if (major < 20) {
260
+ if (major < 22) {
261
261
  process.stderr.write(
262
- `rook requires Node 20 or newer (found ${process.versions.node}).\n`,
262
+ `rook requires Node 22 or newer (found ${process.versions.node}).\n`,
263
263
  );
264
264
  process.exit(1);
265
265
  }
package/bin/rook.test.mjs CHANGED
@@ -1,18 +1,49 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
1
+ import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from "vitest";
2
2
  import {
3
3
  mkdirSync,
4
+ mkdtempSync,
5
+ realpathSync,
6
+ copyFileSync,
4
7
  rmSync,
5
8
  writeFileSync,
6
9
  chmodSync,
7
10
  existsSync,
8
11
  readFileSync,
9
12
  } from "node:fs";
13
+ import { tmpdir } from "node:os";
10
14
  import { join, dirname } from "node:path";
11
- import { fileURLToPath } from "node:url";
15
+ import { fileURLToPath, pathToFileURL } from "node:url";
12
16
  import { spawnSync, spawn } from "node:child_process";
13
17
  import { EventEmitter } from "node:events";
14
18
 
15
- const BIN_DIR = dirname(fileURLToPath(import.meta.url));
19
+ /**
20
+ * A COPY of the trampoline, in a directory belonging to this file alone.
21
+ *
22
+ * The fixtures below are fake bundled-node runtimes, and they are written at
23
+ * the HOST's real platform tag on purpose — that is the path the trampoline
24
+ * resolves, which is the whole point of the test. Written into the real `bin/`,
25
+ * they are also the path the trampoline resolves for **everyone else**: while
26
+ * this file ran, any concurrent `rook.cjs` — `src/e2e/smoke.test.ts` spawns one
27
+ * — picked up `#!/bin/sh\nkill -TERM $$` instead of Node and killed itself.
28
+ * Two test files sharing one directory, run in parallel by vitest, failing
29
+ * intermittently with no output and a signal.
30
+ *
31
+ * rook.cjs requires nothing but node builtins, so a copy resolves exactly as
32
+ * the original does from wherever it sits — which makes isolation free.
33
+ */
34
+ const REAL_BIN_DIR = dirname(fileURLToPath(import.meta.url));
35
+ // realpath, because require.resolve() returns one: on macOS the temp dir is
36
+ // /var/folders/… and resolves as /private/var/folders/…, so the assertions
37
+ // would compare two spellings of the same path.
38
+ const BIN_DIR = realpathSync(mkdtempSync(join(tmpdir(), "rook-trampoline-")));
39
+ copyFileSync(join(REAL_BIN_DIR, "rook.cjs"), join(BIN_DIR, "rook.cjs"));
40
+
41
+ /** The copy, as a specifier `import()` accepts on every platform. */
42
+ const TRAMPOLINE = pathToFileURL(join(BIN_DIR, "rook.cjs")).href;
43
+
44
+ afterAll(() => {
45
+ rmSync(BIN_DIR, { recursive: true, force: true });
46
+ });
16
47
 
17
48
  function fakePkgRoot(tag) {
18
49
  return join(BIN_DIR, "node_modules", "@testmuai", `rook-node-${tag}`);
@@ -60,7 +91,7 @@ describe("rook.cjs bundled runtime resolution", () => {
60
91
  Object.defineProperty(process, "platform", { value: "darwin" });
61
92
  Object.defineProperty(process, "arch", { value: "arm64" });
62
93
 
63
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
94
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
64
95
  expect(findBundledNode()).toBe(expected);
65
96
  });
66
97
 
@@ -69,7 +100,7 @@ describe("rook.cjs bundled runtime resolution", () => {
69
100
  Object.defineProperty(process, "platform", { value: "darwin" });
70
101
  Object.defineProperty(process, "arch", { value: "x64" });
71
102
 
72
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
103
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
73
104
  expect(findBundledNode()).toBe(expected);
74
105
  });
75
106
 
@@ -78,7 +109,7 @@ describe("rook.cjs bundled runtime resolution", () => {
78
109
  Object.defineProperty(process, "platform", { value: "linux" });
79
110
  Object.defineProperty(process, "arch", { value: "arm64" });
80
111
 
81
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
112
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
82
113
  expect(findBundledNode()).toBe(expected);
83
114
  });
84
115
 
@@ -87,7 +118,7 @@ describe("rook.cjs bundled runtime resolution", () => {
87
118
  Object.defineProperty(process, "platform", { value: "win32" });
88
119
  Object.defineProperty(process, "arch", { value: "x64" });
89
120
 
90
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
121
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
91
122
  expect(findBundledNode()).toBe(expected);
92
123
  });
93
124
 
@@ -101,7 +132,7 @@ describe("rook.cjs bundled runtime resolution", () => {
101
132
  Object.defineProperty(process, "platform", { value: "linux" });
102
133
  Object.defineProperty(process, "arch", { value: "x64" });
103
134
 
104
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
135
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
105
136
  expect(findBundledNode()).toBeNull();
106
137
  });
107
138
 
@@ -111,7 +142,7 @@ describe("rook.cjs bundled runtime resolution", () => {
111
142
  Object.defineProperty(process, "platform", { value: "darwin" });
112
143
  Object.defineProperty(process, "arch", { value: "arm64" });
113
144
 
114
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
145
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
115
146
  expect(findBundledNode()).toBeNull();
116
147
  });
117
148
 
@@ -119,7 +150,7 @@ describe("rook.cjs bundled runtime resolution", () => {
119
150
  writeFakePackage("darwin-arm64", "node");
120
151
  Object.defineProperty(process, "platform", { value: "aix" });
121
152
 
122
- const { findBundledNode } = await import("./rook.cjs?t=" + Date.now());
153
+ const { findBundledNode } = await import(TRAMPOLINE + "?t=" + Date.now());
123
154
  expect(findBundledNode()).toBeNull();
124
155
  });
125
156
  });