@smoothbricks/nx-plugin 0.4.28 → 0.4.29
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/README.md +203 -83
- package/dist/bounded-test-policy.d.ts +10 -3
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +19 -25
- package/dist/cargo-closure-input.d.ts +12 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +34 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +265 -159
- package/dist/ensure-built-witness.d.ts +27 -2
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2176 -15
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +34 -53
- package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +43 -19
- package/dist/executors/bounded-exec/executor.d.ts +11 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +139 -39
- package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +27 -13
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +98 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +624 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +921 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +58 -0
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +147 -21
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -114
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +11 -6
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +174 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +19 -27
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.test.ts +60 -11
- package/src/cargo-closure-input.ts +28 -6
- package/src/cargo-resolve-cache.test.ts +140 -25
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +251 -149
- package/src/ensure-built-witness.test.ts +197 -13
- package/src/ensure-built-witness.ts +187 -15
- package/src/ensure-built.test.ts +156 -102
- package/src/ensure-built.ts +114 -64
- package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
- package/src/executors/bounded-exec/cpu-pool.ts +55 -17
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/executor-host.test.ts +51 -41
- package/src/executors/bounded-exec/executor.test.ts +155 -35
- package/src/executors/bounded-exec/executor.ts +156 -45
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
- package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
- package/src/executors/bounded-exec/ram-temp.ts +32 -16
- package/src/executors/bounded-exec/verdict.test.ts +17 -12
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +371 -0
- package/src/graph-input-contract.ts +605 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +5 -5
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +56 -0
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +31 -9
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +631 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +59 -0
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +5 -0
|
@@ -42,21 +42,45 @@ export interface CpuPool {
|
|
|
42
42
|
|
|
43
43
|
type CloseOutcome = { ok: true } | { ok: false; error: string };
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The run's count of descendant work queued for host CPU tokens (specs/cowshed/05_gateway.md, "The bounds start at
|
|
47
|
+
* the grant"). A queued job is not an idle one: its owner stops the run's idle clock while any wait is held. Every
|
|
48
|
+
* pool of one run, its sub-pools included, reports to the same one.
|
|
49
|
+
*/
|
|
50
|
+
export interface HostWaits {
|
|
51
|
+
begin(): void;
|
|
52
|
+
end(): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
/** The one line a child sends: a count of whole tokens, at least one. */
|
|
46
56
|
interface CpuPoolRequest {
|
|
47
57
|
op: 'cpu-pool';
|
|
48
58
|
want: number & typia.tags.Type<'uint32'> & typia.tags.Minimum<1>;
|
|
49
59
|
/** Ask the owning pool to serve this allocation as its own child pool (Cargo's host launcher). */
|
|
50
60
|
children?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Cargo's launcher asks a compile-only build to grow. This pool lends a fixed count, so it accepts the field and never
|
|
63
|
+
* grows a child; the gateway's pools do (specs/cowshed/05_gateway.md, "A short build grows").
|
|
64
|
+
*/
|
|
65
|
+
grow?: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A descendant's word that work it started waits in a host CPU queue (a cowshed job the gateway holds `waiting`). It
|
|
70
|
+
* is held like a grant: the wait lasts while its connection does, so a descendant that dies ends its wait.
|
|
71
|
+
*/
|
|
72
|
+
interface HostWaitRequest {
|
|
73
|
+
op: 'host-wait';
|
|
51
74
|
}
|
|
52
75
|
|
|
53
76
|
/** The pool's answers, in `holdLease`'s framing. */
|
|
54
77
|
type CpuPoolReply =
|
|
55
78
|
| { ok: true; lease: 'queued' }
|
|
56
79
|
| { ok: true; lease: 'granted'; tokens: number; pool?: string }
|
|
80
|
+
| { ok: true; wait: 'held' }
|
|
57
81
|
| { ok: false; code: 'invalid-request'; error: string };
|
|
58
82
|
|
|
59
|
-
const parseRequest = typia.json.createIsParse<CpuPoolRequest>();
|
|
83
|
+
const parseRequest = typia.json.createIsParse<CpuPoolRequest | HostWaitRequest>();
|
|
60
84
|
const stringifyReply = typia.json.createStringify<CpuPoolReply>();
|
|
61
85
|
|
|
62
86
|
/** A request over this many bytes is refused as `invalid-request` (specs/cowshed/05_gateway.md, "Wire"). */
|
|
@@ -69,11 +93,13 @@ const POOL_DIRECTORY = 'cpu-pool-';
|
|
|
69
93
|
const POOL_SOCKET = 'p.sock';
|
|
70
94
|
const CLOSED_WHILE_MADE = 'the grant that lends this CPU pool closed while the pool was being made';
|
|
71
95
|
|
|
72
|
-
/** A child's phase. Tokens are owed back only while `holding`; a queued child holds nothing
|
|
96
|
+
/** A child's phase. Tokens are owed back only while `holding`; a queued child holds nothing; a `waiting` child holds a
|
|
97
|
+
* host wait on the run's idle clock. */
|
|
73
98
|
type Phase =
|
|
74
99
|
| { readonly kind: 'reading' }
|
|
75
100
|
| { readonly kind: 'queued' }
|
|
76
101
|
| { readonly kind: 'holding'; readonly tokens: number }
|
|
102
|
+
| { readonly kind: 'waiting' }
|
|
77
103
|
| { readonly kind: 'done' };
|
|
78
104
|
|
|
79
105
|
/** A child connection and what the pool owes it. Its grant, or its place in line, ends with the connection. */
|
|
@@ -106,17 +132,15 @@ export function readInheritedCpuPool(environment: Readonly<NodeJS.ProcessEnv>):
|
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
/**
|
|
109
|
-
* Ask the immediate parent pool for `
|
|
135
|
+
* Ask the immediate parent pool for `want` tokens. Neither the inherited count nor the host's core count bounds the
|
|
136
|
+
* ask: a lent pool grants at most what it holds, and a gate's relay pool asks the host for each child. A granted
|
|
110
137
|
* lease is the child's local allocation: its connection is the grant, and closing it returns only
|
|
111
138
|
* that allocation. An absent endpoint allows normal host acquisition; a connected endpoint's refusal
|
|
112
139
|
* or protocol failure must fail admission rather than taking a second grant above its parent.
|
|
113
140
|
*/
|
|
114
|
-
export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw new RangeError(
|
|
118
|
-
`a child asks its parent pool for a positive count, not ${ask} (want ${want}, pool ${parent.tokens}, cores ${cores})`,
|
|
119
|
-
);
|
|
141
|
+
export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number): Promise<TokenGrant> {
|
|
142
|
+
if (!Number.isSafeInteger(want) || want < 1) {
|
|
143
|
+
throw new RangeError(`a child asks its parent pool for a positive count, not ${want} (pool ${parent.tokens})`);
|
|
120
144
|
}
|
|
121
145
|
if (parent.socket.length === 0 || parent.socket.includes('\0')) {
|
|
122
146
|
return {
|
|
@@ -125,7 +149,7 @@ export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
|
|
|
125
149
|
reason: `the parent CPU pool's endpoint ${JSON.stringify(parent.socket)} is not a socket path`,
|
|
126
150
|
};
|
|
127
151
|
}
|
|
128
|
-
const lease = await holdLease(parent.socket, { op: 'cpu-pool', want
|
|
152
|
+
const lease = await holdLease(parent.socket, { op: 'cpu-pool', want }, 'the parent CPU pool', {
|
|
129
153
|
ackMs: 2_000,
|
|
130
154
|
afterCloseMs: 5_000,
|
|
131
155
|
grantMs: null,
|
|
@@ -134,12 +158,12 @@ export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
|
|
|
134
158
|
return lease;
|
|
135
159
|
}
|
|
136
160
|
const tokens = lease.answer.tokens;
|
|
137
|
-
if (typeof tokens !== 'number' || !Number.isInteger(tokens) || tokens < 1 || tokens >
|
|
161
|
+
if (typeof tokens !== 'number' || !Number.isInteger(tokens) || tokens < 1 || tokens > want) {
|
|
138
162
|
lease.release();
|
|
139
163
|
return {
|
|
140
164
|
granted: false,
|
|
141
165
|
cause: 'other',
|
|
142
|
-
reason: `the parent CPU pool granted ${JSON.stringify(tokens)} tokens for ${
|
|
166
|
+
reason: `the parent CPU pool granted ${JSON.stringify(tokens)} tokens for ${want}`,
|
|
143
167
|
};
|
|
144
168
|
}
|
|
145
169
|
return { granted: true, tokens, release: lease.release, closed: lease.closed, inherited: true };
|
|
@@ -147,12 +171,14 @@ export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
|
|
|
147
171
|
|
|
148
172
|
/**
|
|
149
173
|
* Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
|
|
150
|
-
* grants, ends its child connections and removes its directory.
|
|
151
|
-
*
|
|
174
|
+
* grants, ends its child connections and removes its directory. A child's `host-wait` is reported
|
|
175
|
+
* to `waits` for as long as its connection holds it; a sub-pool reports to the same `waits`.
|
|
176
|
+
* Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
|
|
152
177
|
*/
|
|
153
178
|
export async function createCpuPool(
|
|
154
179
|
tokens: number,
|
|
155
180
|
closed: Promise<void>,
|
|
181
|
+
waits: HostWaits,
|
|
156
182
|
): Promise<{ ok: true; pool: CpuPool } | { ok: false; error: string }> {
|
|
157
183
|
if (!Number.isSafeInteger(tokens) || tokens < 1) {
|
|
158
184
|
throw new RangeError(`a CPU pool holds a positive safe integer of tokens, not ${tokens}`);
|
|
@@ -206,7 +232,7 @@ export async function createCpuPool(
|
|
|
206
232
|
if (waiter.child.socket.destroyed) done();
|
|
207
233
|
else waiter.child.socket.once('close', done);
|
|
208
234
|
});
|
|
209
|
-
const creation = createCpuPool(granted, ended).then(async (made) => {
|
|
235
|
+
const creation = createCpuPool(granted, ended, waits).then(async (made) => {
|
|
210
236
|
if (!made.ok) {
|
|
211
237
|
failures.push(made.error);
|
|
212
238
|
// Keep holding until close credits exactly this allocation once.
|
|
@@ -253,6 +279,8 @@ export async function createCpuPool(
|
|
|
253
279
|
}
|
|
254
280
|
} else if (child.phase.kind === 'holding') {
|
|
255
281
|
free += child.phase.tokens;
|
|
282
|
+
} else if (child.phase.kind === 'waiting') {
|
|
283
|
+
waits.end();
|
|
256
284
|
}
|
|
257
285
|
child.phase = { kind: 'done' };
|
|
258
286
|
drain();
|
|
@@ -296,7 +324,7 @@ export async function createCpuPool(
|
|
|
296
324
|
}
|
|
297
325
|
const line = buffered.subarray(0, newline).toString('utf8');
|
|
298
326
|
buffered = EMPTY;
|
|
299
|
-
let request: CpuPoolRequest | null;
|
|
327
|
+
let request: CpuPoolRequest | HostWaitRequest | null;
|
|
300
328
|
try {
|
|
301
329
|
request = parseRequest(line);
|
|
302
330
|
} catch (error) {
|
|
@@ -305,7 +333,17 @@ export async function createCpuPool(
|
|
|
305
333
|
request = null;
|
|
306
334
|
}
|
|
307
335
|
if (request === null) {
|
|
308
|
-
refuse(
|
|
336
|
+
refuse(
|
|
337
|
+
child,
|
|
338
|
+
'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>} or {"op":"host-wait"}',
|
|
339
|
+
);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (request.op === 'host-wait') {
|
|
343
|
+
// Counted from here until the connection closes, which `close` reports however it ends.
|
|
344
|
+
child.phase = { kind: 'waiting' };
|
|
345
|
+
waits.begin();
|
|
346
|
+
socket.write(frame({ ok: true, wait: 'held' }));
|
|
309
347
|
return;
|
|
310
348
|
}
|
|
311
349
|
child.phase = { kind: 'queued' };
|
|
@@ -54,7 +54,7 @@ describe('cowshed CPU budget client', () => {
|
|
|
54
54
|
want: 12,
|
|
55
55
|
});
|
|
56
56
|
expect(runnerDemand('cargo nextest run --test-threads=4', undefined, 18, {})).toEqual({ kind: 'nextest', want: 4 });
|
|
57
|
-
expect(runnerDemand('bun test --timeout=
|
|
57
|
+
expect(runnerDemand('bun test --timeout=0 --parallel=3', undefined, 18, {})).toEqual({
|
|
58
58
|
kind: 'bun-parallel',
|
|
59
59
|
want: 3,
|
|
60
60
|
});
|
|
@@ -68,7 +68,7 @@ describe('cowshed CPU budget client', () => {
|
|
|
68
68
|
want: 5,
|
|
69
69
|
});
|
|
70
70
|
// One bun process: `test.concurrent` inside it is not another CPU.
|
|
71
|
-
expect(runnerDemand('bun test --timeout=
|
|
71
|
+
expect(runnerDemand('bun test --timeout=0 native.test.ts', undefined, 18, {})).toEqual({
|
|
72
72
|
kind: 'process',
|
|
73
73
|
want: 1,
|
|
74
74
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from 'bun:test';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { createServer, type Socket } from 'node:net';
|
|
5
5
|
import { tmpdir } from 'node:os';
|
|
@@ -12,7 +12,7 @@ import { VERDICT_FILE } from './verdict.js';
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The production runner's built Node artifact, run in its own process, with the real RAM volume and CPU-budget owners.
|
|
15
|
-
* `test-host` already depends on this package's build; these peers must not compile TypeScript inside a test
|
|
15
|
+
* `test-host` already depends on this package's build; these peers must not compile TypeScript inside a test.
|
|
16
16
|
* These proofs need the host (`hdiutil` on darwin), so the pure shards exclude this file.
|
|
17
17
|
*/
|
|
18
18
|
const PACKAGE_ROOT = fileURLToPath(new URL('../../..', import.meta.url));
|
|
@@ -60,7 +60,9 @@ interface ChildRun {
|
|
|
60
60
|
askResources(): void;
|
|
61
61
|
/** Resolves once `marker` has been printed to stdout; rejects if the child exits without printing it. */
|
|
62
62
|
printed(marker: string): Promise<void>;
|
|
63
|
-
/**
|
|
63
|
+
/** Resolves once `marker` has been written to stderr; rejects if the child exits without writing it. */
|
|
64
|
+
said(marker: string): Promise<void>;
|
|
65
|
+
/** Stops a surviving runner with SIGTERM, which it forwards to its command's process tree, and awaits its exit. */
|
|
64
66
|
stop(): Promise<void>;
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -93,16 +95,16 @@ const children = new Set<ChildRun>();
|
|
|
93
95
|
|
|
94
96
|
describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
95
97
|
afterEach(async () => {
|
|
96
|
-
// A child still open here was not awaited by its case:
|
|
97
|
-
//
|
|
98
|
+
// A child still open here was not awaited by its case: the case failed before awaiting it. Its cumulative output is
|
|
99
|
+
// written before anything waits, so a kill of the run during the waits below cannot lose it. Each live runner is
|
|
98
100
|
// also asked, by SIGUSR2, what Node still has active; the answer lands in its stdout before the child closes.
|
|
99
101
|
const live = [...children].filter((child) => !child.closed());
|
|
100
102
|
for (const child of live) {
|
|
101
|
-
process.stderr.write(attribution(child, '
|
|
103
|
+
process.stderr.write(attribution(child, 'before teardown'));
|
|
102
104
|
child.askResources();
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
// Pools close first
|
|
107
|
+
// Pools close first, then every runner still open is stopped: a closed grant never stops a command on its own.
|
|
106
108
|
const outcomes = await Promise.all([...pools].map((pool) => pool.close()));
|
|
107
109
|
pools.clear();
|
|
108
110
|
await Promise.all([...children].map((child) => child.stop()));
|
|
@@ -159,7 +161,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
159
161
|
}
|
|
160
162
|
await expectChurn(churn);
|
|
161
163
|
});
|
|
162
|
-
}
|
|
164
|
+
});
|
|
163
165
|
|
|
164
166
|
it('admits five concurrent RAM leases without blocking the lock holder behind filesystem workers', async () => {
|
|
165
167
|
const root = await createRoot();
|
|
@@ -192,7 +194,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
192
194
|
expect(run.stdout()).toContain('leases-complete');
|
|
193
195
|
expect([...run.stderr().matchAll(/inherited=true tokens=1\/1/g)]).toHaveLength(5);
|
|
194
196
|
});
|
|
195
|
-
}
|
|
197
|
+
});
|
|
196
198
|
|
|
197
199
|
it('holds a parent pool to its count: three siblings on a pool of two never hold more than two', async () => {
|
|
198
200
|
const root = await createRoot();
|
|
@@ -256,7 +258,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
256
258
|
await barrier.close();
|
|
257
259
|
}
|
|
258
260
|
});
|
|
259
|
-
}
|
|
261
|
+
});
|
|
260
262
|
|
|
261
263
|
it('uses a real backing budget after its named pool is absent and returns the allocation', async () => {
|
|
262
264
|
const root = await createRoot();
|
|
@@ -274,7 +276,6 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
274
276
|
script,
|
|
275
277
|
[
|
|
276
278
|
`import assert from 'node:assert/strict';`,
|
|
277
|
-
`import { availableParallelism } from 'node:os';`,
|
|
278
279
|
`import { runBoundedExec, createProcessTreeKiller } from ${JSON.stringify(EXECUTOR)};`,
|
|
279
280
|
`import { readInheritedCpuPool, takeParentCpuTokens } from ${JSON.stringify(join(dirname(EXECUTOR), 'cpu-pool.js'))};`,
|
|
280
281
|
RESOURCES_HANDLER,
|
|
@@ -288,7 +289,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
288
289
|
'let released = 0;',
|
|
289
290
|
'const budget = { async take(want, checkout, command) {',
|
|
290
291
|
' asked.push({ want, checkout, command });',
|
|
291
|
-
' const grant = await takeParentCpuTokens(backing, want
|
|
292
|
+
' const grant = await takeParentCpuTokens(backing, want);',
|
|
292
293
|
' assert(grant.granted, grant.reason);',
|
|
293
294
|
' allocations.push(grant);',
|
|
294
295
|
' return { ...grant, release() { released++; grant.release(); } };',
|
|
@@ -298,7 +299,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
298
299
|
'assert.deepEqual(asked, [{ want: 1, checkout: context.root, command: options.command }]);',
|
|
299
300
|
'assert.equal(released, 1);',
|
|
300
301
|
'await allocations[0].closed;',
|
|
301
|
-
'const returned = await takeParentCpuTokens(backing, 1
|
|
302
|
+
'const returned = await takeParentCpuTokens(backing, 1);',
|
|
302
303
|
'assert(returned.granted, returned.reason);',
|
|
303
304
|
'assert.equal(returned.tokens, 1);',
|
|
304
305
|
'returned.release();',
|
|
@@ -316,31 +317,36 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
316
317
|
expect(run.stdout()).not.toContain('977');
|
|
317
318
|
expect(await readFile(join(directory, VERDICT_FILE), 'utf8')).toMatch(/"tokens":\s*1/);
|
|
318
319
|
});
|
|
319
|
-
}
|
|
320
|
+
});
|
|
320
321
|
|
|
321
|
-
it('
|
|
322
|
+
it('keeps a command running when its parent pool closes under it, and judges it by its own exit', async () => {
|
|
322
323
|
const root = await createRoot();
|
|
324
|
+
const go = join(root, 'go.fifo');
|
|
325
|
+
expect(spawnSync('mkfifo', [go]).status).toBe(0);
|
|
323
326
|
await withPool(2, async (pool) => {
|
|
324
327
|
const run = await startRunner(
|
|
325
328
|
root,
|
|
326
|
-
'
|
|
329
|
+
'outlives',
|
|
327
330
|
{
|
|
328
|
-
command: `
|
|
331
|
+
command: `sh -c 'echo started; read -r line < "$0"; echo finished' '${go}'`,
|
|
329
332
|
timeoutMs: 30_000,
|
|
330
333
|
killAfterMs: 2_000,
|
|
331
334
|
parallelism: 1,
|
|
332
335
|
},
|
|
333
|
-
join(root, '
|
|
336
|
+
join(root, 'outlives'),
|
|
334
337
|
childEnv(pool.environment),
|
|
335
338
|
);
|
|
336
339
|
await run.printed('started');
|
|
337
340
|
const outcome = await pool.close();
|
|
338
341
|
expect(outcome.ok).toBe(true);
|
|
339
|
-
|
|
340
|
-
expect(run.
|
|
341
|
-
|
|
342
|
+
await run.said('cowshed: cpu-tokens grant ended: the parent pool closed its 1-token grant');
|
|
343
|
+
expect(run.closed()).toBe(false);
|
|
344
|
+
await writeFile(go, 'go\n');
|
|
345
|
+
expect(await run.exited, run.stderr()).toBe(0);
|
|
346
|
+
expect(run.stdout()).toContain('finished');
|
|
347
|
+
expect(await readFile(join(root, 'outlives', VERDICT_FILE), 'utf8')).toMatch(/"outcome":\s*"passed"/);
|
|
342
348
|
});
|
|
343
|
-
}
|
|
349
|
+
});
|
|
344
350
|
|
|
345
351
|
it('fails a run whose sub-pool does not close cleanly, even when its command exits 0', async () => {
|
|
346
352
|
const root = await createRoot();
|
|
@@ -379,7 +385,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
|
|
|
379
385
|
await rm(dirname(stuck), { recursive: true, force: true });
|
|
380
386
|
}
|
|
381
387
|
}
|
|
382
|
-
}
|
|
388
|
+
});
|
|
383
389
|
});
|
|
384
390
|
|
|
385
391
|
async function createRoot(): Promise<string> {
|
|
@@ -399,9 +405,10 @@ function childEnv(extra: Readonly<Record<string, string>>): NodeJS.ProcessEnv {
|
|
|
399
405
|
return { ...env, ...extra };
|
|
400
406
|
}
|
|
401
407
|
|
|
402
|
-
/** A parent's CPU pool of `tokens`, open while `body` runs. Its upstream never closes on its own
|
|
408
|
+
/** A parent's CPU pool of `tokens`, open while `body` runs. Its upstream never closes on its own, and no run owns the
|
|
409
|
+
* host waits its children report. */
|
|
403
410
|
async function withPool<T>(tokens: number, body: (pool: CpuPool) => Promise<T>): Promise<T> {
|
|
404
|
-
const created = await createCpuPool(tokens, new Promise<void>(() => {}));
|
|
411
|
+
const created = await createCpuPool(tokens, new Promise<void>(() => {}), { begin() {}, end() {} });
|
|
405
412
|
if (!created.ok) {
|
|
406
413
|
throw new Error(`cpu pool: ${created.error}`);
|
|
407
414
|
}
|
|
@@ -488,6 +495,7 @@ function startChild(script: string, env: NodeJS.ProcessEnv): ChildRun {
|
|
|
488
495
|
});
|
|
489
496
|
child.stderr.on('data', (chunk: Buffer) => {
|
|
490
497
|
err += chunk.toString('utf8');
|
|
498
|
+
wake();
|
|
491
499
|
});
|
|
492
500
|
const exited = new Promise<number | null>((resolve) => {
|
|
493
501
|
const done = (code: number | null): void => {
|
|
@@ -501,6 +509,21 @@ function startChild(script: string, env: NodeJS.ProcessEnv): ChildRun {
|
|
|
501
509
|
});
|
|
502
510
|
child.once('close', (code) => done(code));
|
|
503
511
|
});
|
|
512
|
+
const appeared = (text: () => string, marker: string, what: string): Promise<void> => {
|
|
513
|
+
const { promise, resolve, reject } = Promise.withResolvers<void>();
|
|
514
|
+
const check = (): void => {
|
|
515
|
+
if (text().includes(marker)) {
|
|
516
|
+
waiters.delete(check);
|
|
517
|
+
resolve();
|
|
518
|
+
} else if (closed) {
|
|
519
|
+
waiters.delete(check);
|
|
520
|
+
reject(new Error(`child exited before ${what} ${JSON.stringify(marker)}; stderr:\n${err}`));
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
waiters.add(check);
|
|
524
|
+
check();
|
|
525
|
+
return promise;
|
|
526
|
+
};
|
|
504
527
|
const run: ChildRun = {
|
|
505
528
|
label: basename(script),
|
|
506
529
|
exited,
|
|
@@ -510,21 +533,8 @@ function startChild(script: string, env: NodeJS.ProcessEnv): ChildRun {
|
|
|
510
533
|
askResources(): void {
|
|
511
534
|
child.kill('SIGUSR2');
|
|
512
535
|
},
|
|
513
|
-
printed(marker
|
|
514
|
-
|
|
515
|
-
const check = (): void => {
|
|
516
|
-
if (out.includes(marker)) {
|
|
517
|
-
waiters.delete(check);
|
|
518
|
-
resolve();
|
|
519
|
-
} else if (closed) {
|
|
520
|
-
waiters.delete(check);
|
|
521
|
-
reject(new Error(`child exited before printing ${JSON.stringify(marker)}; stderr:\n${err}`));
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
waiters.add(check);
|
|
525
|
-
check();
|
|
526
|
-
});
|
|
527
|
-
},
|
|
536
|
+
printed: (marker) => appeared(() => out, marker, 'printing'),
|
|
537
|
+
said: (marker) => appeared(() => err, marker, 'writing to stderr'),
|
|
528
538
|
async stop(): Promise<void> {
|
|
529
539
|
if (!closed) child.kill('SIGTERM');
|
|
530
540
|
await exited;
|
|
@@ -536,7 +546,7 @@ function startChild(script: string, env: NodeJS.ProcessEnv): ChildRun {
|
|
|
536
546
|
|
|
537
547
|
/**
|
|
538
548
|
* What a runner has printed and written so far, named by its script and the stage it is attributed at. Cumulative and
|
|
539
|
-
* untrimmed: a
|
|
549
|
+
* untrimmed: a runner still open at teardown says what it was doing, not just that it never finished.
|
|
540
550
|
*/
|
|
541
551
|
function attribution(child: ChildRun, stage: string): string {
|
|
542
552
|
return [
|