@smoothbricks/nx-plugin 0.6.3-0 → 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.
Files changed (109) hide show
  1. package/README.md +159 -121
  2. package/dist/.build-inputs.json +25 -20
  3. package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
  4. package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-go-test-build.js +79 -0
  6. package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
  7. package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-go-test-run.js +129 -0
  9. package/dist/bounded-test-policy.d.ts +1 -1
  10. package/dist/bounded-test-policy.d.ts.map +1 -1
  11. package/dist/bounded-test-policy.js +9 -8
  12. package/dist/cargo-workspace.d.ts +10 -20
  13. package/dist/cargo-workspace.d.ts.map +1 -1
  14. package/dist/cargo-workspace.js +12 -22
  15. package/dist/cross-check-policy.d.ts +2 -2
  16. package/dist/cross-check-policy.js +2 -2
  17. package/dist/deploy-policy.d.ts +6 -0
  18. package/dist/deploy-policy.d.ts.map +1 -1
  19. package/dist/deploy-policy.js +11 -0
  20. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/executor.js +49 -37
  22. package/dist/executors/bounded-exec/mbx-pool.d.ts +39 -10
  23. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/mbx-pool.js +78 -24
  25. package/dist/executors/bounded-exec/progress.js +5 -5
  26. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  27. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  28. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  29. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  30. package/dist/executors/bounded-exec/verdict.d.ts +6 -0
  31. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/verdict.js +6 -0
  33. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  34. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  35. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  36. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  37. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  38. package/dist/executors/wrangler-deploy/executor.js +43 -0
  39. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  40. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  41. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  42. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  43. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  44. package/dist/go-tests.d.ts +30 -0
  45. package/dist/go-tests.d.ts.map +1 -0
  46. package/dist/go-tests.js +43 -0
  47. package/dist/index.d.ts +9 -2
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +271 -230
  50. package/dist/managed-files/files.d.ts.map +1 -1
  51. package/dist/managed-files/files.js +5 -0
  52. package/dist/process-group.js +2 -2
  53. package/dist/runtime-input-policy.d.ts +3 -3
  54. package/dist/runtime-input-policy.js +3 -3
  55. package/dist/test-timings.d.ts +23 -4
  56. package/dist/test-timings.d.ts.map +1 -1
  57. package/dist/test-timings.js +72 -12
  58. package/dist/version-actions.cjs +10 -11
  59. package/dist/version-actions.d.cts.map +1 -1
  60. package/dist/workspace-config-policy.d.ts.map +1 -1
  61. package/dist/workspace-config-policy.js +17 -22
  62. package/dist/workspace-manifest.js +3 -3
  63. package/executors.json +6 -5
  64. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  65. package/managed/raw/patches/ttsc@0.34.1.patch +64 -0
  66. package/managed/raw/tooling/direnv/developer-links.ts +121 -51
  67. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  68. package/managed/raw/tooling/direnv/setup-environment.ts +14 -4
  69. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  70. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  71. package/package.json +57 -7
  72. package/runtime/nx-publish/.build-inputs.json +11 -0
  73. package/runtime-input.sh +50 -23
  74. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  75. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  76. package/src/bounded-test-policy.ts +9 -8
  77. package/src/cargo-workspace.ts +12 -24
  78. package/src/cross-check-policy.ts +2 -2
  79. package/src/deploy-policy.ts +11 -0
  80. package/src/executors/bounded-exec/executor.ts +61 -42
  81. package/src/executors/bounded-exec/mbx-pool.ts +97 -33
  82. package/src/executors/bounded-exec/progress.ts +5 -5
  83. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  84. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  85. package/src/executors/bounded-exec/verdict.ts +7 -0
  86. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  87. package/src/executors/wrangler-deploy/executor.ts +63 -0
  88. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  89. package/src/executors/wrangler-deploy/schema.json +16 -0
  90. package/src/executors/wrangler-deploy/schema.ts +4 -0
  91. package/src/go-tests.ts +67 -0
  92. package/src/index.ts +294 -253
  93. package/src/managed-files/files.ts +5 -0
  94. package/src/process-group.ts +2 -2
  95. package/src/runtime-input-policy.ts +3 -3
  96. package/src/test-timings.ts +72 -14
  97. package/src/version-actions.cts +10 -11
  98. package/src/workspace-config-policy.ts +20 -29
  99. package/src/workspace-manifest.ts +3 -3
  100. package/test-timings.json +131 -130
  101. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  102. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  103. package/dist/executors/clean-outputs/executor.js +0 -83
  104. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  105. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  106. package/src/executors/clean-outputs/executor.ts +0 -131
  107. package/src/executors/clean-outputs/schema.json +0 -15
  108. package/src/executors/clean-outputs/schema.ts +0 -3
  109. /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
@@ -220,8 +220,8 @@ export function cargoCrossTestTargetName(triple) {
220
220
  return `cargo-cross-test-${triple}`;
221
221
  }
