@ordewell/core 0.12.3 → 0.12.5

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.
@@ -1,8 +1,53 @@
1
- import { J as EventStore, bQ as TreeEvent, bR as TreeFact, aj as NodePath, K as ExecutionBackend, a4 as LeaseRequest, a5 as LeaseSpec, S as Guarantee, a3 as LeaseRepo, b6 as RunnerPlacement, a2 as LeaseRecord, T as GuaranteeReport, aR as ReservedLease, _ as IRunnerSession, aK as QueuedTaskMessage, bt as StructuredTurnEnd, bs as StructuredEvent, bz as TaskCompleteArgs, x as CheckpointAnswer, bf as ScriptExit, bB as TaskMessageFrom, aX as RunnerCommand, $ as InvokedCommand, k as ApprovalDecision, V as IConfig, W as IFileSystem } from './eventStore-BcoMsZtU.mjs';
1
+ import { J as EventStore, bQ as TreeEvent, bR as TreeFact, aj as NodePath, K as ExecutionBackend, a4 as LeaseRequest, a5 as LeaseSpec, S as Guarantee, a3 as LeaseRepo, b6 as RunnerPlacement, a2 as LeaseRecord, T as GuaranteeReport, aR as ReservedLease, _ as IRunnerSession, aK as QueuedTaskMessage, bt as StructuredTurnEnd, bs as StructuredEvent, bz as TaskCompleteArgs, x as CheckpointAnswer, bf as ScriptExit, bB as TaskMessageFrom, aX as RunnerCommand, $ as InvokedCommand, k as ApprovalDecision, V as IConfig, W as IFileSystem } from './eventStore-BbMmQDBw.mjs';
2
2
  import { U as IntegrationDisposal, b5 as RunnerSessionCost, T as IWorktreeIsolation, W as IsolationAvailability, a2 as IsolationMergeResult, bF as TreeSnapshot, bc as SetupFailure, a5 as IsolationPruneResult, a6 as IsolationRemoval, a3 as IsolationOutcome, a9 as IsolationRevertResult, b0 as RevertCommand, aQ as RepairEvidence, ab as IsolationRun, bq as Task, aI as PrepareIntent, aJ as PreparedTask, J as HandoffCommit, ai as LandedWork, b1 as RevertWatch, X as IsolationHandoff } from './Task-D3O49EUo.mjs';
3
3
  import 'child_process';
4
4
  import 'zod/v4';
5
5
 
