@smoothbricks/nx-plugin 0.6.1 → 0.6.3-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 +264 -55
- package/dist/.build-inputs.json +21 -15
- 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/cargo-retention-hook.d.ts +14 -3
- package/dist/cargo-retention-hook.d.ts.map +1 -1
- package/dist/cargo-retention-hook.js +25 -8
- 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 +270 -27
- 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 +27 -3
- package/dist/executors/bounded-exec/mbx-pool.d.ts +20 -3
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +84 -4
- 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 +148 -22
- 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 +20 -2
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +102 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -65
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +6 -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/runtime-input-policy.d.ts +14 -0
- package/dist/runtime-input-policy.d.ts.map +1 -1
- package/dist/runtime-input-policy.js +1 -1
- 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/workspace-index.d.ts +7 -0
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +11 -0
- package/executors.json +1 -1
- package/managed/raw/envrc +15 -0
- package/managed/raw/patches/ttsc@0.34.1.patch +75 -0
- package/managed/raw/tooling/devenv +1 -2
- package/managed/raw/tooling/direnv/developer-links.ts +15 -1
- package/managed/raw/tooling/direnv/devenv.smoo.nix +45 -13
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
- package/managed/raw/tooling/direnv/linked-snapshots.ts +50 -13
- package/managed/raw/tooling/direnv/setup-environment.ts +36 -9
- package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +4 -1
- package/managed/raw/tooling/git-reword-commit +151 -0
- 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 +226 -10
- package/runtime/nx-publish/cache_adapter.js +45 -0
- package/runtime/nx-publish/nx_publish.js +60 -0
- package/runtime-input.sh +12 -3
- package/src/bin/smoo-nx-publish.ts +4 -0
- package/src/cargo-retention-hook.ts +28 -11
- 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 +303 -27
- package/src/executors/bounded-exec/hang-diagnostics.ts +31 -3
- package/src/executors/bounded-exec/mbx-pool.ts +82 -5
- package/src/executors/bounded-exec/mbx-queue.ts +170 -0
- package/src/executors/bounded-exec/progress.ts +168 -15
- 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 +108 -5
- package/src/index.ts +74 -70
- package/src/managed-files/files.ts +6 -0
- package/src/nx-publish.ts +157 -0
- package/src/runtime-input-policy.ts +1 -1
- package/src/tool-bins.ts +13 -9
- package/src/workspace-index.ts +12 -0
- package/test-timings.json +8 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { shellTokens } from '../../runtime-input-policy.js';
|
|
2
|
+
import { invocationSpan, type RunnerKind } from './runner-sizing.js';
|
|
2
3
|
import { shellQuote } from './verdict.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -11,9 +12,15 @@ export interface MbxPool {
|
|
|
11
12
|
readonly priority: 'normal' | 'low';
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged, or
|
|
17
|
+
* where this run is already inside an mbx reservation: `mbx reserve` hands its command `MBX_SCHED_DISABLE=1`, and nested
|
|
18
|
+
* non-Cargo work shares the enclosing grant instead of reserving twice (specs/cowshed/05_gateway.md, "Parallelism
|
|
19
|
+
* inside a job"). A second reservation would wait in the pool while its parent holds a grant, so under a full pool the
|
|
20
|
+
* nested leaf queued behind the very work it belongs to.
|
|
21
|
+
*/
|
|
15
22
|
export function mbxPool(environment: Readonly<NodeJS.ProcessEnv>): MbxPool | null {
|
|
16
|
-
if (environment.MBX_SCHEDULER !== '1' || !environment.MBX_CACHE_DIR) {
|
|
23
|
+
if (environment.MBX_SCHEDULER !== '1' || !environment.MBX_CACHE_DIR || environment.MBX_SCHED_DISABLE === '1') {
|
|
17
24
|
return null;
|
|
18
25
|
}
|
|
19
26
|
return { priority: environment.MBX_SCHEDULER_PRIORITY === 'normal' ? 'normal' : 'low' };
|
|
@@ -36,13 +43,83 @@ export function mbxLeaf(pool: MbxPool, kind: RunnerKind, want: number): MbxLeaf
|
|
|
36
43
|
: { kind: 'reserve', cpus: Math.max(1, want), priority: pool.priority };
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Only a known scheduled execution may stop its idle clock at zero holds. Plain Cargo tests can run doctests;
|
|
48
|
+
* archive-file targets, direct binaries and other runners are not proven scheduled at spawn (11_shell.md,
|
|
49
|
+
* "Cargo test-runner boundaries"). The inferred extracted native nextest command is a supported Cargo invocation.
|
|
50
|
+
*/
|
|
51
|
+
export function mbxIdleGated(leaf: MbxLeaf | null, command: string, environment: Readonly<NodeJS.ProcessEnv>): boolean {
|
|
52
|
+
if (leaf === null) return false;
|
|
53
|
+
if (leaf.kind === 'reserve') return true;
|
|
54
|
+
if (environment.MBX_SCHEDULER_TESTS !== '1') return false;
|
|
55
|
+
if (environment.MBX_SCHEDULER === '0' || environment.MBX_SCHED_DISABLE === '1' || environment.MBX_DISABLE === '1')
|
|
56
|
+
return false;
|
|
57
|
+
// invocationSpan shares the lifecycle mapper's conservative shell-syntax boundary.
|
|
58
|
+
if (/[<>\n\r`\\]/.test(command)) return false;
|
|
59
|
+
if (/[^\S \t]/.test(command)) return false;
|
|
60
|
+
const invocation = /cargo(?:\s+(?:--frozen|--locked|--offline))*\s+(nextest\s+run|test)(?=\s|$)/;
|
|
61
|
+
const found = invocation.exec(command);
|
|
62
|
+
if (found === null) return false;
|
|
63
|
+
const prefix = command.slice(0, found.index).trim();
|
|
64
|
+
if (prefix !== '' && !/^extracted="\$\([^"\n]+\)"\s*&&$/.test(prefix)) return false;
|
|
65
|
+
let remaining = command.slice(found.index);
|
|
66
|
+
const unquoted = remaining.replace(/"[^"]*"|'[^']*'/g, '');
|
|
67
|
+
if (/[$*?{}~[\]]/.test(unquoted)) return false;
|
|
68
|
+
// Only the inferred command's path templates are known expansions; arbitrary words could supply mbx overrides.
|
|
69
|
+
const paths = remaining.replace(/\$PWD(?=\/)/g, '');
|
|
70
|
+
if ((prefix === '' ? paths : paths.replace(/\$extracted(?=\/)/g, '')).includes('$')) return false;
|
|
71
|
+
for (;;) {
|
|
72
|
+
const leg = invocation.exec(remaining);
|
|
73
|
+
if (leg === null || leg.index !== 0) return false;
|
|
74
|
+
const { argsEnd } = invocationSpan(remaining, invocation);
|
|
75
|
+
const args: string[] = [];
|
|
76
|
+
for (const token of shellTokens(remaining.slice(0, argsEnd), [])) {
|
|
77
|
+
if (token.kind !== 'word') return false;
|
|
78
|
+
if (token.text === '--') break;
|
|
79
|
+
if (
|
|
80
|
+
token.text.startsWith('$') &&
|
|
81
|
+
!(
|
|
82
|
+
token.text.startsWith('$extracted/') &&
|
|
83
|
+
['--binaries-metadata', '--cargo-metadata', '--target-dir-remap'].includes(args.at(-1) ?? '')
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
return false;
|
|
87
|
+
args.push(token.text);
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
args.some((arg) =>
|
|
91
|
+
/^(?:--(?:config|directory|archive-file)(?:=|$)|--(?:doc|no-run|list|help)(?:=|$)|-C|-h$|\+)/.test(arg),
|
|
92
|
+
)
|
|
93
|
+
) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (
|
|
97
|
+
leg[1] === 'test' &&
|
|
98
|
+
!args.some((arg) => /^--(?:lib|tests|bins|examples|benches|all-targets|test|bin|example|bench)(?:=|$)/.test(arg))
|
|
99
|
+
) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const suffix = remaining.slice(argsEnd).trim();
|
|
103
|
+
if (suffix === '') return true;
|
|
104
|
+
const separator = /^(?:&&|\|\||;)\s*/.exec(suffix);
|
|
105
|
+
if (separator === null) return false;
|
|
106
|
+
remaining = suffix.slice(separator[0].length);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* mbx writes one byte per admission (g) and permit drop (r). Cargo descendants inherit this descriptor through
|
|
112
|
+
* MBX_GRANT_FD; reserve names it with --grant-fd and closes it on exec of the external command.
|
|
113
|
+
*/
|
|
114
|
+
export const MBX_GRANT_FD = 5;
|
|
115
|
+
|
|
39
116
|
/**
|
|
40
117
|
* `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
|
|
41
|
-
* cowshed's admission proved to be the host's pinned mbx.
|
|
118
|
+
* cowshed's admission proved to be the host's pinned mbx; it writes the grant on this descriptor itself.
|
|
42
119
|
*/
|
|
43
120
|
export function withMbxLeaf(command: string, leaf: MbxLeaf): string {
|
|
44
121
|
if (leaf.kind === 'cargo') {
|
|
45
122
|
return command;
|
|
46
123
|
}
|
|
47
|
-
return `mbx reserve --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
|
|
124
|
+
return `mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
|
|
48
125
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ProcessLineage } from '@smoothbricks/cowshed/process-lineage';
|
|
2
|
+
import typia from 'typia';
|
|
3
|
+
import { type HangDiagnosticHost, runProbe } from './hang-diagnostics.js';
|
|
4
|
+
import { CONTROL_MS } from './lease-wait.js';
|
|
5
|
+
|
|
6
|
+
/** The additive projection of mbx stats --scheduler --json --activity that the admission observer consumes. */
|
|
7
|
+
interface SchedulerStats {
|
|
8
|
+
version: 2;
|
|
9
|
+
scheduler: {
|
|
10
|
+
activity: {
|
|
11
|
+
kind: string;
|
|
12
|
+
pid: number | null;
|
|
13
|
+
ticket: number | null;
|
|
14
|
+
queue_position: number | null;
|
|
15
|
+
live: boolean | null;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const validateStats = typia.createValidate<SchedulerStats>();
|
|
20
|
+
|
|
21
|
+
export interface MbxQueuedRequest {
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
readonly ticket: number;
|
|
24
|
+
readonly queuePosition: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type MbxQueueSnapshot =
|
|
28
|
+
| { readonly ok: true; readonly requests: readonly MbxQueuedRequest[]; readonly diagnostics?: readonly string[] }
|
|
29
|
+
| { readonly ok: false; readonly detail: string };
|
|
30
|
+
|
|
31
|
+
/** One observation, including all scoped process reads, has this monotonic control-plane budget. */
|
|
32
|
+
export const MBX_QUEUE_SNAPSHOT_MS = CONTROL_MS;
|
|
33
|
+
export const MBX_QUEUE_POLL_MS = 1_000;
|
|
34
|
+
|
|
35
|
+
interface MbxQueueHost extends Pick<HangDiagnosticHost, 'probe'> {
|
|
36
|
+
now(): number;
|
|
37
|
+
lineages(pids: readonly number[]): Promise<readonly ProcessLineage[]>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Read only the public pool snapshot and the listed waiters' native per-PID lineage/ancestors. A live member of the
|
|
42
|
+
* task's process group, or its live descendant, corroborates a PID; a command name never does. No ps process or host
|
|
43
|
+
* process census is used. The leaf's environment selects the same machine-wide pool as its observation.
|
|
44
|
+
*/
|
|
45
|
+
export async function snapshotMbxQueue(
|
|
46
|
+
rootPid: number,
|
|
47
|
+
environment: NodeJS.ProcessEnv,
|
|
48
|
+
signal: AbortSignal,
|
|
49
|
+
host: MbxQueueHost = {
|
|
50
|
+
now: () => performance.now(),
|
|
51
|
+
probe: (file, args, timeoutMs, abort) => runProbe(file, args, timeoutMs, abort, environment),
|
|
52
|
+
async lineages(pids) {
|
|
53
|
+
const { processLineages } = await import('@smoothbricks/cowshed/process-lineage');
|
|
54
|
+
return processLineages(pids);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
): Promise<MbxQueueSnapshot> {
|
|
58
|
+
const now = () => host.now();
|
|
59
|
+
const endsAt = now() + MBX_QUEUE_SNAPSHOT_MS;
|
|
60
|
+
const probe = async (file: string, args: readonly string[]) => {
|
|
61
|
+
const remaining = endsAt - now();
|
|
62
|
+
if (remaining <= 0 || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' } as const;
|
|
63
|
+
const result = await host.probe(file, args, remaining, signal);
|
|
64
|
+
if (now() >= endsAt || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' } as const;
|
|
65
|
+
const command = `${file} ${args.join(' ')}`;
|
|
66
|
+
if (result.status !== 'exited') {
|
|
67
|
+
return { ok: false, detail: `${command}: ${result.status}: ${result.detail}; stderr=${result.stderr}` } as const;
|
|
68
|
+
}
|
|
69
|
+
if (result.code !== 0) {
|
|
70
|
+
return { ok: false, detail: `${command}: exit=${result.code}; stderr=${result.stderr}` } as const;
|
|
71
|
+
}
|
|
72
|
+
if (result.stderr.trim() !== '') return { ok: false, detail: `${command}: stderr=${result.stderr}` } as const;
|
|
73
|
+
return { ok: true, stdout: result.stdout } as const;
|
|
74
|
+
};
|
|
75
|
+
const stats = await probe('mbx', ['stats', '--scheduler', '--json', '--activity']);
|
|
76
|
+
if (!stats.ok) return stats;
|
|
77
|
+
let wire: unknown;
|
|
78
|
+
try {
|
|
79
|
+
wire = JSON.parse(stats.stdout);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return { ok: false, detail: `mbx stats --scheduler --json --activity: invalid JSON: ${String(error)}` };
|
|
82
|
+
}
|
|
83
|
+
const validated = validateStats(wire);
|
|
84
|
+
if (!validated.success) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
detail: `mbx stats --scheduler --json --activity: invalid scheduler.activity: ${JSON.stringify(validated.errors)}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const waiters = validated.data.scheduler.activity.filter((row) => row.kind === 'waiter' && row.live !== false);
|
|
91
|
+
const diagnostics: string[] = [];
|
|
92
|
+
const candidates = waiters.flatMap((row) => {
|
|
93
|
+
const pid = row.pid;
|
|
94
|
+
if (pid === null || !Number.isSafeInteger(pid) || pid < 1) {
|
|
95
|
+
diagnostics.push(
|
|
96
|
+
'mbx stats: pending waiter has no valid PID; task membership unavailable, not queue or admission evidence',
|
|
97
|
+
);
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
return [{ ...row, pid }];
|
|
101
|
+
});
|
|
102
|
+
if (now() >= endsAt || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
103
|
+
if (candidates.length === 0) return { ok: true, requests: [], ...(diagnostics.length === 0 ? {} : { diagnostics }) };
|
|
104
|
+
const table = new Map<number, ProcessLineage>();
|
|
105
|
+
const inspected = new Set<number>();
|
|
106
|
+
let pending = [...new Set([rootPid, ...candidates.map((row) => row.pid)])];
|
|
107
|
+
while (pending.length > 0) {
|
|
108
|
+
if (now() >= endsAt || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
109
|
+
let entries: readonly ProcessLineage[];
|
|
110
|
+
try {
|
|
111
|
+
entries = await host.lineages(pending);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return {
|
|
114
|
+
ok: false,
|
|
115
|
+
detail: `admission snapshot: native process lineages: ${error instanceof Error ? error.message : String(error)}`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (now() >= endsAt || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
119
|
+
for (const pid of pending) inspected.add(pid);
|
|
120
|
+
for (const entry of entries) table.set(entry.pid, entry);
|
|
121
|
+
pending = [
|
|
122
|
+
...new Set(
|
|
123
|
+
[...table.values()]
|
|
124
|
+
.filter(
|
|
125
|
+
(entry) =>
|
|
126
|
+
!entry.zombie &&
|
|
127
|
+
entry.pgid !== rootPid &&
|
|
128
|
+
entry.pid !== rootPid &&
|
|
129
|
+
entry.ppid > 1 &&
|
|
130
|
+
!inspected.has(entry.ppid),
|
|
131
|
+
)
|
|
132
|
+
.map((entry) => entry.ppid),
|
|
133
|
+
),
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
const belongs = (pid: number): boolean => {
|
|
137
|
+
const seen = new Set<number>();
|
|
138
|
+
for (let entry = table.get(pid); entry !== undefined && !seen.has(entry.pid); entry = table.get(entry.ppid)) {
|
|
139
|
+
if (entry.zombie) return false;
|
|
140
|
+
if (entry.pid === rootPid || entry.pgid === rootPid) return true;
|
|
141
|
+
seen.add(entry.pid);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
};
|
|
145
|
+
const requests: MbxQueuedRequest[] = [];
|
|
146
|
+
for (const row of candidates) {
|
|
147
|
+
if (!belongs(row.pid)) continue;
|
|
148
|
+
if (row.live === null)
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
detail: `mbx stats --scheduler --json --activity: waiter pid=${row.pid} live status unavailable`,
|
|
152
|
+
};
|
|
153
|
+
if (
|
|
154
|
+
row.ticket === null ||
|
|
155
|
+
!Number.isSafeInteger(row.ticket) ||
|
|
156
|
+
row.ticket < 0 ||
|
|
157
|
+
row.queue_position === null ||
|
|
158
|
+
!Number.isSafeInteger(row.queue_position) ||
|
|
159
|
+
row.queue_position < 1
|
|
160
|
+
) {
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
detail: `mbx stats --scheduler --json --activity: live waiter pid=${row.pid} lacks ticket/queue position`,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
requests.push({ pid: row.pid, ticket: row.ticket, queuePosition: row.queue_position });
|
|
167
|
+
}
|
|
168
|
+
if (now() >= endsAt || signal.aborted) return { ok: false, detail: 'admission snapshot deadline reached' };
|
|
169
|
+
return { ok: true, requests, ...(diagnostics.length === 0 ? {} : { diagnostics }) };
|
|
170
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
2
|
+
import typia, { type tags } from 'typia';
|
|
2
3
|
import { invocationSpan, withInvocationFlag } from './runner-sizing.js';
|
|
4
|
+
import type { NativeTestResult } from './test-result-writer.js';
|
|
3
5
|
import { BUN_TEST, GO_TEST, NEXTEST_RUN } from './verdict.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -30,9 +32,10 @@ import { BUN_TEST, GO_TEST, NEXTEST_RUN } from './verdict.js';
|
|
|
30
32
|
*/
|
|
31
33
|
export interface RunProgress {
|
|
32
34
|
/** One chunk of one output stream; true when it reports a finished test, file or Go package. */
|
|
33
|
-
scan(stream: OutputStream, chunk: string): boolean;
|
|
35
|
+
scan(stream: OutputStream, chunk: Buffer | string): boolean;
|
|
34
36
|
/** The tests the runner reported running and has not reported finished, in the order it first named them. */
|
|
35
37
|
inFlight(): string[];
|
|
38
|
+
error(): string | null;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
export type OutputStream = 'stdout' | 'stderr';
|
|
@@ -42,7 +45,6 @@ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g');
|
|
|
42
45
|
const FINISHED = [
|
|
43
46
|
/^\s*(?:[A-Z0-9][A-Z0-9-]*\s+)+\[\s*[0-9.]+s\]\s+\(\s*\d+\/\d+\)\s+(\S.*)$/,
|
|
44
47
|
/^test (\S+) \.\.\. (?:ok|FAILED|ignored)\b/,
|
|
45
|
-
/^\((?:pass|fail|skip|todo)\) (.+)$/,
|
|
46
48
|
/^\s*[✓×]\s+(\S.*?)\s+\d+ms\b/,
|
|
47
49
|
/^\s*❯\s+(\S.*?)\s+\(\d+ tests?(?: \| \d+ (?:failed|skipped|todo))*\)\s+\d+ms\b/,
|
|
48
50
|
/^\s*↓\s+(\S.*?)\s+\(\d+ tests?(?: \| \d+ (?:skipped|todo))+\)(?:\s+\d+ms\b|$)/,
|
|
@@ -53,21 +55,43 @@ const RUNNING = [
|
|
|
53
55
|
/^test (\S+) has been running for over \d+ seconds$/,
|
|
54
56
|
];
|
|
55
57
|
const DOTS = /^\.+$/;
|
|
58
|
+
const BUN_RESULT =
|
|
59
|
+
/^(?:\((?<status>pass|fail|skip|todo|pending)\)|(?<symbol>✓|✗|×|»|✎|…))\s+(?<name>.+?)(?: \[(?<duration>\d+(?:\.\d+)?)ms\])?$/;
|
|
60
|
+
const UNCAPTURED_NEXTEST = /(?<![\w-])--(?:no-?capture|debugger|tracer)(?=[=\s]|$)/;
|
|
56
61
|
|
|
57
62
|
type GoTestEvent =
|
|
58
63
|
| { Action: 'start'; Package: string }
|
|
59
64
|
| { Action: 'run' | 'pause' | 'cont'; Package: string; Test: string }
|
|
60
|
-
| { Action: 'pass' | 'fail' | 'skip' | 'bench'; Package: string; Test?: string }
|
|
65
|
+
| { Action: 'pass' | 'fail' | 'skip' | 'bench'; Package: string; Test?: string; Elapsed?: number }
|
|
61
66
|
| { Action: 'output'; Package: string; Output: string; Test?: string };
|
|
62
|
-
|
|
67
|
+
type NextestTestEvent =
|
|
68
|
+
| { type: 'test'; event: 'started' | 'ignored'; name: string }
|
|
69
|
+
| {
|
|
70
|
+
type: 'test';
|
|
71
|
+
event: 'ok' | 'failed';
|
|
72
|
+
name: string;
|
|
73
|
+
exec_time: number & tags.Minimum<0>;
|
|
74
|
+
stdout?: string;
|
|
75
|
+
reason?: string;
|
|
76
|
+
};
|
|
77
|
+
type NextestSuiteEvent = { type: 'suite'; event: 'started' | 'ok' | 'failed' };
|
|
78
|
+
type NativeTestEvent = GoTestEvent | NextestTestEvent | NextestSuiteEvent;
|
|
79
|
+
const isNativeTestEvent = typia.createIs<NativeTestEvent>();
|
|
63
80
|
|
|
64
|
-
function
|
|
81
|
+
function nativeTestEvent(text: string, invalid?: (detail: string) => void): NativeTestEvent | null {
|
|
65
82
|
if (!text.startsWith('{')) return null;
|
|
66
83
|
try {
|
|
67
84
|
const event: unknown = JSON.parse(text);
|
|
68
|
-
|
|
85
|
+
if (isNativeTestEvent(event)) return event;
|
|
86
|
+
if (typeof event === 'object' && event !== null && 'type' in event && event.type === 'test') {
|
|
87
|
+
invalid?.(`invalid native test record: ${text}`);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
69
90
|
} catch (error) {
|
|
70
|
-
if (error instanceof SyntaxError)
|
|
91
|
+
if (error instanceof SyntaxError) {
|
|
92
|
+
invalid?.(`invalid native test JSON: ${error.message}`);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
71
95
|
throw error;
|
|
72
96
|
}
|
|
73
97
|
}
|
|
@@ -91,19 +115,43 @@ interface LineState {
|
|
|
91
115
|
countedDots: number;
|
|
92
116
|
}
|
|
93
117
|
|
|
94
|
-
export function createRunProgress(command = ''): RunProgress {
|
|
118
|
+
export function createRunProgress(command = '', closed?: (result: NativeTestResult) => void): RunProgress {
|
|
95
119
|
const goLifecycle = onlyGoTests(command);
|
|
120
|
+
const goResults = command.search(GO_TEST) !== -1;
|
|
96
121
|
const streams: Record<OutputStream, LineState> = {
|
|
97
122
|
stdout: { partial: '', countedDots: 0 },
|
|
98
123
|
stderr: { partial: '', countedDots: 0 },
|
|
99
124
|
};
|
|
100
125
|
const running = new Set<string>();
|
|
101
126
|
const packages = new Map<string, Set<string>>();
|
|
127
|
+
const goOutput = new Map<string, string[]>();
|
|
128
|
+
const decoders: Record<OutputStream, StringDecoder> = {
|
|
129
|
+
stdout: new StringDecoder('utf8'),
|
|
130
|
+
stderr: new StringDecoder('utf8'),
|
|
131
|
+
};
|
|
132
|
+
const nextestStarted = new Set<string>();
|
|
133
|
+
const nextestJson =
|
|
134
|
+
/--message-format(?:=|\s+)libtest-json-plus(?=\s|$)/.test(command) && !UNCAPTURED_NEXTEST.test(command);
|
|
135
|
+
let failure: string | null = null;
|
|
136
|
+
const bunResults = command.search(BUN_TEST) !== -1 && command.search(NEXTEST_RUN) === -1;
|
|
137
|
+
let bunFile = '';
|
|
138
|
+
let bunSummary = false;
|
|
139
|
+
const bunDiagnostics: Record<OutputStream, string[]> = { stdout: [], stderr: [] };
|
|
102
140
|
|
|
103
141
|
// One complete line, ANSI stripped, that is not a line of dots: true when it names a finished test.
|
|
104
|
-
const finishedLine = (text: string): boolean => {
|
|
105
|
-
const event =
|
|
106
|
-
|
|
142
|
+
const finishedLine = (text: string, stream: OutputStream): boolean => {
|
|
143
|
+
const event =
|
|
144
|
+
stream === 'stdout'
|
|
145
|
+
? nativeTestEvent(
|
|
146
|
+
text,
|
|
147
|
+
nextestJson
|
|
148
|
+
? (detail) => {
|
|
149
|
+
failure ??= detail;
|
|
150
|
+
}
|
|
151
|
+
: undefined,
|
|
152
|
+
)
|
|
153
|
+
: null;
|
|
154
|
+
if (event !== null && 'Action' in event) {
|
|
107
155
|
switch (event.Action) {
|
|
108
156
|
case 'start':
|
|
109
157
|
packages.set(event.Package, new Set());
|
|
@@ -116,15 +164,84 @@ export function createRunProgress(command = ''): RunProgress {
|
|
|
116
164
|
case 'skip':
|
|
117
165
|
case 'bench':
|
|
118
166
|
if (event.Test === undefined) packages.delete(event.Package);
|
|
119
|
-
else
|
|
167
|
+
else {
|
|
168
|
+
packages.get(event.Package)?.delete(event.Test);
|
|
169
|
+
const id = `${event.Package}::${event.Test}`;
|
|
170
|
+
if (event.Action !== 'bench' && goResults)
|
|
171
|
+
closed?.({
|
|
172
|
+
id,
|
|
173
|
+
status: event.Action,
|
|
174
|
+
source: 'native',
|
|
175
|
+
durationMs: event.Elapsed === undefined ? null : event.Elapsed * 1000,
|
|
176
|
+
sourceRef: null,
|
|
177
|
+
failureOutput: event.Action === 'fail' ? (goOutput.get(id)?.join('') ?? null) : null,
|
|
178
|
+
});
|
|
179
|
+
goOutput.delete(id);
|
|
180
|
+
}
|
|
120
181
|
return true;
|
|
121
182
|
case 'pause':
|
|
122
183
|
case 'cont':
|
|
184
|
+
return false;
|
|
123
185
|
case 'output':
|
|
186
|
+
if (goResults && closed !== undefined && event.Test !== undefined) {
|
|
187
|
+
const id = `${event.Package}::${event.Test}`;
|
|
188
|
+
const output = goOutput.get(id) ?? [];
|
|
189
|
+
output.push(event.Output);
|
|
190
|
+
goOutput.set(id, output);
|
|
191
|
+
}
|
|
124
192
|
return false;
|
|
125
193
|
}
|
|
126
194
|
}
|
|
195
|
+
if (nextestJson && event !== null && 'type' in event && event.type === 'test') {
|
|
196
|
+
if (event.event === 'started') {
|
|
197
|
+
nextestStarted.add(event.name);
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
// nextest appends #N only after retries; a literal #N in the original name stays intact.
|
|
201
|
+
const name = nextestStarted.has(event.name) ? event.name : event.name.replace(/#\d+$/, '');
|
|
202
|
+
nextestStarted.delete(name);
|
|
203
|
+
const split = name.indexOf('$');
|
|
204
|
+
if (nextestJson && split !== -1)
|
|
205
|
+
closed?.({
|
|
206
|
+
id: `${name.slice(0, split)}::${name.slice(split + 1)}`,
|
|
207
|
+
status: event.event === 'ok' ? 'pass' : event.event === 'failed' ? 'fail' : 'skip',
|
|
208
|
+
source: 'native',
|
|
209
|
+
durationMs: 'exec_time' in event ? event.exec_time * 1000 : null,
|
|
210
|
+
sourceRef: null,
|
|
211
|
+
failureOutput: event.event === 'failed' ? (event.stdout ?? event.reason ?? null) : null,
|
|
212
|
+
});
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
127
215
|
if (goLifecycle) return false;
|
|
216
|
+
const bun = BUN_RESULT.exec(text)?.groups;
|
|
217
|
+
if (
|
|
218
|
+
!bunSummary &&
|
|
219
|
+
bun !== undefined &&
|
|
220
|
+
bun.name !== undefined &&
|
|
221
|
+
((bunResults && stream === 'stderr') || (bun.status !== undefined && bun.status !== 'pending'))
|
|
222
|
+
) {
|
|
223
|
+
const status =
|
|
224
|
+
bun.status === 'fail' ||
|
|
225
|
+
bun.status === 'pending' ||
|
|
226
|
+
bun.symbol === '…' ||
|
|
227
|
+
bun.symbol === '✗' ||
|
|
228
|
+
bun.symbol === '×'
|
|
229
|
+
? 'fail'
|
|
230
|
+
: bun.status === 'skip' || bun.status === 'todo' || bun.symbol === '»' || bun.symbol === '✎'
|
|
231
|
+
? 'skip'
|
|
232
|
+
: 'pass';
|
|
233
|
+
if (bunResults && stream === 'stderr')
|
|
234
|
+
closed?.({
|
|
235
|
+
id: `${bunFile}::${bun.name}`,
|
|
236
|
+
status,
|
|
237
|
+
source: 'progress',
|
|
238
|
+
durationMs: bun.duration === undefined ? null : Number(bun.duration),
|
|
239
|
+
sourceRef: null,
|
|
240
|
+
failureOutput: status === 'fail' ? bunDiagnostics[stream].join('') : null,
|
|
241
|
+
});
|
|
242
|
+
bunDiagnostics[stream] = [];
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
128
245
|
for (const pattern of FINISHED) {
|
|
129
246
|
const name = pattern.exec(text)?.[1];
|
|
130
247
|
if (name !== undefined) {
|
|
@@ -145,18 +262,28 @@ export function createRunProgress(command = ''): RunProgress {
|
|
|
145
262
|
return {
|
|
146
263
|
scan(stream, chunk) {
|
|
147
264
|
const state = streams[stream];
|
|
148
|
-
const
|
|
265
|
+
const decoded = typeof chunk === 'string' ? chunk : decoders[stream].write(chunk);
|
|
266
|
+
const lines = (state.partial + decoded).split('\n');
|
|
149
267
|
const rest = lines.pop() ?? '';
|
|
150
268
|
let progressed = false;
|
|
151
269
|
// The first complete line continues the partial one, whose dots were counted as they came.
|
|
152
270
|
let counted = state.countedDots;
|
|
153
271
|
for (const raw of lines) {
|
|
154
272
|
const text = raw.replace(ANSI, '').trimEnd();
|
|
273
|
+
if (bunResults && stream === 'stderr' && closed !== undefined) {
|
|
274
|
+
const header = /^(?:::group::)?(\S.*\.[cm]?[jt]sx?):(?: \(run #\d+\))?$/.exec(text)?.[1];
|
|
275
|
+
if (header !== undefined) {
|
|
276
|
+
bunFile = header.replace(/^\.\//, '');
|
|
277
|
+
bunSummary = false;
|
|
278
|
+
}
|
|
279
|
+
if (/^\s*\d+ tests (?:skipped|todo|failed):$/.test(text)) bunSummary = true;
|
|
280
|
+
if (!bunSummary) bunDiagnostics[stream].push(`${raw}\n`);
|
|
281
|
+
}
|
|
155
282
|
if (DOTS.test(text)) {
|
|
156
283
|
if (!goLifecycle && DOTS.test(text)) {
|
|
157
284
|
progressed ||= text.length > counted;
|
|
158
285
|
}
|
|
159
|
-
} else if (finishedLine(text)) {
|
|
286
|
+
} else if (finishedLine(text, stream)) {
|
|
160
287
|
progressed = true;
|
|
161
288
|
}
|
|
162
289
|
counted = 0;
|
|
@@ -168,6 +295,7 @@ export function createRunProgress(command = ''): RunProgress {
|
|
|
168
295
|
state.countedDots = dots;
|
|
169
296
|
return progressed;
|
|
170
297
|
},
|
|
298
|
+
error: () => failure,
|
|
171
299
|
inFlight: () => [
|
|
172
300
|
...running,
|
|
173
301
|
...[...packages].flatMap(([name, tests]) =>
|
|
@@ -177,6 +305,31 @@ export function createRunProgress(command = ''): RunProgress {
|
|
|
177
305
|
};
|
|
178
306
|
}
|
|
179
307
|
|
|
308
|
+
/** JSON-plus 0.1 flushes each closed result; plain libtest-json buffers a whole binary. */
|
|
309
|
+
export function withTestResultReport(command: string): { command: string; env: Record<string, string> } {
|
|
310
|
+
if (
|
|
311
|
+
(command.match(NEXTEST_RUN)?.length ?? 0) !== 1 ||
|
|
312
|
+
command.search(BUN_TEST) !== -1 ||
|
|
313
|
+
command.search(GO_TEST) !== -1 ||
|
|
314
|
+
UNCAPTURED_NEXTEST.test(command)
|
|
315
|
+
)
|
|
316
|
+
return { command, env: {} };
|
|
317
|
+
let reported = withInvocationFlag(
|
|
318
|
+
command,
|
|
319
|
+
NEXTEST_RUN,
|
|
320
|
+
/(?<![\w-])--message-format(?:=|\s+)(?:"[^"]*"|'[^']*'|[^\s]+)/g,
|
|
321
|
+
'--message-format=libtest-json-plus',
|
|
322
|
+
true,
|
|
323
|
+
);
|
|
324
|
+
reported = withInvocationFlag(
|
|
325
|
+
reported,
|
|
326
|
+
NEXTEST_RUN,
|
|
327
|
+
/(?<![\w-])--message-format-version(?:=|\s+)(?:"[^"]*"|'[^']*'|[^\s]+)/g,
|
|
328
|
+
'--message-format-version=0.1',
|
|
329
|
+
true,
|
|
330
|
+
);
|
|
331
|
+
return { command: reported, env: { NEXTEST_EXPERIMENTAL_LIBTEST_JSON: '1' } };
|
|
332
|
+
}
|
|
180
333
|
/**
|
|
181
334
|
* `command` with its one `bun test` asked for a line of dots, one per finished test: the only per-test report bun
|
|
182
335
|
* prints whoever runs it. A command that runs no bun, more than one runner, or already chose bun's dots is returned
|