222
222
  /**
223
- * One archive file per triple, beside the host-native
224
- * `CARGO_TEST_ARCHIVE_FILE`, relative to the cargo workspace root. Distinct
223
+ * One archive file per triple, relative to the cargo workspace root: the only
224
+ * test archives, since a same-platform run executes `cargo-test-build`'s binaries in place. Distinct
225
225
  * paths are what let both exist: each is a declared Nx output, so a single path
226
226
  * for two triples would let a restored cache serve one machine's binaries under
227
227
  * the other's name.
@@ -23,4 +23,10 @@ export declare const PRODUCTION_PUSH_DEPLOY_TAG = "production-push-deploy-target
23
23
  * never widens it.
24
24
  */
25
25
  export declare function stageDeploysProject(tags: string[] | undefined, stage: DeploymentStage): boolean;
26
+ /**
27
+ * The tag a deploy uploads its version under, from the artifact hash it deploys: `nx-` and that hash when it is
28
+ * decimal (Nx's own), or the first 32 digits of a hexadecimal hash of at least 32. `smoo wrangler deploy-stage` tags
29
+ * with it, and the wrangler-deploy hasher compares the stage's live tag with it. Null for any other hash.
30
+ */
31
+ export declare function deployVersionTag(artifactHash: string): string | null;
26
32
  //# sourceMappingURL=deploy-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy-policy.d.ts","sourceRoot":"","sources":["../src/deploy-policy.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,MAAM,EAAE,CAAC;AAKvE,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,4BAA4B,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,0BAA0B,kCAAkC,CAAC;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAK/F"}
