@smoothbricks/nx-plugin 0.6.2 → 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.
Files changed (97) hide show
  1. package/README.md +281 -73
  2. package/dist/.build-inputs.json +20 -14
  3. package/dist/bin/smoo-nx-publish.d.ts +3 -0
  4. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-publish.js +3 -0
  6. package/dist/cargo-retention-hook.d.ts +6 -2
  7. package/dist/cargo-retention-hook.d.ts.map +1 -1
  8. package/dist/cargo-retention-hook.js +13 -7
  9. package/dist/eslint-file-set.d.ts +4 -1
  10. package/dist/eslint-file-set.d.ts.map +1 -1
  11. package/dist/eslint-sources.d.ts +25 -0
  12. package/dist/eslint-sources.d.ts.map +1 -0
  13. package/dist/eslint-sources.js +99 -0
  14. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  15. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  16. package/dist/executors/all-verdicts/executor.js +48 -2
  17. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  18. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  19. package/dist/executors/all-verdicts/schema.js +7 -0
  20. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  21. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  22. package/dist/executors/bounded-exec/bounds.js +100 -11
  23. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  24. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/executor.js +270 -27
  26. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  27. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  28. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  29. package/dist/executors/bounded-exec/mbx-pool.d.ts +20 -3
  30. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  31. package/dist/executors/bounded-exec/mbx-pool.js +84 -4
  32. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  33. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  34. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  35. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  36. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/progress.js +148 -22
  38. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  39. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  40. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  41. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  42. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  43. package/dist/executors/bounded-exec/test-results.js +33 -0
  44. package/dist/executors/bounded-exec/verdict.d.ts +20 -2
  45. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  46. package/dist/executors/bounded-exec/verdict.js +102 -4
  47. package/dist/index.d.ts +3 -2
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +67 -65
  50. package/dist/nx-publish.d.ts +24 -0
  51. package/dist/nx-publish.d.ts.map +1 -0
  52. package/dist/nx-publish.js +150 -0
  53. package/dist/runtime-input-policy.d.ts +14 -0
  54. package/dist/runtime-input-policy.d.ts.map +1 -1
  55. package/dist/runtime-input-policy.js +1 -1
  56. package/dist/tool-bins.d.ts +6 -8
  57. package/dist/tool-bins.d.ts.map +1 -1
  58. package/dist/tool-bins.js +7 -5
  59. package/dist/workspace-index.d.ts +7 -0
  60. package/dist/workspace-index.d.ts.map +1 -1
  61. package/dist/workspace-index.js +11 -0
  62. package/executors.json +1 -1
  63. package/managed/raw/patches/ttsc@0.34.1.patch +75 -0
  64. package/managed/raw/tooling/devenv +1 -2
  65. package/managed/raw/tooling/direnv/developer-links.ts +3 -0
  66. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  67. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  68. package/managed/raw/tooling/direnv/setup-environment.ts +35 -20
  69. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  70. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  71. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  72. package/package.json +223 -7
  73. package/runtime/nx-publish/cache_adapter.js +45 -0
  74. package/runtime/nx-publish/nx_publish.js +60 -0
  75. package/runtime-input.sh +12 -3
  76. package/src/bin/smoo-nx-publish.ts +4 -0
  77. package/src/cargo-retention-hook.ts +16 -10
  78. package/src/eslint-file-set.ts +4 -1
  79. package/src/eslint-sources.ts +134 -0
  80. package/src/executors/all-verdicts/executor.ts +58 -3
  81. package/src/executors/all-verdicts/schema.json +4 -0
  82. package/src/executors/all-verdicts/schema.ts +14 -0
  83. package/src/executors/bounded-exec/bounds.ts +132 -15
  84. package/src/executors/bounded-exec/executor.ts +303 -27
  85. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  86. package/src/executors/bounded-exec/mbx-pool.ts +82 -5
  87. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  88. package/src/executors/bounded-exec/progress.ts +168 -15
  89. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  90. package/src/executors/bounded-exec/test-results.ts +39 -0
  91. package/src/executors/bounded-exec/verdict.ts +108 -5
  92. package/src/index.ts +74 -70
  93. package/src/nx-publish.ts +157 -0
  94. package/src/runtime-input-policy.ts +1 -1
  95. package/src/tool-bins.ts +13 -9
  96. package/src/workspace-index.ts +12 -0
  97. package/test-timings.json +8 -3
@@ -1,7 +1,15 @@
1
+ import { shellTokens } from '../../runtime-input-policy.js';
2
+ import { invocationSpan } from './runner-sizing.js';
1
3
  import { shellQuote } from './verdict.js';
2
- /** The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged. */
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' };
@@ -12,13 +20,85 @@ export function mbxLeaf(pool, kind, want) {
12
20
  ? { kind: 'cargo' }
13
21
  : { kind: 'reserve', cpus: Math.max(1, want), priority: pool.priority };
14
22
  }
