@zgeoff/rig 0.0.6 → 0.1.0
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 +5 -5
- package/dist/browser/collect-descendant-pids.d.ts +2 -0
- package/dist/browser/pick-descendant-stop-step.d.ts +15 -0
- package/dist/browser/pick-listing-read-step.d.ts +10 -0
- package/dist/browser/probe-process.d.ts +1 -1
- package/dist/browser/read-process-table.d.ts +1 -0
- package/dist/browser/stop-descendant-processes.d.ts +10 -0
- package/dist/read-cli-args.d.ts +1 -0
- package/dist/test-run-args.d.ts +1 -0
- package/package.json +5 -5
- package/src/browser/browser-preload.ts +18 -4
- package/src/browser/collect-descendant-pids.ts +22 -0
- package/src/browser/make-browser-lane-hooks.ts +2 -3
- package/src/browser/pick-descendant-stop-step.ts +40 -0
- package/src/browser/pick-listing-read-step.ts +17 -0
- package/src/browser/probe-host-process.ts +1 -3
- package/src/browser/probe-process.ts +1 -1
- package/src/browser/read-process-table.ts +10 -6
- package/src/browser/stop-descendant-processes.ts +90 -0
- package/src/build-unit-command.ts +2 -15
- package/src/make-repo-lane-hooks.ts +2 -0
- package/src/read-cli-args.ts +30 -1
- package/src/run-cli.ts +8 -0
- package/src/standard-lanes.ts +1 -1
- package/src/test-run-args.ts +3 -0
package/README.md
CHANGED
|
@@ -35,8 +35,7 @@ so a run that outgrows its memory budget fails alone when `diet` finds a
|
|
|
35
35
|
|
|
36
36
|
## Commands
|
|
37
37
|
|
|
38
|
-
- `rig unit` runs the unit tests in random order with the host's worker count
|
|
39
|
-
so the files of a worker share one module graph. Pass `--isolate` to turn that off.
|
|
38
|
+
- `rig unit` runs the unit tests in random order with the host's worker count.
|
|
40
39
|
- `rig related <paths...>` runs the unit tests beside the changed files, for a pre-push hook.
|
|
41
40
|
- `rig <lane>` runs one lane: `e2e`, `browser`, `docker`, `host`, `agent-sdk`, `model-api`, or a
|
|
42
41
|
lane the repo declares.
|
|
@@ -46,9 +45,10 @@ so a run that outgrows its memory budget fails alone when `diet` finds a
|
|
|
46
45
|
has files for, and a starter config.
|
|
47
46
|
|
|
48
47
|
`rig unit` and the lane commands pass every argument after the command on to `bun test`, so
|
|
49
|
-
`bun run test --seed=1` replays a run's order, and rig drops one `--` among them. The
|
|
50
|
-
`--timeout
|
|
51
|
-
|
|
48
|
+
`bun run test --seed=1` replays a run's order, and rig drops one `--` among them. The exceptions are
|
|
49
|
+
`--timeout` and `--isolate`. The lane's limit in `rig.config.ts` is its one per-test timeout, and
|
|
50
|
+
every lane runs its files in random order with `--no-isolate`, so rig exits 2 on a `--timeout`,
|
|
51
|
+
`--timeout=<ms>` or `--isolate` argument and runs nothing. `rig related` takes changed file paths
|
|
52
52
|
only, and exits 2 on an option.
|
|
53
53
|
|
|
54
54
|
An `e2e/` folder is the e2e lane's in a folder that holds a `package.json`, and at the repo root
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
|
+
export type DescendantStopStep = {
|
|
3
|
+
readonly kind: 'stopped';
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: 'wait';
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'failed';
|
|
8
|
+
readonly running: readonly number[];
|
|
9
|
+
};
|
|
10
|
+
export interface DescendantStopState {
|
|
11
|
+
readonly descendants: readonly number[];
|
|
12
|
+
readonly listing: readonly ProcessEntry[] | null;
|
|
13
|
+
readonly isPastDeadline: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function pickDescendantStopStep(state: DescendantStopState): DescendantStopStep;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
|
+
export type ListingReadStep = {
|
|
3
|
+
readonly kind: 'listed';
|
|
4
|
+
readonly listing: readonly ProcessEntry[];
|
|
5
|
+
} | {
|
|
6
|
+
readonly kind: 'retry';
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'failed';
|
|
9
|
+
};
|
|
10
|
+
export declare function pickListingReadStep(listing: readonly ProcessEntry[] | null, isPastDeadline: boolean): ListingReadStep;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
2
|
export interface ProcessProbeDependencies {
|
|
3
|
-
readonly signalProcess: (pid: number, signal: number) =>
|
|
3
|
+
readonly signalProcess: (pid: number, signal: number) => boolean;
|
|
4
4
|
readonly readProcessTable: () => readonly ProcessEntry[] | null;
|
|
5
5
|
}
|
|
6
6
|
export declare function probeProcess(pid: number, dependencies: ProcessProbeDependencies): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Clock } from '../system-clock.ts';
|
|
2
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
3
|
+
export interface DescendantStop {
|
|
4
|
+
readonly rootPID: number;
|
|
5
|
+
readonly timeoutMs: number;
|
|
6
|
+
readonly clock: Clock;
|
|
7
|
+
readonly readProcessTable: () => readonly ProcessEntry[] | null;
|
|
8
|
+
readonly signalProcess: (pid: number, signal: NodeJS.Signals) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function stopDescendantProcesses(stop: DescendantStop): Promise<void>;
|
package/dist/read-cli-args.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const testRunArgs: readonly string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/rig",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Run every test lane of a repo from one declaration of its limits, with a browser lane built in",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"typecheck": "tsrs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@zgeoff/diet": "0.
|
|
51
|
-
"@zgeoff/std": "0.
|
|
50
|
+
"@zgeoff/diet": "0.2.0",
|
|
51
|
+
"@zgeoff/std": "0.4.0",
|
|
52
52
|
"gunshi": "1.0.0-rc.1",
|
|
53
53
|
"ts-pattern": "5.9.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/bun": "1.4.4",
|
|
57
|
-
"@zgeoff/std": "0.
|
|
58
|
-
"@zgeoff/testing": "0.
|
|
57
|
+
"@zgeoff/std": "0.4.0",
|
|
58
|
+
"@zgeoff/testing": "0.2.0",
|
|
59
59
|
"tiny-invariant": "1.3.3",
|
|
60
60
|
"tsrs": "0.18.0-ts7.1.0-dev.20260929",
|
|
61
61
|
"typescript": "7.0.2",
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
// A cold Chrome start on a fresh CI runner can run past the test timeout, so the preload starts
|
|
2
|
-
// Chrome before the
|
|
3
|
-
//
|
|
2
|
+
// Chrome before the first test. Bun spawns one Chrome per process, on the options of the first
|
|
3
|
+
// view, and every later view in the process, in every file, reuses it.
|
|
4
4
|
|
|
5
|
+
import { afterAll } from 'bun:test';
|
|
5
6
|
import { hostname } from 'node:os';
|
|
7
|
+
import { systemClock } from '../system-clock.ts';
|
|
6
8
|
import { laneFiles } from './lane-files.ts';
|
|
9
|
+
import { readProcessTable } from './read-process-table.ts';
|
|
7
10
|
import { startBrowser } from './start-browser.ts';
|
|
11
|
+
import { stopDescendantProcesses } from './stop-descendant-processes.ts';
|
|
12
|
+
|
|
13
|
+
// Chrome's helper processes outlive the `bun test` that starts them, and diet then keeps its cgroup
|
|
14
|
+
// for them, so the preload stops them after the last file.
|
|
15
|
+
afterAll(() =>
|
|
16
|
+
stopDescendantProcesses({
|
|
17
|
+
rootPID: process.pid,
|
|
18
|
+
timeoutMs: 5000,
|
|
19
|
+
clock: systemClock,
|
|
20
|
+
readProcessTable,
|
|
21
|
+
signalProcess: process.kill.bind(process),
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
8
24
|
|
|
9
25
|
await startBrowser({
|
|
10
26
|
// The lane starts each test process in the repo's root.
|
|
@@ -12,8 +28,6 @@ await startBrowser({
|
|
|
12
28
|
hostName: hostname(),
|
|
13
29
|
environment: process.env,
|
|
14
30
|
|
|
15
|
-
// `bun test --parallel=1` stops each file's Chrome and loads this module again for the next
|
|
16
|
-
// file. A new Chrome on the last one's profile can start before the last one lets go of it.
|
|
17
31
|
profileName: crypto.randomUUID(),
|
|
18
32
|
readDirNames: laneFiles.readDirNames,
|
|
19
33
|
openView: openChromeView,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
|
+
|
|
3
|
+
export function collectDescendantPIDs(
|
|
4
|
+
table: readonly ProcessEntry[],
|
|
5
|
+
rootPID: number,
|
|
6
|
+
): readonly number[] {
|
|
7
|
+
const descendants: number[] = [];
|
|
8
|
+
const parents = [rootPID];
|
|
9
|
+
|
|
10
|
+
for (const parentID of parents) {
|
|
11
|
+
const children = table.filter((entry) => entry.parentID === parentID && entry.pid !== rootPID);
|
|
12
|
+
|
|
13
|
+
for (const child of children) {
|
|
14
|
+
if (!descendants.includes(child.pid)) {
|
|
15
|
+
descendants.push(child.pid);
|
|
16
|
+
parents.push(child.pid);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return descendants;
|
|
22
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import type { LaneHooks, LaneStartOutcome } from '../lane-hooks.ts';
|
|
3
|
+
import { testRunArgs } from '../test-run-args.ts';
|
|
3
4
|
import type { BrowserRun } from './build-browser-run.ts';
|
|
4
5
|
import type { LaneEnvironments } from './build-lane-environments.ts';
|
|
5
6
|
import { buildLaneEnvironments } from './build-lane-environments.ts';
|
|
@@ -48,8 +49,6 @@ export interface BrowserLaneOptions {
|
|
|
48
49
|
) => Promise<number>;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
// `bun test --parallel=1` isolates each file, so the preload runs again for each one, and the
|
|
52
|
-
// build and the run ID come from here, once per run.
|
|
53
52
|
export function makeBrowserLaneHooks(options: BrowserLaneOptions): LaneHooks {
|
|
54
53
|
const state = { hasRunFolders: false, keepsFolders: false };
|
|
55
54
|
|
|
@@ -190,7 +189,7 @@ async function runBrowserTests(
|
|
|
190
189
|
const testsRecord = await createPendingRecord(options.run.groupsDir, 'tests', options.files);
|
|
191
190
|
|
|
192
191
|
const testsExitCode = await options.runTests(
|
|
193
|
-
['--parallel=1', '--preload', options.preloadPath, ...testArgs],
|
|
192
|
+
['--parallel=1', ...testRunArgs, '--preload', options.preloadPath, ...testArgs],
|
|
194
193
|
environment,
|
|
195
194
|
options.signal,
|
|
196
195
|
testsRecord,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isZombieState } from './is-zombie-state.ts';
|
|
2
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
3
|
+
|
|
4
|
+
export type DescendantStopStep =
|
|
5
|
+
| { readonly kind: 'stopped' }
|
|
6
|
+
| { readonly kind: 'wait' }
|
|
7
|
+
| { readonly kind: 'failed'; readonly running: readonly number[] };
|
|
8
|
+
|
|
9
|
+
export interface DescendantStopState {
|
|
10
|
+
readonly descendants: readonly number[];
|
|
11
|
+
|
|
12
|
+
readonly listing: readonly ProcessEntry[] | null;
|
|
13
|
+
|
|
14
|
+
readonly isPastDeadline: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A killed process stays in its cgroup until its parent or the host's first process reaps it, so
|
|
18
|
+
// the stop waits until each one leaves the listing. A host whose first process never reaps its
|
|
19
|
+
// orphans keeps a zombie forever, so at the deadline only a process that is no zombie fails it.
|
|
20
|
+
export function pickDescendantStopStep(state: DescendantStopState): DescendantStopStep {
|
|
21
|
+
// A failed listing leaves every process's state unknown, so each one counts as running.
|
|
22
|
+
if (state.listing === null) {
|
|
23
|
+
return state.isPastDeadline ? { kind: 'failed', running: state.descendants } : { kind: 'wait' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const listing = state.listing;
|
|
27
|
+
const listed = state.descendants.flatMap((pid) => listing.filter((entry) => entry.pid === pid));
|
|
28
|
+
|
|
29
|
+
if (listed.length === 0) {
|
|
30
|
+
return { kind: 'stopped' };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!state.isPastDeadline) {
|
|
34
|
+
return { kind: 'wait' };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const running = listed.filter((entry) => !isZombieState(entry.state)).map((entry) => entry.pid);
|
|
38
|
+
|
|
39
|
+
return running.length === 0 ? { kind: 'stopped' } : { kind: 'failed', running };
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
|
+
|
|
3
|
+
export type ListingReadStep =
|
|
4
|
+
| { readonly kind: 'listed'; readonly listing: readonly ProcessEntry[] }
|
|
5
|
+
| { readonly kind: 'retry' }
|
|
6
|
+
| { readonly kind: 'failed' };
|
|
7
|
+
|
|
8
|
+
export function pickListingReadStep(
|
|
9
|
+
listing: readonly ProcessEntry[] | null,
|
|
10
|
+
isPastDeadline: boolean,
|
|
11
|
+
): ListingReadStep {
|
|
12
|
+
if (listing !== null) {
|
|
13
|
+
return { kind: 'listed', listing };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return isPastDeadline ? { kind: 'failed' } : { kind: 'retry' };
|
|
17
|
+
}
|
|
@@ -3,9 +3,7 @@ import { readProcessTable } from './read-process-table.ts';
|
|
|
3
3
|
|
|
4
4
|
export function probeHostProcess(pid: number): boolean {
|
|
5
5
|
return probeProcess(pid, {
|
|
6
|
-
signalProcess: (
|
|
7
|
-
process.kill(target, signal);
|
|
8
|
-
},
|
|
6
|
+
signalProcess: process.kill.bind(process),
|
|
9
7
|
readProcessTable,
|
|
10
8
|
});
|
|
11
9
|
}
|
|
@@ -4,7 +4,7 @@ import type { ProcessEntry } from './read-process-table.ts';
|
|
|
4
4
|
|
|
5
5
|
export interface ProcessProbeDependencies {
|
|
6
6
|
// Throws as `process.kill` does: ESRCH for a missing process, EPERM for another user's.
|
|
7
|
-
readonly signalProcess: (pid: number, signal: number) =>
|
|
7
|
+
readonly signalProcess: (pid: number, signal: number) => boolean;
|
|
8
8
|
|
|
9
9
|
readonly readProcessTable: () => readonly ProcessEntry[] | null;
|
|
10
10
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export interface ProcessEntry {
|
|
2
2
|
readonly pid: number;
|
|
3
3
|
|
|
4
|
+
readonly parentID: number;
|
|
5
|
+
|
|
4
6
|
readonly groupID: number;
|
|
5
7
|
|
|
6
8
|
readonly state: string;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
// Null when `ps` fails to start or exits nonzero. `ps -A` lists every process, so a nonzero exit
|
|
10
|
-
// is a failed listing, never a sign that a process has exited.
|
|
12
|
+
// is a failed listing, never a sign that a process has exited. It lists itself too, as a child of
|
|
13
|
+
// the reader that has exited by then, so the listing leaves it out.
|
|
11
14
|
export function readProcessTable(): readonly ProcessEntry[] | null {
|
|
12
15
|
const listing = runListing();
|
|
13
16
|
|
|
@@ -19,16 +22,17 @@ export function readProcessTable(): readonly ProcessEntry[] | null {
|
|
|
19
22
|
.toString()
|
|
20
23
|
.split('\n')
|
|
21
24
|
.map((line) => line.trim().split(/\s+/u))
|
|
22
|
-
.flatMap(([pid, groupID, state]) =>
|
|
23
|
-
pid === undefined || groupID === undefined || state === undefined
|
|
25
|
+
.flatMap(([pid, parentID, groupID, state]) =>
|
|
26
|
+
pid === undefined || parentID === undefined || groupID === undefined || state === undefined
|
|
24
27
|
? []
|
|
25
|
-
: [{ pid: Number(pid), groupID: Number(groupID), state }],
|
|
26
|
-
)
|
|
28
|
+
: [{ pid: Number(pid), parentID: Number(parentID), groupID: Number(groupID), state }],
|
|
29
|
+
)
|
|
30
|
+
.filter((entry) => entry.pid !== listing.pid);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
function runListing() {
|
|
30
34
|
try {
|
|
31
|
-
return Bun.spawnSync(['ps', '-A', '-o', 'pid=,pgid=,stat=']);
|
|
35
|
+
return Bun.spawnSync(['ps', '-A', '-o', 'pid=,ppid=,pgid=,stat=']);
|
|
32
36
|
} catch {
|
|
33
37
|
return null;
|
|
34
38
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { match } from 'ts-pattern';
|
|
2
|
+
import type { Clock } from '../system-clock.ts';
|
|
3
|
+
import { collectDescendantPIDs } from './collect-descendant-pids.ts';
|
|
4
|
+
import { hasErrorCode } from './has-error-code.ts';
|
|
5
|
+
import { pickDescendantStopStep } from './pick-descendant-stop-step.ts';
|
|
6
|
+
import { pickListingReadStep } from './pick-listing-read-step.ts';
|
|
7
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
8
|
+
|
|
9
|
+
export interface DescendantStop {
|
|
10
|
+
readonly rootPID: number;
|
|
11
|
+
|
|
12
|
+
readonly timeoutMs: number;
|
|
13
|
+
|
|
14
|
+
readonly clock: Clock;
|
|
15
|
+
|
|
16
|
+
readonly readProcessTable: () => readonly ProcessEntry[] | null;
|
|
17
|
+
|
|
18
|
+
// Throws as `process.kill` does: ESRCH for a process that has exited.
|
|
19
|
+
readonly signalProcess: (pid: number, signal: NodeJS.Signals) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const pollIntervalMs = 50;
|
|
23
|
+
|
|
24
|
+
export async function stopDescendantProcesses(stop: DescendantStop): Promise<void> {
|
|
25
|
+
const deadlineMs = stop.clock.now() + stop.timeoutMs;
|
|
26
|
+
|
|
27
|
+
const table = await readFirstListing(stop, deadlineMs);
|
|
28
|
+
|
|
29
|
+
const descendants = collectDescendantPIDs(table, stop.rootPID);
|
|
30
|
+
|
|
31
|
+
for (const pid of descendants) {
|
|
32
|
+
killProcess(pid, stop);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let isStopped = false;
|
|
36
|
+
|
|
37
|
+
while (!isStopped) {
|
|
38
|
+
const step = pickDescendantStopStep({
|
|
39
|
+
descendants,
|
|
40
|
+
listing: stop.readProcessTable(),
|
|
41
|
+
isPastDeadline: stop.clock.now() >= deadlineMs,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
isStopped = await match(step)
|
|
45
|
+
.with({ kind: 'stopped' }, () => Promise.resolve(true))
|
|
46
|
+
.with({ kind: 'failed' }, (failed) =>
|
|
47
|
+
Promise.reject(
|
|
48
|
+
new Error(
|
|
49
|
+
`the processes ${failed.running.join(', ')} still run ${stop.timeoutMs} ms after SIGKILL`,
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
.with({ kind: 'wait' }, () => stop.clock.sleep(pollIntervalMs).then(() => false))
|
|
54
|
+
.exhaustive();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Only a listing names the processes to stop, so a failed one is read again until the deadline.
|
|
59
|
+
async function readFirstListing(
|
|
60
|
+
stop: DescendantStop,
|
|
61
|
+
deadlineMs: number,
|
|
62
|
+
): Promise<readonly ProcessEntry[]> {
|
|
63
|
+
let listing: readonly ProcessEntry[] | null = null;
|
|
64
|
+
|
|
65
|
+
while (listing === null) {
|
|
66
|
+
const step = pickListingReadStep(stop.readProcessTable(), stop.clock.now() >= deadlineMs);
|
|
67
|
+
|
|
68
|
+
listing = await match(step)
|
|
69
|
+
.with({ kind: 'listed' }, (listed) => Promise.resolve(listed.listing))
|
|
70
|
+
.with({ kind: 'failed' }, () =>
|
|
71
|
+
Promise.reject(
|
|
72
|
+
new Error(`the process listing failed for ${stop.timeoutMs} ms, so no process stopped`),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
.with({ kind: 'retry' }, () => stop.clock.sleep(pollIntervalMs).then(() => null))
|
|
76
|
+
.exhaustive();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return listing;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function killProcess(pid: number, stop: DescendantStop): void {
|
|
83
|
+
try {
|
|
84
|
+
stop.signalProcess(pid, 'SIGKILL');
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (!hasErrorCode(error, 'ESRCH')) {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { testRunArgs } from './test-run-args.ts';
|
|
1
2
|
import type { RigConfig } from './types.ts';
|
|
2
3
|
|
|
3
|
-
const isolationFlags: ReadonlySet<string> = new Set(['--isolate', '--no-isolate']);
|
|
4
|
-
|
|
5
4
|
// The e2e lane has no suffix, so the unit run leaves out the folders that the e2e lane selects,
|
|
6
5
|
// from the same list, and nothing else.
|
|
7
6
|
export function buildUnitCommand(
|
|
@@ -20,17 +19,5 @@ export function buildUnitCommand(
|
|
|
20
19
|
(pattern) => `--path-ignore-patterns=${pattern}`,
|
|
21
20
|
);
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
? []
|
|
25
|
-
: ['--no-isolate'];
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
'bun',
|
|
29
|
-
'test',
|
|
30
|
-
`--parallel=${workerCount}`,
|
|
31
|
-
'--randomize',
|
|
32
|
-
...isolationArgs,
|
|
33
|
-
...ignoreArgs,
|
|
34
|
-
...extraArgs,
|
|
35
|
-
];
|
|
22
|
+
return ['bun', 'test', `--parallel=${workerCount}`, ...testRunArgs, ...ignoreArgs, ...extraArgs];
|
|
36
23
|
}
|
|
@@ -4,6 +4,7 @@ import type { LaneHooks } from './lane-hooks.ts';
|
|
|
4
4
|
import { parseLaneHook } from './parse-lane-hook.ts';
|
|
5
5
|
import { parseLaneStart } from './parse-lane-start.ts';
|
|
6
6
|
import type { CommandOptions } from './run-command.ts';
|
|
7
|
+
import { testRunArgs } from './test-run-args.ts';
|
|
7
8
|
import type { LaneContext } from './types.ts';
|
|
8
9
|
|
|
9
10
|
export interface RepoLaneOptions {
|
|
@@ -47,6 +48,7 @@ export function makeRepoLaneHooks(options: RepoLaneOptions): LaneHooks {
|
|
|
47
48
|
'bun',
|
|
48
49
|
'test',
|
|
49
50
|
`--parallel=${options.parallel}`,
|
|
51
|
+
...testRunArgs,
|
|
50
52
|
...testArgs,
|
|
51
53
|
]),
|
|
52
54
|
{ cwd: options.context.repoRoot, environment, signal: options.signal },
|
package/src/read-cli-args.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface CLIArgs {
|
|
|
7
7
|
// Every argument after the command, flags and paths alike, which the command passes on to
|
|
8
8
|
// `bun test`.
|
|
9
9
|
readonly extraArgs: readonly string[];
|
|
10
|
+
|
|
11
|
+
readonly hasIsolateOption: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
const argSchema = { command: { type: 'positional' } } as const;
|
|
@@ -27,6 +29,7 @@ export async function readCLIArgs(argv: readonly string[]): Promise<CLIArgs | st
|
|
|
27
29
|
parsed = {
|
|
28
30
|
command: ctx.values.command,
|
|
29
31
|
extraArgs: dropFirstSeparator(argv.slice(1)),
|
|
32
|
+
hasIsolateOption: false,
|
|
30
33
|
};
|
|
31
34
|
},
|
|
32
35
|
});
|
|
@@ -37,7 +40,13 @@ export async function readCLIArgs(argv: readonly string[]): Promise<CLIArgs | st
|
|
|
37
40
|
return formatParseError(error);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
if (parsed === null) {
|
|
44
|
+
return 'the command line could not be parsed';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const commandArgs: CLIArgs = parsed;
|
|
48
|
+
|
|
49
|
+
return { ...commandArgs, hasIsolateOption: await probeIsolateOption(commandArgs.extraArgs) };
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
function dropFirstSeparator(args: readonly string[]): readonly string[] {
|
|
@@ -55,3 +64,23 @@ function formatParseError(error: unknown): string {
|
|
|
55
64
|
|
|
56
65
|
return error instanceof Error ? error.message : String(error);
|
|
57
66
|
}
|
|
67
|
+
|
|
68
|
+
const forwardedArgSchema = { isolate: { type: 'boolean' } } as const;
|
|
69
|
+
|
|
70
|
+
// The forwarded arguments hold `bun test` options that rig never declares, so this parse is not
|
|
71
|
+
// strict, and it reads only whether an isolate option, in any of its forms, is among them.
|
|
72
|
+
async function probeIsolateOption(args: readonly string[]): Promise<boolean> {
|
|
73
|
+
let isExplicit = false;
|
|
74
|
+
|
|
75
|
+
const forwarded = define({
|
|
76
|
+
name: 'rig',
|
|
77
|
+
args: forwardedArgSchema,
|
|
78
|
+
run: (ctx) => {
|
|
79
|
+
isExplicit = ctx.explicit.isolate;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await cli([...args], forwarded, { strict: false });
|
|
84
|
+
|
|
85
|
+
return isExplicit;
|
|
86
|
+
}
|
package/src/run-cli.ts
CHANGED
|
@@ -61,6 +61,14 @@ export async function runCLI(argv: readonly string[], run: RigRun, deps: CLIDeps
|
|
|
61
61
|
return 2;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
if (args.hasIsolateOption) {
|
|
65
|
+
deps.output.err(
|
|
66
|
+
`rig: rig ${command} refuses --isolate, because every lane runs its files in one global per process\n`,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return 2;
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
return lane.name === 'unit'
|
|
65
73
|
? runUnit(config, args.extraArgs, run, deps)
|
|
66
74
|
: runLane({ config, lane, extraArgs: args.extraArgs }, run, deps);
|
package/src/standard-lanes.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface StandardLane {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// The limits are the per-test timeouts of the Lanes table in the testing skill. Every lane but
|
|
14
|
-
// unit runs one
|
|
14
|
+
// unit runs its files one at a time, because it needs a real system that two files cannot share.
|
|
15
15
|
export const standardLanes: readonly StandardLane[] = [
|
|
16
16
|
{ name: 'unit', suffix: null, limitMs: 5000, parallel: 'workers' },
|
|
17
17
|
{ name: 'e2e', suffix: null, limitMs: 15_000, parallel: 1 },
|