@smoothbricks/nx-plugin 0.7.18 → 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 (143) hide show
  1. package/README.md +160 -99
  2. package/dist/.build-inputs.json +35 -29
  3. package/dist/built-output-packages.js +1 -1
  4. package/dist/cargo-closure-input.js +1 -1
  5. package/dist/cargo-source-hash.d.ts +3 -21
  6. package/dist/cargo-source-hash.d.ts.map +1 -1
  7. package/dist/cargo-source-hash.js +4 -91
  8. package/dist/cargo-toolchain-paths.d.ts +2 -2
  9. package/dist/cargo-toolchain-paths.js +2 -2
  10. package/dist/cargo-workspace.d.ts.map +1 -1
  11. package/dist/cargo-workspace.js +2 -1
  12. package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
  13. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
  14. package/dist/executors/bounded-exec/admission-queue.js +9 -10
  15. package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
  16. package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
  17. package/dist/executors/bounded-exec/awake-clock.js +22 -0
  18. package/dist/executors/bounded-exec/bounds.d.ts +7 -5
  19. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  20. package/dist/executors/bounded-exec/bounds.js +14 -11
  21. package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
  22. package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
  23. package/dist/executors/bounded-exec/case-gate.js +342 -0
  24. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
  25. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  26. package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
  27. package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
  28. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  29. package/dist/executors/bounded-exec/cpu-pool.js +102 -16
  30. package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
  31. package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
  32. package/dist/executors/bounded-exec/endpoint-life.js +228 -0
  33. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  34. package/dist/executors/bounded-exec/executor.js +207 -69
  35. package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
  36. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/gateway-lease.js +8 -1
  38. package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
  39. package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
  40. package/dist/executors/bounded-exec/go-run-summary.js +98 -0
  41. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +3 -3
  42. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  43. package/dist/executors/bounded-exec/hang-diagnostics.js +66 -48
  44. package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
  45. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
  46. package/dist/executors/bounded-exec/lease-wait.js +1 -0
  47. package/dist/executors/bounded-exec/mbx-pool.d.ts +28 -7
  48. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  49. package/dist/executors/bounded-exec/mbx-pool.js +30 -9
  50. package/dist/executors/bounded-exec/mbx-reservations.d.ts +8 -5
  51. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  52. package/dist/executors/bounded-exec/mbx-reservations.js +187 -283
  53. package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
  54. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
  55. package/dist/executors/bounded-exec/parent-grant.js +1 -0
  56. package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
  57. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
  58. package/dist/executors/bounded-exec/pool-admission.js +47 -1
  59. package/dist/executors/bounded-exec/progress.d.ts +3 -0
  60. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  61. package/dist/executors/bounded-exec/progress.js +31 -1
  62. package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
  63. package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
  64. package/dist/executors/bounded-exec/reservation-connection.js +248 -0
  65. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
  67. package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
  68. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/runner-sizing.js +13 -9
  70. package/dist/executors/bounded-exec/schema.d.ts +2 -2
  71. package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
  72. package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/suite-minimum.js +85 -0
  74. package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
  75. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
  76. package/dist/executors/bounded-exec/test-result-writer.js +1 -0
  77. package/dist/executors/bounded-exec/test-results.d.ts +5 -0
  78. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
  79. package/dist/executors/bounded-exec/test-results.js +2 -2
  80. package/dist/executors/bounded-exec/verdict.d.ts +26 -4
  81. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  82. package/dist/executors/bounded-exec/verdict.js +26 -5
  83. package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
  84. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  85. package/dist/executors/cargo-zigbuild/executor.js +32 -19
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +105 -73
  88. package/dist/managed-files/ci-workflow.d.ts +4 -1
  89. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  90. package/dist/managed-files/ci-workflow.js +9 -14
  91. package/dist/managed-files/files.d.ts +3 -3
  92. package/dist/managed-files/files.js +3 -3
  93. package/dist/task-results.js +2 -1
  94. package/dist/workspace-config-policy.d.ts.map +1 -1
  95. package/dist/workspace-config-policy.js +135 -42
  96. package/executors.json +2 -0
  97. package/managed/raw/envrc +24 -0
  98. package/managed/raw/patches/nx@24.0.3.patch +1179 -133
  99. package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
  100. package/managed/raw/tooling/direnv/developer-links.ts +105 -11
  101. package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
  102. package/package.json +67 -11
  103. package/runtime/nx-publish/.build-inputs.json +2 -2
  104. package/runtime/nx-publish/cache_adapter.js +293 -3
  105. package/runtime/nx-publish/nx_publish.js +36 -14
  106. package/src/built-output-packages.ts +1 -1
  107. package/src/cargo-closure-input.ts +1 -1
  108. package/src/cargo-source-hash.ts +16 -132
  109. package/src/cargo-toolchain-paths.ts +2 -2
  110. package/src/cargo-workspace.ts +1 -2
  111. package/src/executors/bounded-exec/admission-queue.ts +11 -10
  112. package/src/executors/bounded-exec/awake-clock.ts +20 -0
  113. package/src/executors/bounded-exec/bounds.ts +28 -15
  114. package/src/executors/bounded-exec/case-gate.ts +365 -0
  115. package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
  116. package/src/executors/bounded-exec/cpu-pool.ts +139 -12
  117. package/src/executors/bounded-exec/endpoint-life.ts +279 -0
  118. package/src/executors/bounded-exec/executor.ts +280 -106
  119. package/src/executors/bounded-exec/gateway-lease.ts +6 -0
  120. package/src/executors/bounded-exec/go-run-summary.ts +137 -0
  121. package/src/executors/bounded-exec/hang-diagnostics.ts +70 -52
  122. package/src/executors/bounded-exec/lease-wait.ts +1 -0
  123. package/src/executors/bounded-exec/mbx-pool.ts +36 -9
  124. package/src/executors/bounded-exec/mbx-reservations.ts +213 -182
  125. package/src/executors/bounded-exec/parent-grant.ts +3 -0
  126. package/src/executors/bounded-exec/pool-admission.ts +59 -2
  127. package/src/executors/bounded-exec/progress.ts +37 -2
  128. package/src/executors/bounded-exec/reservation-connection.ts +221 -0
  129. package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
  130. package/src/executors/bounded-exec/runner-sizing.ts +13 -8
  131. package/src/executors/bounded-exec/schema.json +1 -1
  132. package/src/executors/bounded-exec/schema.ts +2 -2
  133. package/src/executors/bounded-exec/suite-minimum.ts +81 -0
  134. package/src/executors/bounded-exec/test-result-writer.ts +3 -0
  135. package/src/executors/bounded-exec/test-results.ts +5 -0
  136. package/src/executors/bounded-exec/verdict.ts +39 -6
  137. package/src/executors/cargo-zigbuild/executor.ts +30 -19
  138. package/src/index.ts +112 -78
  139. package/src/managed-files/ci-workflow.ts +13 -17
  140. package/src/managed-files/files.ts +3 -3
  141. package/src/workspace-config-policy.ts +161 -43
  142. package/test-timings.json +157 -147
  143. package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case-gate.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/case-gate.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AACjE,mCAAmC;AACnC,eAAO,MAAM,EAAE,OAAO,CAAC;AASvB,uFAAuF;AACvF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B,sEAAsE;IACtE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AS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EAC3B,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,QAAQ,GAC5C,UAAU,CA4BZ;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErE;AAOD,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,+GAA+G;IAC/G,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,mHAAmH;IACnH,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAMD,oFAAoF;AACpF,wBAAsB,aAAa,CACjC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAmG5E"}
