@smoothbricks/nx-plugin 0.7.17 → 0.7.19

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 (199) hide show
  1. package/README.md +315 -114
  2. package/dist/.build-inputs.json +47 -38
  3. package/dist/built-output-packages.js +1 -1
  4. package/dist/bun-lock-scope.d.ts +128 -20
  5. package/dist/bun-lock-scope.d.ts.map +1 -1
  6. package/dist/bun-lock-scope.js +267 -44
  7. package/dist/cargo-closure-input.d.ts +8 -6
  8. package/dist/cargo-closure-input.d.ts.map +1 -1
  9. package/dist/cargo-closure-input.js +15 -12
  10. package/dist/cargo-source-hash.d.ts +26 -25
  11. package/dist/cargo-source-hash.d.ts.map +1 -1
  12. package/dist/cargo-source-hash.js +84 -105
  13. package/dist/cargo-toolchain-paths.d.ts +2 -2
  14. package/dist/cargo-toolchain-paths.js +2 -2
  15. package/dist/cargo-workspace.d.ts +20 -2
  16. package/dist/cargo-workspace.d.ts.map +1 -1
  17. package/dist/cargo-workspace.js +43 -22
  18. package/dist/ensure-built-receipt.d.ts +3 -2
  19. package/dist/ensure-built-receipt.d.ts.map +1 -1
  20. package/dist/ensure-built-receipt.js +3 -2
  21. package/dist/eslint-config-closure.d.ts +8 -3
  22. package/dist/eslint-config-closure.d.ts.map +1 -1
  23. package/dist/eslint-config-closure.js +24 -5
  24. package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
  25. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
  26. package/dist/executors/bounded-exec/admission-queue.js +9 -10
  27. package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
  28. package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
  29. package/dist/executors/bounded-exec/awake-clock.js +22 -0
  30. package/dist/executors/bounded-exec/bounds.d.ts +19 -6
  31. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/bounds.js +22 -15
  33. package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
  34. package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
  35. package/dist/executors/bounded-exec/case-gate.js +342 -0
  36. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
  37. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  38. package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
  39. package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
  40. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  41. package/dist/executors/bounded-exec/cpu-pool.js +102 -16
  42. package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
  43. package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
  44. package/dist/executors/bounded-exec/cpu-rise.js +111 -0
  45. package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
  46. package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
  47. package/dist/executors/bounded-exec/endpoint-life.js +228 -0
  48. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  49. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  50. package/dist/executors/bounded-exec/executor.js +256 -86
  51. package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
  52. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  53. package/dist/executors/bounded-exec/gateway-lease.js +8 -1
  54. package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
  55. package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
  56. package/dist/executors/bounded-exec/go-run-summary.js +98 -0
  57. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +11 -3
  58. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  59. package/dist/executors/bounded-exec/hang-diagnostics.js +125 -47
  60. package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
  61. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
  62. package/dist/executors/bounded-exec/lease-wait.js +1 -0
  63. package/dist/executors/bounded-exec/mbx-pool.d.ts +42 -7
  64. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  65. package/dist/executors/bounded-exec/mbx-pool.js +45 -8
  66. package/dist/executors/bounded-exec/mbx-reservations.d.ts +12 -6
  67. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  68. package/dist/executors/bounded-exec/mbx-reservations.js +190 -284
  69. package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
  70. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
  71. package/dist/executors/bounded-exec/parent-grant.js +1 -0
  72. package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
  73. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
  74. package/dist/executors/bounded-exec/pool-admission.js +47 -1
  75. package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
  76. package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
  77. package/dist/executors/bounded-exec/progress-channel.js +113 -0
  78. package/dist/executors/bounded-exec/progress.d.ts +5 -1
  79. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  80. package/dist/executors/bounded-exec/progress.js +31 -1
  81. package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
  82. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  83. package/dist/executors/bounded-exec/ram-temp.js +123 -16
  84. package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
  85. package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
  86. package/dist/executors/bounded-exec/reservation-connection.js +248 -0
  87. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  88. package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
  89. package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
  90. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  91. package/dist/executors/bounded-exec/runner-sizing.js +13 -9
  92. package/dist/executors/bounded-exec/schema.d.ts +7 -2
  93. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  94. package/dist/executors/bounded-exec/schema.js +17 -1
  95. package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
  96. package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
  97. package/dist/executors/bounded-exec/suite-minimum.js +85 -0
  98. package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
  99. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
  100. package/dist/executors/bounded-exec/test-result-writer.js +1 -0
  101. package/dist/executors/bounded-exec/test-results.d.ts +5 -0
  102. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/test-results.js +2 -2
  104. package/dist/executors/bounded-exec/verdict.d.ts +39 -10
  105. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  106. package/dist/executors/bounded-exec/verdict.js +60 -14
  107. package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
  108. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  109. package/dist/executors/cargo-zigbuild/executor.js +32 -19
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +294 -152
  112. package/dist/managed-files/ci-workflow.d.ts +4 -1
  113. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  114. package/dist/managed-files/ci-workflow.js +9 -14
  115. package/dist/managed-files/files.d.ts +3 -3
  116. package/dist/managed-files/files.js +3 -3
  117. package/dist/managed-files/generator.d.ts +5 -1
  118. package/dist/managed-files/generator.d.ts.map +1 -1
  119. package/dist/managed-files/generator.js +22 -7
  120. package/dist/managed-files/render-memo.d.ts +13 -0
  121. package/dist/managed-files/render-memo.d.ts.map +1 -0
  122. package/dist/managed-files/render-memo.js +94 -0
  123. package/dist/task-results.js +2 -1
  124. package/dist/test-program.d.ts +11 -6
  125. package/dist/test-program.d.ts.map +1 -1
  126. package/dist/test-program.js +39 -35
  127. package/dist/tool-bins.d.ts +12 -0
  128. package/dist/tool-bins.d.ts.map +1 -1
  129. package/dist/tool-bins.js +31 -6
  130. package/dist/typecheck-test-policy.d.ts +10 -1
  131. package/dist/typecheck-test-policy.d.ts.map +1 -1
  132. package/dist/typecheck-test-policy.js +40 -24
  133. package/dist/workspace-config-policy.d.ts.map +1 -1
  134. package/dist/workspace-config-policy.js +135 -42
  135. package/dist/workspace-index.d.ts +14 -1
  136. package/dist/workspace-index.d.ts.map +1 -1
  137. package/dist/workspace-index.js +36 -4
  138. package/executors.json +2 -0
  139. package/managed/raw/envrc +24 -0
  140. package/managed/raw/patches/nx@24.0.3.patch +1851 -221
  141. package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
  142. package/managed/raw/tooling/direnv/developer-links.ts +122 -14
  143. package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
  144. package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
  145. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  146. package/package.json +68 -11
  147. package/runtime/nx-publish/.build-inputs.json +2 -2
  148. package/runtime/nx-publish/cache_adapter.js +293 -3
  149. package/runtime/nx-publish/nx_publish.js +36 -14
  150. package/src/built-output-packages.ts +1 -1
  151. package/src/bun-lock-scope.ts +293 -40
  152. package/src/cargo-closure-input.ts +20 -12
  153. package/src/cargo-source-hash.ts +119 -145
  154. package/src/cargo-toolchain-paths.ts +2 -2
  155. package/src/cargo-workspace.ts +59 -21
  156. package/src/ensure-built-receipt.ts +3 -2
  157. package/src/eslint-config-closure.ts +27 -6
  158. package/src/executors/bounded-exec/admission-queue.ts +11 -10
  159. package/src/executors/bounded-exec/awake-clock.ts +20 -0
  160. package/src/executors/bounded-exec/bounds.ts +41 -19
  161. package/src/executors/bounded-exec/case-gate.ts +365 -0
  162. package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
  163. package/src/executors/bounded-exec/cpu-pool.ts +139 -12
  164. package/src/executors/bounded-exec/cpu-rise.ts +156 -0
  165. package/src/executors/bounded-exec/endpoint-life.ts +279 -0
  166. package/src/executors/bounded-exec/executor.ts +341 -123
  167. package/src/executors/bounded-exec/gateway-lease.ts +6 -0
  168. package/src/executors/bounded-exec/go-run-summary.ts +137 -0
  169. package/src/executors/bounded-exec/hang-diagnostics.ts +150 -50
  170. package/src/executors/bounded-exec/lease-wait.ts +1 -0
  171. package/src/executors/bounded-exec/mbx-pool.ts +57 -9
  172. package/src/executors/bounded-exec/mbx-reservations.ts +216 -183
  173. package/src/executors/bounded-exec/parent-grant.ts +3 -0
  174. package/src/executors/bounded-exec/pool-admission.ts +59 -2
  175. package/src/executors/bounded-exec/progress-channel.ts +129 -0
  176. package/src/executors/bounded-exec/progress.ts +39 -3
  177. package/src/executors/bounded-exec/ram-temp.ts +137 -17
  178. package/src/executors/bounded-exec/reservation-connection.ts +221 -0
  179. package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
  180. package/src/executors/bounded-exec/runner-sizing.ts +13 -8
  181. package/src/executors/bounded-exec/schema.json +1 -1
  182. package/src/executors/bounded-exec/schema.ts +21 -2
  183. package/src/executors/bounded-exec/suite-minimum.ts +81 -0
  184. package/src/executors/bounded-exec/test-result-writer.ts +3 -0
  185. package/src/executors/bounded-exec/test-results.ts +5 -0
  186. package/src/executors/bounded-exec/verdict.ts +83 -22
  187. package/src/executors/cargo-zigbuild/executor.ts +30 -19
  188. package/src/index.ts +357 -166
  189. package/src/managed-files/ci-workflow.ts +13 -17
  190. package/src/managed-files/files.ts +3 -3
  191. package/src/managed-files/generator.ts +21 -6
  192. package/src/managed-files/render-memo.ts +135 -0
  193. package/src/test-program.ts +36 -41
  194. package/src/tool-bins.ts +35 -6
  195. package/src/typecheck-test-policy.ts +49 -24
  196. package/src/workspace-config-policy.ts +161 -43
  197. package/src/workspace-index.ts +40 -5
  198. package/test-timings.json +157 -141
  199. package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
