@smoothbricks/nx-plugin 0.4.30 → 0.4.31
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 +21 -10
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +22 -5
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-tokens.js +189 -18
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +3 -2
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/run-cpu-pool.js +63 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/managed/raw/tooling/direnv/setup-environment.ts +13 -0
- package/package.json +1 -1
- package/src/cargo-closure-key.test.ts +3 -2
- package/src/executors/bounded-exec/cpu-tokens.test.ts +205 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +229 -22
- package/src/executors/bounded-exec/executor.ts +3 -2
- package/src/executors/bounded-exec/run-cpu-pool.test.ts +76 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +75 -0
- package/src/index.test.ts +12 -2
- package/src/index.ts +13 -3
- package/test-timings.json +1 -0
package/README.md
CHANGED
|
@@ -1435,16 +1435,27 @@ callers use the CLI facade rather than introducing another disk-command runner.
|
|
|
1435
1435
|
Without an inherited parent pool, a `bounded-exec` command takes CPU tokens from cowshed's host budget before it starts,
|
|
1436
1436
|
when the gateway answers on the same socket (`specs/cowshed/05_gateway.md`, "Host CPU budget"), so concurrent gates on
|
|
1437
1437
|
one host keep their runnable work near the core count instead of each sizing its runners to the whole machine. It asks
|
|
1438
|
-
for the runner's requested parallelism
|
|
1439
|
-
|
|
1440
|
-
`
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
`
|
|
1447
|
-
|
|
1438
|
+
for the runner's requested parallelism, read from the runner's own flag rather than the core count — nextest's
|
|
1439
|
+
`--test-threads` or one per core (one for `--no-capture`, which runs tests serially), `bun test --parallel=N` N,
|
|
1440
|
+
Stryker's `--concurrency` N or N% (default one per core less one past four cores), Vitest's `--maxWorkers` N or N%
|
|
1441
|
+
(default one per core less one), `go test -p` (default `GOMAXPROCS`), cargo-mutants' `--jobserver-tasks` (default one
|
|
1442
|
+
per core, whatever `--jobs` says), a cargo build one per core, anything else one, or the target's `parallelism` option —
|
|
1443
|
+
bounded by positive inherited `NEXTEST_TEST_THREADS`/`CARGO_BUILD_JOBS` ceilings. A configured count can lower an
|
|
1444
|
+
inherited ceiling, never raise it. The runner uses `min(bounded request, granted tokens)`: nextest's environment and
|
|
1445
|
+
named flag, Bun's parallel flag, Stryker's, Vitest's and go's worker flag (added when the command names none),
|
|
1446
|
+
cargo-mutants' jobserver tasks, `--jobs` and per-process test threads, and Cargo's jobs are sized to that limit. A
|
|
1447
|
+
runner that starts its own workers or jobserver (cargo-mutants, Stryker, Vitest, `go test`) ignores the `cargo`
|
|
1448
|
+
launcher's fifo, so it must run under `bounded-exec`; the inferred `mutation` target does. Cargo's `RUST_TEST_THREADS`
|
|
1449
|
+
retains its independent inherited/configured ceiling. `BOUNDED_EXEC_CPU_TOKENS`, the sub-ledger and telemetry still name
|
|
1450
|
+
the actual held grant. The gateway shares tokens fairly between checkouts (Nx workspace roots). `timeoutMs` and
|
|
1451
|
+
`idleTimeoutMs` start at the grant. The tokens go back when the command exits, or with the executor's socket when it is
|
|
1452
|
+
killed. The wait prints one `cowshed: cpu-tokens wait done elapsed=… tokens=<granted>/<asked>` line. On a host whose
|
|
1453
|
+
gateway socket does not exist (a CI runner, a machine without cowshed), the plugin's `preTasksExecution` serves each Nx
|
|
1454
|
+
run that inherits no pool its own `BOUNDED_EXEC_CPU_POOL` of one token per core, and `postTasksExecution` closes it: the
|
|
1455
|
+
run's targets, started side by side under `NX_PARALLEL=100%`, queue for its cores instead of each sizing its runner to
|
|
1456
|
+
the whole host (`specs/cowshed/05_gateway.md`, "A run without a gateway budgets itself"). Its scope is one run. A
|
|
1457
|
+
command no pool and no gateway answers runs exactly as configured and nothing is said; a gateway from before the budget
|
|
1458
|
+
runs it unbudgeted and stderr says so.
|
|
1448
1459
|
|
|
1449
1460
|
A granted executor serves a private `BOUNDED_EXEC_CPU_POOL` with its actual token count. A nested default executor asks
|
|
1450
1461
|
that immediate parent pool for its own demand, instead of taking from the host while the parent holds its grant; the
|
|
@@ -16,26 +16,42 @@ export type RunnerKind =
|
|
|
16
16
|
'nextest'
|
|
17
17
|
/** `bun test --parallel`: its worker processes. */
|
|
18
18
|
| 'bun-parallel'
|
|
19
|
+
/** A runner whose worker count is one flag of its own (`WORKER_FLAGS`). */
|
|
20
|
+
| WorkerFlagKind
|
|
21
|
+
/** `cargo mutants`: its own jobserver's tasks, `--jobserver-tasks`, shared by the `--jobs` cargo processes it starts. */
|
|
22
|
+
| 'cargo-mutants'
|
|
19
23
|
/** A cargo build (`cargo build`/`test`/`clippy`/…, `nextest archive`, `napi build`): its jobs. */
|
|
20
24
|
| 'cargo'
|
|
21
25
|
/** Anything else, one `bun test` process included: one process unless it declares more. */
|
|
22
26
|
| 'process';
|
|
23
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* What a runner asks the budget for. Cargo also carries its independent test-thread ceiling; cargo-mutants carries
|
|
29
|
+
* how many cargo processes it runs at once, which share its grant.
|
|
30
|
+
*/
|
|
24
31
|
export type Demand = {
|
|
25
32
|
kind: 'cargo';
|
|
26
33
|
want: number;
|
|
27
34
|
testThreads: number | null;
|
|
28
35
|
} | {
|
|
29
|
-
kind:
|
|
36
|
+
kind: 'cargo-mutants';
|
|
37
|
+
want: number;
|
|
38
|
+
jobs: number;
|
|
39
|
+
} | {
|
|
40
|
+
kind: Exclude<RunnerKind, 'cargo' | 'cargo-mutants'>;
|
|
30
41
|
want: number;
|
|
31
42
|
};
|
|
32
43
|
/** Every budgeted command learns its grant here, so a script that starts a runner can size it. */
|
|
33
44
|
export declare const CPU_TOKENS_ENV = "BOUNDED_EXEC_CPU_TOKENS";
|
|
45
|
+
type WorkerFlagKind = 'stryker' | 'vitest' | 'go-test';
|
|
34
46
|
/**
|
|
35
47
|
* What `command` asks for: its kind by invocation, and `declared` (the target's `parallelism`)
|
|
36
|
-
* when it says, else the count the command names (`--test-threads=N`, `--parallel=N
|
|
37
|
-
* runner's own default — one thread per core for
|
|
38
|
-
*
|
|
48
|
+
* when it says, else the count the command names (`--test-threads=N`, `--parallel=N`, a worker
|
|
49
|
+
* flag's N or N%, `--jobserver-tasks=N`), else the runner's own default — one thread per core for
|
|
50
|
+
* nextest, a bare `--parallel` and cargo; a worker-flag runner's own (`WORKER_FLAGS`); one per core
|
|
51
|
+
* for cargo-mutants, whose own jobserver defaults to one task per core whatever `--jobs` says; one
|
|
52
|
+
* process for anything else. A nextest run with `--no-capture` runs one test at a time whatever
|
|
53
|
+
* thread count it names, so it asks for one. Positive inherited runner counts are ceilings;
|
|
54
|
+
* configured counts may only lower them.
|
|
39
55
|
*/
|
|
40
56
|
export declare function runnerDemand(command: string, declared: number | undefined, cores: number, inherited: Readonly<NodeJS.ProcessEnv>, configured?: Readonly<NodeJS.ProcessEnv>): Demand;
|
|
41
57
|
/**
|
|
@@ -79,4 +95,5 @@ export interface CpuBudget {
|
|
|
79
95
|
* workspace root: the gateway shares tokens fairly between checkouts.
|
|
80
96
|
*/
|
|
81
97
|
export declare function gatewayCpuBudget(socket?: string): CpuBudget;
|
|
98
|
+
export {};
|
|
82
99
|
//# sourceMappingURL=cpu-tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cpu-tokens.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnF;;;;;;;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U,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GACvC,MAAM,CAyBR;AAkHD;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAkDlD;AASD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM7E;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,SAAS,CAAC,EAAE,IAAI,CAAA;CAAE,GAC/F;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,uFAAuF;AACvF,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC5E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,MAAuB,GAAG,SAAS,CAuB3E"}
|
|
@@ -4,36 +4,181 @@ import { BUN_TEST, NEXTEST_RUN } from './verdict.js';
|
|
|
4
4
|
export const CPU_TOKENS_ENV = 'BOUNDED_EXEC_CPU_TOKENS';
|
|
5
5
|
const CARGO_BUILD = /(?<=^|[\s;&|()])(?:cargo(?:\s+-\S+)*\s+(?:build|test|check|clippy|rustc|doc|run|nextest\s+archive)|napi\s+build)(?=\s|$)/;
|
|
6
6
|
const TEST_THREADS = /--test-threads(?:=|\s+)(\d+)/g;
|
|
7
|
+
/** nextest's `--no-capture` (`--nocapture` past `--`): it runs tests serially and ignores `--test-threads`. */
|
|
8
|
+
const NO_CAPTURE = /(?<![\w-])--no-?capture(?![\w-])/;
|
|
7
9
|
const BUN_PARALLEL = /--parallel(?:=(\d+))?(?=\s|$)/g;
|
|
10
|
+
/** `cargo mutants`, cargo's global options allowed between, or the `cargo-mutants` binary itself. */
|
|
11
|
+
const CARGO_MUTANTS = /(?<=^|[\s;&|()])(?:cargo(?:\s+-\S+)*|cargo-mutants)\s+mutants(?=\s|$)/;
|
|
12
|
+
/** cargo-mutants' own jobserver, one per run, whose tasks every cargo it starts shares: `--jobserver-tasks N`. */
|
|
13
|
+
const JOBSERVER_TASKS = /(?<![\w-])--jobserver-tasks(?:=|\s+)(\d+)(?![\w.])/g;
|
|
14
|
+
/** cargo-mutants' cargo build/test processes at once: `--jobs N` or `-j N`. */
|
|
15
|
+
const MUTANTS_JOBS = /(?<![\w-])(?:--jobs(?:=|\s+)|-j(?:=|\s*))(\d+)(?![\w.])/g;
|
|
16
|
+
/** A count, or a share of the cores (`N%`), optionally quoted. Any other word (`"$(nproc)"`) names no count. */
|
|
17
|
+
const WORKER_COUNT = /^(["']?)(\d+)(%?)\1$/;
|
|
8
18
|
const INHERITED_COUNT = /^[1-9]\d*$/;
|
|
19
|
+
/** One shell word: quoted, a `$(…)` substitution, or bare. */
|
|
20
|
+
const WORD = String.raw `("[^"]*"|'[^']*'|\$\([^)]*\)|[^\s;&|()'"]+)`;
|
|
21
|
+
const WORKER_FLAGS = {
|
|
22
|
+
/** StrykerJS's `concurrency`: n - 1 workers past four cores, else n. */
|
|
23
|
+
stryker: {
|
|
24
|
+
invocation: /(?<=^|[\s;&|()/])stryker\s+run(?=\s|$)/,
|
|
25
|
+
flag: new RegExp(String.raw `(?<![\w-])(?:--concurrency|-c)(?:=|\s+)${WORD}`, 'g'),
|
|
26
|
+
sized: (count) => `--concurrency=${count}`,
|
|
27
|
+
ownDefault: (cores) => (cores > 4 ? cores - 1 : cores),
|
|
28
|
+
},
|
|
29
|
+
/** Vitest's `maxWorkers`: n - 1 workers outside watch mode, one with file parallelism off. */
|
|
30
|
+
vitest: {
|
|
31
|
+
invocation: /(?<=^|[\s;&|()/])vitest(?:\s+run)?(?=\s|$)/,
|
|
32
|
+
flag: new RegExp(String.raw `(?<![\w-])--max(?:W|-w)orkers(?:=|\s+)${WORD}`, 'g'),
|
|
33
|
+
sized: (count) => `--maxWorkers=${count}`,
|
|
34
|
+
ownDefault: (cores) => Math.max(cores - 1, 1),
|
|
35
|
+
serial: /(?<![\w-])(?:--no-file-parallelism|--file(?:P|-p)arallelism=false)(?![\w-])/,
|
|
36
|
+
},
|
|
37
|
+
/** `go test -p`: packages built and tested at once, `GOMAXPROCS` by default, normally one per core. */
|
|
38
|
+
'go-test': {
|
|
39
|
+
invocation: /(?<=^|[\s;&|()])go\s+test(?=\s|$)/,
|
|
40
|
+
flag: new RegExp(String.raw `(?<![\w-])-p(?:=|\s+)${WORD}`, 'g'),
|
|
41
|
+
sized: (count) => `-p=${count}`,
|
|
42
|
+
ownDefault: (cores, env) => parseInheritedTokens(env.GOMAXPROCS) ?? cores,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
9
45
|
/**
|
|
10
46
|
* What `command` asks for: its kind by invocation, and `declared` (the target's `parallelism`)
|
|
11
|
-
* when it says, else the count the command names (`--test-threads=N`, `--parallel=N
|
|
12
|
-
* runner's own default — one thread per core for
|
|
13
|
-
*
|
|
47
|
+
* when it says, else the count the command names (`--test-threads=N`, `--parallel=N`, a worker
|
|
48
|
+
* flag's N or N%, `--jobserver-tasks=N`), else the runner's own default — one thread per core for
|
|
49
|
+
* nextest, a bare `--parallel` and cargo; a worker-flag runner's own (`WORKER_FLAGS`); one per core
|
|
50
|
+
* for cargo-mutants, whose own jobserver defaults to one task per core whatever `--jobs` says; one
|
|
51
|
+
* process for anything else. A nextest run with `--no-capture` runs one test at a time whatever
|
|
52
|
+
* thread count it names, so it asks for one. Positive inherited runner counts are ceilings;
|
|
53
|
+
* configured counts may only lower them.
|
|
14
54
|
*/
|
|
15
55
|
export function runnerDemand(command, declared, cores, inherited, configured) {
|
|
16
|
-
const kind = command
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const named = counted === null
|
|
25
|
-
? []
|
|
26
|
-
: [...command.matchAll(counted)].flatMap((match) => (match[1] === undefined ? [] : [Number(match[1])]));
|
|
27
|
-
const requested = declared ?? (named.length > 0 ? Math.max(...named) : kind === 'process' ? 1 : cores);
|
|
56
|
+
const kind = runnerKind(command);
|
|
57
|
+
// cargo-mutants' cargo processes at once: `--jobs`, else `CARGO_MUTANTS_JOBS` as the command will see it, else one.
|
|
58
|
+
const jobs = kind === 'cargo-mutants'
|
|
59
|
+
? (namedCounts(invocationArgs(command, CARGO_MUTANTS), MUTANTS_JOBS).at(-1) ??
|
|
60
|
+
parseInheritedTokens(configured?.CARGO_MUTANTS_JOBS ?? inherited.CARGO_MUTANTS_JOBS) ??
|
|
61
|
+
1)
|
|
62
|
+
: 1;
|
|
63
|
+
const requested = declared ?? ownParallelism(kind, command, cores, jobs, { ...inherited, ...configured });
|
|
28
64
|
const ceiling = kind === 'nextest'
|
|
29
65
|
? inheritedCeiling(inherited.NEXTEST_TEST_THREADS, configured?.NEXTEST_TEST_THREADS)
|
|
30
66
|
: kind === 'cargo'
|
|
31
67
|
? inheritedCeiling(inherited.CARGO_BUILD_JOBS, configured?.CARGO_BUILD_JOBS)
|
|
32
68
|
: null;
|
|
33
69
|
const want = Math.max(1, Math.min(requested, ceiling ?? requested));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
70
|
+
switch (kind) {
|
|
71
|
+
case 'cargo':
|
|
72
|
+
return { kind, want, testThreads: inheritedCeiling(inherited.RUST_TEST_THREADS, configured?.RUST_TEST_THREADS) };
|
|
73
|
+
case 'cargo-mutants':
|
|
74
|
+
return { kind, want, jobs };
|
|
75
|
+
default:
|
|
76
|
+
return { kind, want };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function runnerKind(command) {
|
|
80
|
+
if (command.search(NEXTEST_RUN) !== -1) {
|
|
81
|
+
return 'nextest';
|
|
82
|
+
}
|
|
83
|
+
// Stryker before Vitest: its vitest runner is Stryker's workers, not a `vitest` invocation of the command.
|
|
84
|
+
for (const kind of ['stryker', 'vitest', 'go-test']) {
|
|
85
|
+
if (WORKER_FLAGS[kind].invocation.test(command)) {
|
|
86
|
+
return kind;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (CARGO_MUTANTS.test(command)) {
|
|
90
|
+
return 'cargo-mutants';
|
|
91
|
+
}
|
|
92
|
+
if (command.search(BUN_TEST) !== -1 && command.search(BUN_PARALLEL) !== -1) {
|
|
93
|
+
return 'bun-parallel';
|
|
94
|
+
}
|
|
95
|
+
return CARGO_BUILD.test(command) ? 'cargo' : 'process';
|
|
96
|
+
}
|
|
97
|
+
/** What the runner runs at once when the target declares nothing: the count it names, else its own default. */
|
|
98
|
+
function ownParallelism(kind, command, cores, jobs, env) {
|
|
99
|
+
switch (kind) {
|
|
100
|
+
case 'nextest': {
|
|
101
|
+
const named = namedCounts(command, TEST_THREADS);
|
|
102
|
+
return NO_CAPTURE.test(command) ? 1 : named.length > 0 ? Math.max(...named) : cores;
|
|
103
|
+
}
|
|
104
|
+
case 'bun-parallel': {
|
|
105
|
+
const named = namedCounts(command, BUN_PARALLEL);
|
|
106
|
+
return named.length > 0 ? Math.max(...named) : cores;
|
|
107
|
+
}
|
|
108
|
+
case 'stryker':
|
|
109
|
+
case 'vitest':
|
|
110
|
+
case 'go-test': {
|
|
111
|
+
const runner = WORKER_FLAGS[kind];
|
|
112
|
+
const args = invocationArgs(command, runner.invocation);
|
|
113
|
+
if (runner.serial?.test(args)) {
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
// The runner takes the last count it is given; a share is of the cores, between one worker and all of them.
|
|
117
|
+
const named = [...args.matchAll(runner.flag)].flatMap((match) => {
|
|
118
|
+
const count = WORKER_COUNT.exec(match[1] ?? '');
|
|
119
|
+
if (count === null) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const value = Number(count[2]);
|
|
123
|
+
return [count[3] === '%' ? Math.max(1, Math.min(cores, Math.round((cores * value) / 100))) : value];
|
|
124
|
+
});
|
|
125
|
+
return named.at(-1) ?? runner.ownDefault(cores, env);
|
|
126
|
+
}
|
|
127
|
+
case 'cargo-mutants':
|
|
128
|
+
// Its compiles share its own jobserver (one task per core unless named); its `jobs` test runs need a thread each.
|
|
129
|
+
return Math.max(namedCounts(invocationArgs(command, CARGO_MUTANTS), JOBSERVER_TASKS).at(-1) ?? cores, jobs);
|
|
130
|
+
case 'cargo':
|
|
131
|
+
return cores;
|
|
132
|
+
case 'process':
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function namedCounts(text, flag) {
|
|
137
|
+
return [...text.matchAll(flag)].flatMap((match) => (match[1] === undefined ? [] : [Number(match[1])]));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Where `invocation` ends in `command`, and where its own arguments end: the next `;`, `&`, `|`, `(` or `)` outside
|
|
141
|
+
* quotes and `$(…)`.
|
|
142
|
+
*/
|
|
143
|
+
function invocationSpan(command, invocation) {
|
|
144
|
+
const found = invocation.exec(command);
|
|
145
|
+
const end = found === null ? command.length : found.index + found[0].length;
|
|
146
|
+
let quote = null;
|
|
147
|
+
let substitutions = 0;
|
|
148
|
+
for (let at = end; at < command.length; at += 1) {
|
|
149
|
+
const char = command[at];
|
|
150
|
+
if (quote !== null) {
|
|
151
|
+
quote = char === quote ? null : quote;
|
|
152
|
+
}
|
|
153
|
+
else if (char === '"' || char === "'") {
|
|
154
|
+
quote = char;
|
|
155
|
+
}
|
|
156
|
+
else if (char === '$' && command[at + 1] === '(') {
|
|
157
|
+
substitutions += 1;
|
|
158
|
+
at += 1;
|
|
159
|
+
}
|
|
160
|
+
else if (char === ')' && substitutions > 0) {
|
|
161
|
+
substitutions -= 1;
|
|
162
|
+
}
|
|
163
|
+
else if (substitutions === 0 && (char === ';' || char === '&' || char === '|' || char === '(' || char === ')')) {
|
|
164
|
+
return { end, argsEnd: at };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return { end, argsEnd: command.length };
|
|
168
|
+
}
|
|
169
|
+
function invocationArgs(command, invocation) {
|
|
170
|
+
const { end, argsEnd } = invocationSpan(command, invocation);
|
|
171
|
+
return command.slice(end, argsEnd);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* `command` with every `flag` in `invocation`'s own arguments replaced by `sized`; when it names none, `sized` is
|
|
175
|
+
* added right after the invocation if `add` says so.
|
|
176
|
+
*/
|
|
177
|
+
function withSizedFlag(command, invocation, flag, sized, add) {
|
|
178
|
+
const { end, argsEnd } = invocationSpan(command, invocation);
|
|
179
|
+
const args = command.slice(end, argsEnd);
|
|
180
|
+
const sizedArgs = args.search(flag) === -1 && add ? ` ${sized}${args}` : args.replace(flag, sized);
|
|
181
|
+
return `${command.slice(0, end)}${sizedArgs}${command.slice(argsEnd)}`;
|
|
37
182
|
}
|
|
38
183
|
/**
|
|
39
184
|
* Size the runner to the lesser of its bounded demand and grant, retaining Cargo's test-thread ceiling.
|
|
@@ -60,6 +205,32 @@ export function sizeRunner(demand, command, tokens) {
|
|
|
60
205
|
RUST_TEST_THREADS: String(Math.min(runnerCount, demand.testThreads ?? runnerCount)),
|
|
61
206
|
},
|
|
62
207
|
};
|
|
208
|
+
case 'stryker':
|
|
209
|
+
case 'vitest':
|
|
210
|
+
case 'go-test': {
|
|
211
|
+
const runner = WORKER_FLAGS[demand.kind];
|
|
212
|
+
return {
|
|
213
|
+
command: withSizedFlag(command, runner.invocation, runner.flag, runner.sized(runnerCount), true),
|
|
214
|
+
env: { [CPU_TOKENS_ENV]: held },
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
case 'cargo-mutants': {
|
|
218
|
+
// Its own jobserver bounds every compile it starts; each of its `jobs` cargo processes runs tests on its share.
|
|
219
|
+
// `--jobs` is lowered only where it was set: cargo-mutants refuses it beside `--in-place`.
|
|
220
|
+
const jobs = Math.min(demand.jobs, runnerCount);
|
|
221
|
+
const share = String(Math.max(1, Math.floor(runnerCount / jobs)));
|
|
222
|
+
const tasks = withSizedFlag(command, CARGO_MUTANTS, JOBSERVER_TASKS, `--jobserver-tasks=${count}`, true);
|
|
223
|
+
return {
|
|
224
|
+
command: withSizedFlag(tasks, CARGO_MUTANTS, MUTANTS_JOBS, `--jobs=${jobs}`, false),
|
|
225
|
+
env: {
|
|
226
|
+
[CPU_TOKENS_ENV]: held,
|
|
227
|
+
...(demand.jobs > 1 ? { CARGO_MUTANTS_JOBS: String(jobs) } : {}),
|
|
228
|
+
CARGO_BUILD_JOBS: share,
|
|
229
|
+
RUST_TEST_THREADS: share,
|
|
230
|
+
NEXTEST_TEST_THREADS: share,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
63
234
|
case 'process':
|
|
64
235
|
return { command, env: { [CPU_TOKENS_ENV]: held } };
|
|
65
236
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,gBAAgB,EAGtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uBAAuB,CAAC;AAGhF,OAAO,EAML,aAAa,EAEd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAEL,KAAK,eAAe,EAar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AqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CA2B5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,kBAAkB,CAiBxE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,UAAU,GAAG,IAAI,EAC7B,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,SAAS,GAAE,gBAAgB,GAAG,IAAW,EACzC,kBAAkB,GAAE,OAAO,sBAA+C,GACzE,OAAO,CAAC,iBAAiB,CAAC,CA8iB5B;AAED,wBAAgB,uBAAuB,IAAI,iBAAiB,CAM3D"}
|
|
@@ -191,8 +191,9 @@ export async function runBoundedExec(options, context, killer, tempVolume, budge
|
|
|
191
191
|
appendStderr(`${describeRamTempError(released.error)}\n`);
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
|
-
// The wait is one span line, as cowshed's own spans read.
|
|
195
|
-
//
|
|
194
|
+
// The wait is one span line, as cowshed's own spans read. On a host without a gateway the Nx run serves its own
|
|
195
|
+
// pool (`run-cpu-pool.ts`), taken below as a parent's; a command no pool and no gateway answers runs exactly as
|
|
196
|
+
// asked and nothing is said.
|
|
196
197
|
const cores = availableParallelism();
|
|
197
198
|
const demand = runnerDemand(requested, options.parallelism, cores, process.env, options.env);
|
|
198
199
|
const asked = Date.now();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serve `context`'s run a pool of `cores` tokens and publish it in `env`, which every task inherits, when the run
|
|
4
|
+
* inherits no pool and no gateway exists at `gateway`. A pool that cannot be made is said and leaves the run
|
|
5
|
+
* unbudgeted, as a run without a gateway was before.
|
|
6
|
+
*/
|
|
7
|
+
export declare function serveRunCpuPool(context: Pick<PreTasksExecutionContext, 'id'>, env?: NodeJS.ProcessEnv, gateway?: string, cores?: number): Promise<void>;
|
|
8
|
+
/** Close the pool `context`'s run was served, if it was served one. */
|
|
9
|
+
export declare function closeRunCpuPool(context: Pick<PostTasksExecutionContext, 'id'>): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=run-cpu-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAsBtH;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,OAAO,GAAE,MAAuB,EAChC,KAAK,GAAE,MAA+B,GACrC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { lstat } from 'node:fs/promises';
|
|
2
|
+
import { availableParallelism } from 'node:os';
|
|
3
|
+
import { logger } from 'nx/src/devkit-exports.js';
|
|
4
|
+
import { createCpuPool, readInheritedCpuPool } from './cpu-pool.js';
|
|
5
|
+
import { GATEWAY_SOCKET } from './gateway-lease.js';
|
|
6
|
+
/**
|
|
7
|
+
* The CPU budget of an Nx run on a host without a gateway (specs/cowshed/05_gateway.md, "Host CPU budget", "A run
|
|
8
|
+
* without a gateway").
|
|
9
|
+
*
|
|
10
|
+
* Every runner sizes itself to the whole host unless something budgets it, and without a gateway nothing did: under
|
|
11
|
+
* `NX_PARALLEL=100%` Nx starts every target side by side and each one's runner takes the whole machine. The run
|
|
12
|
+
* therefore serves its own pool of one token per core, as a gateway-granted executor serves its children, and every
|
|
13
|
+
* task inherits it: `bounded-exec` and the `cargo` launcher take from it as from any parent pool, FIFO, the head
|
|
14
|
+
* taking `min(want, free)` once one token is free, so the runners of one run together stay within the cores.
|
|
15
|
+
*
|
|
16
|
+
* The run serves it only when nothing else budgets it: it inherits no pool, and the gateway's control socket does
|
|
17
|
+
* not exist. Only `ENOENT` proves the gateway absent, as for the launcher; a socket that exists but does not answer
|
|
18
|
+
* may be a live, saturated gateway, and a run budgeting itself beside it would count the host twice.
|
|
19
|
+
*/
|
|
20
|
+
/** The pools this process serves, by Nx run id, until that run's `postTasksExecution`. */
|
|
21
|
+
const pools = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Serve `context`'s run a pool of `cores` tokens and publish it in `env`, which every task inherits, when the run
|
|
24
|
+
* inherits no pool and no gateway exists at `gateway`. A pool that cannot be made is said and leaves the run
|
|
25
|
+
* unbudgeted, as a run without a gateway was before.
|
|
26
|
+
*/
|
|
27
|
+
export async function serveRunCpuPool(context, env = process.env, gateway = GATEWAY_SOCKET, cores = availableParallelism()) {
|
|
28
|
+
if (readInheritedCpuPool(env) !== null || !(await absent(gateway))) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// The pool lives until the run's `postTasksExecution` closes it, or with this process.
|
|
32
|
+
const made = await createCpuPool(cores, new Promise(() => { }), { begin() { }, end() { } });
|
|
33
|
+
if (!made.ok) {
|
|
34
|
+
logger.warn(`bounded-exec: no gateway at ${gateway}, and this run's CPU pool failed (${made.error}); its tasks run unbudgeted`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
pools.set(context.id, made.pool);
|
|
38
|
+
for (const [name, value] of Object.entries(made.pool.environment)) {
|
|
39
|
+
env[name] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Close the pool `context`'s run was served, if it was served one. */
|
|
43
|
+
export async function closeRunCpuPool(context) {
|
|
44
|
+
const pool = pools.get(context.id);
|
|
45
|
+
if (pool === undefined) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
pools.delete(context.id);
|
|
49
|
+
const closed = await pool.close();
|
|
50
|
+
if (!closed.ok) {
|
|
51
|
+
logger.warn(`bounded-exec: this run's CPU pool did not close cleanly: ${closed.error}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function absent(path) {
|
|
55
|
+
try {
|
|
56
|
+
await lstat(path);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const code = error instanceof Error && 'code' in error ? error.code : undefined;
|
|
61
|
+
return code === 'ENOENT' || code === 'ENOTDIR';
|
|
62
|
+
}
|
|
63
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,9 @@ export declare const createNodesV2: CreateNodesV2;
|
|
|
35
35
|
/**
|
|
36
36
|
* Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
|
|
37
37
|
* hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
|
|
38
|
-
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
|
|
38
|
+
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
|
|
39
|
+
* pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
|
|
40
|
+
* (`run-cpu-pool.ts`), and closes it when the run ends.
|
|
39
41
|
*/
|
|
40
42
|
export declare const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions>;
|
|
41
43
|
export declare const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB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;AAeF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,uBAAuB,CAIxE,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,uBAAuB,CAI1E,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { CARGO_CLOSURE_INPUT, cargoClosureInputs, indexedCargoManifests, resolve
|
|
|
12
12
|
import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS, cargoRuntimeInput, } from './cargo-toolchain-policy.js';
|
|
13
13
|
import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, serialTestGroups, } from './cargo-workspace.js';
|
|
14
14
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
|
|
15
|
+
import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
|
|
15
16
|
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
16
17
|
import { EXTRACTED_BINARIES_METADATA, EXTRACTED_CARGO_METADATA, EXTRACTED_TARGET_DIR, NEXTEST_EXTRACT_BIN, } from './nextest-extraction.js';
|
|
17
18
|
import { postTasksExecution as postProducerReceipts, preTasksExecution as preProducerReceipts, } from './producer-receipts.js';
|
|
@@ -400,6 +401,8 @@ const CARGO_INPUTS = [
|
|
|
400
401
|
// build really reads is the package's `napi` block (binary name, targets) and
|
|
401
402
|
// the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
|
|
402
403
|
const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
|
|
404
|
+
/** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
|
|
405
|
+
const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
|
|
403
406
|
// The toolchain half of a cargo task's identity lives in its own module
|
|
404
407
|
// because `smoo monorepo validate` reads the same two constants to refuse a
|
|
405
408
|
// declaration that drops it. See cargo-toolchain-policy.ts for why it is the
|
|
@@ -849,15 +852,19 @@ function isBuildOutputPackageJson(packageJsonPath) {
|
|
|
849
852
|
/**
|
|
850
853
|
* Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
|
|
851
854
|
* hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
|
|
852
|
-
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
|
|
855
|
+
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
|
|
856
|
+
* pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
|
|
857
|
+
* (`run-cpu-pool.ts`), and closes it when the run ends.
|
|
853
858
|
*/
|
|
854
859
|
export const preTasksExecution = async (options, context) => {
|
|
855
860
|
preTaskResults(options, context);
|
|
856
861
|
await preProducerReceipts(options, context);
|
|
862
|
+
await serveRunCpuPool(context);
|
|
857
863
|
};
|
|
858
864
|
export const postTasksExecution = async (options, context) => {
|
|
859
865
|
await postTaskResults(options, context);
|
|
860
866
|
await postProducerReceipts(options, context);
|
|
867
|
+
await closeRunCpuPool(context);
|
|
861
868
|
};
|
|
862
869
|
export default { createNodesV2, postTasksExecution, preTasksExecution };
|
|
863
870
|
function packageBinOutputs(packageJson, packageJsonPath) {
|
|
@@ -1223,10 +1230,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1223
1230
|
};
|
|
1224
1231
|
// Mutation runs are minutes-to-hours: never cached, never part of build/lint.
|
|
1225
1232
|
// CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
|
|
1233
|
+
// bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
|
|
1234
|
+
// otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
|
|
1235
|
+
// progress, so its bound is a wall-clock backstop, not a performance budget.
|
|
1226
1236
|
targets.mutation = {
|
|
1227
|
-
executor: 'nx:
|
|
1237
|
+
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1228
1238
|
cache: false,
|
|
1229
|
-
options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot },
|
|
1239
|
+
options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
|
|
1230
1240
|
};
|
|
1231
1241
|
targets.bench = {
|
|
1232
1242
|
executor: 'nx:run-commands',
|
|
@@ -253,6 +253,19 @@ try {
|
|
|
253
253
|
current && !hasStaleDeveloperLinks(projectRoot, ['nx']) && danglingStoreLinks(projectRoot).length === 0 ? 0 : 1,
|
|
254
254
|
);
|
|
255
255
|
}
|
|
256
|
+
// Planning reads, apart from a snapshot it may capture, which seals by an atomic rename (linked-snapshots.ts),
|
|
257
|
+
// and applying a plan with no changes only says what this machine cannot honour. So an entry with nothing to
|
|
258
|
+
// write never takes the install lock, and the entries of one checkout do not queue behind each other's probe of
|
|
259
|
+
// a provider checkout: a declaration whose snapshot the provider refuses fails the status on every entry.
|
|
260
|
+
const plan = await planDeclaredLinks(projectRoot);
|
|
261
|
+
if (
|
|
262
|
+
plan.changes.length === 0 &&
|
|
263
|
+
danglingStoreLinks(projectRoot).length === 0 &&
|
|
264
|
+
!hasStaleDeveloperLinks(projectRoot, ['nx'])
|
|
265
|
+
) {
|
|
266
|
+
applyDeclaredLinks(projectRoot, plan);
|
|
267
|
+
process.exit(0);
|
|
268
|
+
}
|
|
256
269
|
await withInstallLock(async () => {
|
|
257
270
|
// Recheck under the install lock: another shell may already have repaired
|
|
258
271
|
// the aliases. Use the same installer as smoo:install, never a second linker.
|
package/package.json
CHANGED
|
@@ -223,8 +223,9 @@ it('the hook run reads the key the gate run wrote, after the gate rewrote compil
|
|
|
223
223
|
const gate = await nx(GATE_RECEIPT);
|
|
224
224
|
expect(gate.exitCode, gate.log).toBe(0);
|
|
225
225
|
expect(await readFile(join(workspace, '.runs'), 'utf8')).toBe('1\n');
|
|
226
|
-
// The gate's own execution left a compiled-in file its graph never saw.
|
|
227
|
-
|
|
226
|
+
// The gate's own execution left a compiled-in file its graph never saw. readdir's order is the filesystem's
|
|
227
|
+
// (hash order on Linux), so the listing is compared as a set.
|
|
228
|
+
expect((await readdir(join(workspace, GENERATED))).sort()).toEqual(['chunk-1.js', 'vocabulary.rs']);
|
|
228
229
|
|
|
229
230
|
const hook = await nx(HOOK_RECEIPT);
|
|
230
231
|
expect(hook.exitCode, hook.log).toBe(0);
|