6
+ /** A test's own limit, `ms` on Linux and macOS, as much longer as {@link PACE} says here. */
7
+ declare function patient(ms: number): number;
8
+ /**
9
+ * Remove a test's scratch directory, waiting out whatever still holds it.
10
+ * Windows removes no directory a process works in, and a process tree it was
11
+ * told to end takes a moment to go. The retries back off linearly, about five
12
+ * seconds in all, and only a held directory waits. Async, so the event loop is
13
+ * free to run the kill that lets it go.
14
+ */
15
+ declare function removeDir(dir: string): Promise<void>;
16
+ /**
17
+ * The variables that make `home` the user's home, for a test that gives this
18
+ * process, or a child, a home of its own.
19
+ *
20
+ * HOME alone is a POSIX home. Node's `os.homedir()` reads USERPROFILE on
21
+ * Windows, so a test that set only HOME there read and wrote the real
22
+ * `~/.ordewell`. The per-user folders the runner probe searches on Windows
23
+ * (`wellKnownBinDirs`: npm's prefix under APPDATA, WinGet's links under
24
+ * LOCALAPPDATA, Chocolatey's under ProgramData, Scoop's own) hang off variables
25
+ * of their own, so those move too, or a CLI really installed there is found.
26
+ */
27
+ declare function homeEnv(home: string, platform?: NodeJS.Platform): Record<string, string | undefined>;
28
+ /**
29
+ * Set `vars` on this process's environment, and return what puts back the
30
+ * values they replaced. A key given as undefined is deleted: assigning
31
+ * undefined to `process.env` stores the string "undefined".
32
+ */
33
+ declare function setEnv(vars: Record<string, string | undefined>): () => void;
34
+ /**
35
+ * A file `name` resolves to on PATH from `bin`, for a test whose spawn is
36
+ * faked: it is never run. Windows starts a native executable ahead of anything
37
+ * else on PATH (ADR-0010), so there it is a `.exe`.
38
+ */
39
+ declare function writeStandIn(bin: string, name: string): string;
40
+ /**
41
+ * A PATH on which `command` starts the fake in `dir`.
42
+ *
43
+ * First on PATH is enough on POSIX. A fake is a batch shim on Windows, and
44
+ * `planDirectLaunch` prefers a native executable anywhere on PATH to a batch
45
+ * shim ahead of it (ADR-0010), so every directory holding a native `command`
46
+ * is left out as well. With {@link homeEnv}, nothing installed on the machine
47
+ * answers in the fake's place.
48
+ */
49
+ declare function pathWithFake(dir: string, command: string, PATH?: string, platform?: NodeJS.Platform): string;
50
+
6
51
  /**
7
52
  * Let an already-queued promise chain run to its next await before asserting,
8
53
  * without a wall-clock sleep. For a chain whose length is not known, drain the
@@ -316,4 +361,4 @@ declare class FakeWorktreeIsolation implements IWorktreeIsolation {
316
361
  sweep(): Promise<void>;
317
362
  }
318
363
 
319
- export { FakeEventStore, FakeExecutionBackend, type FakeIsolationCall, FakeRunnerSession, FakeWorktreeIsolation, fakeConfig, fakeFileSystem, flushMicrotasks };
364
+ export { FakeEventStore, FakeExecutionBackend, type FakeIsolationCall, FakeRunnerSession, FakeWorktreeIsolation, fakeConfig, fakeFileSystem, flushMicrotasks, homeEnv, pathWithFake, patient, removeDir, setEnv, writeStandIn };
package/dist/testing.d.ts CHANGED
@@ -1,8 +1,53 @@
1
- import { J as EventStore, bQ as TreeEvent, bR as TreeFact, aj as NodePath, K as ExecutionBackend, a4 as LeaseRequest, a5 as LeaseSpec, S as Guarantee, a3 as LeaseRepo, b6 as RunnerPlacement, a2 as LeaseRecord, T as GuaranteeReport, aR as ReservedLease, _ as IRunnerSession, aK as QueuedTaskMessage, bt as StructuredTurnEnd, bs as StructuredEvent, bz as TaskCompleteArgs, x as CheckpointAnswer, bf as ScriptExit, bB as TaskMessageFrom, aX as RunnerCommand, $ as InvokedCommand, k as ApprovalDecision, V as IConfig, W as IFileSystem } from './eventStore-CSFKy48Y.js';
1
+ import { J as EventStore, bQ as TreeEvent, bR as TreeFact, aj as NodePath, K as ExecutionBackend, a4 as LeaseRequest, a5 as LeaseSpec, S as Guarantee, a3 as LeaseRepo, b6 as RunnerPlacement, a2 as LeaseRecord, T as GuaranteeReport, aR as ReservedLease, _ as IRunnerSession, aK as QueuedTaskMessage, bt as StructuredTurnEnd, bs as StructuredEvent, bz as TaskCompleteArgs, x as CheckpointAnswer, bf as ScriptExit, bB as TaskMessageFrom, aX as RunnerCommand, $ as InvokedCommand, k as ApprovalDecision, V as IConfig, W as IFileSystem } from './eventStore-br1Tvuh6.js';
2
2
  import { U as IntegrationDisposal, b5 as RunnerSessionCost, T as IWorktreeIsolation, W as IsolationAvailability, a2 as IsolationMergeResult, bF as TreeSnapshot, bc as SetupFailure, a5 as IsolationPruneResult, a6 as IsolationRemoval, a3 as IsolationOutcome, a9 as IsolationRevertResult, b0 as RevertCommand, aQ as RepairEvidence, ab as IsolationRun, bq as Task, aI as PrepareIntent, aJ as PreparedTask, J as HandoffCommit, ai as LandedWork, b1 as RevertWatch, X as IsolationHandoff } from './Task-D3O49EUo.js';
3
3
  import 'child_process';
4
4
  import 'zod/v4';
5
5
 
6
+ /** A test's own limit, `ms` on Linux and macOS, as much longer as {@link PACE} says here. */
7
+ declare function patient(ms: number): number;
8
+ /**
9
+ * Remove a test's scratch directory, waiting out whatever still holds it.
10
+ * Windows removes no directory a process works in, and a process tree it was
11
+ * told to end takes a moment to go. The retries back off linearly, about five
12
+ * seconds in all, and only a held directory waits. Async, so the event loop is
13
+ * free to run the kill that lets it go.
14
+ */
15
+ declare function removeDir(dir: string): Promise<void>;
16
+ /**
17
+ * The variables that make `home` the user's home, for a test that gives this
18
+ * process, or a child, a home of its own.
19
+ *
20
+ * HOME alone is a POSIX home. Node's `os.homedir()` reads USERPROFILE on
21
+ * Windows, so a test that set only HOME there read and wrote the real
22
+ * `~/.ordewell`. The per-user folders the runner probe searches on Windows
23
+ * (`wellKnownBinDirs`: npm's prefix under APPDATA, WinGet's links under
24
+ * LOCALAPPDATA, Chocolatey's under ProgramData, Scoop's own) hang off variables
25
+ * of their own, so those move too, or a CLI really installed there is found.
26
+ */
27
+ declare function homeEnv(home: string, platform?: NodeJS.Platform): Record<string, string | undefined>;
28
+ /**
29
+ * Set `vars` on this process's environment, and return what puts back the
30
+ * values they replaced. A key given as undefined is deleted: assigning
31
+ * undefined to `process.env` stores the string "undefined".
32
+ */
33
+ declare function setEnv(vars: Record<string, string | undefined>): () => void;
34
+ /**
35
+ * A file `name` resolves to on PATH from `bin`, for a test whose spawn is
36
+ * faked: it is never run. Windows starts a native executable ahead of anything
37
+ * else on PATH (ADR-0010), so there it is a `.exe`.
38
+ */
39
+ declare function writeStandIn(bin: string, name: string): string;
40
+ /**
41
+ * A PATH on which `command` starts the fake in `dir`.
42
+ *
43
+ * First on PATH is enough on POSIX. A fake is a batch shim on Windows, and
44
+ * `planDirectLaunch` prefers a native executable anywhere on PATH to a batch
45
+ * shim ahead of it (ADR-0010), so every directory holding a native `command`
46
+ * is left out as well. With {@link homeEnv}, nothing installed on the machine
47
+ * answers in the fake's place.
48
+ */
49
+ declare function pathWithFake(dir: string, command: string, PATH?: string, platform?: NodeJS.Platform): string;
50
+
6
51
  /**
7
52
  * Let an already-queued promise chain run to its next await before asserting,
8
53
  * without a wall-clock sleep. For a chain whose length is not known, drain the
@@ -316,4 +361,4 @@ declare class FakeWorktreeIsolation implements IWorktreeIsolation {
316
361
  sweep(): Promise<void>;
317
362
  }
318
363
 
319
- export { FakeEventStore, FakeExecutionBackend, type FakeIsolationCall, FakeRunnerSession, FakeWorktreeIsolation, fakeConfig, fakeFileSystem, flushMicrotasks };
364
+ export { FakeEventStore, FakeExecutionBackend, type FakeIsolationCall, FakeRunnerSession, FakeWorktreeIsolation, fakeConfig, fakeFileSystem, flushMicrotasks, homeEnv, pathWithFake, patient, removeDir, setEnv, writeStandIn };
package/dist/testing.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/testing.ts
@@ -26,7 +36,13 @@ __export(testing_exports, {
26
36
  FakeWorktreeIsolation: () => FakeWorktreeIsolation,
27
37
  fakeConfig: () => fakeConfig,
28
38
  fakeFileSystem: () => fakeFileSystem,
29
- flushMicrotasks: () => flushMicrotasks
39
+ flushMicrotasks: () => flushMicrotasks,
40
+ homeEnv: () => homeEnv,
41
+ pathWithFake: () => pathWithFake,
42
+ patient: () => patient,
43
+ removeDir: () => removeDir,
44
+ setEnv: () => setEnv,
45
+ writeStandIn: () => writeStandIn
30
46
  });
31
47
  module.exports = __toCommonJS(testing_exports);
32
48
 
@@ -95,6 +111,52 @@ function isWithin(node, ancestor) {
95
111
  return node === ancestor || node.startsWith(`${ancestor}/`);
96
112
  }
97
113
 
114
+ // src/testEnv.ts
115
+ var fs = __toESM(require("fs"));
116
+ var path = __toESM(require("path"));
117
+ var PACE = process.platform === "win32" ? 3 : 1;
118
+ function patient(ms) {
119
+ return ms * PACE;
120
+ }
121
+ function removeDir(dir) {
122
+ return fs.promises.rm(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
123
+ }
124
+ function homeEnv(home, platform = process.platform) {
125
+ if (platform !== "win32") return { HOME: home };
126
+ return {
127
+ HOME: home,
128
+ USERPROFILE: home,
129
+ APPDATA: path.win32.join(home, "AppData", "Roaming"),
130
+ LOCALAPPDATA: path.win32.join(home, "AppData", "Local"),
131
+ ProgramData: path.win32.join(home, "ProgramData"),
132
+ SCOOP: void 0,
133
+ SCOOP_GLOBAL: void 0
134
+ };
135
+ }
136
+ function setEnv(vars) {
137
+ const saved = Object.fromEntries(Object.keys(vars).map((key) => [key, process.env[key]]));
138
+ applyEnv(vars);
139
+ return () => applyEnv(saved);
140
+ }
141
+ function applyEnv(vars) {
142
+ for (const [key, value] of Object.entries(vars)) {
143
+ if (value === void 0) delete process.env[key];
144
+ else process.env[key] = value;
145
+ }
146
+ }
147
+ function writeStandIn(bin, name) {
148
+ const file = path.join(bin, process.platform === "win32" ? `${name}.exe` : name);
149
+ fs.writeFileSync(file, "#!/bin/sh\nexit 1\n");
150
+ fs.chmodSync(file, 493);
151
+ return file;
152
+ }
153
+ function pathWithFake(dir, command, PATH = process.env.PATH ?? "", platform = process.platform) {
154
+ const paths = platform === "win32" ? path.win32 : path.posix;
155
+ const native = platform === "win32" ? [".exe", ".com"] : [];
156
+ const holdsNative = (entry) => native.some((ext) => fs.existsSync(paths.join(entry.replace(/^"|"$/g, ""), `${command}${ext}`)));
157
+ return [dir, ...PATH.split(paths.delimiter).filter((entry) => entry && !holdsNative(entry))].join(paths.delimiter);
158
+ }
159
+
98
160
  // src/testing.ts
99
161
  async function flushMicrotasks(rounds = 20) {
100
162
  for (let i = 0; i < rounds; i += 1) await Promise.resolve();
@@ -375,9 +437,9 @@ var FakeEventStore = class {
375
437
  if (this.failing) throw this.failing;
376
438
  for (const event of events) this.events.push({ ...event, seq: this.events.length + 1 });
377
439
  }
378
- async *read(after, path) {
440
+ async *read(after, path2) {
379
441
  for (const event of [...this.events]) {
380
- if (event.seq > after && (path === void 0 || isWithin(event.node, path))) yield event;
442
+ if (event.seq > after && (path2 === void 0 || isWithin(event.node, path2))) yield event;
381
443
  }
382
444
  }
383
445
  async close() {
@@ -780,6 +842,12 @@ var FakeWorktreeIsolation = class {
780
842
  FakeWorktreeIsolation,
781
843
  fakeConfig,
782
844
  fakeFileSystem,
783
- flushMicrotasks
845
+ flushMicrotasks,
846
+ homeEnv,
847
+ pathWithFake,
848
+ patient,
849
+ removeDir,
850
+ setEnv,
851
+ writeStandIn
784
852
  });
785
853
  //# sourceMappingURL=testing.js.map