1
+ {"version":3,"file":"deploy-policy.d.ts","sourceRoot":"","sources":["../src/deploy-policy.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,MAAM,EAAE,CAAC;AAKvE,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,4BAA4B,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,0BAA0B,kCAAkC,CAAC;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAK/F;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIpE"}
@@ -34,3 +34,14 @@ export function stageDeploysProject(tags, stage) {
34
34
  return stage === 'staging';
35
35
  return tags.includes(STAGE_DEPLOY_TAG);
36
36
  }
37
+ /**
38
+ * The tag a deploy uploads its version under, from the artifact hash it deploys: `nx-` and that hash when it is
39
+ * decimal (Nx's own), or the first 32 digits of a hexadecimal hash of at least 32. `smoo wrangler deploy-stage` tags
40
+ * with it, and the wrangler-deploy hasher compares the stage's live tag with it. Null for any other hash.
41
+ */
42
+ export function deployVersionTag(artifactHash) {
43
+ if (/^(?:0|[1-9][0-9]*)$/.test(artifactHash))
44
+ return `nx-${artifactHash}`;
45
+ const normalized = artifactHash.toLowerCase();
46
+ return /^[0-9a-f]{32,}$/.test(normalized) ? `nx-${normalized.slice(0, 32)}` : null;
47
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AA0BA,OAAO,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B,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,UAAU,GAAG,IAAI,EAC7B,SAAS,GAAE,gBAAgB,GAAG,IAAW,EACzC,kBAAkB,GAAE,OAAO,sBAA+C,EAC1E,KAAK,GAAE,YAAY,GAAG,IAAW,EACjC,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACjD,OAAO,CAAC,iBAAiB,CAAC,CA4hC5B;AAED,wBAAgB,uBAAuB,IAAI,iBAAiB,CAM3D"}
@@ -11,14 +11,14 @@ import { admissionWaitMs, earliestBound, NO_ADMISSION_WAIT, stepAdmissionWait, s
11
11
  import { CPU_POOL_ENV, createCpuPool, readInheritedCpuPool, takeParentCpuTokens, } from './cpu-pool.js';
12
12
  import { GATEWAY_SOCKET } from './gateway-lease.js';
13
13
  import { captureHangDiagnostics, HANG_CAPTURE_MS } from './hang-diagnostics.js';
14
- import { MBX_GRANT_FD, mbxIdleGated, mbxLeaf, mbxPool, withMbxLeaf } from './mbx-pool.js';
14
+ import { MBX_GRANT_FD, mbxIdleGated, mbxLeaf, mbxPool, nxTaskCores, runsPrebuiltNextest, withMbxLeaf, } from './mbx-pool.js';
15
15
  import { MBX_QUEUE_POLL_MS, snapshotMbxQueue } from './mbx-queue.js';
16
16
  import { createNoSpaceWatch } from './no-space.js';
17
17
  import { COWSHED_EXECUTABLE_ENV, cowshedSubtreeOwner, HANDLE_FD, readAdmission, SUPERVISOR_SOCKET_ENV, } from './owned-subtree.js';
18
18
  import { createRunProgress, withProgressReport, withTestResultReport } from './progress.js';
19
19
  import { createHostCommands, describeCoverageGap, describeRamTempError, describeSignalled, LEFTOVER_GRACE_MS, PRODUCTION, RAM_TEMP_CAPACITY_BYTES, RamTempVolume, ramTempPaths, } from './ram-temp.js';
20
20
  import { createRunnerLifecycle, withFixtureLifecycle, withRunnerLifecycle } from './runner-lifecycle.js';
21
- import { CPU_TOKENS_ENV, runnerDemand, sizeRunner } from './runner-sizing.js';
21
+ import { CPU_TOKENS_ENV, runnerDemand, sizeRunner, sizeRunnerToGrant } from './runner-sizing.js';
22
22
  import { checkRuntimePin, describeRuntimePinRefusal } from './runtime-pin.js';
23
23
  import { createTestResultWriter } from './test-result-writer.js';
24
24
  import { BUN_TEST, clearTaskDirectory, describeAdmissionQueue, describeNoSpace, JUNIT_FILE, JUNIT_REPORT_ENV, judgeOperationalFailure, judgeRun, readJunitReport, taskDirectory, withJunitReport, writeRecord, } from './verdict.js';
@@ -353,7 +353,11 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
353
353
  // (`run-cpu-pool.ts`), so a task takes its tokens from a parent's pool; a command that inherits none runs exactly as
354
354
  // asked and nothing is said.
355
355
  const cores = availableParallelism();
356
- const demand = runnerDemand(requested, options.parallelism, cores, process.env, options.env);
356
+ // A prebuilt nextest leaf under mbx asks for its task's share of the host (`nxTaskCores`), not every core: it knows
357
+ // no count of its tests. A declared or named count still wins.
358
+ const mbx = mbxPool(process.env);
359
+ const leafCores = mbx !== null && runsPrebuiltNextest(requested) ? nxTaskCores(cores, { ...process.env, ...options.env }) : cores;
360
+ const demand = runnerDemand(requested, options.parallelism, leafCores, process.env, options.env);
357
361
  const asked = Date.now();
358
362
  // A pool that answered and refused is a live budget, and running beside it would count the run twice: the run fails
359
363
  // instead. A pool whose endpoint is gone (its holder exited) lends nothing, and the run goes on as asked.
@@ -376,16 +380,18 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
376
380
  const waitedMs = Date.now() - asked;
377
381
  let cpu;
378
382
  let sized = { command: requested, env: {} };
379
- // With mbx the leaf's admission is mbx's one pool, not a parent's tokens: its runner is sized to the job's count,
380
- // and a non-Cargo leaf holds that much of the pool for its run (specs/cowshed/05_gateway.md, "Parallelism inside a
381
- // job"). No grant and no sub-pool beside it.
382
- const mbx = mbxPool(process.env);
383
- const leaf = mbx === null ? null : mbxLeaf(mbx, demand.kind, demand.want);
383
+ // With mbx the leaf's admission is mbx's one pool, not a parent's tokens. A leaf mbx does not admit itself asks for
384
+ // its runner's count, a maximum, and its runner runs on the cores it is granted, which only the command learns
385
+ // (specs/cowshed/05_gateway.md, "Parallelism inside a job"). No grant and no sub-pool beside it.
386
+ const leaf = mbx === null ? null : mbxLeaf(mbx, demand, requested);
384
387
  if (grant !== null) {
385
388
  sized = sizeRunner(demand, requested, grant.tokens);
386
389
  cpu = { tokens: grant.tokens, want: demand.want, waitedMs };
387
390
  appendStderr(`cowshed: cpu-pool wait done elapsed=${waitedMs}ms status=ok tokens=${grant.tokens}/${demand.want} runner=${demand.kind}\n`);
388
391
  }
392
+ else if (leaf?.kind === 'reserve') {
393
+ sized = { command: sizeRunnerToGrant(leaf.demand, requested), env: {} };
394
+ }
389
395
  else if (leaf !== null) {
390
396
  sized = sizeRunner(demand, requested, demand.want);
391
397
  }
@@ -411,7 +417,14 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
411
417
  let mbxAdmitted = false;
412
418
  let admissionWait = NO_ADMISSION_WAIT;
413
419
  let lastQueueRequests = [];
414
- let queueFailure = null;
420
+ /**
421
+ * Why the last admission snapshot failed, while the one after it has not succeeded; null otherwise. A snapshot only
422
+ * decides whether waiting on mbx admission is credited against the idle bound, so a failed one withholds that credit
423
+ * and ends nothing: the bounds decide, and an idle expiry names it.
424
+ */
425
+ let unconfirmedAdmission = null;
426
+ /** When the last successful snapshot completed (`Date.now()`): credit runs to it and no further. */
427
+ let confirmedAdmissionAt = null;
415
428
  const queueWait = () => mbxAdmitted || lastQueueRequests.length === 0
416
429
  ? null
417
430
  : {
@@ -522,7 +535,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
522
535
  // With a supervisor, `cowshed subtree-root` asks it for a handle on itself, writes the answer to the handle
523
536
  // descriptor, and execs `/bin/sh -c command` in the same process: the command's pid, group and life are unchanged.
524
537
  const unadmitted = hooked?.command ?? (fixture === null ? command : `${fixture.command} && ${command}`);
525
- const shellCommand = leaf === null ? unadmitted : withMbxLeaf(unadmitted, leaf);
538
+ const shellCommand = withMbxLeaf(unadmitted, leaf);
526
539
  // Only leaves known to be scheduled can exclude zero-hold time. Others keep lifecycle hang protection.
527
540
  const queued = mbxIdleGated(leaf, sized.command, { ...process.env, ...env });
528
541
  // fd 4 is unused without a subtree admission, so the grant takes fd 5 either way.
@@ -652,7 +665,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
652
665
  let checkingIdle = false;
653
666
  const armBoundTimer = () => {
654
667
  clearTimeout(boundTimer);
655
- if (state.settled || state.expiry !== null || queueFailure !== null)
668
+ if (state.settled || state.expiry !== null)
656
669
  return;
657
670
  const next = earliestBound(checkingIdle ? { ...bounds, idle: null } : bounds);
658
671
  if (next !== null) {
@@ -662,7 +675,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
662
675
  }
663
676
  };
664
677
  const confirmExpiry = async (kind, at) => {
665
- if (state.settled || state.expiry !== null || queueFailure !== null)
678
+ if (state.settled || state.expiry !== null)
666
679
  return;
667
680
  const scheduled = earliestBound(checkingIdle ? { ...bounds, idle: null } : bounds);
668
681
  if (scheduled?.kind !== kind || scheduled.at !== at)
@@ -681,7 +694,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
681
694
  checkingIdle = false;
682
695
  }
683
696
  }
684
- if (state.settled || state.expiry !== null || queueFailure !== null)
697
+ if (state.settled || state.expiry !== null)
685
698
  return;
686
699
  const next = earliestBound(bounds);
687
700
  if (next !== null && next.at <= Date.now())
@@ -690,7 +703,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
690
703
  armBoundTimer();
691
704
  };
692
705
  const stepTo = (event) => {
693
- if (state.settled || state.expiry !== null || queueFailure !== null)
706
+ if (state.settled || state.expiry !== null)
694
707
  return;
695
708
  const idleBefore = bounds.idle;
696
709
  bounds = stepBounds(bounds, {
@@ -709,15 +722,17 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
709
722
  let lastQueueDiagnostic = '';
710
723
  let lastQueueDiagnosticAt = null;
711
724
  let lastSnapshotDiagnostics = '';
712
- const failQueueObservation = (detail) => {
713
- if (state.settled || state.expiry !== null || queueAbort.signal.aborted || queueFailure !== null)
725
+ const unconfirmAdmission = (detail) => {
726
+ if (state.settled || state.expiry !== null || queueAbort.signal.aborted)
714
727
  return;
715
- queueFailure = detail;
716
- tell(`bounded-exec: mbx admission snapshot failed: ${detail}; queue/admission state unconfirmed, not an idle wedge\n`);
717
- clearTimeout(boundTimer);
718
- cancelCapture();
719
- stopQueueObservation();
720
- termination = terminate();
728
+ if (unconfirmedAdmission !== detail) {
729
+ tell(`bounded-exec: mbx admission snapshot failed: ${detail}; admission is unconfirmed, so this wait earns no idle credit until a snapshot succeeds\n`);
730
+ }
731
+ unconfirmedAdmission = detail;
732
+ lastQueueRequests = [];
733
+ admissionWait = stepAdmissionWait(admissionWait, { kind: 'snapshot', at: performance.now(), waiting: false });
734
+ // The wait since the last confirmed snapshot is unconfirmed: the idle bound resumes from that snapshot.
735
+ stepTo({ kind: 'admission-queue', at: confirmedAdmissionAt ?? Date.now(), waiting: false, testing: isTesting() });
721
736
  };
722
737
  const refreshQueue = async (fresh) => {
723
738
  if (fresh && queueSnapshot !== null)
@@ -730,7 +745,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
730
745
  if (state.settled || state.expiry !== null || queueAbort.signal.aborted)
731
746
  return;
732
747
  if (!snapshot.ok) {
733
- failQueueObservation(snapshot.detail);
748
+ unconfirmAdmission(snapshot.detail);
734
749
  return;
735
750
  }
736
751
  const diagnostics = snapshot.diagnostics?.join('; ') ?? '';
@@ -741,6 +756,8 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
741
756
  const observedAt = Date.now();
742
757
  const observedWaitAt = performance.now();
743
758
  admissionWait = stepAdmissionWait(admissionWait, { kind: 'snapshot', at: observedWaitAt, waiting });
759
+ unconfirmedAdmission = null;
760
+ confirmedAdmissionAt = observedAt;
744
761
  if (waiting) {
745
762
  lastQueueRequests = snapshot.requests;
746
763
  const positions = JSON.stringify(snapshot.requests);
@@ -759,7 +776,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
759
776
  stepTo({ kind: 'admission-queue', at: observedAt, waiting, testing: isTesting() });
760
777
  })()
761
778
  .catch((error) => {
762
- failQueueObservation(error instanceof Error ? error.message : String(error));
779
+ unconfirmAdmission(error instanceof Error ? error.message : String(error));
763
780
  })
764
781
  .finally(() => {
765
782
  queueSnapshot = null;
@@ -861,7 +878,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
861
878
  cancelCapture();
862
879
  clearTimeout(boundTimer);
863
880
  // Preserve explicit live membership before cancellation removes the queued process. A failed bounded observation
864
- // reports an operational failure, never a manufactured queue or admission.
881
+ // leaves the admission unconfirmed, never a manufactured queue or admission.
865
882
  signalCleanup = (leaf === null ? Promise.resolve() : refreshQueue(false))
866
883
  .finally(() => {
867
884
  stopQueueObservation();
@@ -869,10 +886,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
869
886
  })
870
887
  .finally(releaseCpu)
871
888
  .finally(() => releaseLease(true))
872
- .finally(async () => recordRun(signalToExitCode(signal), state.expiry, Date.now() - startedAt, state.poolCloseError !== null ||
873
- lifecycleFailure !== null ||
874
- state.retireError !== null ||
875
- queueFailure !== null, state.noSpace === null ? null : await state.noSpace, state.lockWaits))
889
+ .finally(async () => recordRun(signalToExitCode(signal), state.expiry, Date.now() - startedAt, state.poolCloseError !== null || lifecycleFailure !== null || state.retireError !== null, state.noSpace === null ? null : await state.noSpace, state.lockWaits))
876
890
  .finally(() => process.kill(process.pid, signal));
877
891
  };
878
892
  const onSigint = () => onTerminationSignal('SIGINT');
@@ -920,7 +934,9 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
920
934
  appendStderr(bound.kind === 'idle'
921
935
  ? `\nCommand made no progress: no test finished for ${bound.limitMs}ms (idleTimeoutMs=${bound.limitMs}) after ${elapsedMs}ms of runtime; ${bound.tests.length > 0
922
936
  ? `still running: ${bound.tests.join(', ')}`
923
- : 'the runner named no test still running'} (cwd=${cwd}): ${command}\n`
937
+ : 'the runner named no test still running'} (cwd=${cwd}): ${command}\n${unconfirmedAdmission === null
938
+ ? ''
939
+ : `The last mbx admission snapshot failed (${unconfirmedAdmission}), so the wait it could not confirm earned no idle credit\n`}`
924
940
  : bound.kind === 'fixture'
925
941
  ? `\nFixture command timed out after ${elapsedMs}ms (fixtureTimeoutMs=${bound.limitMs}, cwd=${cwd}): ${fixture?.command ?? command}\n`
926
942
  : `\nCommand timed out after ${elapsedMs}ms (timeoutMs=${bound.limitMs}, cwd=${cwd}): ${command}\n`);
@@ -1027,7 +1043,7 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
1027
1043
  mbxAdmitted = true;
1028
1044
  said = true;
1029
1045
  tell(leaf.kind === 'reserve'
1030
- ? `cowshed: mbx reserve granted elapsed=${Date.now() - startedAt}ms cpus=${leaf.cpus} priority=${leaf.priority}\n`
1046
+ ? `cowshed: mbx reserve granted elapsed=${Date.now() - startedAt}ms asked=${leaf.demand.want} priority=${leaf.priority}\n`
1031
1047
  : `cowshed: mbx cargo granted elapsed=${Date.now() - startedAt}ms\n`);
1032
1048
  }
1033
1049
  stepTo({ kind: 'granted', at: Date.now(), testing: isTesting(), fixture: !fixtureDone });
@@ -1098,14 +1114,10 @@ export async function runBoundedExec(options, context, killer, tempVolume, inher
1098
1114
  appendStderr(`${describeRamTempError(full)}\n`);
1099
1115
  }
1100
1116
  }
1101
- await releaseLease(code !== 0 ||
1102
- state.expiry !== null ||
1103
- state.poolCloseError !== null ||
1104
- lifecycleFailure !== null ||
1105
- queueFailure !== null);
1117
+ await releaseLease(code !== 0 || state.expiry !== null || state.poolCloseError !== null || lifecycleFailure !== null);
1106
1118
  // Broken resource ownership, a lost native lifecycle, or leftovers that could not be retired fail even if a shell
1107
1119
  // branch later exited 0: its verdict is an ordinary operational failure, never a successful or silently unbounded run.
1108
- const operationalFailure = state.poolCloseError !== null || lifecycleFailure !== null || state.retireError !== null || queueFailure !== null;
1120
+ const operationalFailure = state.poolCloseError !== null || lifecycleFailure !== null || state.retireError !== null;
1109
1121
  await recordRun(code, state.expiry, Date.now() - startedAt, operationalFailure, seen, state.lockWaits);
1110
1122
  return {
1111
1123
  success: !operationalFailure && resultFailure === null && state.expiry === null && code === 0,
@@ -1,4 +1,4 @@
1
- import { type RunnerKind } from './runner-sizing.js';
1
+ import { type Demand, type ReservedDemand } from './runner-sizing.js';
2
2
  /**
3
3
  * mbx's machine-wide pool as a leaf runner meets it (specs/cowshed/05_gateway.md, "Host scheduling", "Parallelism inside
4
4
  * a job"). With the mbx capability the canonical environment names the one pool (`MBX_SCHEDULER=1` beside the shared
@@ -17,22 +17,49 @@ export interface MbxPool {
17
17
  */
18
18
  export declare function mbxPool(environment: Readonly<NodeJS.ProcessEnv>): MbxPool | null;
19
19
  /**
20
- * How a leaf enters the pool once: a Cargo leaf runs through mbx, which admits its compiler and supported test work
21
- * itself, so wrapping it would charge it twice; any other leaf holds `cpus` of the pool for its whole run through
22
- * `mbx reserve`, `cpus` being the job's own count.
20
+ * How a leaf enters the pool once. A Cargo leaf that builds runs through mbx, which admits its compilers and supported
21
+ * test work itself, so wrapping it would charge it twice. Any other leaf reserves for its whole run through
22
+ * `mbx reserve --cpus <its runner's count>`, a maximum: mbx grants as many of those cores as are free once one is, and
23
+ * the runner runs on the count it is granted (`sizeRunnerToGrant`). That includes a nextest run of test binaries
24
+ * already built (the inferred extracted-archive run, or one from `--archive-file`): it compiles nothing, and beneath a
25
+ * reservation mbx schedules none of its test processes, so they run inside the one grant. Admitted one by one under
26
+ * `MBX_SCHEDULER_TESTS=1`, each queued for a ticket of its own: in a downstream gate on 2026-10-30, codec tests of at
27
+ * most 0.25 s took 73.5 s apiece, and their 121 tests run in 1.18 s unqueued (specs/cowshed/05_gateway.md,
28
+ * "Parallelism inside a job").
23
29
  */
24
30
  export type MbxLeaf = {
25
31
  readonly kind: 'cargo';
26
32
  } | {
27
33
  readonly kind: 'reserve';
28
- readonly cpus: number;
29
34
  readonly priority: 'normal' | 'low';
35
+ readonly demand: ReservedDemand;
30
36
  };
31
- export declare function mbxLeaf(pool: MbxPool, kind: RunnerKind, want: number): MbxLeaf;
37
+ /** Whether `command` runs nextest over test binaries already built, which compiles nothing. */
38
+ export declare function runsPrebuiltNextest(command: string): boolean;
39
+ /**
40
+ * A Vitest or Go test leaf enters no pool, `null` (owner's ruling, 2026-10-31): it holds nothing and runs its own
41
+ * default workers, uncapped. Reserved like any other leaf, it asked for that default, which sizes to the host: Vitest one
42
+ * 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
43
+ * kept every reservation queued behind it waiting while the pool drained. On 2026-10-31 a downstream gate ran 4.9 of 18
44
+ * 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.
45
+ */
46
+ export declare function mbxLeaf(pool: MbxPool, demand: Demand, command: string): MbxLeaf | null;
47
+ /**
48
+ * 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
49
+ * least one. Nx reads that count from `NX_PARALLEL`, a number or a share of the cores (`100%`), else runs three.
50
+ *
51
+ * A prebuilt nextest leaf asks for this share rather than its runner's own count, every core by default, because it
52
+ * 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
53
+ * long tests asking for every core would hold the idle rest for its whole run (specs/cowshed/05_gateway.md, "Open
54
+ * questions"). Before mbx granted reservations their free cores, every cargo-test leaf of a gate reserved the whole
55
+ * 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
56
+ * `mbx reserve --cpus 18`.
57
+ */
58
+ export declare function nxTaskCores(cores: number, environment: Readonly<NodeJS.ProcessEnv>): number;
32
59
  /**
33
60
  * Only a known scheduled execution may stop its idle clock at zero holds. Plain Cargo tests can run doctests;
34
61
  * archive-file targets, direct binaries and other runners are not proven scheduled at spawn (11_shell.md,
35
- * "Cargo test-runner boundaries"). The inferred extracted native nextest command is a supported Cargo invocation.
62
+ * "Cargo test-runner boundaries"). The inferred in-place nextest command is a supported Cargo invocation.
36
63
  */
37
64
  export declare function mbxIdleGated(leaf: MbxLeaf | null, command: string, environment: Readonly<NodeJS.ProcessEnv>): boolean;
38
65
  /**
@@ -41,8 +68,10 @@ export declare function mbxIdleGated(leaf: MbxLeaf | null, command: string, envi
41
68
  */
42
69
  export declare const MBX_GRANT_FD = 5;
43
70
  /**
44
- * `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
45
- * cowshed's admission proved to be the host's pinned mbx; it writes the grant on this descriptor itself.
71
+ * `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
72
+ * asks for its runner's count, and its reservation first sizes the runner to what mbx granted (`grantedSizing`) and says
73
+ * so on stderr. `mbx` is the canonical environment's, whose realpath cowshed's admission proved to be the host's pinned
74
+ * mbx; it writes the grant on this descriptor itself.
46
75
  */
47
- export declare function withMbxLeaf(command: string, leaf: MbxLeaf): string;
76
+ export declare function withMbxLeaf(command: string, leaf: MbxLeaf | null): string;
48
77
  //# sourceMappingURL=mbx-pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mbx-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/mbx-pool.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC;CACrC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,GAAG,IAAI,CAKhF;AAED;;;;GAIG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC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gB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAoBtF;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAM3F;AAQD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAkDrH;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,CAOzE"}
@@ -1,5 +1,5 @@
1
1
  import { shellTokens } from '../../runtime-input-policy.js';
2
- import { invocationSpan } from './runner-sizing.js';
2
+ import { CPU_TOKENS_ENV, grantedSizing, invocationSpan } from './runner-sizing.js';
3
3
  import { shellQuote } from './verdict.js';
4
4
  /**
5
5
  * The pool the environment names, or `null` where the project has no mbx and cowshed's own pools apply unchanged, or
@@ -14,16 +14,69 @@ export function mbxPool(environment) {
14
14
  }
15
15
  return { priority: environment.MBX_SCHEDULER_PRIORITY === 'normal' ? 'normal' : 'low' };
16
16
  }
17
- const CARGO_LEAVES = new Set(['cargo', 'cargo-mutants', 'nextest']);
18
- export function mbxLeaf(pool, kind, want) {
19
- return CARGO_LEAVES.has(kind)
20
- ? { kind: 'cargo' }
21
- : { kind: 'reserve', cpus: Math.max(1, want), priority: pool.priority };
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
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));
70
+ }
71
+ /**
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;
23
76
  /**
24
77
  * Only a known scheduled execution may stop its idle clock at zero holds. Plain Cargo tests can run doctests;
25
78
  * 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.
79
+ * "Cargo test-runner boundaries"). The inferred in-place nextest command is a supported Cargo invocation.
27
80
  */
28
81
  export function mbxIdleGated(leaf, command, environment) {
29
82
  if (leaf === null)
@@ -34,25 +87,24 @@ export function mbxIdleGated(leaf, command, environment) {
34
87
  return false;
35
88
  if (environment.MBX_SCHEDULER === '0' || environment.MBX_SCHED_DISABLE === '1' || environment.MBX_DISABLE === '1')
36
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');
37
93
  // invocationSpan shares the lifecycle mapper's conservative shell-syntax boundary.
38
- if (/[<>\n\r`\\]/.test(command))
94
+ if (/[<>\n\r`\\]/.test(known))
39
95
  return false;
40
- if (/[^\S \t]/.test(command))
96
+ if (/[^\S \t]/.test(known))
41
97
  return false;
42
98
  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))
99
+ const found = invocation.exec(known);
100
+ if (found === null || known.slice(0, found.index).trim() !== '')
48
101
  return false;
49
- let remaining = command.slice(found.index);
102
+ let remaining = known.slice(found.index);
50
103
  const unquoted = remaining.replace(/"[^"]*"|'[^']*'/g, '');
51
104
  if (/[$*?{}~[\]]/.test(unquoted))
52
105
  return false;
53
106
  // 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('$'))
107
+ if (remaining.replace(/\$PWD(?=\/)/g, '').includes('$'))
56
108
  return false;
57
109
  for (;;) {
58
110
  const leg = invocation.exec(remaining);
@@ -65,9 +117,7 @@ export function mbxIdleGated(leaf, command, environment) {
65
117
  return false;
66
118
  if (token.text === '--')
67
119
  break;
68
- if (token.text.startsWith('$') &&
69
- !(token.text.startsWith('$extracted/') &&
70
- ['--binaries-metadata', '--cargo-metadata', '--target-dir-remap'].includes(args.at(-1) ?? '')))
120
+ if (token.text.startsWith('$'))
71
121
  return false;
72
122
  args.push(token.text);
73
123
  }
@@ -93,12 +143,16 @@ export function mbxIdleGated(leaf, command, environment) {
93
143
  */
94
144
  export const MBX_GRANT_FD = 5;
95
145
  /**
96
- * `command` as the shell runs it under its leaf's admission. `mbx` is the canonical environment's, whose realpath
97
- * cowshed's admission proved to be the host's pinned mbx; it writes the grant on this descriptor itself.
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.
98
150
  */
99
151
  export function withMbxLeaf(command, leaf) {
100
- if (leaf.kind === 'cargo') {
152
+ if (leaf === null || leaf.kind === 'cargo') {
101
153
  return command;
102
154
  }
103
- return `mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus ${leaf.cpus} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(command)}`;
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}`)}`;
104
158
  }
@@ -1,7 +1,7 @@
1
1
  import { StringDecoder } from 'node:string_decoder';
2
2
  import typia from 'typia';
3
3
  import { invocationSpan, withInvocationFlag } from './runner-sizing.js';
4
- import { BUN_TEST, GO_TEST, NEXTEST_RUN } from './verdict.js';
4
+ import { BUN_TEST, GO_TEST, GO_TEST_RUNNER, NEXTEST_RUN } from './verdict.js';
5
5
  const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[A-Za-z]`, 'g');
6
6
  /** Lines naming a test or file that finished; group 1 is its name. */
7
7
  const FINISHED = [
@@ -72,8 +72,8 @@ function nativeTestEvent(text, invalid) {
72
72
  /** A direct Go chain reports tests only through JSON; other commands may also carry text runner reports. */
73
73
  function onlyGoTests(command) {
74
74
  let rest = command.trim();
75
- while (rest.search(GO_TEST) === 0) {
76
- rest = rest.slice(invocationSpan(rest, GO_TEST).argsEnd).trimStart();
75
+ while (rest.search(GO_TEST_RUNNER) === 0) {
76
+ rest = rest.slice(invocationSpan(rest, GO_TEST_RUNNER).argsEnd).trimStart();
77
77
  if (rest === '')
78
78
  return true;
79
79
  const separator = /^(?:&&|\|\||;)\s*/.exec(rest);
@@ -85,7 +85,7 @@ function onlyGoTests(command) {
85
85
  }
86
86
  export function createRunProgress(command = '', closed) {
87
87
  const goLifecycle = onlyGoTests(command);
88
- const goResults = command.search(GO_TEST) !== -1;
88
+ const goResults = command.search(GO_TEST_RUNNER) !== -1;
89
89
  const streams = {
90
90
  stdout: { partial: '', countedDots: 0 },
91
91
  stderr: { partial: '', countedDots: 0 },
@@ -269,7 +269,7 @@ export function createRunProgress(command = '', closed) {
269
269
  export function withTestResultReport(command) {
270
270
  if ((command.match(NEXTEST_RUN)?.length ?? 0) !== 1 ||
271
271
  command.search(BUN_TEST) !== -1 ||
272
- command.search(GO_TEST) !== -1 ||
272
+ command.search(GO_TEST_RUNNER) !== -1 ||
273
273
  UNCAPTURED_NEXTEST.test(command))
274
274
  return { command, env: {} };
275
275
  let reported = withInvocationFlag(command, NEXTEST_RUN, /(?<![\w-])--message-format(?:=|\s+)(?:"[^"]*"|'[^']*'|[^\s]+)/g, '--message-format=libtest-json-plus', true);
@@ -35,7 +35,11 @@ export interface TestThreadCeilings {
35
35
  * ceilings their sizing keeps; cargo-mutants carries how many cargo processes it runs at once, which share its grant.
36
36
  */
37
37
  export type Demand = {
38
- kind: 'cargo' | 'process';
38
+ kind: 'cargo';
39
+ want: number;
40
+ testThreads: TestThreadCeilings;
41
+ } | {
42
+ kind: 'process';
39
43
  want: number;
40
44
  testThreads: TestThreadCeilings;
41
45
  } | {
@@ -43,11 +47,32 @@ export type Demand = {
43
47
  want: number;
44
48
  jobs: number;
45
49
  } | {
46
- kind: Exclude<RunnerKind, 'cargo' | 'cargo-mutants' | 'process'>;
50
+ kind: 'nextest';
51
+ want: number;
52
+ } | {
53
+ kind: 'bun-parallel';
54
+ want: number;
55
+ } | {
56
+ kind: 'stryker';
57
+ want: number;
58
+ } | {
59
+ kind: 'vitest';
60
+ want: number;
61
+ } | {
62
+ kind: 'go-test';
47
63
  want: number;
48
64
  };
65
+ /** A runner a leaf reserves for under mbx (mbx-pool.ts, `mbxLeaf`): one that Cargo does not admit through mbx itself. */
66
+ export type ReservedDemand = Extract<Demand, {
67
+ kind: 'nextest' | 'bun-parallel' | 'stryker' | 'process';
68
+ }>;
49
69
  /** Every budgeted command learns its grant here, so a script that starts a runner can size it. */
50
70
  export declare const CPU_TOKENS_ENV = "BOUNDED_EXEC_CPU_TOKENS";
71
+ /**
72
+ * The cores mbx granted the reservation a leaf runs under: `mbx reserve --cpus N` names at most N to its command, as many
73
+ * as were free once one was.
74
+ */
75
+ export declare const GRANTED_CPUS_ENV = "MBX_RESERVE_CPUS";
51
76
  type WorkerFlagKind = 'stryker' | 'vitest' | 'go-test';
52
77
  /**
53
78
  * What `command` asks for: its kind by invocation, and `declared` (the target's `parallelism`)
@@ -86,6 +111,19 @@ export declare function sizeRunner(demand: Demand, command: string, tokens: numb
86
111
  command: string;
87
112
  env: Record<string, string>;
88
113
  };
114
+ /**
115
+ * The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
116
+ * the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
117
+ * than the leaf asked for, its `--cpus` (the runner's own count), which also stands in under an mbx that grants a
118
+ * reservation whole and names none. The test-thread variables a sizing sets follow from it, under their inherited
119
+ * ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
120
+ */
121
+ export declare function grantedSizing(demand: ReservedDemand): string;
122
+ /**
123
+ * `command` with a reserved runner's named count read from its grant, `CPU_TOKENS_ENV` as `grantedSizing` sets it,
124
+ * where the runner's shell runs it; the runner then runs on all it holds.
125
+ */
126
+ export declare function sizeRunnerToGrant(demand: ReservedDemand, command: string): string;
89
127
  /**
90
128
  * The count `CPU_TOKENS_ENV` names, as a positive safe integer, or `null` when absent or malformed. It is
91
129
  * descriptor input only: a count proves nothing about a live pool and grants nothing. It is a ceiling the