@@ -0,0 +1,342 @@
1
+ import * as _validateReport_1 from "typia/lib/internal/_validateReport";
2
+ import { rm } from 'node:fs/promises';
3
+ import { createServer } from 'node:net';
4
+ import { join } from 'node:path';
5
+ import typia from 'typia';
6
+ import { ownedSocketDirectory } from '../../testing.js';
7
+ /**
8
+ * A reserved nextest leaf's case gate (specs/cowshed/05_gateway.md, "A case starts on a core"). The leaf's runner
9
+ * starts every thread of its ask, and each case takes a core before it runs: one of the leaf's grant when one is free,
10
+ * else one reserved for that case alone, which the leaf's executor asks its run's endpoint for and gives back when the
11
+ * case ends. A grant never grows, so this is how the cores other work frees after the leaf's grant reach it.
12
+ *
13
+ * The gate is a Unix stream socket the executor serves for one run and names in the command's environment as
14
+ * {@link TEST_GATE_ENV}. mbx's test shim, through which nextest starts every case, connects before the case starts,
15
+ * writes one line ({@link CaseLine}), starts the case when the line {@link GO} answers, and keeps the connection until
16
+ * the case has exited: the connection's end is the case's end.
17
+ */
18
+ export const TEST_GATE_ENV = 'MBX_TEST_GATE';
19
+ /**
20
+ * Set to `1` in a run's environment once its endpoint answered that the installed mbx's shim gates its cases
21
+ * (endpoint-life.ts, `gatesTests`): without it a leaf's runner is sized to its grant.
22
+ */
23
+ export const TEST_GATE_SERVED_ENV = 'BOUNDED_EXEC_MBX_TEST_GATE';
24
+ /** The line that starts a case. */
25
+ export const GO = 'go';
26
+ const parseCaseLine = (() => {
27
+ let errors;
28
+ let _report;
29
+ const _io0 = input => "string" === typeof input.binary && "string" === typeof input.test;
30
+ const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.binary || _report(_exceptionable, {
31
+ path: _path + ".binary",
32
+ expected: "string",
33
+ value: input.binary
34
+ }), "string" === typeof input.test || _report(_exceptionable, {
35
+ path: _path + ".test",
36
+ expected: "string",
37
+ value: input.test
38
+ })].every(flag => flag);
39
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
40
+ const __validate = input => {
41
+ if (false === __is(input)) {
42
+ errors = [];
43
+ _report = _validateReport_1._validateReport(errors);
44
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
45
+ path: _path + "",
46
+ expected: "CaseLine",
47
+ value: input
48
+ })) && _vo0(input, _path + "", true) || _report(true, {
49
+ path: _path + "",
50
+ expected: "CaseLine",
51
+ value: input
52
+ }))(input, "$input", true);
53
+ const success = 0 === errors.length;
54
+ return success ? {
55
+ success,
56
+ data: input
57
+ } : {
58
+ success,
59
+ errors,
60
+ data: input
61
+ };
62
+ }
63
+ return {
64
+ success: true,
65
+ data: input
66
+ };
67
+ };
68
+ return input => __validate(JSON.parse(input));
69
+ })();
70
+ /** A case's id as its result names it (progress.ts): the binary id, `::`, the test. */
71
+ export function caseId(binary, test) {
72
+ return `${binary}::${test}`;
73
+ }
74
+ /**
75
+ * The gate's decisions, as a state machine over three events: a case arrived, the pool granted a case's request, a
76
+ * case ended. `own` is the leaf's granted cores; `wall` a case's last recorded wall, by which a freed core of the
77
+ * grant picks the longest waiting case, so the cores the pool gives go to the shorter ones and come back soonest.
78
+ */
79
+ export class CaseGate {
80
+ own;
81
+ wall;
82
+ effects;
83
+ now;
84
+ #cases = new Map();
85
+ #waited = new Map();
86
+ #ownRunning = 0;
87
+ #own = 0;
88
+ #lent = 0;
89
+ #lentCoreMs = 0;
90
+ #waitedCaseMs = 0;
91
+ #ranWallMs = 0;
92
+ constructor(own, wall, effects, now = Date.now) {
93
+ this.own = own;
94
+ this.wall = wall;
95
+ this.effects = effects;
96
+ this.now = now;
97
+ }
98
+ /** A case's shim connected. False for a case already at the gate, which its second connection may not join. */
99
+ arrived(id) {
100
+ if (this.#cases.has(id))
101
+ return false;
102
+ if (this.#ownRunning < this.own) {
103
+ this.#startOwn(id, 0);
104
+ return true;
105
+ }
106
+ this.#cases.set(id, { kind: 'waiting', since: this.now() });
107
+ this.effects.reserve(id);
108
+ return true;
109
+ }
110
+ /** The pool granted the case's request. One whose case no longer waits gives the core straight back. */
111
+ granted(id) {
112
+ const state = this.#cases.get(id);
113
+ if (state?.kind !== 'waiting') {
114
+ this.effects.release(id);
115
+ return;
116
+ }
117
+ const at = this.now();
118
+ this.#startedAfter(id, at - state.since);
119
+ this.#cases.set(id, { kind: 'lent', since: at });
120
+ this.#lent += 1;
121
+ this.effects.start(id);
122
+ }
123
+ /** A case's connection ended: its core goes back where it came from, a waiting case's request is withdrawn. */
124
+ ended(id) {
125
+ const state = this.#cases.get(id);
126
+ if (state === undefined)
127
+ return;
128
+ this.#cases.delete(id);
129
+ if (state.kind !== 'waiting')
130
+ this.#ranWallMs += this.wall(id);
131
+ switch (state.kind) {
132
+ case 'waiting':
133
+ this.effects.release(id);
134
+ return;
135
+ case 'lent':
136
+ this.#lentCoreMs += this.now() - state.since;
137
+ this.effects.release(id);
138
+ return;
139
+ case 'own': {
140
+ this.#ownRunning -= 1;
141
+ let longest = null;
142
+ for (const [waiting, other] of this.#cases) {
143
+ if (other.kind !== 'waiting')
144
+ continue;
145
+ if (longest === null || this.wall(waiting) > this.wall(longest.id)) {
146
+ longest = { id: waiting, since: other.since };
147
+ }
148
+ }
149
+ if (longest === null)
150
+ return;
151
+ this.effects.release(longest.id);
152
+ this.#startOwn(longest.id, this.now() - longest.since);
153
+ return;
154
+ }
155
+ }
156
+ }
157
+ /** How long the case waited at the gate before it started, in ms; zero for one that never did. */
158
+ waitedMs(id) {
159
+ return this.#waited.get(id) ?? 0;
160
+ }
161
+ /** The last recorded walls of the cases that ran and ended, summed. */
162
+ ranWallMs() {
163
+ return this.#ranWallMs;
164
+ }
165
+ summary() {
166
+ return { own: this.#own, lent: this.#lent, lentCoreMs: this.#lentCoreMs, waitedCaseMs: this.#waitedCaseMs };
167
+ }
168
+ #startOwn(id, waitedMs) {
169
+ this.#startedAfter(id, waitedMs);
170
+ this.#cases.set(id, { kind: 'own' });
171
+ this.#ownRunning += 1;
172
+ this.#own += 1;
173
+ this.effects.start(id);
174
+ }
175
+ #startedAfter(id, waitedMs) {
176
+ this.#waited.set(id, waitedMs);
177
+ this.#waitedCaseMs += waitedMs;
178
+ }
179
+ }
180
+ /**
181
+ * The gate of a leaf that holds `own` cores, over whichever pool `ask` asks: mbx's, through the run's reservation
182
+ * endpoint, or the run's own token pool (cpu-pool.ts, `lendParentToken`). `start` answers a case's connection.
183
+ * `walls` are the cases' last recorded walls; a request is told the work the leaf has left, their sum less the walls
184
+ * of the cases that ran, by which a token pool lends to the leaf that would otherwise end last.
185
+ */
186
+ export function gateCases(own, walls, start, ask) {
187
+ const requests = new Map();
188
+ let total = 0;
189
+ for (const wall of walls.values())
190
+ total += wall;
191
+ const cases = new CaseGate(own, (id) => walls.get(id) ?? 0, {
192
+ start,
193
+ reserve: (id) => {
194
+ const held = ask(id, Math.max(0, total - cases.ranWallMs()));
195
+ requests.set(id, held);
196
+ void held.granted.then((granted) => {
197
+ // Released since: the case started on a core of the grant, or ended while it waited.
198
+ if (requests.get(id) !== held)
199
+ return;
200
+ if (granted)
201
+ cases.granted(id);
202
+ else
203
+ requests.delete(id);
204
+ });
205
+ },
206
+ release: (id) => {
207
+ requests.get(id)?.release();
208
+ requests.delete(id);
209
+ },
210
+ });
211
+ return {
212
+ cases,
213
+ releaseAll: () => {
214
+ for (const held of requests.values())
215
+ held.release();
216
+ requests.clear();
217
+ },
218
+ };
219
+ }
220
+ /**
221
+ * A case's wall as its result records it: nextest times a case from the shim's start, so its own duration includes the
222
+ * wait at the gate, which is taken off. Never below zero.
223
+ */
224
+ export function runWallMs(nextestMs, waitedMs) {
225
+ return Math.max(0, nextestMs - waitedMs);
226
+ }
227
+ const GATE_DIRECTORY = 'bounded-gate-';
228
+ const GATE_SOCKET = 'g.sock';
229
+ /** No case line is longer: a binary id and a test name. */
230
+ const LINE_BYTES = 16 * 1024;
231
+ function describe(error) {
232
+ return error instanceof Error ? error.message : String(error);
233
+ }
234
+ /** Serve one run's case gate; a gate that cannot be served is the run's refusal. */
235
+ export async function serveCaseGate(handlers) {
236
+ let directory;
237
+ try {
238
+ directory = await ownedSocketDirectory(GATE_DIRECTORY, GATE_SOCKET);
239
+ }
240
+ catch (error) {
241
+ return { ok: false, error: `its directory could not be made: ${describe(error)}` };
242
+ }
243
+ const socketPath = join(directory, GATE_SOCKET);
244
+ const clients = new Set();
245
+ const named = new Map();
246
+ const serve = (client) => {
247
+ clients.add(client);
248
+ // A case that is killed loses its connection with its process: that end is the case's end, read below.
249
+ client.on('error', () => { });
250
+ client.setEncoding('utf8');
251
+ let partial = '';
252
+ let id = null;
253
+ const refuse = (detail) => {
254
+ client.destroy();
255
+ handlers.invalid(detail);
256
+ };
257
+ client.on('data', (text) => {
258
+ if (id !== null) {
259
+ refuse(`case ${id} wrote a second line at its gate`);
260
+ return;
261
+ }
262
+ partial += text;
263
+ const end = partial.indexOf('\n');
264
+ if (end === -1) {
265
+ if (partial.length > LINE_BYTES)
266
+ refuse(`a case line is at most ${LINE_BYTES} bytes`);
267
+ return;
268
+ }
269
+ let parsed;
270
+ try {
271
+ parsed = parseCaseLine(partial.slice(0, end));
272
+ }
273
+ catch {
274
+ parsed = null;
275
+ }
276
+ if (parsed === null || !parsed.success || partial.length > end + 1) {
277
+ refuse(`a case line names a binary and a test, one line; got ${JSON.stringify(partial.slice(0, 200))}`);
278
+ return;
279
+ }
280
+ const arriving = caseId(parsed.data.binary, parsed.data.test);
281
+ named.set(arriving, client);
282
+ if (!handlers.arrived(arriving)) {
283
+ named.delete(arriving);
284
+ refuse(`case ${arriving} is already at its gate`);
285
+ return;
286
+ }
287
+ id = arriving;
288
+ });
289
+ client.on('close', () => {
290
+ clients.delete(client);
291
+ if (id === null)
292
+ return;
293
+ if (named.get(id) === client)
294
+ named.delete(id);
295
+ handlers.ended(id);
296
+ });
297
+ };
298
+ const server = createServer(serve);
299
+ // 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
300
+ const listened = await new Promise((settle) => {
301
+ server.once('error', settle);
302
+ server.listen(socketPath, () => {
303
+ server.off('error', settle);
304
+ settle(null);
305
+ });
306
+ });
307
+ const close = async () => {
308
+ const failures = [];
309
+ for (const client of clients)
310
+ client.destroy();
311
+ if (listened === null) {
312
+ // 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
313
+ const closed = await new Promise((settle) => server.close(settle));
314
+ if (closed !== undefined)
315
+ failures.push(`its socket did not close: ${closed.message}`);
316
+ }
317
+ try {
318
+ await rm(directory, { recursive: true, force: true });
319
+ }
320
+ catch (error) {
321
+ failures.push(`its directory was not removed: ${describe(error)}`);
322
+ }
323
+ return failures.length === 0 ? null : `the case gate at ${socketPath}: ${failures.join('; ')}`;
324
+ };
325
+ if (listened !== null) {
326
+ const left = await close();
327
+ return {
328
+ ok: false,
329
+ error: `its socket ${socketPath} could not be bound: ${listened.message}${left === null ? '' : `; ${left}`}`,
330
+ };
331
+ }
332
+ return {
333
+ ok: true,
334
+ gate: {
335
+ socket: socketPath,
336
+ start: (id) => {
337
+ named.get(id)?.write(`${GO}\n`);
338
+ },
339
+ close,
340
+ },
341
+ };
342
+ }
@@ -26,5 +26,6 @@ export type CpuPoolThreadReport = {
26
26
  } | {
27
27
  readonly kind: 'closed';
28
28
  readonly outcome: CloseOutcome;
29
+ readonly idle: string | null;
29
30
  };
