@smoothbricks/nx-plugin 0.4.27 → 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 +363 -125
- 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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { once } from 'node:events';
|
|
2
4
|
import {
|
|
3
5
|
chmodSync,
|
|
4
6
|
existsSync,
|
|
@@ -14,10 +16,11 @@ import {
|
|
|
14
16
|
} from 'node:fs';
|
|
15
17
|
import { tmpdir, userInfo } from 'node:os';
|
|
16
18
|
import { join } from 'node:path';
|
|
19
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
17
20
|
import { fileURLToPath } from 'node:url';
|
|
18
21
|
import type { OpContextBinding } from '@smoothbricks/lmao';
|
|
19
22
|
import { useTestSpan } from '@smoothbricks/lmao/testing/bun';
|
|
20
|
-
import {
|
|
23
|
+
import { processTable, terminate } from '../../testing.js';
|
|
21
24
|
import {
|
|
22
25
|
type CommandOutput,
|
|
23
26
|
createHostCommands,
|
|
@@ -25,6 +28,7 @@ import {
|
|
|
25
28
|
leaseProcessesOn,
|
|
26
29
|
mountsBelow,
|
|
27
30
|
operationDisk,
|
|
31
|
+
pidsInLease,
|
|
28
32
|
type RamDisk,
|
|
29
33
|
type RamTempError,
|
|
30
34
|
type RamTempPaths,
|
|
@@ -121,7 +125,7 @@ async function nativeRamVolume(): Promise<void> {
|
|
|
121
125
|
async workingIn(directory) {
|
|
122
126
|
const startedAt = Date.now();
|
|
123
127
|
const starting = JSON.stringify({
|
|
124
|
-
phase: '
|
|
128
|
+
phase: 'lease-census-start',
|
|
125
129
|
directory,
|
|
126
130
|
pid: process.pid,
|
|
127
131
|
wallAtMs: startedAt,
|
|
@@ -130,10 +134,10 @@ async function nativeRamVolume(): Promise<void> {
|
|
|
130
134
|
trace.log.info(starting);
|
|
131
135
|
process.stderr.write(`${starting}\n`);
|
|
132
136
|
try {
|
|
133
|
-
const pids = await
|
|
137
|
+
const pids = await pidsInLease(directory);
|
|
134
138
|
const endedAt = Date.now();
|
|
135
139
|
const finished = JSON.stringify({
|
|
136
|
-
phase: '
|
|
140
|
+
phase: 'lease-census-end',
|
|
137
141
|
directory,
|
|
138
142
|
pid: process.pid,
|
|
139
143
|
wallAtMs: endedAt,
|
|
@@ -149,7 +153,7 @@ async function nativeRamVolume(): Promise<void> {
|
|
|
149
153
|
const details = typeof error === 'object' && error !== null ? error : {};
|
|
150
154
|
const failed = JSON.stringify(
|
|
151
155
|
{
|
|
152
|
-
phase: '
|
|
156
|
+
phase: 'lease-census-error',
|
|
153
157
|
directory,
|
|
154
158
|
pid: process.pid,
|
|
155
159
|
wallAtMs: endedAt,
|
|
@@ -364,17 +368,45 @@ async function nativeRamVolume(): Promise<void> {
|
|
|
364
368
|
expect(statSync(join(leaseB.directory, 'tree')).mode & 0o777).toBe(0o555);
|
|
365
369
|
|
|
366
370
|
// Once its owner has detached the image, the next task reclaims the lease, and its release,
|
|
367
|
-
// the last, detaches the volume.
|
|
371
|
+
// the last, detaches the volume. The dead task left a writer behind, as a test's ttsc plugin
|
|
372
|
+
// build is left: working elsewhere, writing into the lease through its TMPDIR, with a child.
|
|
373
|
+
// The pid the lease is named after is dead; the writer is stopped before the lease goes, so
|
|
374
|
+
// its removal never meets a file made after the lease was judged dead. A second dead lease,
|
|
375
|
+
// that nothing works in, is reclaimed beside it.
|
|
368
376
|
attachedBelow.image = null;
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
377
|
+
const writer = spawn('sh', ['-c', 'sleep 600 & echo $!; i=0; while :; do i=$((i+1)); : > "$TMPDIR/w$i"; done'], {
|
|
378
|
+
cwd: parent,
|
|
379
|
+
env: { ...process.env, TMPDIR: leaseB.directory },
|
|
380
|
+
detached: true,
|
|
381
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
382
|
+
});
|
|
383
|
+
const writerExited = once(writer, 'close');
|
|
384
|
+
const writerChild = Number(String((await once(writer.stdout, 'data'))[0]).trim());
|
|
385
|
+
const quiet = join(paths.mountpoint, '303-quiet1');
|
|
386
|
+
mkdirSync(quiet);
|
|
387
|
+
writeFileSync(join(quiet, 'left'), 'by a task nothing of which still runs');
|
|
388
|
+
try {
|
|
389
|
+
while (!existsSync(join(leaseB.directory, 'w1'))) {
|
|
390
|
+
await sleep(5);
|
|
391
|
+
}
|
|
392
|
+
const fourth = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
|
|
393
|
+
const d = await fourth.acquire();
|
|
394
|
+
if (!d.ok || d.value.kind !== 'leased') {
|
|
395
|
+
throw new Error(`fourth lease failed: ${JSON.stringify(d)}`);
|
|
396
|
+
}
|
|
397
|
+
expect(d.value.held).toEqual([]);
|
|
398
|
+
expect(d.value.reaped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
|
|
399
|
+
[writer.pid ?? 0, writerChild].sort((a, b) => a - b),
|
|
400
|
+
);
|
|
401
|
+
expect(existsSync(leaseB.directory)).toBe(false);
|
|
402
|
+
expect(existsSync(quiet)).toBe(false);
|
|
403
|
+
expectUntouched(outside);
|
|
404
|
+
expect(await fourth.release(d.value.lease)).toEqual({ ok: true, value: undefined });
|
|
405
|
+
} finally {
|
|
406
|
+
terminate(writer.pid ?? 0, 'SIGKILL');
|
|
407
|
+
terminate(writerChild, 'SIGKILL');
|
|
408
|
+
await writerExited;
|
|
373
409
|
}
|
|
374
|
-
expect(d.value.held).toEqual([]);
|
|
375
|
-
expect(existsSync(leaseB.directory)).toBe(false);
|
|
376
|
-
expectUntouched(outside);
|
|
377
|
-
expect(await fourth.release(d.value.lease)).toEqual({ ok: true, value: undefined });
|
|
378
410
|
expect(existsSync(paths.mountpoint)).toBe(false);
|
|
379
411
|
expect(await attachedDisks(paths, capacity)).toEqual([]);
|
|
380
412
|
} finally {
|
|
@@ -588,18 +620,15 @@ describe('temporary-directory policy on this host', () => {
|
|
|
588
620
|
it(
|
|
589
621
|
'reclaims what a dead creator left, shares the volume between leases, and detaches it at the last release, never mounting beside it as "<name> 1"',
|
|
590
622
|
nativeRamVolume,
|
|
591
|
-
60_000,
|
|
592
623
|
);
|
|
593
624
|
it(
|
|
594
625
|
'leaves no volume under its final name, and no staging directory, when any provisioning step fails',
|
|
595
626
|
aFailedStepLeavesNoNamedVolume,
|
|
596
|
-
180_000,
|
|
597
627
|
);
|
|
598
628
|
} else {
|
|
599
629
|
it(
|
|
600
630
|
'keeps inherited temporary storage, honors a target override, and never provisions an APFS disk',
|
|
601
631
|
inheritedTempDirectory,
|
|
602
|
-
30_000,
|
|
603
632
|
);
|
|
604
633
|
}
|
|
605
634
|
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
2
|
import { execFileSync, spawn } from 'node:child_process';
|
|
3
3
|
import { once } from 'node:events';
|
|
4
|
-
import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
4
|
+
import { mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync } from 'node:fs';
|
|
5
5
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { createServer, type Socket } from 'node:net';
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { createInterface } from 'node:readline';
|
|
10
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
10
11
|
import { awaitExit, ownedSocketDirectory, pidsWorkingIn, processTable, terminate } from '../../testing.js';
|
|
11
12
|
import {
|
|
12
13
|
COWSHED_EXECUTABLE_ENV,
|
|
@@ -186,7 +187,7 @@ describe('RAM temp volume on this host', () => {
|
|
|
186
187
|
const spawned = result.stdout.trim();
|
|
187
188
|
expect(spawned).toMatch(/^\d+$/);
|
|
188
189
|
// Gone, or a zombie its new parent has yet to reap: either way no longer running.
|
|
189
|
-
const state = await createHostCommands().run('
|
|
190
|
+
const state = await createHostCommands().run('ps', ['-o', 'stat=', '-p', spawned]);
|
|
190
191
|
expect(state.status === 1 || state.stdout.trim().startsWith('Z')).toBe(true);
|
|
191
192
|
});
|
|
192
193
|
|
|
@@ -658,15 +659,76 @@ describe('processes a task left working in its RAM lease', () => {
|
|
|
658
659
|
}
|
|
659
660
|
});
|
|
660
661
|
|
|
662
|
+
it('stops what writes into the lease through its TMPDIR from elsewhere, so the lease can be removed', async () => {
|
|
663
|
+
const lease = scratch();
|
|
664
|
+
const elsewhere = scratch();
|
|
665
|
+
// As a dead task's ttsc plugin build leaves it: working in its project, writing into `$TMPDIR`
|
|
666
|
+
// as fast as it can (shell builtins only, so it forks nothing), with a child of its own. macOS
|
|
667
|
+
// spells TMPDIR with a trailing slash.
|
|
668
|
+
const writer = spawn('sh', ['-c', 'sleep 600 & echo $!; i=0; while :; do i=$((i+1)); : > "$TMPDIR/w$i"; done'], {
|
|
669
|
+
cwd: elsewhere,
|
|
670
|
+
env: { ...process.env, TMPDIR: `${lease}/` },
|
|
671
|
+
detached: true,
|
|
672
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
673
|
+
});
|
|
674
|
+
// Another, started on its own with a TMPDIR beneath the lease.
|
|
675
|
+
mkdirSync(join(lease, 'nested'));
|
|
676
|
+
const nested = spawn('sleep', ['600'], {
|
|
677
|
+
cwd: elsewhere,
|
|
678
|
+
env: { ...process.env, TMPDIR: join(lease, 'nested') },
|
|
679
|
+
detached: true,
|
|
680
|
+
stdio: 'ignore',
|
|
681
|
+
});
|
|
682
|
+
const exited = [once(writer, 'close'), once(nested, 'close')];
|
|
683
|
+
const pids = [writer.pid ?? 0, nested.pid ?? 0];
|
|
684
|
+
let child = 0;
|
|
685
|
+
try {
|
|
686
|
+
child = Number(String((await once(writer.stdout, 'data'))[0]).trim());
|
|
687
|
+
while (readdirSync(lease).length < 2) {
|
|
688
|
+
await sleep(5);
|
|
689
|
+
}
|
|
690
|
+
// None of them works in the lease by its working directory.
|
|
691
|
+
expect(await pidsWorkingIn(lease)).toEqual([]);
|
|
692
|
+
|
|
693
|
+
const stopped = await hostLeaseProcesses.stopWorkingIn(lease);
|
|
694
|
+
|
|
695
|
+
expect(stopped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
|
|
696
|
+
[...pids, child].sort((a, b) => a - b),
|
|
697
|
+
);
|
|
698
|
+
expect(await liveAmong([...pids, child])).toEqual([]);
|
|
699
|
+
// Nothing writes there any more: the lease goes whole, with no ENOTEMPTY.
|
|
700
|
+
await rm(lease, { recursive: true });
|
|
701
|
+
} finally {
|
|
702
|
+
for (const pid of [...pids, child]) {
|
|
703
|
+
if (pid !== 0) {
|
|
704
|
+
terminate(pid, 'SIGKILL');
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
await Promise.all(exited);
|
|
708
|
+
rmSync(lease, { recursive: true, force: true });
|
|
709
|
+
rmSync(elsewhere, { recursive: true, force: true });
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
661
713
|
it('stops nothing in a lease no process works in, and nothing that works elsewhere', async () => {
|
|
662
714
|
const lease = scratch();
|
|
663
715
|
const elsewhere = scratch();
|
|
664
716
|
const bystander = spawn('sleep', ['600'], { cwd: elsewhere, detached: true, stdio: 'ignore' });
|
|
717
|
+
// A TMPDIR that only starts with the lease's name is another directory.
|
|
718
|
+
const sibling = spawn('sleep', ['600'], {
|
|
719
|
+
cwd: elsewhere,
|
|
720
|
+
env: { ...process.env, TMPDIR: `${lease}x` },
|
|
721
|
+
detached: true,
|
|
722
|
+
stdio: 'ignore',
|
|
723
|
+
});
|
|
665
724
|
try {
|
|
666
725
|
expect(await hostLeaseProcesses.stopWorkingIn(lease)).toEqual([]);
|
|
667
|
-
|
|
726
|
+
for (const left of [bystander, sibling]) {
|
|
727
|
+
expect(left.exitCode === null && left.signalCode === null).toBe(true);
|
|
728
|
+
}
|
|
668
729
|
} finally {
|
|
669
730
|
bystander.kill('SIGKILL');
|
|
731
|
+
sibling.kill('SIGKILL');
|
|
670
732
|
rmSync(lease, { recursive: true, force: true });
|
|
671
733
|
rmSync(elsewhere, { recursive: true, force: true });
|
|
672
734
|
}
|
|
@@ -22,6 +22,7 @@ import { setTimeout as sleep } from 'node:timers/promises';
|
|
|
22
22
|
import {
|
|
23
23
|
awaitExit,
|
|
24
24
|
type ProcessEntry,
|
|
25
|
+
pidsWithTempIn,
|
|
25
26
|
pidsWorkingIn,
|
|
26
27
|
processTable,
|
|
27
28
|
terminate,
|
|
@@ -80,7 +81,11 @@ import {
|
|
|
80
81
|
* checks that the volume, the lease directory and its own claim are still as
|
|
81
82
|
* it claimed them. A lease is a directory named after the task process's pid;
|
|
82
83
|
* a lease whose pid is gone is reclaimed by the next task, and the volume is
|
|
83
|
-
* detached when the last lease ends.
|
|
84
|
+
* detached when the last lease ends. The pid's death proves only that the task
|
|
85
|
+
* process is gone, not what it started: its command runs in a process group of
|
|
86
|
+
* its own, and every process started with the lease as its `TMPDIR` writes
|
|
87
|
+
* there wherever it works. So a dead lease is removed only once every process
|
|
88
|
+
* working in it, by working directory or by `TMPDIR`, has been stopped.
|
|
84
89
|
*
|
|
85
90
|
* The volume is created under its final name and never renamed. It is mounted by `mount_apfs` at a
|
|
86
91
|
* private staging directory and marked there; the kernel then unmounts it (`umount`) and `diskutil mount`, the
|
|
@@ -180,16 +185,16 @@ const LEFTOVER_GRACE_MS = 5_000;
|
|
|
180
185
|
*/
|
|
181
186
|
export interface LeaseProcesses {
|
|
182
187
|
/**
|
|
183
|
-
* End every process
|
|
184
|
-
* and answer each as `<pid> (<command>)`.
|
|
185
|
-
* would not rejects with its name.
|
|
188
|
+
* End every process that works in `directory` — its working directory or the `TMPDIR` it was
|
|
189
|
+
* started with is there — and everything those started, and answer each as `<pid> (<command>)`.
|
|
190
|
+
* Every one has exited when this settles; one that would not rejects with its name.
|
|
186
191
|
*/
|
|
187
192
|
stopWorkingIn(directory: string): Promise<string[]>;
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
/** The host reads and signals cleanup uses; a seam for process ordering and signal failures. */
|
|
191
196
|
export interface ProcessHost {
|
|
192
|
-
/** The processes whose working directory is `directory` or lies beneath it. */
|
|
197
|
+
/** The processes whose working directory, or the `TMPDIR` they were started with, is `directory` or lies beneath it. */
|
|
193
198
|
workingIn(directory: string): Promise<number[]>;
|
|
194
199
|
/** Every process on the host. */
|
|
195
200
|
table(): Promise<ProcessEntry[]>;
|
|
@@ -201,13 +206,17 @@ const STARTS_NOTHING = /^[TtZ]/;
|
|
|
201
206
|
|
|
202
207
|
/**
|
|
203
208
|
* The processes `host` reads. A lease belongs to one task and its command is gone by the time the
|
|
204
|
-
* lease ends, so what still works in it is what the command left behind.
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
209
|
+
* lease ends, so what still works in it is what the command left behind. Most of that works in the
|
|
210
|
+
* lease only through `TMPDIR`, never by working directory: a test's ttsc plugin build copies the
|
|
211
|
+
* typescript-go sources into `$TMPDIR` from a process working in its project, and a Bun or Node
|
|
212
|
+
* process writes its compile cache there as it exits. Neither is known to the task's pid, and
|
|
213
|
+
* whichever outlived that pid would write into a lease being removed (measured 2026-10-18: `rm`
|
|
214
|
+
* failing ENOTEMPTY under a ttsc copy whose task had died). A fixture's Nx daemon is another: Nx
|
|
215
|
+
* detaches it into a session of its own, so the process-group kill that ends a timed-out command
|
|
216
|
+
* never reaches it, and a test process that is killed runs no teardown of its own. Deleting the
|
|
217
|
+
* lease asks such a daemon to leave only by deleting its record, which it notices within a second
|
|
218
|
+
* when it is idle and not at all while it is wedged; a signal does not depend on the daemon
|
|
219
|
+
* noticing, and a process left on the volume is what keeps it from detaching.
|
|
211
220
|
*
|
|
212
221
|
* A leftover keeps running while it is looked for, and a child it starts after the process table
|
|
213
222
|
* was read is in no table that was. So each one found is held with SIGSTOP and the table is read
|
|
@@ -290,8 +299,14 @@ export function leaseProcessesOn(host: ProcessHost): LeaseProcesses {
|
|
|
290
299
|
};
|
|
291
300
|
}
|
|
292
301
|
|
|
302
|
+
/** What works in `directory` on this host: by working directory, and by the `TMPDIR` it was started with. */
|
|
303
|
+
export async function pidsInLease(directory: string): Promise<number[]> {
|
|
304
|
+
const [working, temp] = await Promise.all([pidsWorkingIn(directory), pidsWithTempIn(directory)]);
|
|
305
|
+
return [...new Set([...working, ...temp])];
|
|
306
|
+
}
|
|
307
|
+
|
|
293
308
|
export const hostLeaseProcesses: LeaseProcesses = leaseProcessesOn({
|
|
294
|
-
workingIn:
|
|
309
|
+
workingIn: pidsInLease,
|
|
295
310
|
table: processTable,
|
|
296
311
|
signal: terminate,
|
|
297
312
|
});
|
|
@@ -1054,9 +1069,10 @@ export class RamTempVolume {
|
|
|
1054
1069
|
}
|
|
1055
1070
|
const reaped: string[] = [];
|
|
1056
1071
|
for (const candidate of candidates) {
|
|
1057
|
-
// Its task is gone, so what works in it is what that task left: stopped before the lease
|
|
1058
|
-
//
|
|
1059
|
-
|
|
1072
|
+
// Its task is gone, so what works in it is what that task left: stopped before the lease is
|
|
1073
|
+
// removed, even where the removal is refused below. An empty lease is asked too: a leftover
|
|
1074
|
+
// that has not written yet writes once it runs again. A task reaps its own (`reap`).
|
|
1075
|
+
if (!candidate.own) {
|
|
1060
1076
|
reaped.push(...(await this.processes.stopWorkingIn(candidate.directory)));
|
|
1061
1077
|
}
|
|
1062
1078
|
}
|
|
@@ -179,12 +179,17 @@ describe('bounded-exec verdicts', () => {
|
|
|
179
179
|
});
|
|
180
180
|
|
|
181
181
|
it('records a failing command with no report as a failure, and a passing one as passed', async () => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
// How an exit is classified, not how soon it comes: the clock is faked and nothing moves it, so the total bound
|
|
183
|
+
// cannot end a `node` still starting on a loaded host (a land gate measured 5243 ms for `node -e ""`). The run
|
|
184
|
+
// ends only by exiting.
|
|
185
|
+
const exiting = (command: string) =>
|
|
186
|
+
onProgressClock(
|
|
187
|
+
() => false,
|
|
188
|
+
0,
|
|
189
|
+
() => verdictOf(command, { timeoutMs: 5_000 }),
|
|
190
|
+
);
|
|
191
|
+
expect((await exiting('node -e "process.exit(3)"')).result).toEqual({ outcome: 'failed', exitCode: 3, tests: [] });
|
|
192
|
+
expect((await exiting('node -e ""')).result).toEqual({ outcome: 'passed' });
|
|
188
193
|
});
|
|
189
194
|
|
|
190
195
|
it("reads nextest's typed timeout from its JUnit report", () => {
|
|
@@ -358,8 +363,8 @@ setInterval(() => console.log('running'), 10);
|
|
|
358
363
|
const directory = context.record?.directory ?? '';
|
|
359
364
|
await mkdir(directory, { recursive: true });
|
|
360
365
|
const report = join(directory, JUNIT_FILE);
|
|
361
|
-
expect(await withJunitReport('bun test --timeout=
|
|
362
|
-
`bun test --reporter=junit --reporter-outfile='${report}' --timeout=
|
|
366
|
+
expect(await withJunitReport('bun test --timeout=0 src', directory)).toBe(
|
|
367
|
+
`bun test --reporter=junit --reporter-outfile='${report}' --timeout=0 src`,
|
|
363
368
|
);
|
|
364
369
|
const nextest = await withJunitReport('extracted="$(x)" && cargo --frozen nextest run -E all', directory);
|
|
365
370
|
expect(nextest).toBe(
|
|
@@ -377,15 +382,15 @@ setInterval(() => console.log('running'), 10);
|
|
|
377
382
|
const directory = context.record?.directory ?? '';
|
|
378
383
|
await mkdir(directory, { recursive: true });
|
|
379
384
|
const flags = `--reporter=junit --reporter-outfile='${join(directory, JUNIT_FILE)}'`;
|
|
380
|
-
expect(await withJunitReport('../bun-runtime/.runtime/bun test --timeout=
|
|
381
|
-
`../bun-runtime/.runtime/bun test ${flags} --timeout=
|
|
385
|
+
expect(await withJunitReport('../bun-runtime/.runtime/bun test --timeout=0 --shard=1/4', directory)).toBe(
|
|
386
|
+
`../bun-runtime/.runtime/bun test ${flags} --timeout=0 --shard=1/4`,
|
|
382
387
|
);
|
|
383
388
|
expect(
|
|
384
389
|
await withJunitReport(
|
|
385
|
-
'BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test --timeout=
|
|
390
|
+
'BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test --timeout=0 tests',
|
|
386
391
|
directory,
|
|
387
392
|
),
|
|
388
|
-
).toBe(`BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test ${flags} --timeout=
|
|
393
|
+
).toBe(`BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test ${flags} --timeout=0 tests`);
|
|
389
394
|
expect(await withJunitReport('cd pkg && $RUNTIME/bun test src', directory)).toBe(
|
|
390
395
|
`cd pkg && $RUNTIME/bun test ${flags} src`,
|
|
391
396
|
);
|
|
@@ -6,11 +6,9 @@ import {
|
|
|
6
6
|
BOUNDED_TEST_EXECUTOR,
|
|
7
7
|
BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
8
8
|
BOUNDED_TEST_KILL_AFTER_MS,
|
|
9
|
-
|
|
9
|
+
BUN_TEST_TIMEOUT_FLAG as TIMEOUT_FLAG,
|
|
10
10
|
} from '../../bounded-test-policy.js';
|
|
11
11
|
|
|
12
|
-
const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
|
|
13
|
-
|
|
14
12
|
import generator from './generator.js';
|
|
15
13
|
|
|
16
14
|
describe('bounded-test-targets generator', () => {
|
|
@@ -5,7 +5,7 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
|
5
5
|
import {
|
|
6
6
|
BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
7
7
|
BOUNDED_TEST_KILL_AFTER_MS,
|
|
8
|
-
|
|
8
|
+
BUN_TEST_TIMEOUT_FLAG,
|
|
9
9
|
} from '../../bounded-test-policy.js';
|
|
10
10
|
import generator from './generator.js';
|
|
11
11
|
|
|
@@ -77,7 +77,7 @@ describe('bun-test-tracing generator', () => {
|
|
|
77
77
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
78
78
|
dependsOn: ['typecheck-tests', '^build'],
|
|
79
79
|
options: {
|
|
80
|
-
command: `bun test
|
|
80
|
+
command: `bun test ${BUN_TEST_TIMEOUT_FLAG}`,
|
|
81
81
|
cwd: '{projectRoot}',
|
|
82
82
|
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
83
83
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -141,8 +141,8 @@ function writeBunfig(tree: Tree, projectRoot: string): void {
|
|
|
141
141
|
// Bun silently ignores `[test] timeout` in bunfig.toml — only the `--timeout`
|
|
142
142
|
// CLI flag and `setDefaultTimeout()` actually take effect. Strip any stale
|
|
143
143
|
// `timeout = N` lines so the file isn't lying about what's enforced; the real
|
|
144
|
-
// per-test timeout is
|
|
145
|
-
//
|
|
144
|
+
// per-test timeout is the leg's `--timeout`, which the bounded-test policy
|
|
145
|
+
// derives from bounded-exec's progress bound (see BUN_TEST_TIMEOUT_FLAG).
|
|
146
146
|
const current = stripBunTestTimeoutLine(tree.read(bunfigPath, 'utf-8') ?? '');
|
|
147
147
|
|
|
148
148
|
// Already has the package specifier preloads
|