23
+ /**
24
+ * Only a known scheduled execution may stop its idle clock at zero holds. Plain Cargo tests can run doctests;
25
+ * archive-file targets, direct binaries and other runners are not proven scheduled at spawn (11_shell.md,
26
+ * "Cargo test-runner boundaries"). The inferred extracted native nextest command is a supported Cargo invocation.
27
+ */
28
+ export function mbxIdleGated(leaf, command, environment) {
29
+ if (leaf === null)
30
+ return false;
31
+ if (leaf.kind === 'reserve')
32
+ return true;
33
+ if (environment.MBX_SCHEDULER_TESTS !== '1')
34
+ return false;
35
+ if (environment.MBX_SCHEDULER === '0' || environment.MBX_SCHED_DISABLE === '1' || environment.MBX_DISABLE === '1')
36
+ return false;
37
+ // invocationSpan shares the lifecycle mapper's conservative shell-syntax boundary.
38
+ if (/[<>\n\r`\\]/.test(command))
39
+ return false;
40
+ if (/[^\S \t]/.test(command))
41
+ return false;
42
+ const invocation = /cargo(?:\s+(?:--frozen|--locked|--offline))*\s+(nextest\s+run|test)(?=\s|$)/;
43
+ const found = invocation.exec(command);
44
+ if (found === null)
45
+ return false;
46
+ const prefix = command.slice(0, found.index).trim();
47
+ if (prefix !== '' && !/^extracted="\$\([^"\n]+\)"\s*&&$/.test(prefix))
48
+ return false;
49
+ let remaining = command.slice(found.index);
50
+ const unquoted = remaining.replace(/"[^"]*"|'[^']*'/g, '');
51
+ if (/[$*?{}~[\]]/.test(unquoted))
52
+ return false;
53
+ // Only the inferred command's path templates are known expansions; arbitrary words could supply mbx overrides.
54
+ const paths = remaining.replace(/\$PWD(?=\/)/g, '');
55
+ if ((prefix === '' ? paths : paths.replace(/\$extracted(?=\/)/g, '')).includes('$'))
56
+ return false;
57
+ for (;;) {
58
+ const leg = invocation.exec(remaining);
59
+ if (leg === null || leg.index !== 0)
60
+ return false;
61
+ const { argsEnd } = invocationSpan(remaining, invocation);
62
+ const args = [];
63
+ for (const token of shellTokens(remaining.slice(0, argsEnd), [])) {
64
+ if (token.kind !== 'word')
65
+ return false;
66
+ if (token.text === '--')
67
+ break;
68
+ if (token.text.startsWith('$') &&
69
+ !(token.text.startsWith('$extracted/') &&
70
+ ['--binaries-metadata', '--cargo-metadata', '--target-dir-remap'].includes(args.at(-1) ?? '')))
71
+ return false;
72
+ args.push(token.text);
73
+ }
74
+ if (args.some((arg) => /^(?:--(?:config|directory|archive-file)(?:=|$)|--(?:doc|no-run|list|help)(?:=|$)|-C|-h$|\+)/.test(arg))) {
75
+ return false;
76
+ }
77
+ if (leg[1] === 'test' &&
78
+ !args.some((arg) => /^--(?:lib|tests|bins|examples|benches|all-targets|test|bin|example|bench)(?:=|$)/.test(arg))) {
79
+ return false;
80
+ }
81
+ const suffix = remaining.slice(argsEnd).trim();
82
+ if (suffix === '')
83
+ return true;
84
+ const separator = /^(?:&&|\|\||;)\s*/.exec(suffix);
85
+ if (separator === null)
86
+ return false;
87
+ remaining = suffix.slice(separator[0].length);
88
+ }
89
+ }
90
+ /**
91
+ * mbx writes one byte per admission (g) and permit drop (r). Cargo descendants inherit this descriptor through
92
+ * MBX_GRANT_FD; reserve names it with --grant-fd and closes it on exec of the external command.
93
+ */
94
+ export const MBX_GRANT_FD = 5;
15
95
  /**
16
96
  * `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
17
- * cowshed's admission proved to be the host's pinned mbx.
97
+ * cowshed's admission proved to be the host's pinned mbx; it writes the grant on this descriptor itself.
18
98
  */
19
99
  export function withMbxLeaf(command, leaf) {
20
100
  if (leaf.kind === 'cargo') {
21
101
  return command;
22
102
  }
23
- return `mbx reserve --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
103
+ return `mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
24
104
  }
@@ -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":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,WAAW;IAC1B,gGAAgG;IAChG,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACnD,6GAA6G;IAC7G,QAAQ,IAAI,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAwD/C,wBAAgB,iBAAiB,CAAC,OAAO,SAAK,GAAG,WAAW,CAoF3D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAmB1D"}
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"}