30
31
  //# sourceMappingURL=cpu-pool-thread.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cpu-pool-thread.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool-thread.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AAEH,6GAA6G;AAC7G,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B;AAED,8GAA8G;AAC9G,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"cpu-pool-thread.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool-thread.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAA+B,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AAEH,6GAA6G;AAC7G,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B;AAED,8GAA8G;AAC9G,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { parentPort, workerData } from 'node:worker_threads';
2
- import { createCpuPool } from './cpu-pool.js';
2
+ import { createCpuPool, describeIdle } from './cpu-pool.js';
3
3
  const host = parentPort;
4
4
  if (host === null) {
5
5
  throw new Error('cpu-pool-thread runs as the worker thread run-cpu-pool starts, never as a module of its own');
@@ -11,7 +11,7 @@ const made = await createCpuPool(data.tokens, new Promise(() => { }), data.memor
11
11
  if (made.ok) {
12
12
  const { pool } = made;
13
13
  host.once('message', () => {
14
- void pool.close().then((outcome) => report({ kind: 'closed', outcome }));
14
+ void pool.close().then((outcome) => report({ kind: 'closed', outcome, idle: describeIdle(made.summary()) }));
15
15
  });
16
16
  report({ kind: 'serving', environment: pool.environment });
17
17
  }
@@ -1,4 +1,5 @@
1
1
  import typia from 'typia';
2
+ import type { CaseCore } from './case-gate.js';
2
3
  import { type Unleased } from './gateway-lease.js';
3
4
  import { type LiveUsageReading, type RunMemory } from './host-memory.js';
4
5
  import { type InheritedCpuPool } from './pool-environment.js';
@@ -38,6 +39,22 @@ export interface CpuPool {
38
39
  */
39
40
  close(): Promise<CloseOutcome>;
40
41
  }
42
+ /** What a pool says when it closes: the token-time idle beside starved holds, and the grants that made them. */
43
+ export interface PoolSummary {
44
+ /** Token-milliseconds no socket grant held while a hold was starved (pool-admission.ts, `IdleBesideStarved`). */
45
+ readonly idleBesideStarvedMs: number;
46
+ /** Leaves granted fewer tokens than they asked, whether gated or not. */
47
+ readonly starved: number;
48
+ /** Lent tokens granted, one per test case. */
49
+ readonly lent: number;
50
+ }
51
+ /** When a pool lends: its clock, and how long after a leaf's grant returns it grants no lent request. */
52
+ export interface Lending {
53
+ readonly settleMs: number;
54
+ readonly now: () => number;
55
+ }
56
+ /** The line a run's pool says of `summary` when it closes; null for a pool that starved no leaf and lent nothing. */
57
+ export declare function describeIdle(summary: PoolSummary): string | null;
41
58
  export type CloseOutcome = {
42
59
  ok: true;
43
60
  } | {
@@ -70,6 +87,8 @@ export interface AskContext {
70
87
  readonly task?: string | undefined;
71
88
  /** The kernel killed the command for memory: it is run again, granted only while nothing else holds a grant. */
72
89
  readonly alone?: boolean | undefined;
90
+ /** Its cases each ask the pool for a token of their own. */
91
+ readonly gated?: boolean | undefined;
73
92
  }
74
93
  /**
75
94
  * Ask the immediate parent pool for `want` tokens, charged `memory` bytes: the task's last recorded peak, or null when
@@ -81,6 +100,13 @@ export interface AskContext {
81
100
  * the child beside its parent's count.
82
101
  */
83
102
  export declare function takeParentCpuTokens(parent: InheritedCpuPool, want: number, memory: number | null, context?: AskContext): Promise<TokenGrant>;
103
+ /**
104
+ * One token of `parent` asked for one test case of a leaf that holds a grant of it, named `task` in the request
105
+ * (specs/cowshed/05_gateway.md, "A case starts on a core", Inside a hold). The pool grants it only while no other
106
+ * request waits. `release` gives the token back, or withdraws the request while it waits. A pool that refuses, falls
107
+ * silent or is gone grants nothing: the case waits for a token of its leaf's own grant.
108
+ */
109
+ export declare function lendParentToken(parent: InheritedCpuPool, task: string, left: number): CaseCore;
84
110
  /**
85
111
  * Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
86
112
  * grants, ends its child connections, drains its jobserver fifo and removes its directory. A run's own
@@ -88,9 +114,10 @@ export declare function takeParentCpuTokens(parent: InheritedCpuPool, want: numb
88
114
  * (`liveUsage`); a sub-pool charges none (null).
89
115
  * Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
90
116
  */
91
- export declare function createCpuPool(tokens: number, closed: Promise<void>, memory: RunMemory | null, liveUsage?: (bound: string) => LiveUsageReading): Promise<{
117
+ export declare function createCpuPool(tokens: number, closed: Promise<void>, memory: RunMemory | null, liveUsage?: (bound: string) => LiveUsageReading, lending?: Lending): Promise<{
92
118
  ok: true;
93
119
  pool: CpuPool;
120
+ summary: () => PoolSummary;
94
121
  } | {
95
122
  ok: false;
96
123
  error: string;
@@ -1 +1 @@
1
- {"version":3,"file":"cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAiB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