@smoothbricks/nx-plugin 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +417 -171
  2. package/dist/.build-inputs.json +39 -28
  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/bin/smoo-nx-publish.d.ts +3 -0
  10. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-publish.js +3 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +9 -8
  15. package/dist/cargo-retention-hook.d.ts +6 -2
  16. package/dist/cargo-retention-hook.d.ts.map +1 -1
  17. package/dist/cargo-retention-hook.js +13 -7
  18. package/dist/cargo-workspace.d.ts +10 -20
  19. package/dist/cargo-workspace.d.ts.map +1 -1
  20. package/dist/cargo-workspace.js +12 -22
  21. package/dist/cross-check-policy.d.ts +2 -2
  22. package/dist/cross-check-policy.js +2 -2
  23. package/dist/deploy-policy.d.ts +6 -0
  24. package/dist/deploy-policy.d.ts.map +1 -1
  25. package/dist/deploy-policy.js +11 -0
  26. package/dist/eslint-file-set.d.ts +4 -1
  27. package/dist/eslint-file-set.d.ts.map +1 -1
  28. package/dist/eslint-sources.d.ts +25 -0
  29. package/dist/eslint-sources.d.ts.map +1 -0
  30. package/dist/eslint-sources.js +99 -0
  31. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  32. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  33. package/dist/executors/all-verdicts/executor.js +48 -2
  34. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  35. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  36. package/dist/executors/all-verdicts/schema.js +7 -0
  37. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  38. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/bounds.js +100 -11
  40. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  41. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  42. package/dist/executors/bounded-exec/executor.js +289 -34
  43. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  44. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  45. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  46. package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
  47. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  48. package/dist/executors/bounded-exec/mbx-pool.js +145 -11
  49. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  50. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  51. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  52. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  53. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  54. package/dist/executors/bounded-exec/progress.js +151 -25
  55. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  56. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  57. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  58. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  59. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  60. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  62. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  63. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  64. package/dist/executors/bounded-exec/test-results.js +33 -0
  65. package/dist/executors/bounded-exec/verdict.d.ts +26 -2
  66. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  67. package/dist/executors/bounded-exec/verdict.js +108 -4
  68. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  69. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  70. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  71. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  72. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  73. package/dist/executors/wrangler-deploy/executor.js +43 -0
  74. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  75. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  76. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  77. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  78. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  79. package/dist/go-tests.d.ts +30 -0
  80. package/dist/go-tests.d.ts.map +1 -0
  81. package/dist/go-tests.js +43 -0
  82. package/dist/index.d.ts +12 -4
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +338 -295
  85. package/dist/managed-files/files.d.ts.map +1 -1
  86. package/dist/managed-files/files.js +5 -0
  87. package/dist/nx-publish.d.ts +24 -0
  88. package/dist/nx-publish.d.ts.map +1 -0
  89. package/dist/nx-publish.js +150 -0
  90. package/dist/process-group.js +2 -2
  91. package/dist/runtime-input-policy.d.ts +17 -3
  92. package/dist/runtime-input-policy.d.ts.map +1 -1
  93. package/dist/runtime-input-policy.js +4 -4
  94. package/dist/test-timings.d.ts +23 -4
  95. package/dist/test-timings.d.ts.map +1 -1
  96. package/dist/test-timings.js +72 -12
  97. package/dist/tool-bins.d.ts +6 -8
  98. package/dist/tool-bins.d.ts.map +1 -1
  99. package/dist/tool-bins.js +7 -5
  100. package/dist/version-actions.cjs +10 -11
  101. package/dist/version-actions.d.cts.map +1 -1
  102. package/dist/workspace-config-policy.d.ts.map +1 -1
  103. package/dist/workspace-config-policy.js +17 -22
  104. package/dist/workspace-index.d.ts +7 -0
  105. package/dist/workspace-index.d.ts.map +1 -1
  106. package/dist/workspace-index.js +11 -0
  107. package/dist/workspace-manifest.js +3 -3
  108. package/executors.json +7 -6
  109. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  110. package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
  111. package/managed/raw/tooling/devenv +1 -2
  112. package/managed/raw/tooling/direnv/developer-links.ts +124 -51
  113. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  114. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  115. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  116. package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
  117. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  118. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  119. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  120. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  121. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  122. package/package.json +277 -11
  123. package/runtime/nx-publish/.build-inputs.json +11 -0
  124. package/runtime/nx-publish/cache_adapter.js +45 -0
  125. package/runtime/nx-publish/nx_publish.js +60 -0
  126. package/runtime-input.sh +62 -26
  127. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  128. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  129. package/src/bin/smoo-nx-publish.ts +4 -0
  130. package/src/bounded-test-policy.ts +9 -8
  131. package/src/cargo-retention-hook.ts +16 -10
  132. package/src/cargo-workspace.ts +12 -24
  133. package/src/cross-check-policy.ts +2 -2
  134. package/src/deploy-policy.ts +11 -0
  135. package/src/eslint-file-set.ts +4 -1
  136. package/src/eslint-sources.ts +134 -0
  137. package/src/executors/all-verdicts/executor.ts +58 -3
  138. package/src/executors/all-verdicts/schema.json +4 -0
  139. package/src/executors/all-verdicts/schema.ts +14 -0
  140. package/src/executors/bounded-exec/bounds.ts +132 -15
  141. package/src/executors/bounded-exec/executor.ts +329 -34
  142. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  143. package/src/executors/bounded-exec/mbx-pool.ts +158 -17
  144. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  145. package/src/executors/bounded-exec/progress.ts +171 -18
  146. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  147. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  148. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  149. package/src/executors/bounded-exec/test-results.ts +39 -0
  150. package/src/executors/bounded-exec/verdict.ts +115 -5
  151. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  152. package/src/executors/wrangler-deploy/executor.ts +63 -0
  153. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  154. package/src/executors/wrangler-deploy/schema.json +16 -0
  155. package/src/executors/wrangler-deploy/schema.ts +4 -0
  156. package/src/go-tests.ts +67 -0
  157. package/src/index.ts +368 -323
  158. package/src/managed-files/files.ts +5 -0
  159. package/src/nx-publish.ts +157 -0
  160. package/src/process-group.ts +2 -2
  161. package/src/runtime-input-policy.ts +4 -4
  162. package/src/test-timings.ts +72 -14
  163. package/src/tool-bins.ts +13 -9
  164. package/src/version-actions.cts +10 -11
  165. package/src/workspace-config-policy.ts +20 -29
  166. package/src/workspace-index.ts +12 -0
  167. package/src/workspace-manifest.ts +3 -3
  168. package/test-timings.json +131 -125
  169. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  170. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  171. package/dist/executors/clean-outputs/executor.js +0 -83
  172. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  173. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  174. package/src/executors/clean-outputs/executor.ts +0 -131
  175. package/src/executors/clean-outputs/schema.json +0 -15
  176. package/src/executors/clean-outputs/schema.ts +0 -3
  177. /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
