@smoothbricks/nx-plugin 0.4.29 → 0.4.31

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 (110) hide show
  1. package/README.md +104 -25
  2. package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
  3. package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-test-clocks.js +28 -0
  5. package/dist/bounded-test-policy.d.ts +1 -8
  6. package/dist/bounded-test-policy.d.ts.map +1 -1
  7. package/dist/bounded-test-policy.js +2 -8
  8. package/dist/cargo-closure-input.d.ts +11 -0
  9. package/dist/cargo-closure-input.d.ts.map +1 -1
  10. package/dist/cargo-closure-input.js +16 -6
  11. package/dist/ensure-built-receipt.d.ts +8 -2
  12. package/dist/ensure-built-receipt.d.ts.map +1 -1
  13. package/dist/ensure-built-receipt.js +45 -13
  14. package/dist/ensure-built-witness.d.ts +40 -4
  15. package/dist/ensure-built-witness.d.ts.map +1 -1
  16. package/dist/ensure-built-witness.js +68 -15
  17. package/dist/ensure-built.d.ts.map +1 -1
  18. package/dist/ensure-built.js +11 -3
  19. package/dist/executors/bounded-exec/cpu-pool.d.ts +7 -3
  20. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/cpu-pool.js +9 -4
  22. package/dist/executors/bounded-exec/cpu-tokens.d.ts +22 -5
  23. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/cpu-tokens.js +189 -18
  25. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  26. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/executor.js +38 -14
  28. package/dist/executors/bounded-exec/no-space.d.ts +8 -0
  29. package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
  30. package/dist/executors/bounded-exec/no-space.js +31 -0
  31. package/dist/executors/bounded-exec/ram-temp.d.ts +3 -0
  32. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  33. package/dist/executors/bounded-exec/ram-temp.js +15 -4
  34. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -0
  35. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -0
  36. package/dist/executors/bounded-exec/run-cpu-pool.js +63 -0
  37. package/dist/executors/bounded-exec/verdict.d.ts +34 -4
  38. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/verdict.js +54 -3
  40. package/dist/graph-input-contract.d.ts +4 -0
  41. package/dist/graph-input-contract.d.ts.map +1 -1
  42. package/dist/graph-input-contract.js +17 -4
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +13 -3
  46. package/dist/owned-installation.d.ts +14 -0
  47. package/dist/owned-installation.d.ts.map +1 -0
  48. package/dist/owned-installation.js +324 -0
  49. package/dist/producer-receipts.d.ts.map +1 -1
  50. package/dist/producer-receipts.js +15 -10
  51. package/dist/test-backstop.d.ts +9 -0
  52. package/dist/test-backstop.d.ts.map +1 -0
  53. package/dist/test-backstop.js +10 -0
  54. package/dist/test-clock-policy.d.ts +30 -0
  55. package/dist/test-clock-policy.d.ts.map +1 -0
  56. package/dist/test-clock-policy.js +686 -0
  57. package/dist/testing.d.ts.map +1 -1
  58. package/dist/testing.js +8 -1
  59. package/managed/raw/tooling/direnv/developer-links.ts +1 -8
  60. package/managed/raw/tooling/direnv/setup-environment.ts +13 -1
  61. package/package.json +15 -4
  62. package/src/__tests__/cargo-closure-fixture.ts +113 -0
  63. package/src/__tests__/counted-cargo.ts +8 -25
  64. package/src/__tests__/directory-change.ts +27 -0
  65. package/src/__tests__/owned-installation.ts +4 -164
  66. package/src/__tests__/past-tick.ts +12 -0
  67. package/src/bin/smoo-nx-test-clocks.ts +29 -0
  68. package/src/bounded-test-policy.ts +2 -8
  69. package/src/cargo-closure-input.property.test.ts +50 -0
  70. package/src/cargo-closure-input.test.ts +15 -112
  71. package/src/cargo-closure-input.ts +23 -6
  72. package/src/cargo-closure-key.test.ts +240 -0
  73. package/src/cargo-resolve-cache.test.ts +29 -7
  74. package/src/ensure-built-receipt.ts +56 -13
  75. package/src/ensure-built-witness.test.ts +113 -4
  76. package/src/ensure-built-witness.ts +75 -16
  77. package/src/ensure-built.test.ts +74 -2
  78. package/src/ensure-built.ts +13 -2
  79. package/src/executors/bounded-exec/cpu-pool.test.ts +18 -0
  80. package/src/executors/bounded-exec/cpu-pool.ts +10 -4
  81. package/src/executors/bounded-exec/cpu-tokens.test.ts +205 -0
  82. package/src/executors/bounded-exec/cpu-tokens.ts +229 -22
  83. package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
  84. package/src/executors/bounded-exec/executor-host.test.ts +23 -11
  85. package/src/executors/bounded-exec/executor.test.ts +189 -63
  86. package/src/executors/bounded-exec/executor.ts +39 -13
  87. package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
  88. package/src/executors/bounded-exec/no-space.ts +40 -0
  89. package/src/executors/bounded-exec/ram-temp-host.test.ts +9 -8
  90. package/src/executors/bounded-exec/ram-temp.test.ts +32 -18
  91. package/src/executors/bounded-exec/ram-temp.ts +17 -4
  92. package/src/executors/bounded-exec/run-cpu-pool.test.ts +76 -0
  93. package/src/executors/bounded-exec/run-cpu-pool.ts +75 -0
  94. package/src/executors/bounded-exec/verdict.test.ts +125 -25
  95. package/src/executors/bounded-exec/verdict.ts +78 -3
  96. package/src/graph-input-contract.test.ts +8 -0
  97. package/src/graph-input-contract.ts +26 -4
  98. package/src/index.test.ts +12 -2
  99. package/src/index.ts +13 -3
  100. package/src/nextest-extraction.test.ts +114 -4
  101. package/src/nx-daemon-claim.test.ts +5 -3
  102. package/src/nx-daemon-idle-policy.test.ts +22 -18
  103. package/src/nx-daemon-validity.test.ts +5 -13
  104. package/src/owned-installation.ts +174 -0
  105. package/src/producer-receipts.ts +15 -10
  106. package/src/test-backstop.ts +11 -0
  107. package/src/test-clock-policy.test.ts +338 -0
  108. package/src/test-clock-policy.ts +708 -0
  109. package/src/testing.ts +8 -1
  110. package/test-timings.json +4 -0
