@smoothbricks/nx-plugin 0.6.2 → 0.7.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 +417 -171
- package/dist/.build-inputs.json +39 -28
- package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
- package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
- package/dist/bin/smoo-nx-go-test-build.js +79 -0
- package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
- package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
- package/dist/bin/smoo-nx-go-test-run.js +129 -0
- package/dist/bin/smoo-nx-publish.d.ts +3 -0
- package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
- package/dist/bin/smoo-nx-publish.js +3 -0
- package/dist/bounded-test-policy.d.ts +1 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +9 -8
- package/dist/cargo-retention-hook.d.ts +6 -2
- package/dist/cargo-retention-hook.d.ts.map +1 -1
- package/dist/cargo-retention-hook.js +13 -7
- package/dist/cargo-workspace.d.ts +10 -20
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +12 -22
- package/dist/cross-check-policy.d.ts +2 -2
- package/dist/cross-check-policy.js +2 -2
- package/dist/deploy-policy.d.ts +6 -0
- package/dist/deploy-policy.d.ts.map +1 -1
- package/dist/deploy-policy.js +11 -0
- package/dist/eslint-file-set.d.ts +4 -1
- package/dist/eslint-file-set.d.ts.map +1 -1
- package/dist/eslint-sources.d.ts +25 -0
- package/dist/eslint-sources.d.ts.map +1 -0
- package/dist/eslint-sources.js +99 -0
- package/dist/executors/all-verdicts/executor.d.ts +2 -1
- package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
- package/dist/executors/all-verdicts/executor.js +48 -2
- package/dist/executors/all-verdicts/schema.d.ts +13 -0
- package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
- package/dist/executors/all-verdicts/schema.js +7 -0
- package/dist/executors/bounded-exec/bounds.d.ts +57 -8
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +100 -11
- package/dist/executors/bounded-exec/executor.d.ts +2 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +289 -34
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
- package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +145 -11
- package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
- package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-queue.js +229 -0
- package/dist/executors/bounded-exec/progress.d.ts +9 -2
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +151 -25
- package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +55 -4
- package/dist/executors/bounded-exec/runtime-pin.js +1 -1
- package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
- package/dist/executors/bounded-exec/test-result-writer.js +126 -0
- package/dist/executors/bounded-exec/test-results.d.ts +33 -0
- package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
- package/dist/executors/bounded-exec/test-results.js +33 -0
- package/dist/executors/bounded-exec/verdict.d.ts +26 -2
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +108 -4
- package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
- package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
- package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
- package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/executor.js +43 -0
- package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
- package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/hasher.js +90 -0
- package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
- package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
- package/dist/go-tests.d.ts +30 -0
- package/dist/go-tests.d.ts.map +1 -0
- package/dist/go-tests.js +43 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +338 -295
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +5 -0
- package/dist/nx-publish.d.ts +24 -0
- package/dist/nx-publish.d.ts.map +1 -0
- package/dist/nx-publish.js +150 -0
- package/dist/process-group.js +2 -2
- package/dist/runtime-input-policy.d.ts +17 -3
- package/dist/runtime-input-policy.d.ts.map +1 -1
- package/dist/runtime-input-policy.js +4 -4
- package/dist/test-timings.d.ts +23 -4
- package/dist/test-timings.d.ts.map +1 -1
- package/dist/test-timings.js +72 -12
- package/dist/tool-bins.d.ts +6 -8
- package/dist/tool-bins.d.ts.map +1 -1
- package/dist/tool-bins.js +7 -5
- package/dist/version-actions.cjs +10 -11
- package/dist/version-actions.d.cts.map +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +17 -22
- package/dist/workspace-index.d.ts +7 -0
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +11 -0
- package/dist/workspace-manifest.js +3 -3
- package/executors.json +7 -6
- package/managed/raw/patches/nx@23.2.1.patch +118 -24
- package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
- package/managed/raw/tooling/devenv +1 -2
- package/managed/raw/tooling/direnv/developer-links.ts +124 -51
- package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
- package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
- package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
- package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
- package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
- package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
- package/package.json +277 -11
- package/runtime/nx-publish/.build-inputs.json +11 -0
- package/runtime/nx-publish/cache_adapter.js +45 -0
- package/runtime/nx-publish/nx_publish.js +60 -0
- package/runtime-input.sh +62 -26
- package/src/bin/smoo-nx-go-test-build.ts +83 -0
- package/src/bin/smoo-nx-go-test-run.ts +140 -0
- package/src/bin/smoo-nx-publish.ts +4 -0
- package/src/bounded-test-policy.ts +9 -8
- package/src/cargo-retention-hook.ts +16 -10
- package/src/cargo-workspace.ts +12 -24
- package/src/cross-check-policy.ts +2 -2
- package/src/deploy-policy.ts +11 -0
- package/src/eslint-file-set.ts +4 -1
- package/src/eslint-sources.ts +134 -0
- package/src/executors/all-verdicts/executor.ts +58 -3
- package/src/executors/all-verdicts/schema.json +4 -0
- package/src/executors/all-verdicts/schema.ts +14 -0
- package/src/executors/bounded-exec/bounds.ts +132 -15
- package/src/executors/bounded-exec/executor.ts +329 -34
- package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
- package/src/executors/bounded-exec/mbx-pool.ts +158 -17
- package/src/executors/bounded-exec/mbx-queue.ts +170 -0
- package/src/executors/bounded-exec/progress.ts +171 -18
- package/src/executors/bounded-exec/runner-sizing.ts +73 -7
- package/src/executors/bounded-exec/runtime-pin.ts +1 -1
- package/src/executors/bounded-exec/test-result-writer.ts +152 -0
- package/src/executors/bounded-exec/test-results.ts +39 -0
- package/src/executors/bounded-exec/verdict.ts +115 -5
- package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
- package/src/executors/wrangler-deploy/executor.ts +63 -0
- package/src/executors/wrangler-deploy/hasher.ts +111 -0
- package/src/executors/wrangler-deploy/schema.json +16 -0
- package/src/executors/wrangler-deploy/schema.ts +4 -0
- package/src/go-tests.ts +67 -0
- package/src/index.ts +368 -323
- package/src/managed-files/files.ts +5 -0
- package/src/nx-publish.ts +157 -0
- package/src/process-group.ts +2 -2
- package/src/runtime-input-policy.ts +4 -4
- package/src/test-timings.ts +72 -14
- package/src/tool-bins.ts +13 -9
- package/src/version-actions.cts +10 -11
- package/src/workspace-config-policy.ts +20 -29
- package/src/workspace-index.ts +12 -0
- package/src/workspace-manifest.ts +3 -3
- package/test-timings.json +131 -125
- package/dist/executors/clean-outputs/executor.d.ts +0 -26
- package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
- package/dist/executors/clean-outputs/executor.js +0 -83
- package/dist/executors/clean-outputs/schema.d.ts +0 -4
- package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
- package/src/executors/clean-outputs/executor.ts +0 -131
- package/src/executors/clean-outputs/schema.json +0 -15
- package/src/executors/clean-outputs/schema.ts +0 -3
- /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
|
@@ -1,24 +1,158 @@
|
|
|
1
|
+
import { shellTokens } from '../../runtime-input-policy.js';
|
|
2
|
+
import { CPU_TOKENS_ENV, grantedSizing, invocationSpan } from './runner-sizing.js';
|
|
1
3
|
import { shellQuote } from './verdict.js';
|
|
2
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged, or
|
|
6
|
+
* where this run is already inside an mbx reservation: `mbx reserve` hands its command `MBX_SCHED_DISABLE=1`, and nested
|
|
7
|
+
* non-Cargo work shares the enclosing grant instead of reserving twice (specs/cowshed/05_gateway.md, "Parallelism
|
|
8
|
+
* inside a job"). A second reservation would wait in the pool while its parent holds a grant, so under a full pool the
|
|
9
|
+
* nested leaf queued behind the very work it belongs to.
|
|
10
|
+
*/
|
|
3
11
|
export function mbxPool(environment) {
|
|
4
|
-
if (environment.MBX_SCHEDULER !== '1' || !environment.MBX_CACHE_DIR) {
|
|
12
|
+
if (environment.MBX_SCHEDULER !== '1' || !environment.MBX_CACHE_DIR || environment.MBX_SCHED_DISABLE === '1') {
|
|
5
13
|
return null;
|
|
6
14
|
}
|
|
7
15
|
return { priority: environment.MBX_SCHEDULER_PRIORITY === 'normal' ? 'normal' : 'low' };
|
|
8
16
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
/** A nextest invocation that runs test binaries already built, from extracted archive metadata or an archive file. */
|
|
18
|
+
const PREBUILT_NEXTEST = /(?<![\w-])--(?:binaries-metadata|archive-file)(?=[=\s]|$)/;
|
|
19
|
+
/** Whether `command` runs nextest over test binaries already built, which compiles nothing. */
|
|
20
|
+
export function runsPrebuiltNextest(command) {
|
|
21
|
+
return PREBUILT_NEXTEST.test(command);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A Vitest or Go test leaf enters no pool, `null` (owner's ruling, 2026-10-31): it holds nothing and runs its own
|
|
25
|
+
* default workers, uncapped. Reserved like any other leaf, it asked for that default, which sizes to the host: Vitest one
|
|
26
|
+
* worker per core but one, Go one package per core. So each held 17 or 18 of an 18-core pool, and mbx's ordered admission
|
|
27
|
+
* kept every reservation queued behind it waiting while the pool drained. On 2026-10-31 a downstream gate ran 4.9 of 18
|
|
28
|
+
* cores busy while 25 of its tasks queued a minute or more, and a gate's Go test leaf waited 401 s for all 18 cores.
|
|
29
|
+
*/
|
|
30
|
+
export function mbxLeaf(pool, demand, command) {
|
|
31
|
+
const reserve = (reserved) => ({
|
|
32
|
+
kind: 'reserve',
|
|
33
|
+
priority: pool.priority,
|
|
34
|
+
demand: reserved,
|
|
35
|
+
});
|
|
36
|
+
switch (demand.kind) {
|
|
37
|
+
case 'vitest':
|
|
38
|
+
case 'go-test':
|
|
39
|
+
return null;
|
|
40
|
+
case 'cargo':
|
|
41
|
+
case 'cargo-mutants':
|
|
42
|
+
return { kind: 'cargo' };
|
|
43
|
+
case 'nextest':
|
|
44
|
+
return runsPrebuiltNextest(command) ? reserve(demand) : { kind: 'cargo' };
|
|
45
|
+
case 'bun-parallel':
|
|
46
|
+
case 'stryker':
|
|
47
|
+
case 'process':
|
|
48
|
+
return reserve(demand);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Nx's own default count of tasks at once, when nothing names one. */
|
|
52
|
+
const NX_DEFAULT_PARALLEL = 3;
|
|
53
|
+
/**
|
|
54
|
+
* The cores one task of an Nx run counts as its own: the host's cores divided among the tasks Nx runs at once, at
|
|
55
|
+
* least one. Nx reads that count from `NX_PARALLEL`, a number or a share of the cores (`100%`), else runs three.
|
|
56
|
+
*
|
|
57
|
+
* A prebuilt nextest leaf asks for this share rather than its runner's own count, every core by default, because it
|
|
58
|
+
* does not know how many tests it runs: mbx grants a reservation as many of its cores as are free, so a leaf of a few
|
|
59
|
+
* long tests asking for every core would hold the idle rest for its whole run (specs/cowshed/05_gateway.md, "Open
|
|
60
|
+
* questions"). Before mbx granted reservations their free cores, every cargo-test leaf of a gate reserved the whole
|
|
61
|
+
* pool and they ran one at a time: on 2026-10-30 a gate's 18-core host ran 4.2 cores busy, its leaves each holding
|
|
62
|
+
* `mbx reserve --cpus 18`.
|
|
63
|
+
*/
|
|
64
|
+
export function nxTaskCores(cores, environment) {
|
|
65
|
+
const named = environment.NX_PARALLEL?.trim() ?? '';
|
|
66
|
+
const share = /^(\d+)%$/.exec(named);
|
|
67
|
+
const count = share?.[1] !== undefined ? (cores * Number(share[1])) / 100 : /^\d+$/.test(named) ? Number(named) : 0;
|
|
68
|
+
const parallel = count >= 1 ? Math.floor(count) : NX_DEFAULT_PARALLEL;
|
|
69
|
+
return Math.max(1, Math.floor(cores / parallel));
|
|
14
70
|
}
|
|
15
71
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
72
|
+
* The value an in-place runner gives `--target-dir-remap`: smoo-nx-nextest-binaries' answer, quoted. The plugin infers
|
|
73
|
+
* the native helper; a repository's own runner may name its script through bun, which prints the same path.
|
|
74
|
+
*/
|
|
75
|
+
const INFERRED_TARGET_DIR_REMAP = /--target-dir-remap "\$\((?:bun )?[^\s"'$`;&|()<>\\]+\/smoo-nx-nextest-binaries(?:\.js)? target-dir\)"/g;
|
|
76
|
+
/**
|
|
77
|
+
* Only a known scheduled execution may stop its idle clock at zero holds. Plain Cargo tests can run doctests;
|
|
78
|
+
* archive-file targets, direct binaries and other runners are not proven scheduled at spawn (11_shell.md,
|
|
79
|
+
* "Cargo test-runner boundaries"). The inferred in-place nextest command is a supported Cargo invocation.
|
|
80
|
+
*/
|
|
81
|
+
export function mbxIdleGated(leaf, command, environment) {
|
|
82
|
+
if (leaf === null)
|
|
83
|
+
return false;
|
|
84
|
+
if (leaf.kind === 'reserve')
|
|
85
|
+
return true;
|
|
86
|
+
if (environment.MBX_SCHEDULER_TESTS !== '1')
|
|
87
|
+
return false;
|
|
88
|
+
if (environment.MBX_SCHEDULER === '0' || environment.MBX_SCHED_DISABLE === '1' || environment.MBX_DISABLE === '1')
|
|
89
|
+
return false;
|
|
90
|
+
// The inferred in-place runner names this checkout's target directory through the plugin's helper: one quoted
|
|
91
|
+
// substitution, the value of `--target-dir-remap`, that prints a path and runs nothing mbx schedules.
|
|
92
|
+
const known = command.replace(INFERRED_TARGET_DIR_REMAP, '--target-dir-remap target');
|
|
93
|
+
// invocationSpan shares the lifecycle mapper's conservative shell-syntax boundary.
|
|
94
|
+
if (/[<>\n\r`\\]/.test(known))
|
|
95
|
+
return false;
|
|
96
|
+
if (/[^\S \t]/.test(known))
|
|
97
|
+
return false;
|
|
98
|
+
const invocation = /cargo(?:\s+(?:--frozen|--locked|--offline))*\s+(nextest\s+run|test)(?=\s|$)/;
|
|
99
|
+
const found = invocation.exec(known);
|
|
100
|
+
if (found === null || known.slice(0, found.index).trim() !== '')
|
|
101
|
+
return false;
|
|
102
|
+
let remaining = known.slice(found.index);
|
|
103
|
+
const unquoted = remaining.replace(/"[^"]*"|'[^']*'/g, '');
|
|
104
|
+
if (/[$*?{}~[\]]/.test(unquoted))
|
|
105
|
+
return false;
|
|
106
|
+
// Only the inferred command's path templates are known expansions; arbitrary words could supply mbx overrides.
|
|
107
|
+
if (remaining.replace(/\$PWD(?=\/)/g, '').includes('$'))
|
|
108
|
+
return false;
|
|
109
|
+
for (;;) {
|
|
110
|
+
const leg = invocation.exec(remaining);
|
|
111
|
+
if (leg === null || leg.index !== 0)
|
|
112
|
+
return false;
|
|
113
|
+
const { argsEnd } = invocationSpan(remaining, invocation);
|
|
114
|
+
const args = [];
|
|
115
|
+
for (const token of shellTokens(remaining.slice(0, argsEnd), [])) {
|
|
116
|
+
if (token.kind !== 'word')
|
|
117
|
+
return false;
|
|
118
|
+
if (token.text === '--')
|
|
119
|
+
break;
|
|
120
|
+
if (token.text.startsWith('$'))
|
|
121
|
+
return false;
|
|
122
|
+
args.push(token.text);
|
|
123
|
+
}
|
|
124
|
+
if (args.some((arg) => /^(?:--(?:config|directory|archive-file)(?:=|$)|--(?:doc|no-run|list|help)(?:=|$)|-C|-h$|\+)/.test(arg))) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (leg[1] === 'test' &&
|
|
128
|
+
!args.some((arg) => /^--(?:lib|tests|bins|examples|benches|all-targets|test|bin|example|bench)(?:=|$)/.test(arg))) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const suffix = remaining.slice(argsEnd).trim();
|
|
132
|
+
if (suffix === '')
|
|
133
|
+
return true;
|
|
134
|
+
const separator = /^(?:&&|\|\||;)\s*/.exec(suffix);
|
|
135
|
+
if (separator === null)
|
|
136
|
+
return false;
|
|
137
|
+
remaining = suffix.slice(separator[0].length);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* mbx writes one byte per admission (g) and permit drop (r). Cargo descendants inherit this descriptor through
|
|
142
|
+
* MBX_GRANT_FD; reserve names it with --grant-fd and closes it on exec of the external command.
|
|
143
|
+
*/
|
|
144
|
+
export const MBX_GRANT_FD = 5;
|
|
145
|
+
/**
|
|
146
|
+
* `command` as the shell runs it under its leaf's admission, or as it is for a leaf in no pool (`null`). A reserved leaf
|
|
147
|
+
* asks for its runner's count, and its reservation first sizes the runner to what mbx granted (`grantedSizing`) and says
|
|
148
|
+
* so on stderr. `mbx` is the canonical environment's, whose realpath cowshed's admission proved to be the host's pinned
|
|
149
|
+
* mbx; it writes the grant on this descriptor itself.
|
|
18
150
|
*/
|
|
19
151
|
export function withMbxLeaf(command, leaf) {
|
|
20
|
-
if (leaf.kind === 'cargo') {
|
|
152
|
+
if (leaf === null || leaf.kind === 'cargo') {
|
|
21
153
|
return command;
|
|
22
154
|
}
|
|
23
|
-
|
|
155
|
+
const asked = leaf.demand.want;
|
|
156
|
+
const said = `printf 'cowshed: mbx reserve running cpus=%s asked=${asked}\\n' "$${CPU_TOKENS_ENV}" >&2; `;
|
|
157
|
+
return `mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus ${asked} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(`${grantedSizing(leaf.demand)}${said}${command}`)}`;
|
|
24
158
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProcessLineage } from '@smoothbricks/cowshed/process-lineage';
|
|
2
|
+
import { type HangDiagnosticHost } from './hang-diagnostics.js';
|
|
3
|
+
export interface MbxQueuedRequest {
|
|
4
|
+
readonly pid: number;
|
|
5
|
+
readonly ticket: number;
|
|
6
|
+
readonly queuePosition: number;
|
|
7
|
+
}
|
|
8
|
+
export type MbxQueueSnapshot = {
|
|
9
|
+
readonly ok: true;
|
|
10
|
+
readonly requests: readonly MbxQueuedRequest[];
|
|
11
|
+
readonly diagnostics?: readonly string[];
|
|
12
|
+
} | {
|
|
13
|
+
readonly ok: false;
|
|
14
|
+
readonly detail: string;
|
|
15
|
+
};
|
|
16
|
+
/** One observation, including all scoped process reads, has this monotonic control-plane budget. */
|
|
17
|
+
export declare const MBX_QUEUE_SNAPSHOT_MS = 5000;
|
|
18
|
+
export declare const MBX_QUEUE_POLL_MS = 1000;
|
|
19
|
+
interface MbxQueueHost extends Pick<HangDiagnosticHost, 'probe'> {
|
|
20
|
+
now(): number;
|
|
21
|
+
lineages(pids: readonly number[]): Promise<readonly ProcessLineage[]>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Read only the public pool snapshot and the listed waiters' native per-PID lineage/ancestors. A live member of the
|
|
25
|
+
* task's process group, or its live descendant, corroborates a PID; a command name never does. No ps process or host
|
|
26
|
+
* process census is used. The leaf's environment selects the same machine-wide pool as its observation.
|
|
27
|
+
*/
|
|
28
|
+
export declare function snapshotMbxQueue(rootPid: number, environment: NodeJS.ProcessEnv, signal: AbortSignal, host?: MbxQueueHost): Promise<MbxQueueSnapshot>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=mbx-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mbx-queue.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/mbx-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EAAE,KAAK,kBAAkB,EAAY,MAAM,uBAAuB,CAAC;AAkB1E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC/G;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,OAAa,CAAC;AAChD,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAEvC,UAAU,YAAa,SAAQ,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC;IAC9D,GAAG,IAAI,MAAM,CAAC;IACd,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAC;CACvE;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,MAAM,EAAE,WAAW,EACnB,IAAI,GAAE,YAOL,GACA,OAAO,CAAC,gBAAgB,CAAC,CAiH3B"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import * as _validateReport_1 from "typia/lib/internal/_validateReport";
|
|
2
|
+
import * as _createStandardSchema_1 from "typia/lib/internal/_createStandardSchema";
|
|
3
|
+
import typia from 'typia';
|
|
4
|
+
import { runProbe } from './hang-diagnostics.js';
|
|
5
|
+
import { CONTROL_MS } from './lease-wait.js';
|
|
6
|
+
const validateStats = (() => {
|
|
7
|
+
let errors;
|
|
8
|
+
let _report;
|
|
9
|
+
const _ve0 = "{ activity: { kind: string; pid: number | null; ticket: number | null; queue_position: number | null; live: boolean | null; }[]; }";
|
|
10
|
+
const _io0 = input => 2 === input.version && ("object" === typeof input.scheduler && null !== input.scheduler && _io1(input.scheduler));
|
|
11
|
+
const _io1 = input => Array.isArray(input.activity) && input.activity.every(elem => "object" === typeof elem && null !== elem && _io2(elem));
|
|
12
|
+
const _io2 = input => "string" === typeof input.kind && (null === input.pid || "number" === typeof input.pid) && (null === input.ticket || "number" === typeof input.ticket) && (null === input.queue_position || "number" === typeof input.queue_position) && (null === input.live || "boolean" === typeof input.live);
|
|
13
|
+
const _vo0 = (input, _path, _exceptionable = true) => [2 === input.version || _report(_exceptionable, {
|
|
14
|
+
path: _path + ".version",
|
|
15
|
+
expected: "2",
|
|
16
|
+
value: input.version
|
|
17
|
+
}), ("object" === typeof input.scheduler && null !== input.scheduler || _report(_exceptionable, {
|
|
18
|
+
path: _path + ".scheduler",
|
|
19
|
+
expected: _ve0,
|
|
20
|
+
value: input.scheduler
|
|
21
|
+
})) && _vo1(input.scheduler, _path + ".scheduler", true && _exceptionable) || _report(_exceptionable, {
|
|
22
|
+
path: _path + ".scheduler",
|
|
23
|
+
expected: _ve0,
|
|
24
|
+
value: input.scheduler
|
|
25
|
+
})].every(flag => flag);
|
|
26
|
+
const _vo1 = (input, _path, _exceptionable = true) => [(Array.isArray(input.activity) || _report(_exceptionable, {
|
|
27
|
+
path: _path + ".activity",
|
|
28
|
+
expected: "{ kind: string; pid: number | null; ticket: number | null; queue_position: number | null; live: boolean | null; }[]",
|
|
29
|
+
value: input.activity
|
|
30
|
+
})) && input.activity.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
31
|
+
path: _path + ".activity[" + _index2 + "]",
|
|
32
|
+
expected: "{ kind: string; pid: number | null; ticket: number | null; queue_position: number | null; live: boolean | null; }",
|
|
33
|
+
value: elem
|
|
34
|
+
})) && _vo2(elem, _path + ".activity[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
|
|
35
|
+
path: _path + ".activity[" + _index2 + "]",
|
|
36
|
+
expected: "{ kind: string; pid: number | null; ticket: number | null; queue_position: number | null; live: boolean | null; }",
|
|
37
|
+
value: elem
|
|
38
|
+
})).every(flag => flag) || _report(_exceptionable, {
|
|
39
|
+
path: _path + ".activity",
|
|
40
|
+
expected: "{ kind: string; pid: number | null; ticket: number | null; queue_position: number | null; live: boolean | null; }[]",
|
|
41
|
+
value: input.activity
|
|
42
|
+
})].every(flag => flag);
|
|
43
|
+
const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.kind || _report(_exceptionable, {
|
|
44
|
+
path: _path + ".kind",
|
|
45
|
+
expected: "string",
|
|
46
|
+
value: input.kind
|
|
47
|
+
}), null === input.pid || "number" === typeof input.pid || _report(_exceptionable, {
|
|
48
|
+
path: _path + ".pid",
|
|
49
|
+
expected: "(null | number)",
|
|
50
|
+
value: input.pid
|
|
51
|
+
}), null === input.ticket || "number" === typeof input.ticket || _report(_exceptionable, {
|
|
52
|
+
path: _path + ".ticket",
|
|
53
|
+
expected: "(null | number)",
|
|
54
|
+
value: input.ticket
|
|
55
|
+
}), null === input.queue_position || "number" === typeof input.queue_position || _report(_exceptionable, {
|
|
56
|
+
path: _path + ".queue_position",
|
|
57
|
+
expected: "(null | number)",
|
|
58
|
+
value: input.queue_position
|
|
59
|
+
}), null === input.live || "boolean" === typeof input.live || _report(_exceptionable, {
|
|
60
|
+
path: _path + ".live",
|
|
61
|
+
expected: "(boolean | null)",
|
|
62
|
+
value: input.live
|
|
63
|
+
})].every(flag => flag);
|
|
64
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
65
|
+
return _createStandardSchema_1._createStandardSchema(input => {
|
|
66
|
+
if (false === __is(input)) {
|
|
67
|
+
errors = [];
|
|
68
|
+
_report = _validateReport_1._validateReport(errors);
|
|
69
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
70
|
+
path: _path + "",
|
|
71
|
+
expected: "SchedulerStats",
|
|
72
|
+
value: input
|
|
73
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
74
|
+
path: _path + "",
|
|
75
|
+
expected: "SchedulerStats",
|
|
76
|
+
value: input
|
|
77
|
+
}))(input, "$input", true);
|
|
78
|
+
const success = 0 === errors.length;
|
|
79
|
+
return success ? {
|
|
80
|
+
success,
|
|
81
|
+
data: input
|
|
82
|
+
} : {
|
|
83
|
+
success,
|
|
84
|
+
errors,
|
|
85
|
+
data: input
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
data: input
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
})();
|
|
94
|
+
/** One observation, including all scoped process reads, has this monotonic control-plane budget. */
|
|
95
|
+
export const MBX_QUEUE_SNAPSHOT_MS = CONTROL_MS;
|
|
96
|
+
export const MBX_QUEUE_POLL_MS = 1_000;
|
|
97
|
+
/**
|
|
98
|
+
* Read only the public pool snapshot and the listed waiters' native per-PID lineage/ancestors. A live member of the
|
|
99
|
+
* task's process group, or its live descendant, corroborates a PID; a command name never does. No ps process or host
|
|
100
|
+
* process census is used. The leaf's environment selects the same machine-wide pool as its observation.
|
|
101
|
+
*/
|
|
102
|
+
export async function snapshotMbxQueue(rootPid, environment, signal, host = {
|
|
103
|
+
now: () => performance.now(),
|
|
104
|
+
probe: (file, args, timeoutMs, abort) => runProbe(file, args, timeoutMs, abort, environment),
|
|
105
|
+
async lineages(pids) {
|
|
106
|
+
const { processLineages } = await import('@smoothbricks/cowshed/process-lineage');
|
|
107
|
+
return processLineages(pids);
|
|
108
|
+
},
|
|
109
|
+
}) {
|
|
110
|
+
const now = () => host.now();
|
|
111
|
+
const endsAt = now() + MBX_QUEUE_SNAPSHOT_MS;
|
|
112
|
+
const probe = async (file, args) => {
|
|
113
|
+
const remaining = endsAt - now();
|
|
114
|
+
if (remaining <= 0 || signal.aborted)
|
|
115
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
116
|
+
const result = await host.probe(file, args, remaining, signal);
|
|
117
|
+
if (now() >= endsAt || signal.aborted)
|
|
118
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
119
|
+
const command = `${file} ${args.join(' ')}`;
|
|
120
|
+
if (result.status !== 'exited') {
|
|
121
|
+
return { ok: false, detail: `${command}: ${result.status}: ${result.detail}; stderr=${result.stderr}` };
|
|
122
|
+
}
|
|
123
|
+
if (result.code !== 0) {
|
|
124
|
+
return { ok: false, detail: `${command}: exit=${result.code}; stderr=${result.stderr}` };
|
|
125
|
+
}
|
|
126
|
+
if (result.stderr.trim() !== '')
|
|
127
|
+
return { ok: false, detail: `${command}: stderr=${result.stderr}` };
|
|
128
|
+
return { ok: true, stdout: result.stdout };
|
|
129
|
+
};
|
|
130
|
+
const stats = await probe('mbx', ['stats', '--scheduler', '--json', '--activity']);
|
|
131
|
+
if (!stats.ok)
|
|
132
|
+
return stats;
|
|
133
|
+
let wire;
|
|
134
|
+
try {
|
|
135
|
+
wire = JSON.parse(stats.stdout);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return { ok: false, detail: `mbx stats --scheduler --json --activity: invalid JSON: ${String(error)}` };
|
|
139
|
+
}
|
|
140
|
+
const validated = validateStats(wire);
|
|
141
|
+
if (!validated.success) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
detail: `mbx stats --scheduler --json --activity: invalid scheduler.activity: ${JSON.stringify(validated.errors)}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const waiters = validated.data.scheduler.activity.filter((row) => row.kind === 'waiter' && row.live !== false);
|
|
148
|
+
const diagnostics = [];
|
|
149
|
+
const candidates = waiters.flatMap((row) => {
|
|
150
|
+
const pid = row.pid;
|
|
151
|
+
if (pid === null || !Number.isSafeInteger(pid) || pid < 1) {
|
|
152
|
+
diagnostics.push('mbx stats: pending waiter has no valid PID; task membership unavailable, not queue or admission evidence');
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
return [{ ...row, pid }];
|
|
156
|
+
});
|
|
157
|
+
if (now() >= endsAt || signal.aborted)
|
|
158
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
159
|
+
if (candidates.length === 0)
|
|
160
|
+
return { ok: true, requests: [], ...(diagnostics.length === 0 ? {} : { diagnostics }) };
|
|
161
|
+
const table = new Map();
|
|
162
|
+
const inspected = new Set();
|
|
163
|
+
let pending = [...new Set([rootPid, ...candidates.map((row) => row.pid)])];
|
|
164
|
+
while (pending.length > 0) {
|
|
165
|
+
if (now() >= endsAt || signal.aborted)
|
|
166
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
167
|
+
let entries;
|
|
168
|
+
try {
|
|
169
|
+
entries = await host.lineages(pending);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
return {
|
|
173
|
+
ok: false,
|
|
174
|
+
detail: `admission snapshot: native process lineages: ${error instanceof Error ? error.message : String(error)}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (now() >= endsAt || signal.aborted)
|
|
178
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
179
|
+
for (const pid of pending)
|
|
180
|
+
inspected.add(pid);
|
|
181
|
+
for (const entry of entries)
|
|
182
|
+
table.set(entry.pid, entry);
|
|
183
|
+
pending = [
|
|
184
|
+
...new Set([...table.values()]
|
|
185
|
+
.filter((entry) => !entry.zombie &&
|
|
186
|
+
entry.pgid !== rootPid &&
|
|
187
|
+
entry.pid !== rootPid &&
|
|
188
|
+
entry.ppid > 1 &&
|
|
189
|
+
!inspected.has(entry.ppid))
|
|
190
|
+
.map((entry) => entry.ppid)),
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
const belongs = (pid) => {
|
|
194
|
+
const seen = new Set();
|
|
195
|
+
for (let entry = table.get(pid); entry !== undefined && !seen.has(entry.pid); entry = table.get(entry.ppid)) {
|
|
196
|
+
if (entry.zombie)
|
|
197
|
+
return false;
|
|
198
|
+
if (entry.pid === rootPid || entry.pgid === rootPid)
|
|
199
|
+
return true;
|
|
200
|
+
seen.add(entry.pid);
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
};
|
|
204
|
+
const requests = [];
|
|
205
|
+
for (const row of candidates) {
|
|
206
|
+
if (!belongs(row.pid))
|
|
207
|
+
continue;
|
|
208
|
+
if (row.live === null)
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
detail: `mbx stats --scheduler --json --activity: waiter pid=${row.pid} live status unavailable`,
|
|
212
|
+
};
|
|
213
|
+
if (row.ticket === null ||
|
|
214
|
+
!Number.isSafeInteger(row.ticket) ||
|
|
215
|
+
row.ticket < 0 ||
|
|
216
|
+
row.queue_position === null ||
|
|
217
|
+
!Number.isSafeInteger(row.queue_position) ||
|
|
218
|
+
row.queue_position < 1) {
|
|
219
|
+
return {
|
|
220
|
+
ok: false,
|
|
221
|
+
detail: `mbx stats --scheduler --json --activity: live waiter pid=${row.pid} lacks ticket/queue position`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
requests.push({ pid: row.pid, ticket: row.ticket, queuePosition: row.queue_position });
|
|
225
|
+
}
|
|
226
|
+
if (now() >= endsAt || signal.aborted)
|
|
227
|
+
return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
228
|
+
return { ok: true, requests, ...(diagnostics.length === 0 ? {} : { diagnostics }) };
|
|
229
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NativeTestResult } from './test-result-writer.js';
|
|
1
2
|
/**
|
|
2
3
|
* What a run's output says about its forward motion: whether a test finished, and which tests the runner said
|
|
3
4
|
* are running and has not said finished. `idleTimeoutMs` re-arms only on a finished test.
|
|
@@ -26,12 +27,18 @@
|
|
|
26
27
|
*/
|
|
27
28
|
export interface RunProgress {
|
|
28
29
|
/** One chunk of one output stream; true when it reports a finished test, file or Go package. */
|
|
29
|
-
scan(stream: OutputStream, chunk: string): boolean;
|
|
30
|
+
scan(stream: OutputStream, chunk: Buffer | string): boolean;
|
|
30
31
|
/** The tests the runner reported running and has not reported finished, in the order it first named them. */
|
|
31
32
|
inFlight(): string[];
|
|
33
|
+
error(): string | null;
|
|
32
34
|
}
|
|
33
35
|
export type OutputStream = 'stdout' | 'stderr';
|
|
34
|
-
export declare function createRunProgress(command?: string): RunProgress;
|
|
36
|
+
export declare function createRunProgress(command?: string, closed?: (result: NativeTestResult) => void): RunProgress;
|
|
37
|
+
/** JSON-plus 0.1 flushes each closed result; plain libtest-json buffers a whole binary. */
|
|
38
|
+
export declare function withTestResultReport(command: string): {
|
|
39
|
+
command: string;
|
|
40
|
+
env: Record<string, string>;
|
|
41
|
+
};
|
|
35
42
|
/**
|
|
36
43
|
* `command` with its one `bun test` asked for a line of dots, one per finished test: the only per-test report bun
|
|
37
44
|
* prints whoever runs it. A command that runs no bun, more than one runner, or already chose bun's dots is returned
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/progress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/progress.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,WAAW;IAC1B,gGAAgG;IAChG,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC5D,6GAA6G;IAC7G,QAAQ,IAAI,MAAM,EAAE,CAAC;IACrB,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AA6E/C,wBAAgB,iBAAiB,CAAC,OAAO,SAAK,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,WAAW,CA4LxG;AAED,2FAA2F;AAC3F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAuBtG;AACD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAmB1D"}
|