@@ -2,7 +2,7 @@ import { type ChildProcessByStdio, spawn } from 'node:child_process';
2
2
  import { resolve } from 'node:path';
3
3
  import type { Readable } from 'node:stream';
4
4
 
5
- import type { AllVerdictsOptions } from './schema.js';
5
+ import { type AllVerdictsOptions, ESLINT_SOURCES_TOKEN } from './schema.js';
6
6
 
7
7
  /**
8
8
  * A command's verdict. Only a command that exited reached one. A command a signal ended, one that never started and
@@ -113,12 +113,44 @@ function judge(run: Run, cwd: string): Promise<Verdict> {
113
113
  });
114
114
  }
115
115
 
116
+ /** A command as it will run: the text the shell gets, or why it needs no run. */
117
+ interface Planned {
118
+ readonly command: string;
119
+ readonly noRun?: string;
120
+ }
121
+
122
+ /**
123
+ * The commands as they run now. A command that names {@link ESLINT_SOURCES_TOKEN} gets the files ESLint is handed for
124
+ * `eslintProjectRoot` as the filesystem holds them at this moment, read through a fresh workspace file index: a graph the
125
+ * daemon serves past a deletion or an addition its watcher never reported still lints the files that exist. A project
126
+ * with none has nothing to lint, and no ESLint process starts for it.
127
+ */
128
+ async function planCommands(options: AllVerdictsOptions, root: string): Promise<readonly Planned[]> {
129
+ if (!options.commands.some((command) => command.includes(ESLINT_SOURCES_TOKEN))) {
130
+ return options.commands.map((command) => ({ command }));
131
+ }
132
+ const projectRoot = options.eslintProjectRoot;
133
+ if (projectRoot === undefined) {
134
+ throw new Error(
135
+ `a command names ${ESLINT_SOURCES_TOKEN}, and the target names no eslintProjectRoot to resolve it for`,
136
+ );
137
+ }
138
+ const { expandEslintSources, freshEslintSources } = await import('../../eslint-sources.js');
139
+ const { files } = freshEslintSources(root, projectRoot);
140
+ return options.commands.map((command): Planned => {
141
+ if (!command.includes(ESLINT_SOURCES_TOKEN)) return { command };
142
+ if (files.length === 0) return { command, noRun: `no ESLint sources under ${projectRoot}: nothing to lint` };
143
+ return { command: expandEslintSources(command, files) };
144
+ });
145
+ }
146
+
116
147
  /**
117
148
  * Starts every command at once and lets each reach its own verdict. Nx's run-commands cannot: in parallel it terminates
118
149
  * the other commands once one fails, and serially it never starts the ones after a failure, so one tool's errors hide
119
150
  * another's until a later run. Here no command ends another. Each command's output prints as one block when it closes,
120
151
  * then every command's verdict. A signal to the run ends every command's process group, reports each command still
121
152
  * running UNJUDGED, and ends the run by the same signal. The run succeeds only when every command passed.
153
+ * A command that names the ESLint sources placeholder is resolved first, and the verdicts name it as it ran.
122
154
  */
