@smoothbricks/nx-plugin 0.5.2 → 0.5.4
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 +40 -9
- package/dist/cargo-source-hash.d.ts +2 -2
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +106 -46
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +13 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-tokens.js +9 -9
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +20 -6
- package/dist/executors/bounded-exec/progress.d.ts +8 -3
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +100 -10
- package/dist/executors/bounded-exec/verdict.d.ts +5 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +1 -0
- package/dist/testing.js +1 -1
- package/managed/raw/patches/nx@23.2.1.patch +208 -45
- package/package.json +2 -2
- package/src/cargo-source-hash.test.ts +143 -2
- package/src/cargo-source-hash.ts +108 -44
- package/src/executors/bounded-exec/cpu-tokens.ts +15 -9
- package/src/executors/bounded-exec/executor.test.ts +26 -23
- package/src/executors/bounded-exec/executor.ts +19 -4
- package/src/executors/bounded-exec/go-progress-host.test.ts +171 -0
- package/src/executors/bounded-exec/progress.test.ts +73 -0
- package/src/executors/bounded-exec/progress.ts +95 -12
- package/src/executors/bounded-exec/verdict.ts +5 -4
- package/src/nx-daemon-start-never.test.ts +155 -0
- package/src/nx-task-output-lease.test.ts +136 -0
- package/src/testing.ts +1 -1
- package/test-timings.json +92 -91
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
2
3
|
import { channel } from 'node:diagnostics_channel';
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, readlinkSync, realpathSync } from 'node:fs';
|
|
3
5
|
import { mkdir, readdir, readFile, symlink, writeFile } from 'node:fs/promises';
|
|
4
6
|
import { join } from 'node:path';
|
|
5
7
|
import type { Subprocess } from 'bun';
|
|
@@ -247,6 +249,140 @@ it('shares ownership across configurations without blocking independent targets,
|
|
|
247
249
|
}
|
|
248
250
|
});
|
|
249
251
|
|
|
252
|
+
/** One output target of its own, so persistent lock files from other runs never contend. */
|
|
253
|
+
function leaseTask(target: string) {
|
|
254
|
+
return {
|
|
255
|
+
id: `${target}:build`,
|
|
256
|
+
target: { project: `${target}-${crypto.randomUUID()}`, target: 'build' },
|
|
257
|
+
overrides: {},
|
|
258
|
+
outputs: ['app/dist'],
|
|
259
|
+
cache: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The helper pid a held lease's lock file names; the file is the helper's own record. */
|
|
264
|
+
async function leaseHolder(path: string): Promise<number> {
|
|
265
|
+
const record: unknown = JSON.parse(await readFile(path, 'utf8'));
|
|
266
|
+
if (typeof record !== 'object' || record === null || !('pid' in record) || typeof record.pid !== 'number') {
|
|
267
|
+
throw new Error(`lease file ${path} names no helper pid`);
|
|
268
|
+
}
|
|
269
|
+
return record.pid;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** The lock path of the next lease `acquire` asks for, read from the diagnostics channel it publishes before waiting. */
|
|
273
|
+
function nextLeasePath(): Promise<string> {
|
|
274
|
+
const path = Promise.withResolvers<string>();
|
|
275
|
+
const events = channel('nx:task-output-lease');
|
|
276
|
+
const onEvent = (message: unknown) => {
|
|
277
|
+
if (typeof message !== 'object' || message === null || !('phase' in message) || message.phase !== 'waiting') return;
|
|
278
|
+
events.unsubscribe(onEvent);
|
|
279
|
+
if ('paths' in message && Array.isArray(message.paths) && typeof message.paths[0] === 'string')
|
|
280
|
+
path.resolve(message.paths[0]);
|
|
281
|
+
else path.reject(new Error(`waiting event names no lock path: ${JSON.stringify(message)}`));
|
|
282
|
+
};
|
|
283
|
+
events.subscribe(onEvent);
|
|
284
|
+
return path.promise;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Whether process `pid` is reaped: the parent's exit handler has then run in the same libuv callback. */
|
|
288
|
+
async function reaped(pid: number): Promise<void> {
|
|
289
|
+
for (;;) {
|
|
290
|
+
try {
|
|
291
|
+
process.kill(pid, 0);
|
|
292
|
+
} catch {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const turn = Promise.withResolvers<void>();
|
|
296
|
+
setImmediate(turn.resolve);
|
|
297
|
+
await turn.promise;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
it('wakes a waiter with the slot of a helper that died holding a lease, failing only the holder', async () => {
|
|
302
|
+
const leases = new TaskOutputLeases(1, null, 'output');
|
|
303
|
+
try {
|
|
304
|
+
const heldPath = nextLeasePath();
|
|
305
|
+
const release = await leases.acquire([leaseTask('held')]);
|
|
306
|
+
const helper = await leaseHolder(await heldPath);
|
|
307
|
+
// The one slot is taken, so this waits for it.
|
|
308
|
+
const waiting = leases.acquire([leaseTask('queued')]);
|
|
309
|
+
process.kill(helper, 'SIGKILL');
|
|
310
|
+
await expect(release()).rejects.toThrow('worker exited (code null, signal SIGKILL)');
|
|
311
|
+
// The helper's exit freed its slot: the waiter forks a successor rather than waiting for a release no one can send.
|
|
312
|
+
const releaseQueued = await guardEvent(waiting, "a waiter for a dead helper's slot", () => 'no successor helper');
|
|
313
|
+
await releaseQueued();
|
|
314
|
+
} finally {
|
|
315
|
+
await leases.close();
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('retires a helper that replied with an error, so the next acquire takes its slot', async () => {
|
|
320
|
+
const leases = new TaskOutputLeases(1, null, 'output');
|
|
321
|
+
try {
|
|
322
|
+
// The helper cannot open a lock path that is a directory, so it replies with an error and serves no more.
|
|
323
|
+
const blockedPath = nextLeasePath().then((path) => mkdirSync(path, { recursive: true }));
|
|
324
|
+
const refused = leases.acquire([leaseTask('unopenable')]);
|
|
325
|
+
await blockedPath;
|
|
326
|
+
await expect(refused).rejects.toThrow('failed:');
|
|
327
|
+
const release = await guardEvent(
|
|
328
|
+
leases.acquire([leaseTask('after-error')]),
|
|
329
|
+
'an acquire after a helper replied with an error',
|
|
330
|
+
() => 'the failed helper still holds the only slot',
|
|
331
|
+
);
|
|
332
|
+
await release();
|
|
333
|
+
} finally {
|
|
334
|
+
await leases.close();
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('does not hand an idle helper that died to the next acquire', async () => {
|
|
339
|
+
const leases = new TaskOutputLeases(1, null, 'output');
|
|
340
|
+
try {
|
|
341
|
+
const idlePath = nextLeasePath();
|
|
342
|
+
const release = await leases.acquire([leaseTask('idle')]);
|
|
343
|
+
const helper = await leaseHolder(await idlePath);
|
|
344
|
+
await release();
|
|
345
|
+
process.kill(helper, 'SIGKILL');
|
|
346
|
+
await reaped(helper);
|
|
347
|
+
const releaseNext = await guardEvent(
|
|
348
|
+
leases.acquire([leaseTask('after-idle-death')]),
|
|
349
|
+
'an acquire after the idle helper died',
|
|
350
|
+
() => 'no successor helper',
|
|
351
|
+
);
|
|
352
|
+
await releaseNext();
|
|
353
|
+
} finally {
|
|
354
|
+
await leases.close();
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
/** The descriptors process `pid` holds open on `file`: /proc on Linux, lsof elsewhere, both naming its real path. */
|
|
359
|
+
function openDescriptors(pid: number, file: string): number {
|
|
360
|
+
const path = realpathSync(file);
|
|
361
|
+
const proc = `/proc/${pid}/fd`;
|
|
362
|
+
if (existsSync(proc)) return readdirSync(proc).filter((fd) => readlinkSync(join(proc, fd)) === path).length;
|
|
363
|
+
const listed = spawnSync('lsof', ['-nP', '-p', String(pid), '-Fn'], { encoding: 'utf8' });
|
|
364
|
+
if (listed.status !== 0 && listed.stdout === '') throw new Error(`lsof -p ${pid} failed: ${listed.stderr}`);
|
|
365
|
+
return listed.stdout.split('\n').filter((line) => line === `n${path}`).length;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
it('keeps one lock descriptor per lock file in a helper across acquires', async () => {
|
|
369
|
+
const leases = new TaskOutputLeases(1, null, 'output');
|
|
370
|
+
const task = leaseTask('repeated');
|
|
371
|
+
try {
|
|
372
|
+
const counts: number[] = [];
|
|
373
|
+
for (let round = 0; round < 5; round++) {
|
|
374
|
+
const pathEvent = nextLeasePath();
|
|
375
|
+
const release = await leases.acquire([task]);
|
|
376
|
+
const path = await pathEvent;
|
|
377
|
+
counts.push(openDescriptors(await leaseHolder(path), path));
|
|
378
|
+
await release();
|
|
379
|
+
}
|
|
380
|
+
expect(counts).toEqual([1, 1, 1, 1, 1]);
|
|
381
|
+
} finally {
|
|
382
|
+
await leases.close();
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
250
386
|
it('refuses an ancestor-owned target before waiting for its output lease', async () => {
|
|
251
387
|
await withNxFixture('nx-task-output-loop-', async ({ workspace, socketDirectory }) => {
|
|
252
388
|
await mkdir(join(workspace, 'app'));
|
package/src/testing.ts
CHANGED
|
@@ -168,7 +168,7 @@ export async function pidsWorkingIn(root: string): Promise<number[]> {
|
|
|
168
168
|
for (const pid of (await readdir('/proc')).filter((name) => /^\d+$/.test(name))) {
|
|
169
169
|
const cwd = await readlink(`/proc/${pid}/cwd`).catch((error: unknown) => {
|
|
170
170
|
// Another user's process, or one that exited since the listing.
|
|
171
|
-
if (errorCode(error) === 'EACCES' || errorCode(error) === 'ENOENT') {
|
|
171
|
+
if (errorCode(error) === 'EACCES' || errorCode(error) === 'ENOENT' || errorCode(error) === 'ESRCH') {
|
|
172
172
|
return null;
|
|
173
173
|
}
|
|
174
174
|
throw error;
|
package/test-timings.json
CHANGED
|
@@ -1,101 +1,102 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
3
|
"files": {
|
|
4
|
-
"src/ensure-built.test.ts":
|
|
5
|
-
"src/
|
|
6
|
-
"src/
|
|
7
|
-
"src/
|
|
8
|
-
"src/task-results.test.ts":
|
|
9
|
-
"src/nx-daemon-
|
|
10
|
-
"src/
|
|
11
|
-
"src/
|
|
12
|
-
"src/
|
|
13
|
-
"src/
|
|
14
|
-
"src/
|
|
15
|
-
"src/nx-use-local.test.ts":
|
|
16
|
-
"src/
|
|
17
|
-
"src/
|
|
18
|
-
"src/executors/bounded-exec/
|
|
19
|
-
"src/
|
|
20
|
-
"src/
|
|
21
|
-
"src/
|
|
22
|
-
"src/
|
|
23
|
-
"src/
|
|
24
|
-
"src/
|
|
25
|
-
"src/
|
|
26
|
-
"src/nx-
|
|
27
|
-
"src/nx-
|
|
28
|
-
"src/
|
|
29
|
-
"src/
|
|
30
|
-
"src/
|
|
31
|
-
"src/
|
|
32
|
-
"src/nx-
|
|
33
|
-
"src/managed-files/
|
|
34
|
-
"src/
|
|
35
|
-
"src/nx-
|
|
36
|
-
"src/
|
|
37
|
-
"src/
|
|
38
|
-
"src/
|
|
39
|
-
"src/
|
|
40
|
-
"src/
|
|
41
|
-
"src/nx-
|
|
42
|
-
"src/nx-skipped-task-exit.test.ts":
|
|
43
|
-
"src/
|
|
44
|
-
"src/nx-
|
|
45
|
-
"src/
|
|
46
|
-
"src/
|
|
47
|
-
"src/
|
|
48
|
-
"src/
|
|
49
|
-
"src/nx-
|
|
50
|
-
"src/nx-
|
|
51
|
-
"src/
|
|
52
|
-
"src/
|
|
53
|
-
"src/
|
|
54
|
-
"src/
|
|
55
|
-
"src/
|
|
56
|
-
"src/
|
|
57
|
-
"src/test-
|
|
58
|
-
"src/
|
|
59
|
-
"src/
|
|
60
|
-
"src/package-target-policy.test.ts": 406,
|
|
4
|
+
"src/ensure-built.test.ts": 74030,
|
|
5
|
+
"src/nextest-partitions.test.ts": 65735,
|
|
6
|
+
"src/nx-daemon-validity.test.ts": 61972,
|
|
7
|
+
"src/cargo-resolve-cache.test.ts": 59317,
|
|
8
|
+
"src/task-results.test.ts": 57421,
|
|
9
|
+
"src/nx-daemon-ignore-files.test.ts": 50341,
|
|
10
|
+
"src/cargo-closure-key.test.ts": 26380,
|
|
11
|
+
"src/linked-snapshots.nx.test.ts": 25519,
|
|
12
|
+
"src/testing.test.ts": 23681,
|
|
13
|
+
"src/nx-daemon-claim.test.ts": 21992,
|
|
14
|
+
"src/cargo-closure-input.test.ts": 20555,
|
|
15
|
+
"src/nx-use-local.test.ts": 19732,
|
|
16
|
+
"src/owned-installation.test.ts": 15674,
|
|
17
|
+
"src/cargo-source-hash.test.ts": 14605,
|
|
18
|
+
"src/executors/bounded-exec/executor.test.ts": 12053,
|
|
19
|
+
"src/index.test.ts": 10682,
|
|
20
|
+
"src/executors/bounded-exec/ram-temp.test.ts": 9310,
|
|
21
|
+
"src/nx-project-graph-errors.test.ts": 7876,
|
|
22
|
+
"src/ensure-built-receipt.test.ts": 7171,
|
|
23
|
+
"src/cross-check-policy.test.ts": 7162,
|
|
24
|
+
"src/runtime-input.test.ts": 7097,
|
|
25
|
+
"src/nx-dot-input-policy.test.ts": 7064,
|
|
26
|
+
"src/nx-failure-life-cycles.test.ts": 6163,
|
|
27
|
+
"src/nx-plugin-load-errors.test.ts": 5908,
|
|
28
|
+
"src/bounded-test-policy.test.ts": 5876,
|
|
29
|
+
"src/task-history-namespace.test.ts": 5536,
|
|
30
|
+
"src/nx-cache-restore-mtime.test.ts": 5437,
|
|
31
|
+
"src/nx-daemon-idle-policy.test.ts": 5013,
|
|
32
|
+
"src/nx-task-output-lease.test.ts": 4643,
|
|
33
|
+
"src/managed-files/forgejo-artifact.test.ts": 4427,
|
|
34
|
+
"src/nx-foreign-workspace-env.test.ts": 4198,
|
|
35
|
+
"src/bin/smoo-nx-bound-failures.test.ts": 4008,
|
|
36
|
+
"src/graph-input-contract.test.ts": 3739,
|
|
37
|
+
"src/nextest-extraction.test.ts": 3656,
|
|
38
|
+
"src/nx-incomplete-run-summary.test.ts": 3519,
|
|
39
|
+
"src/executors/typescript-emit/executor.test.ts": 3508,
|
|
40
|
+
"src/managed-files/managed-format-json.test.ts": 3336,
|
|
41
|
+
"src/nx-resident-graph-workers.test.ts": 3195,
|
|
42
|
+
"src/nx-skipped-task-exit.test.ts": 3087,
|
|
43
|
+
"src/nx-daemon-start-never.test.ts": 3021,
|
|
44
|
+
"src/nx-daemon-root-normalization.test.ts": 2795,
|
|
45
|
+
"src/nx-files-archive-racy.test.ts": 2678,
|
|
46
|
+
"src/typescript-resolution.test.ts": 2312,
|
|
47
|
+
"src/nextest-code-bound.test.ts": 2293,
|
|
48
|
+
"src/serial-group-wiring.test.ts": 2149,
|
|
49
|
+
"src/nx-store-resolution.test.ts": 1902,
|
|
50
|
+
"src/nx-cache-bound.test.ts": 1821,
|
|
51
|
+
"src/managed-files/repo-path.test.ts": 1820,
|
|
52
|
+
"src/typecheck-test-policy.test.ts": 1716,
|
|
53
|
+
"src/executors/bounded-exec/verdict.test.ts": 1674,
|
|
54
|
+
"src/managed-files/generator.test.ts": 1580,
|
|
55
|
+
"src/nx-raw-inputs.test.ts": 1373,
|
|
56
|
+
"src/package-target-policy.test.ts": 1277,
|
|
57
|
+
"src/test-walk-policy.test.ts": 1157,
|
|
58
|
+
"src/test-clock-policy.test.ts": 798,
|
|
59
|
+
"src/bun-bootstrap.test.ts": 595,
|
|
61
60
|
"src/nx-state-location.test.ts": 323,
|
|
62
|
-
"src/
|
|
63
|
-
"src/
|
|
64
|
-
"src/managed-files/github-host-cache-isolation.test.ts":
|
|
65
|
-
"src/
|
|
66
|
-
"src/
|
|
67
|
-
"src/
|
|
68
|
-
"src/cargo-closure-filesets.test.ts":
|
|
69
|
-
"src/
|
|
70
|
-
"src/
|
|
71
|
-
"src/
|
|
72
|
-
"src/
|
|
73
|
-
"src/producer-receipts.test.ts":
|
|
74
|
-
"src/
|
|
75
|
-
"src/
|
|
76
|
-
"src/executors/bounded-exec/
|
|
77
|
-
"src/
|
|
78
|
-
"src/
|
|
79
|
-
"src/managed-files/tree-permissions.test.ts": 35,
|
|
80
|
-
"src/generators/create-package/generator.test.ts": 33,
|
|
81
|
-
"src/generators/bun-test-tracing/generator.test.ts": 32,
|
|
82
|
-
"src/test-program.test.ts": 32,
|
|
61
|
+
"src/ensure-built-witness.test.ts": 321,
|
|
62
|
+
"src/version-actions.test.ts": 280,
|
|
63
|
+
"src/managed-files/github-host-cache-isolation.test.ts": 264,
|
|
64
|
+
"src/executors/bounded-exec/hang-diagnostics.test.ts": 238,
|
|
65
|
+
"src/cargo-workspace.test.ts": 220,
|
|
66
|
+
"src/executors/bounded-exec/cpu-pool.test.ts": 155,
|
|
67
|
+
"src/cargo-closure-filesets.test.ts": 100,
|
|
68
|
+
"src/test-timings.test.ts": 99,
|
|
69
|
+
"src/manifest-hash.test.ts": 97,
|
|
70
|
+
"src/release-config-policy.test.ts": 97,
|
|
71
|
+
"src/managed-files/setup-devenv-free-disk.test.ts": 85,
|
|
72
|
+
"src/producer-receipts.test.ts": 82,
|
|
73
|
+
"src/workspace-config-policy.test.ts": 78,
|
|
74
|
+
"src/managed-files/tree-permissions.test.ts": 50,
|
|
75
|
+
"src/executors/bounded-exec/cpu-tokens.test.ts": 35,
|
|
76
|
+
"src/generators/make-public/generator.test.ts": 30,
|
|
77
|
+
"src/managed-files/trace-db-artifact.test.ts": 30,
|
|
83
78
|
"src/executors/nextest-group/executor.test.ts": 28,
|
|
84
|
-
"src/
|
|
85
|
-
"src/generators/
|
|
79
|
+
"src/generators/create-package/generator.test.ts": 28,
|
|
80
|
+
"src/generators/bun-test-tracing/generator.test.ts": 24,
|
|
81
|
+
"src/executors/bounded-exec/disk-lease.test.ts": 22,
|
|
86
82
|
"src/executors/bounded-exec/run-cpu-pool.test.ts": 22,
|
|
87
|
-
"src/
|
|
88
|
-
"src/
|
|
89
|
-
"src/
|
|
90
|
-
"src/
|
|
91
|
-
"src/executors/cargo-zigbuild/executor.test.ts": 19,
|
|
83
|
+
"src/executors/cargo-zigbuild/executor.test.ts": 22,
|
|
84
|
+
"src/build-state-output-policy.test.ts": 20,
|
|
85
|
+
"src/disk-command-policy.test.ts": 19,
|
|
86
|
+
"src/generators/bounded-test-targets/generator.test.ts": 19,
|
|
92
87
|
"src/host-controller-wiring.test.ts": 19,
|
|
88
|
+
"src/nx-daemon-idle-cpu.test.ts": 19,
|
|
89
|
+
"src/cargo-closure-input.property.test.ts": 18,
|
|
90
|
+
"src/executors/bounded-exec/ram-temp-held.test.ts": 15,
|
|
93
91
|
"src/executors/clean-outputs/executor.test.ts": 15,
|
|
94
|
-
"src/
|
|
95
|
-
"src/
|
|
96
|
-
"src/
|
|
97
|
-
"src/
|
|
98
|
-
"src/
|
|
99
|
-
"src/
|
|
92
|
+
"src/nx-task-graph-cycles.test.ts": 14,
|
|
93
|
+
"src/test-program.test.ts": 14,
|
|
94
|
+
"src/bun-file-packages.test.ts": 13,
|
|
95
|
+
"src/nx-project-resolution-cache.test.ts": 13,
|
|
96
|
+
"src/managed-files/json-edit.test.ts": 11,
|
|
97
|
+
"src/executors/bounded-exec/progress.test.ts": 10,
|
|
98
|
+
"src/managed-files/tree.test.ts": 10,
|
|
99
|
+
"src/managed-files/managed-content.test.ts": 9,
|
|
100
|
+
"src/nx-run-information.test.ts": 9
|
|
100
101
|
}
|
|
101
102
|
}
|