@@ -29,6 +29,8 @@ export interface Ask {
29
29
  readonly parallelism: number | null;
30
30
  readonly alone: boolean;
31
31
  readonly task: string | undefined;
32
+ /** Its cases each ask the pool for a token of their own (case-gate.ts). */
33
+ readonly gated: boolean;
32
34
  }
33
35
 
34
36
  /**
@@ -43,6 +45,7 @@ export async function askParentPool(inherited: InheritedCpuPool | null, ask: Ask
43
45
  parallelism: ask.parallelism ?? undefined,
44
46
  alone: ask.alone ? true : undefined,
45
47
  task: ask.task,
48
+ gated: ask.gated ? true : undefined,
46
49
  });
47
50
  if (answer.granted) {
48
51
  return { grant: answer, refusal: null, wait: undefined, said: [] };
@@ -28,6 +28,10 @@ export interface PoolAsk {
28
28
  readonly parallelism?: number | undefined;
29
29
  /** A leaf the kernel killed for memory, run again: granted while nothing else holds a grant, and alone. */
30
30
  readonly alone?: boolean | undefined;
31
+ /** One token for one test case of a leaf that holds a grant: granted only while no leaf's request waits. */
32
+ readonly lend?: boolean | undefined;
33
+ /** A lent request's leaf's predicted work left, in ms: its cases' last recorded walls, less those that ran. */
34
+ readonly left?: number | undefined;
31
35
  }