@@ -1,22 +1,31 @@
1
- import { afterEach, describe, expect, it } from 'bun:test';
1
+ import { afterEach, describe, expect, it, jest } from 'bun:test';
2
2
  import { rmSync } from 'node:fs';
3
3
  import { mkdtemp, readFile } from 'node:fs/promises';
4
4
  import { createServer, type Server, type Socket } from 'node:net';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { join } from 'node:path';
7
+ import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from '../../bounded-test-policy.js';
7
8
  import { ownedSocketDirectory } from '../../testing.js';
8
9
  import { diskClassOf, takeDiskLease, unixMicros, waitRecord } from './disk-lease.js';
10
+ import { holdLease, type LeaseBounds } from './gateway-lease.js';
9
11
 
10
12
  /**
11
- * Real, short bounds: the client's half-close and grant expiry are socket behavior against the
12
- * platform clock, which fake timers would not drive through a real Unix socket.
13
+ * The leg's backstop for each lease bound these cases are not about. The stand-ins answer at once, refuse at once, or
14
+ * are absent, so no such bound decides a verdict; a case that did wait on one would hang, and the leg's idle timeout
15
+ * ends the run (packages/nx-plugin/README.md, "Bounded Test Targets"). `grantMs: null` waits for as long as the gateway
16
+ * keeps the request queued.
13
17
  */
14
- const QUICK = { ackMs: 200, afterCloseMs: 5_000, grantMs: 500 };
18
+ const BACKSTOP: LeaseBounds = {
19
+ ackMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
20
+ afterCloseMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
21
+ grantMs: null,
22
+ };
15
23
 
16
24
  const servers: Server[] = [];
17
25
  const directories: string[] = [];
18
26
 