123
155
  export default async function allVerdictsExecutor(
124
156
  options: AllVerdictsOptions,
@@ -129,7 +161,23 @@ export default async function allVerdictsExecutor(
129
161
  return { success: false };
130
162
  }
131
163
  const cwd = resolve(context.root, options.cwd);
132
- const runs: Run[] = options.commands.map((command) => ({ command, output: [], pid: undefined, verdict: null }));
164
+ let planned: readonly Planned[];
165
+ try {
166
+ planned = await planCommands(options, context.root);
167
+ } catch (error) {
168
+ process.stderr.write(
169
+ `all-verdicts: cannot resolve the commands to run: ${error instanceof Error ? error.message : String(error)}\n`,
170
+ );
171
+ return { success: false };
172
+ }
173
+ const runs = planned.map(
174
+ ({ command, noRun }): Run => ({
175
+ command,
176
+ output: noRun === undefined ? [] : [`${noRun}\n`],
177
+ pid: undefined,
178
+ verdict: noRun === undefined ? null : { kind: 'pass' },
179
+ }),
180
+ );
133
181
  const onExit = (): void => {
134
182
  for (const run of runs) {
135
183
  if (run.verdict === null && run.pid !== undefined) signalCommand(run.pid, 'SIGTERM');
@@ -154,9 +202,16 @@ export default async function allVerdictsExecutor(
154
202
  };
155
203
  process.on('exit', onExit);
156
204
  for (const [signal, listener] of listeners) process.on(signal, listener);
205
+ // A command that needs no run is already judged: its block prints now, the others' as they close.
206
+ for (const run of runs) if (run.verdict !== null) process.stdout.write(block(run));
157
207
 
158
208
  const verdicts = await Promise.all(
159
- runs.map(async (run): Promise<CommandVerdict> => ({ command: run.command, verdict: await judge(run, cwd) })),
209
+ runs.map(
210
+ async (run): Promise<CommandVerdict> => ({
211
+ command: run.command,
212
+ verdict: run.verdict ?? (await judge(run, cwd)),
213
+ }),
214
+ ),
160
215
  );
161
216
  detach();
162
217
  process.stdout.write(verdictReport(verdicts));
@@ -16,6 +16,10 @@
16
16
  "cwd": {
17
17
  "type": "string",
18
18
  "description": "Where every command runs, relative to the workspace root."
19
+ },
20
+ "eslintProjectRoot": {
21
+ "type": "string",
22
+ "description": "The project, by workspace-relative root, whose ESLint sources replace {eslintSources} in a command when it runs."
19
23
  }
20
24
  },
21
25
  "additionalProperties": false
@@ -1,10 +1,24 @@
1
1
  /** The executor the inferred `lint` target runs its tool commands with. */
2
2
  export const ALL_VERDICTS_EXECUTOR = '@smoothbricks/nx-plugin:all-verdicts';
3
3
 
4
+ /**
5
+ * Where an inferred ESLint command names its files. The graph holds no list of them: a list is the files of the moment
6
+ * the graph was computed, and a run that outlives that moment fails on a file since deleted (ESLint refuses a pattern
7
+ * no file matches) and skips one since added. The executor replaces each occurrence with the files ESLint is handed
8
+ * when the command runs.
9
+ */
10
+ export const ESLINT_SOURCES_TOKEN = '{eslintSources}';
11
+
4
12
  /** Options of `@smoothbricks/nx-plugin:all-verdicts`. */
5
13
  export interface AllVerdictsOptions {
6
14
  /** Shell commands, all started at once; none ends another. An empty list is refused: it could never fail. */
7
15
  readonly commands: readonly string[];
8
16
  /** Where every command runs, relative to the workspace root. */
9
17
  readonly cwd: string;
18
+ /**
19
+ * The project, by workspace-relative root, whose ESLint sources replace {@link ESLINT_SOURCES_TOKEN} in a command when
20
+ * it runs: its `src` files and those its `tsconfig.test.json` declares, read from a fresh workspace file index. A
21
+ * command that names the token with no project is refused. A project with none passes without running ESLint.
22
+ */
23
+ readonly eslintProjectRoot?: string;
10
24
  }
@@ -3,11 +3,10 @@
3
3
  * a pure function of the run's events and the times they happened at, so a table can test it with no clock and no
4
4
  * process (verdict.ts says why the bounds are separate).
5
5
  *
6
- * - The total ceiling runs from the spawn.
7
- * - The fixture ceiling runs from the spawn while a supervised fixture runs, and ends with the fixture's segment.
8
- * - The progress bound runs only while the runner is testing (runner-lifecycle.ts): from the spawn when the runner is
9
- * testing then (startup is bounded until a build declares itself), restarted by a finished test or by the clock
10
- * starting again after a build, and stopped while nothing tests.
6
+ * - A scheduled leaf arms nothing until its first grant. Later zero-hold intervals pause only the idle budget.
7
+ * - Any explicitly queued task process pauses idle, including alongside held grants; ceilings keep running.
8
+ * - The fixture ceiling ends with its segment. The idle clock also stops outside the testing lifecycle.
9
+ * - Finished tests reset the idle budget whether their release byte arrived before or after their output.
11
10
  */
12
11
 
13
12
  /** The limits a run was given, in milliseconds; an absent one never expires. */
@@ -17,18 +16,39 @@ export interface BoundLimits {
17
16
  readonly totalMs?: number;
18
17
  }
19
18
 
20
- /** When each armed bound expires, in the clock's milliseconds; `null` when it is not armed. */
19
+ /**
20
+ * When each armed bound expires, in the clock's milliseconds; `null` when it is not armed. `queued`: the run waits for
21
+ * its pool's grant, so none is armed yet.
22
+ */
21
23
  export interface Bounds {
22
24
  readonly idle: number | null;
23
25
  readonly fixture: number | null;
24
26
  readonly total: number | null;
27
+ readonly queued: boolean;
28
+ readonly holds: number | null;
29
+ readonly idleRemaining: number | null;
30
+ readonly admissionWaiting: boolean;
25
31
  }
26
32
 
27
- export type BoundKind = keyof Bounds;
33
+ export type BoundKind = 'idle' | 'fixture' | 'total';
28
34
 
29
35
  export type BoundEvent =
30
- /** The command started; `testing` is the lifecycle's answer then, `fixture` whether a supervised fixture leads it. */
31
- | { readonly kind: 'spawn'; readonly at: number; readonly testing: boolean; readonly fixture: boolean }
36
+ /**
37
+ * The command started; `testing` is the lifecycle's answer then, `fixture` whether a supervised fixture leads it,
38
+ * `queued` whether mbx schedules this leaf, as known before spawn.
39
+ */
40
+ | {
41
+ readonly kind: 'spawn';
42
+ readonly at: number;
43
+ readonly testing: boolean;
44
+ readonly fixture: boolean;
45
+ readonly queued: boolean;
46
+ }
47
+ /** Each admission begins a hold; the first one starts the queued leaf's ceilings. */
48
+ | { readonly kind: 'granted'; readonly at: number; readonly testing: boolean; readonly fixture: boolean }
49
+ | { readonly kind: 'released'; readonly at: number }
50
+ /** A successful public snapshot proved whether a live task process is queued; `at` is completion, not poll start. */
51
+ | { readonly kind: 'admission-queue'; readonly at: number; readonly waiting: boolean; readonly testing: boolean }
32
52
  /**
33
53
  * The runner's state may have moved: a test finished (`finished`), a phase changed, or the lifecycle failed.
34
54
  * `wasTesting` is the answer before the event, `testing` the answer after it.
@@ -43,22 +63,95 @@ export type BoundEvent =
43
63
  /** The fixture's segment ended: its ceiling no longer applies. */
44
64
  | { readonly kind: 'fixture-done' };
45
65
 
46
- export const UNARMED: Bounds = { idle: null, fixture: null, total: null };
66
+ export const UNARMED: Bounds = {
67
+ idle: null,
68
+ fixture: null,
69
+ total: null,
70
+ queued: false,
71
+ admissionWaiting: false,
72
+ holds: null,
73
+ idleRemaining: null,
74
+ };
75
+
76
+ /** The bounds a command that starts running at `at` arms. */
77
+ function armed(limits: BoundLimits, at: number, testing: boolean, fixture: boolean): Bounds {
78
+ return {
79
+ idle: testing && limits.idleMs !== undefined ? at + limits.idleMs : null,
80
+ fixture: fixture && limits.fixtureMs !== undefined ? at + limits.fixtureMs : null,
81
+ total: limits.totalMs !== undefined ? at + limits.totalMs : null,
82
+ queued: false,
83
+ admissionWaiting: false,
84
+ holds: null,
85
+ idleRemaining: limits.idleMs ?? null,
86
+ };
87
+ }
47
88
 
48
89
  /** The bounds after `event`. */
49
90
  export function stepBounds(bounds: Bounds, limits: BoundLimits, event: BoundEvent): Bounds {
50
91
  switch (event.kind) {
51
92
  case 'spawn':
93
+ return event.queued
94
+ ? { ...UNARMED, queued: true, holds: 0, idleRemaining: limits.idleMs ?? null }
95
+ : armed(limits, event.at, event.testing, event.fixture);
96
+ case 'granted': {
97
+ if (bounds.holds === null) return bounds;
98
+ if (bounds.queued) {
99
+ const admitted = armed(limits, event.at, event.testing, event.fixture);
100
+ return {
101
+ ...admitted,
102
+ holds: 1,
103
+ admissionWaiting: bounds.admissionWaiting,
104
+ idle: bounds.admissionWaiting ? null : admitted.idle,
105
+ };
106
+ }
107
+ return {
108
+ ...bounds,
109
+ holds: bounds.holds + 1,
110
+ idle:
111
+ bounds.holds === 0 && !bounds.admissionWaiting && event.testing && bounds.idleRemaining !== null
112
+ ? event.at + bounds.idleRemaining
113
+ : bounds.idle,
114
+ };
115
+ }
116
+ case 'admission-queue': {
117
+ if (bounds.admissionWaiting === event.waiting) return bounds;
118
+ if (event.waiting) {
119
+ return {
120
+ ...bounds,
121
+ admissionWaiting: true,
122
+ idle: null,
123
+ idleRemaining: bounds.idle === null ? bounds.idleRemaining : Math.max(0, bounds.idle - event.at),
124
+ };
125
+ }
52
126
  return {
53
- idle: event.testing && limits.idleMs !== undefined ? event.at + limits.idleMs : null,
54
- fixture: event.fixture && limits.fixtureMs !== undefined ? event.at + limits.fixtureMs : null,
55
- total: limits.totalMs !== undefined ? event.at + limits.totalMs : null,
127
+ ...bounds,
128
+ admissionWaiting: false,
129
+ idle:
130
+ !bounds.queued && bounds.holds !== 0 && event.testing && bounds.idleRemaining !== null
131
+ ? event.at + bounds.idleRemaining
132
+ : null,
56
133
  };
134
+ }
135
+ case 'released': {
136
+ if (bounds.holds === null || bounds.holds === 0) return bounds;
137
+ if (bounds.holds > 1) return { ...bounds, holds: bounds.holds - 1 };
138
+ return {
139
+ ...bounds,
140
+ holds: 0,
141
+ idle: null,
142
+ idleRemaining: bounds.idle === null ? bounds.idleRemaining : Math.max(0, bounds.idle - event.at),
143
+ };
144
+ }
57
145
  case 'progress': {
58
- if (!event.testing) return { ...bounds, idle: null };
146
+ if (bounds.queued) return event.finished ? { ...bounds, idleRemaining: limits.idleMs ?? null } : bounds;
147
+ if (!event.testing) return { ...bounds, idle: null, idleRemaining: limits.idleMs ?? null };
59
148
  const restart = event.finished || !event.wasTesting;
60
149
  if (!restart || limits.idleMs === undefined) return bounds;
61
- return { ...bounds, idle: event.at + limits.idleMs };
150
+ return {
151
+ ...bounds,
152
+ idle: bounds.holds === 0 || bounds.admissionWaiting ? null : event.at + limits.idleMs,
153
+ idleRemaining: limits.idleMs,
154
+ };
62
155
  }
63
156
  case 'fixture-done':
64
157
  return { ...bounds, fixture: null };
@@ -74,3 +167,27 @@ export function earliestBound(bounds: Bounds): { readonly kind: BoundKind; reado
74
167
  }
75
168
  return earliest;
76
169
  }
170
+
171
+ /** Observed queue duration on a monotonic clock; stopping closes its interval permanently, before cleanup begins. */
172
+ export type AdmissionWait =
173
+ | { readonly kind: 'observing'; readonly since: number | null; readonly waitedMs: number }
174
+ | { readonly kind: 'stopped'; readonly waitedMs: number };
175
+
176
+ export type AdmissionWaitEvent =
177
+ | { readonly kind: 'snapshot'; readonly at: number; readonly waiting: boolean }
178
+ | { readonly kind: 'stop'; readonly at: number };
179
+
180
+ export const NO_ADMISSION_WAIT: AdmissionWait = { kind: 'observing', since: null, waitedMs: 0 };
181
+
182
+ /** Read the observed duration, not the time later spent tearing down the command or reading its report. */
183
+ export function admissionWaitMs(wait: AdmissionWait, at: number): number {
184
+ return wait.waitedMs + (wait.kind === 'observing' && wait.since !== null ? at - wait.since : 0);
185
+ }
186
+
187
+ /** A successful completed observation opens/closes an interval; terminal/cancellation stops freeze it. */
188
+ export function stepAdmissionWait(wait: AdmissionWait, event: AdmissionWaitEvent): AdmissionWait {
189
+ if (wait.kind === 'stopped') return wait;
190
+ if (event.kind === 'stop') return { kind: 'stopped', waitedMs: admissionWaitMs(wait, event.at) };
191
+ if (event.waiting) return wait.since === null ? { ...wait, since: event.at } : wait;
192
+ return wait.since === null ? wait : { kind: 'observing', since: null, waitedMs: admissionWaitMs(wait, event.at) };
193
+ }