32
36
 
33
37
  /** Who holds a grant when the pool decides: how many leaves, and whether one of them runs alone. */
@@ -56,11 +60,12 @@ export interface PoolGrant<Ask extends PoolAsk> {
56
60
 
57
61
  /**
58
62
  * The grants of the queue's first requests, in its order, and what the first request left waiting waits for: free
59
- * tokens (`cpu`), the run's memory (`memory`) or the grants others hold (`alone`). `waiting` is null when every request was granted.
63
+ * tokens (`cpu`), the run's memory (`memory`), the grants others hold (`alone`) or, a lent request, the settle time
64
+ * after a leaf's grant returned (`settle`). `waiting` is null when every request was granted.
60
65
  */
61
66
  export interface Admission<Ask extends PoolAsk> {
62
67
  readonly grants: readonly PoolGrant<Ask>[];
63
- readonly waiting: 'cpu' | 'memory' | 'alone' | null;
68
+ readonly waiting: 'cpu' | 'memory' | 'alone' | 'settle' | null;
64
69
  }
65
70
 
66
71
  /** The bytes `ask` is charged when it is lent `tokens`: its peak, scaled up when that is more than it was measured under. */
@@ -86,6 +91,7 @@ export function admit<Ask extends PoolAsk>(
86
91
  available: number,
87
92
  memory: MemoryLedger | null,
88
93
  holding: Holding = NOTHING_HELD,
94
+ lendable = true,
89
95
  ): Admission<Ask> {
90
96
  const grants: PoolGrant<Ask>[] = [];
91
97
  if (holding.alone) {
@@ -97,6 +103,9 @@ export function admit<Ask extends PoolAsk>(
97
103
  if (request.alone === true && holding.holders + grants.length > 0) {
98
104
  return { grants, waiting: 'alone' };
99
105
  }
106
+ if (request.lend === true && !lendable) {
107
+ return { grants, waiting: 'settle' };
108
+ }
100
109
  const oversized = memory !== null && request.memory > memory.capacity;
101
110
  const room = memory === null ? Number.POSITIVE_INFINITY : memory.capacity - held;
102
111
  if (request.memory > room && !(oversized && held === 0)) {
@@ -117,3 +126,51 @@ export function admit<Ask extends PoolAsk>(
117
126
  }
118
127
  return { grants, waiting: null };
119
128
  }
129
+
130
+ /**
131
+ * Where a request joins the queue (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself"). A leaf the
132
+ * kernel killed, run again alone, has waited once already and goes ahead of the leaves that have not run. A leaf goes
133
+ * behind the leaves and ahead of every lent request: a case is lent only a token no leaf waits for. A lent request goes
134
+ * among the lent ones behind those whose leaves have as much work left or more, so a free token goes to the leaf that
135
+ * would otherwise end last, in arrival order among equals.
136
+ */
137
+ export function place(queue: readonly PoolAsk[], ask: PoolAsk): number {
138
+ const before = (found: number): number => (found === -1 ? queue.length : found);
139
+ if (ask.alone === true) {
140
+ return before(queue.findIndex((waiting) => waiting.alone !== true));
141
+ }
142
+ if (ask.lend !== true) {
143
+ return before(queue.findIndex((waiting) => waiting.lend === true));
144
+ }
145
+ const left = ask.left ?? 0;
146
+ return before(queue.findIndex((waiting) => waiting.lend === true && (waiting.left ?? 0) < left));
147
+ }
148
+
149
+ /**
150
+ * The token-time a pool's tokens stood idle beside a starved hold: a leaf holding fewer tokens than it asked that
151
+ * cannot ask for more, or a case waiting for a lent token. The pool tells it the idle count and whether a hold is
152
+ * starved at each change, on its own clock; what is counted is the idle count over the time a starved hold stood.
153
+ */
154
+ export class IdleBesideStarved {
155
+ #at: number;
156
+ #idle = 0;
157
+ #starved = false;
158
+ #tokenMs = 0;
159
+
160
+ constructor(now: number) {
161
+ this.#at = now;
162
+ }
163
+
164
+ /** From `now` on, `idle` tokens are free and a hold is `starved` or none is. */
165
+ observe(now: number, idle: number, starved: boolean): void {
166
+ this.#tokenMs = this.tokenMs(now);
167
+ this.#at = now;
168
+ this.#idle = idle;
169
+ this.#starved = starved;
170
+ }
171
+
172
+ /** The token-milliseconds counted up to `now`. */
173
+ tokenMs(now: number): number {
174
+ return this.#tokenMs + (this.#starved ? this.#idle * (now - this.#at) : 0);
175
+ }
176
+ }
@@ -0,0 +1,129 @@
1
+ import { rm } from 'node:fs/promises';
2
+ import { createServer, type Server, type Socket } from 'node:net';
3
+ import { join } from 'node:path';
4
+ import { ownedSocketDirectory } from '../../testing.js';
5
+
6
+ /**
7
+ * A run's progress channel: a running test reports its own forward motion on it, and each record restarts the idle
8
+ * bound as a finished test does (specs/cowshed/08_testing.md, "Integration tests (real substrate)"). An agent harness
9
+ * that enforces its own no-progress bound over what its run does (a span written, a byte of output) reports each
10
+ * movement that check sees, so a long test that keeps moving is not ended because it is the last test still running.
11
+ * CPU is never a record: a compile inside a test reports nothing and is still ended at the bound, where the pre-signal
12
+ * snapshot names it (cpu-rise.ts).
13
+ *
14
+ * The channel is a Unix stream socket the executor serves for one run, in a fresh 0700 directory, and names in the
15
+ * command's environment as {@link PROGRESS_SOCKET_ENV}. Each line a client writes is one record and must be
16
+ * {@link PROGRESS_RECORD}; anything else is a broken reporter, said and failed, never read as progress. A client may
17
+ * write one record per connection or many. The server ends its side when the client ends its own, after every record
18
+ * the client wrote was read, so a client that waits for that end knows its records counted.
19
+ */
20
+ export const PROGRESS_SOCKET_ENV = 'BOUNDED_EXEC_PROGRESS_SOCKET';
21
+ /** The one record: something the test watches moved. */
22
+ export const PROGRESS_RECORD = 'moved';
23
+
24
+ const CHANNEL_DIRECTORY = 'bounded-progress-';
25
+ const CHANNEL_SOCKET = 'p.sock';
26
+ /** How much of a refused line its refusal quotes. */
27
+ const QUOTED_CHARS = 80;
28
+
29
+ export interface ProgressChannel {
30
+ /** The socket's path, as the command's environment names it. */
31
+ readonly socket: string;
32
+ /** Ends every connection and removes the socket's directory; the error that left something behind, or null. */
33
+ close(): Promise<string | null>;
34
+ }
35
+
36
+ export interface ProgressHandlers {
37
+ /** A record was read. */
38
+ readonly moved: () => void;
39
+ /** A client wrote something that is not a record; its connection is ended. */
40
+ readonly invalid: (detail: string) => void;
41
+ }
42
+
43
+ function describe(error: unknown): string {
44
+ return error instanceof Error ? error.message : String(error);
45
+ }
46
+
47
+ function quoted(line: string): string {
48
+ return JSON.stringify(line.length > QUOTED_CHARS ? `${line.slice(0, QUOTED_CHARS)}…` : line);
49
+ }
50
+
51
+ /** Serve one run's progress channel; a channel that cannot be served is the run's refusal, never a silent bound. */
52
+ export async function serveProgressChannel(
53
+ handlers: ProgressHandlers,
54
+ ): Promise<{ ok: true; channel: ProgressChannel } | { ok: false; error: string }> {
55
+ let directory: string;
56
+ try {
57
+ directory = await ownedSocketDirectory(CHANNEL_DIRECTORY, CHANNEL_SOCKET);
58
+ } catch (error) {
59
+ return { ok: false, error: `its directory could not be made: ${describe(error)}` };
60
+ }
61
+ const socketPath = join(directory, CHANNEL_SOCKET);
62
+ const clients = new Set<Socket>();
63
+ const serve = (client: Socket): void => {
64
+ clients.add(client);
65
+ client.on('close', () => clients.delete(client));
66
+ // A client that dies mid-record (its test was killed) loses that record with its connection; nothing else is read.
67
+ client.on('error', () => {});
68
+ client.setEncoding('utf8');
69
+ let partial = '';
70
+ const refuse = (detail: string): void => {
71
+ partial = '';
72
+ client.destroy();
73
+ handlers.invalid(detail);
74
+ };
75
+ client.on('data', (text: string) => {
76
+ const lines = (partial + text).split('\n');
77
+ partial = lines.pop() ?? '';
78
+ for (const line of lines) {
79
+ if (line !== PROGRESS_RECORD) {
80
+ refuse(`a progress record is the line ${PROGRESS_RECORD}, not ${quoted(line)}`);
81
+ return;
82
+ }
83
+ handlers.moved();
84
+ }
85
+ // No prefix longer than the record can still become one.
86
+ if (partial.length > PROGRESS_RECORD.length) {
87
+ refuse(`a progress record is the line ${PROGRESS_RECORD}, not ${quoted(partial)}`);
88
+ }
89
+ });
90
+ client.on('end', () => {
91
+ if (partial !== '') refuse(`a progress connection ended inside a record: ${quoted(partial)}`);
92
+ });
93
+ };
94
+ const server: Server = createServer(serve);
95
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: listen is this process's own bind of a path in its fresh directory; the kernel answers it with the listening callback or an error, and no peer takes part
96
+ const listened = await new Promise<Error | null>((settle) => {
97
+ server.once('error', settle);
98
+ server.listen(socketPath, () => {
99
+ server.off('error', settle);
100
+ settle(null);
101
+ });
102
+ });
103
+ const close = async (): Promise<string | null> => {
104
+ const failures: string[] = [];
105
+ for (const client of clients) client.destroy();
106
+ if (listened === null) {
107
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: every accepted connection was destroyed just above, so the server closes without waiting on a peer
108
+ const closed = await new Promise<Error | undefined>((settle) => server.close(settle));
109
+ if (closed !== undefined) failures.push(`its socket did not close: ${closed.message}`);
110
+ }
111
+ try {
112
+ await rm(directory, { recursive: true, force: true });
113
+ } catch (error) {
114
+ failures.push(`its directory was not removed: ${describe(error)}`);
115
+ }
116
+ return failures.length === 0 ? null : `the progress channel at ${socketPath}: ${failures.join('; ')}`;
117
+ };
118
+ if (listened !== null) {
119
+ const left = await close();
120
+ return {
121
+ ok: false,
122
+ error: `it could not listen at ${socketPath}: ${listened.message}${left === null ? '' : `; ${left}`}`,
123
+ };
124
+ }
125
+ server.on('error', (error) => {
126
+ handlers.invalid(`the progress channel at ${socketPath} failed: ${error.message}`);
127
+ });
128
+ return { ok: true, channel: { socket: socketPath, close } };
129
+ }
@@ -1,12 +1,14 @@
1
1
  import { StringDecoder } from 'node:string_decoder';
2
2
  import typia, { type tags } from 'typia';
3
+ import type { GoRunSummary } from './go-run-summary.js';
3
4
  import { invocationSpan, withInvocationFlag } from './runner-sizing.js';
4
5
  import type { NativeTestResult } from './test-result-writer.js';
5
6
  import { BUN_TEST, GO_TEST, GO_TEST_RUNNER, NEXTEST_RUN } from './verdict.js';
6
7
 
7
8
  /**
8
9
  * What a run's output says about its forward motion: whether a test finished, and which tests the runner said
9
- * are running and has not said finished. `idleTimeoutMs` re-arms only on a finished test.
10
+ * are running and has not said finished. In the output, `idleTimeoutMs` re-arms only on a finished test; a running test
11
+ * reports its own progress on the run's progress channel instead (progress-channel.ts).
10
12
  *
11
13
  * Output alone is not progress. nextest repeats a `SLOW` line for every test still running at each slow-timeout
12
14
  * period, and a hung test may print a heartbeat, so a bound on silence never fires on either. A finished test is
@@ -36,6 +38,8 @@ export interface RunProgress {
36
38
  /** The tests the runner reported running and has not reported finished, in the order it first named them. */
37
39
  inFlight(): string[];
38
40
  error(): string | null;
41
+ /** The Go run so far, by its top-level tests; null for a command that runs no Go tests. */
42
+ goSummary(): GoRunSummary | null;
39
43
  }
40
44
 
41
45
  export type OutputStream = 'stdout' | 'stderr';
@@ -125,6 +129,10 @@ export function createRunProgress(command = '', closed?: (result: NativeTestResu
125
129
  const running = new Set<string>();
126
130
  const packages = new Map<string, Set<string>>();
127
131
  const goOutput = new Map<string, string[]>();
132
+ // A Go run prints no count: its events are summed here, by top-level test, for the summary its output ends with.
133
+ const goVerdicts = new Map<string, { package: string; test: string; status: 'pass' | 'fail' | 'skip' }>();
134
+ const goPackages = new Set<string>();
135
+ const goFailedPackages: string[] = [];
128
136
  const decoders: Record<OutputStream, StringDecoder> = {
129
137
  stdout: new StringDecoder('utf8'),
130
138
  stderr: new StringDecoder('utf8'),
@@ -155,6 +163,7 @@ export function createRunProgress(command = '', closed?: (result: NativeTestResu
155
163
  switch (event.Action) {
156
164
  case 'start':
157
165
  packages.set(event.Package, new Set());
166
+ goPackages.add(event.Package);
158
167
  return false;
159
168
  case 'run':
160
169
  packages.get(event.Package)?.add(event.Test);
@@ -163,10 +172,21 @@ export function createRunProgress(command = '', closed?: (result: NativeTestResu
163
172
  case 'fail':
164
173
  case 'skip':
165
174
  case 'bench':
166
- if (event.Test === undefined) packages.delete(event.Package);
167
- else {
175
+ if (event.Test === undefined) {
176
+ packages.delete(event.Package);
177
+ goPackages.add(event.Package);
178
+ // A package that fails with no failed test of its own did not get to run them: a build, a TestMain.
179
+ if (
180
+ event.Action === 'fail' &&
181
+ ![...goVerdicts.values()].some((test) => test.package === event.Package && test.status === 'fail')
182
+ )
183
+ goFailedPackages.push(event.Package);
184
+ } else {
168
185
  packages.get(event.Package)?.delete(event.Test);
169
186
  const id = `${event.Package}::${event.Test}`;
187
+ // A subtest's verdict is its parent's, which Go reports after it: only the parent is counted.
188
+ if (event.Action !== 'bench' && !event.Test.includes('/'))
189
+ goVerdicts.set(id, { package: event.Package, test: event.Test, status: event.Action });
170
190
  if (event.Action !== 'bench' && goResults)
171
191
  closed?.({
172
192
  id,
@@ -296,6 +316,22 @@ export function createRunProgress(command = '', closed?: (result: NativeTestResu
296
316
  return progressed;
297
317
  },
298
318
  error: () => failure,
319
+ goSummary: () => {
320
+ if (!goResults) return null;
321
+ const verdicts = [...goVerdicts.values()];
322
+ const count = (status: 'pass' | 'fail' | 'skip'): number =>
323
+ verdicts.filter((test) => test.status === status).length;
324
+ return {
325
+ passed: count('pass'),
326
+ failed: count('fail'),
327
+ skipped: count('skip'),
328
+ packages: goPackages.size,
329
+ failedTests: verdicts
330
+ .filter((test) => test.status === 'fail')
331
+ .map((test) => ({ package: test.package, test: test.test })),
332
+ failedPackages: [...goFailedPackages],
333
+ };
334
+ },
299
335
  inFlight: () => [
300
336
  ...running,
301
337
  ...[...packages].flatMap(([name, tests]) =>
@@ -445,6 +445,11 @@ export interface RamTempLease {
445
445
  * another attach, or none, is not this lease's volume: its free space is some other filesystem's.
446
446
  */
447
447
  attach: string;
448
+ /**
449
+ * The I/O Registry entry of the disk that attach is on, which the volume's marker named and the registry proved when
450
+ * the lease was taken: the disk a release of a lease whose volume lost its mount detaches.
451
+ */
452
+ registryEntry: string;
448
453
  }
449
454
 
450
455
  export interface RamUnavailable {
@@ -686,7 +691,8 @@ type Taken =
686
691
  };
687
692
 
688
693
  type Releasing =
689
- | { readonly kind: 'lost'; readonly detail: string }
694
+ /** `stranded`: the volume itself went from the mountpoint, not just the lease from the volume. */
695
+ | { readonly kind: 'lost'; readonly detail: string; readonly stranded: boolean }
690
696
  | { readonly kind: 'wait'; readonly claim: LifecycleClaim }
691
697
  | {
692
698
  readonly kind: 'claimed';
@@ -901,6 +907,7 @@ export class RamTempVolume {
901
907
  directory: value.directory,
902
908
  mountpoint: this.paths.mountpoint,
903
909
  attach: value.volume.attach,
910
+ registryEntry: value.volume.registryEntry,
904
911
  },
905
912
  held: [...value.held, ...settled.value.held].map((lease) => lease.text),
906
913
  reaped: [...settled.value.reaped],
@@ -942,7 +949,15 @@ export class RamTempVolume {
942
949
  const directory = await this.make(op);
943
950
  return {
944
951
  ledger: next,
945
- value: { ok: true, value: { directory, mountpoint: this.paths.mountpoint, attach: volume.attach } },
952
+ value: {
953
+ ok: true,
954
+ value: {
955
+ directory,
956
+ mountpoint: this.paths.mountpoint,
957
+ attach: volume.attach,
958
+ registryEntry: volume.registryEntry,
959
+ },
960
+ },
946
961
  };
947
962
  },
948
963
  );
@@ -1015,7 +1030,7 @@ export class RamTempVolume {
1015
1030
  // A lease that went while its task held it is said, never released as though it were there.
1016
1031
  const held = leaseOn(lease, volume);
1017
1032
  if ('lost' in held) {
1018
- return { ledger, value: { kind: 'lost', detail: held.lost } };
1033
+ return { ledger, value: { kind: 'lost', detail: held.lost, stranded: volume?.attach !== lease.attach } };
1019
1034
  }
1020
1035
  if (ledger.lifecycle !== null) {
1021
1036
  return { ledger, value: { kind: 'wait', claim: ledger.lifecycle } };
@@ -1034,7 +1049,9 @@ export class RamTempVolume {
1034
1049
  case 'lost':
1035
1050
  return {
1036
1051
  ok: false,
1037
- error: { kind: 'lease-lost', lease: lease.directory, mountpoint: lease.mountpoint, detail: value.detail },
1052
+ error: value.stranded
1053
+ ? await this.releaseLost(op, lease, value.detail)
1054
+ : { kind: 'lease-lost', lease: lease.directory, mountpoint: lease.mountpoint, detail: value.detail },
1038
1055
  };
1039
1056
  case 'wait': {
1040
1057
  const yielded = await this.yieldTo(op, value.claim, waited);
@@ -1086,6 +1103,90 @@ export class RamTempVolume {
1086
1103
  }
1087
1104
  }
1088
1105
 
1106
+ /**
1107
+ * Release a lease whose volume went from the mountpoint while its task held it. A volume that lost its mount leaves its
1108
+ * disk attached and mounted nowhere: no path reaches its files and no lease can be taken on it, yet its pages stay
1109
+ * resident until it is detached (on 2026-11-10 a restart of fseventsd stranded the user's 8 GiB disk so, owned by no
1110
+ * lease). The lease's own registry entry, which the registry proved when the lease was taken, makes the disk this
1111
+ * volume's: the release detaches it through the gateway's registry-bound `ram-detach`, under a detach claim no other
1112
+ * caller passes, and the lease is said lost with what became of its disk. A disk mounted anywhere is left as it is and
1113
+ * named, and one already gone is said so; nothing is forced.
1114
+ */
1115
+ private async releaseLost(op: Operation, lease: RamTempLease, lost: string): Promise<RamTempError> {
1116
+ const said = (detail: string): RamTempError => ({
1117
+ kind: 'lease-lost',
1118
+ lease: lease.directory,
1119
+ mountpoint: lease.mountpoint,
1120
+ detail: `${lost}; ${detail}`,
1121
+ });
1122
+ const entry = lease.registryEntry;
1123
+ let waited: ClaimWait | null = null;
1124
+ for (;;) {
1125
+ const found = await this.diskOf(entry);
1126
+ if (!found.ok)
1127
+ return said(`its disk (registry ${entry}) could not be read: ${describeRamTempError(found.error)}`);
1128
+ const disk = found.value;
1129
+ if (disk === null) return said(`its disk (registry ${entry}) is no longer attached`);
1130
+ if (disk.mountpoints.length > 0) {
1131
+ return said(
1132
+ `its disk ${disk.physical} (registry ${entry}) is mounted at ${disk.mountpoints.join(', ')}, so this release left it attached`,
1133
+ );
1134
+ }
1135
+ const stranded = `its disk ${disk.physical} (registry ${entry}) stayed attached with its mount at ${lease.mountpoint} lost`;
1136
+ const taken = await this.locked(
1137
+ op,
1138
+ 'release',
1139
+ async (ledger): Promise<Step<LifecycleClaim | null>> =>
1140
+ ledger.lifecycle !== null
1141
+ ? { ledger, value: ledger.lifecycle }
1142
+ : { ledger: { ...ledger, lifecycle: { kind: 'detach', owner: op.owner } }, value: null },
1143
+ );
1144
+ if (!taken.ok) {
1145
+ const why = taken.error.kind === 'lock-denied' ? taken.error.detail : describeRamTempError(taken.error);
1146
+ return said(`${stranded}, and no detach claim could be taken: ${why}`);
1147
+ }
1148
+ if (taken.value !== null) {
1149
+ // Another caller is creating or detaching: look at the disk again once it has.
1150
+ const yielded = await this.yieldTo(op, taken.value, waited);
1151
+ if (!yielded.ok) {
1152
+ const why = yielded.error.kind === 'lock-denied' ? yielded.error.detail : describeRamTempError(yielded.error);
1153
+ return said(`${stranded}, and waiting on another caller's ${taken.value.kind} failed: ${why}`);
1154
+ }
1155
+ waited = yielded.value;
1156
+ continue;
1157
+ }
1158
+ const command = await this.runDetach(op, disk.physical, entry);
1159
+ if (!command.ok) return said(`${stranded}, and its detach failed: ${describeRamTempError(command.error)}`);
1160
+ if (command.value.pending !== undefined) {
1161
+ return said(`${stranded}; its detach still runs in the gateway (${commandText(command.value)})`);
1162
+ }
1163
+ const detached = detachOutcome(command.value, disk, 'hdiutil detach (lost mount)');
1164
+ return said(
1165
+ detached.ok
1166
+ ? `${stranded}, and this release detached it`
1167
+ : `${stranded}, and its detach failed: ${describeRamTempError(detached.error)}`,
1168
+ );
1169
+ }
1170
+ }
1171
+
1172
+ /** The RAM disk of this volume's user and size that registry entry `entry` registers, as one read finds it; else null. */
1173
+ private async diskOf(entry: string): Promise<Result<AttachedRamDisk | null, RamTempError>> {
1174
+ const registry = await this.commands.run('/usr/sbin/ioreg', ['-r', '-c', 'IOHDIXHDDriveOutKernel', '-l', '-w0']);
1175
+ if (registry.status !== 0) return failed('ioreg (RAM disks)', commandText(registry));
1176
+ const table = await this.commands.run('/sbin/mount', []);
1177
+ if (table.status !== 0) return failed('mount (mount table)', commandText(table));
1178
+ const disks = ramDisksIn(registry.stdout, table.stdout);
1179
+ if (!disks.ok) return failed('ioreg (RAM disks)', disks.error);
1180
+ const disk = disks.value.find(
1181
+ (candidate) =>
1182
+ candidate.entry === entry && candidate.uid === this.paths.uid && candidate.sectors === this.sectors,
1183
+ );
1184
+ if (disk === undefined) return { ok: true, value: null };
1185
+ const { physical } = disk;
1186
+ return physical === null
1187
+ ? failed('ioreg (RAM disks)', `registry entry ${entry} has published no whole disk`)
1188
+ : { ok: true, value: { ...disk, physical } };
1189
+ }
1089
1190
  /**
1090
1191
  * Wait out another caller's creation or detach. Liveness of its owner is its pid's, so a crashed
1091
1192
  * owner whose pid was reused holds every caller here; past each `CLAIM_WAIT_NOTICE_MS` on the same
@@ -1798,22 +1899,41 @@ export class RamTempVolume {
1798
1899
  return confirmed;
1799
1900
  }
1800
1901
 
1801
- /** Check the root the volume mounts below, detach what earlier creators left, then attach and provision the volume. */
1902
+ /**
1903
+ * Check the root the volume mounts below, detach what earlier creators left, then attach and provision the volume. An
1904
+ * unmounted mountpoint with contents is never mounted over and its files never touched: the volume is unavailable.
1905
+ * Only the disk the ledger records as kept is still detached first, by that registry entry, since a lost mount
1906
+ * strands it beside such a directory: tasks that held leases on it may have written there after the loss. With no
1907
+ * kept record the refusal inspects nothing on the host.
1908
+ */
1802
1909
  private async provisionVolume(op: Operation): Promise<Result<void, RamTempError>> {
1910
+ let unowned: boolean;
1803
1911
  try {
1804
- const [root, parent] = await Promise.all([stat(this.paths.mountpoint), stat(join(this.paths.mountpoint, '..'))]);
1805
- if (root.dev === parent.dev && (await readdir(this.paths.mountpoint)).length !== 0) {
1806
- return {
1807
- ok: false,
1808
- error: {
1809
- kind: 'ram-unavailable',
1810
- reason: 'unproven-owner',
1811
- detail: `${this.paths.mountpoint} is an unmounted directory with unowned contents; nothing removed or hidden by a new mount`,
1812
- },
1813
- };
1814
- }
1912
+ const [mount, parent] = await Promise.all([stat(this.paths.mountpoint), stat(join(this.paths.mountpoint, '..'))]);
1913
+ unowned = mount.dev === parent.dev && (await readdir(this.paths.mountpoint)).length !== 0;
1815
1914
  } catch (error) {
1816
1915
  if (errorCode(error) !== 'ENOENT') return failed('provenance', errorText(error));
1916
+ unowned = false;
1917
+ }
1918
+ if (unowned) {
1919
+ const read = await this.readLedger();
1920
+ if (!read.ok) {
1921
+ return read;
1922
+ }
1923
+ if (read.value.ledger.kept !== null) {
1924
+ const strays = await this.reclaimStrays(op, this.holdersPass());
1925
+ if (!strays.ok) {
1926
+ return strays;
1927
+ }
1928
+ }
1929
+ return {
1930
+ ok: false,
1931
+ error: {
1932
+ kind: 'ram-unavailable',
1933
+ reason: 'unproven-owner',
1934
+ detail: `${this.paths.mountpoint} is an unmounted directory with unowned contents; nothing removed or hidden by a new mount`,
1935
+ },
1936
+ };
1817
1937
  }
1818
1938
  const root = await rootReadiness(this.paths);
1819
1939
  if (!root.ok) {
@@ -2276,7 +2396,7 @@ function leaseOn(
2276
2396
  ): { readonly on: MountedVolume } | { readonly lost: string } {
2277
2397
  if (volume === null) {
2278
2398
  return {
2279
- lost: `no marked volume is mounted at ${lease.mountpoint} any more: it was detached while the task held its lease`,
2399
+ lost: `no marked volume is mounted at ${lease.mountpoint} any more: it was unmounted or detached while the task held its lease`,
2280
2400
  };
2281
2401
  }
2282
2402
  if (volume.attach !== lease.attach) {