19
27
  afterEach(() => {
28
+ jest.useRealTimers();
20
29
  for (const server of servers.splice(0)) {
21
30
  server.close();
22
31
  }
@@ -78,7 +87,7 @@ describe('cowshed disk-lifecycle lease client', () => {
78
87
  // after the peer closes until the server ends it, so 'close' is not that signal on Linux.
79
88
  client.on('end', () => close());
80
89
  });
81
- const lease = await takeDiskLease(socket, 'storage', '/usr/bin/hdiutil detach /dev/disk9', QUICK, 'shared');
90
+ const lease = await takeDiskLease(socket, 'storage', '/usr/bin/hdiutil detach /dev/disk9', BACKSTOP, 'shared');
82
91
  expect(await request).toBe(
83
92
  '{"op":"disk-lease","class":"storage","command":"/usr/bin/hdiutil detach /dev/disk9"}\n',
84
93
  );
@@ -90,14 +99,22 @@ describe('cowshed disk-lifecycle lease client', () => {
90
99
  });
91
100
 
92
101
  it('recognizes a gateway that predates leases by its answer to the half-close', async () => {
102
+ // The ack bound is the subject: this gateway answers nothing until it reads EOF, so only the expiry of the ack bound
103
+ // half-closes the request. The bound is armed on connect, right after the request is written, and the read below
104
+ // happens before the advance, so the advance expires an armed ack bound and no other bound is due.
105
+ jest.useFakeTimers();
106
+ const { promise: requested, resolve: sawRequest } = Promise.withResolvers<void>();
93
107
  const socket = await gateway((client) => {
94
- client.resume();
108
+ client.once('data', () => sawRequest());
95
109
  client.on('end', () =>
96
110
  client.end('{"ok":false,"code":"invalid-request","error":"unknown gateway control operation"}\n'),
97
111
  );
98
112
  });
99
- const lease = await takeDiskLease(socket, 'namespace', '/sbin/umount /x', QUICK, 'shared');
100
- expect(lease).toEqual({
113
+ const ackMs = 200;
114
+ const lease = takeDiskLease(socket, 'namespace', '/sbin/umount /x', { ...BACKSTOP, ackMs }, 'shared');
115
+ await requested;
116
+ jest.advanceTimersByTime(ackMs);
117
+ expect(await lease).toEqual({
101
118
  granted: false,
102
119
  cause: 'predates',
103
120
  reason:
@@ -113,7 +130,7 @@ describe('cowshed disk-lifecycle lease client', () => {
113
130
  client.write('{"ok":true,"lease":"queued"}\n{"ok":true,"lease":"granted"}\n');
114
131
  });
115
132
  });
116
- const lease = await takeDiskLease(socket, 'storage', '/usr/bin/hdiutil detach /dev/disk9', QUICK, 'alone');
133
+ const lease = await takeDiskLease(socket, 'storage', '/usr/bin/hdiutil detach /dev/disk9', BACKSTOP, 'alone');
117
134
  expect(await request).toBe(
118
135
  '{"op":"disk-lease","class":"storage","share":"alone","command":"/usr/bin/hdiutil detach /dev/disk9"}\n',
119
136
  );
@@ -131,21 +148,38 @@ describe('cowshed disk-lifecycle lease client', () => {
131
148
  ),
132
149
  );
133
150
  });
134
- const lease = await takeDiskLease(socket, 'storage', 'x', QUICK, 'alone');
151
+ const lease = await takeDiskLease(socket, 'storage', 'x', BACKSTOP, 'alone');
135
152
  expect(lease.granted === false && lease.cause).toBe('predates-field');
136
153
  });
137
154
 
138
155
  it('runs unleased, said as absent, when no gateway listens', async () => {
139
- const lease = await takeDiskLease(await socketPath('none.sock'), 'storage', 'x', QUICK, 'shared');
156
+ const lease = await takeDiskLease(await socketPath('none.sock'), 'storage', 'x', BACKSTOP, 'shared');
140
157
  expect(lease.granted === false && lease.cause).toBe('absent');
141
158
  });
142
159
 
143
160
  it('runs unleased when the grant never comes', async () => {
161
+ // The grant bound is the subject, so this case advances a clock it owns. `holdLease` arms the grant bound when the
162
+ // gateway's `queued` is read, and `sawQueued` runs in that same read, so the advance below expires an armed grant
163
+ // bound and nothing else is due: the grant never comes, so only that expiry ends the wait.
164
+ jest.useFakeTimers();
165
+ const { promise: queued, resolve: sawQueued } = Promise.withResolvers<void>();
144
166
  const socket = await gateway((client) => {
145
167
  client.once('data', () => client.write('{"ok":true,"lease":"queued"}\n'));
146
168
  });
147
- const lease = await takeDiskLease(socket, 'storage', 'x', QUICK, 'shared');
148
- expect(lease).toEqual({ granted: false, cause: 'other', reason: 'the gateway granted nothing within 500 ms' });
169
+ const lease = holdLease(
170
+ socket,
171
+ { op: 'disk-lease', class: 'storage', command: 'x' },
172
+ 'disk leases',
173
+ { ...BACKSTOP, grantMs: 500 },
174
+ () => sawQueued(),
175
+ );
176
+ await queued;
177
+ jest.advanceTimersByTime(500);
178
+ expect(await lease).toEqual({
179
+ granted: false,
180
+ cause: 'other',
181
+ reason: 'the gateway granted nothing within 500 ms',
182
+ });
149
183
  });
150
184
 
151
185
  it('appends a start and an end line per wait, numbered per record and stamped in microseconds', async () => {
@@ -5,6 +5,7 @@ import { createServer, type Socket } from 'node:net';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { basename, dirname, join } from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
+ import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from '../../bounded-test-policy.js';
8
9
  import { CPU_POOL_ENV, type CpuPool, createCpuPool } from './cpu-pool.js';
9
10
  import { CPU_TOKENS_ENV } from './cpu-tokens.js';
10
11
  import type { BoundedExecOptions } from './schema.js';
@@ -37,8 +38,11 @@ const ACTIVE_RESOURCES = 'cowshed-test active-resources ';
37
38
  const CHURN_NAMES = ['churna', 'churnb'] as const;
38
39
  /** Written into a case's root to stop its churn workers; each checks it between runs, never mid-run. */
39
40
  const CHURN_STOP = 'churn.stop';
40
- /** One churn run: `true` on one token, so each lease is a real acquire, run and release. */
41
- const CHURN_OPTIONS: BoundedExecOptions = { command: 'true', timeoutMs: 20_000, parallelism: 1 };
41
+ /**
42
+ * One churn run: `true` on one token, so each lease is a real acquire, run and release. Its `timeoutMs` is the leg
43
+ * backstop: a run ends on its own exit, and only a hung run reaches the bound (`specs/cowshed/08_testing.md:511-514`).
44
+ */
45
+ const CHURN_OPTIONS: BoundedExecOptions = { command: 'true', timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 };
42
46
  /** A churn worker's stdout: a `begin` line before each run it starts, a `ran` line after each run that succeeded. */
43
47
  const CHURN_BEGIN = /^cowshed-test churn [a-z]+ begin [0-9]+$/gm;
44
48
  const CHURN_RAN = /^cowshed-test churn [a-z]+ ran [0-9]+$/gm;
@@ -128,7 +132,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
128
132
  const leafScript = await writeRunner(
129
133
  root,
130
134
  'leaf',
131
- { command: `node -e "console.log('leaf')"`, timeoutMs: 20_000, parallelism: 1 },
135
+ { command: `node -e "console.log('leaf')"`, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 },
132
136
  leafDirectory,
133
137
  );
134
138
  const nestedDirectory = join(root, 'nested');
@@ -138,7 +142,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
138
142
  const run = await startRunner(
139
143
  root,
140
144
  'nested',
141
- { command: nestedCommand, cwd: PACKAGE_ROOT, timeoutMs: 20_000, parallelism: 2 },
145
+ { command: nestedCommand, cwd: PACKAGE_ROOT, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 2 },
142
146
  nestedDirectory,
143
147
  childEnv(pool.environment),
144
148
  );
@@ -175,7 +179,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
175
179
  `const options = ${JSON.stringify({
176
180
  command: `node -e "console.log('lease')"`,
177
181
  cwd: PACKAGE_ROOT,
178
- timeoutMs: 20_000,
182
+ timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
179
183
  parallelism: 1,
180
184
  })};`,
181
185
  `const context = ${JSON.stringify({ root })};`,
@@ -209,7 +213,11 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
209
213
  startRunner(
210
214
  root,
211
215
  name,
212
- { command: siblingCommand(barrier.port, name), timeoutMs: 20_000, parallelism: 1 },
216
+ {
217
+ command: siblingCommand(barrier.port, name),
218
+ timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
219
+ parallelism: 1,
220
+ },
213
221
  join(root, name),
214
222
  childEnv(pool.environment),
215
223
  ),
@@ -266,7 +274,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
266
274
  await withPool(1, async (outer) => {
267
275
  const options: BoundedExecOptions = {
268
276
  command: `node -e "console.log('actual-tokens=' + process.env.${CPU_TOKENS_ENV})"`,
269
- timeoutMs: 20_000,
277
+ timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
270
278
  parallelism: 1,
271
279
  };
272
280
  const directory = join(root, 'stale');
@@ -329,8 +337,8 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
329
337
  'outlives',
330
338
  {
331
339
  command: `sh -c 'echo started; read -r line < "$0"; echo finished' '${go}'`,
332
- timeoutMs: 30_000,
333
- killAfterMs: 2_000,
340
+ timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
341
+ killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
334
342
  parallelism: 1,
335
343
  },
336
344
  join(root, 'outlives'),
@@ -356,7 +364,7 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
356
364
  const unremovable = await startRunner(
357
365
  root,
358
366
  'unremovable',
359
- { command: UNREMOVABLE_COMMAND, timeoutMs: 20_000, parallelism: 1 },
367
+ { command: UNREMOVABLE_COMMAND, timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, parallelism: 1 },
360
368
  join(root, 'unremovable'),
361
369
  childEnv(pool.environment),
362
370
  );
@@ -371,7 +379,11 @@ describe('@smoothbricks/nx-plugin:bounded-exec host proofs', () => {
371
379
  const next = await startRunner(
372
380
  root,
373
381
  'next',
374
- { command: `node -e "console.log(process.env.${CPU_TOKENS_ENV})"`, timeoutMs: 20_000, parallelism: 1 },
382
+ {
383
+ command: `node -e "console.log(process.env.${CPU_TOKENS_ENV})"`,
384
+ timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
385
+ parallelism: 1,
386
+ },
375
387
  join(root, 'next'),
376
388
  childEnv(pool.environment),
377
389
  );