@smoothbricks/nx-plugin 0.4.29 → 0.4.30

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 (95) hide show
  1. package/README.md +83 -15
  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/executor.d.ts +1 -1
  23. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/executor.js +35 -12
  25. package/dist/executors/bounded-exec/no-space.d.ts +8 -0
  26. package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
  27. package/dist/executors/bounded-exec/no-space.js +31 -0
  28. package/dist/executors/bounded-exec/ram-temp.d.ts +3 -0
  29. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  30. package/dist/executors/bounded-exec/ram-temp.js +15 -4
  31. package/dist/executors/bounded-exec/verdict.d.ts +34 -4
  32. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  33. package/dist/executors/bounded-exec/verdict.js +54 -3
  34. package/dist/graph-input-contract.d.ts +4 -0
  35. package/dist/graph-input-contract.d.ts.map +1 -1
  36. package/dist/graph-input-contract.js +17 -4
  37. package/dist/owned-installation.d.ts +14 -0
  38. package/dist/owned-installation.d.ts.map +1 -0
  39. package/dist/owned-installation.js +324 -0
  40. package/dist/producer-receipts.d.ts.map +1 -1
  41. package/dist/producer-receipts.js +15 -10
  42. package/dist/test-backstop.d.ts +9 -0
  43. package/dist/test-backstop.d.ts.map +1 -0
  44. package/dist/test-backstop.js +10 -0
  45. package/dist/test-clock-policy.d.ts +30 -0
  46. package/dist/test-clock-policy.d.ts.map +1 -0
  47. package/dist/test-clock-policy.js +686 -0
  48. package/dist/testing.d.ts.map +1 -1
  49. package/dist/testing.js +8 -1
  50. package/managed/raw/tooling/direnv/developer-links.ts +1 -8
  51. package/managed/raw/tooling/direnv/setup-environment.ts +0 -1
  52. package/package.json +15 -4
  53. package/src/__tests__/cargo-closure-fixture.ts +113 -0
  54. package/src/__tests__/counted-cargo.ts +8 -25
  55. package/src/__tests__/directory-change.ts +27 -0
  56. package/src/__tests__/owned-installation.ts +4 -164
  57. package/src/__tests__/past-tick.ts +12 -0
  58. package/src/bin/smoo-nx-test-clocks.ts +29 -0
  59. package/src/bounded-test-policy.ts +2 -8
  60. package/src/cargo-closure-input.property.test.ts +50 -0
  61. package/src/cargo-closure-input.test.ts +15 -112
  62. package/src/cargo-closure-input.ts +23 -6
  63. package/src/cargo-closure-key.test.ts +239 -0
  64. package/src/cargo-resolve-cache.test.ts +29 -7
  65. package/src/ensure-built-receipt.ts +56 -13
  66. package/src/ensure-built-witness.test.ts +113 -4
  67. package/src/ensure-built-witness.ts +75 -16
  68. package/src/ensure-built.test.ts +74 -2
  69. package/src/ensure-built.ts +13 -2
  70. package/src/executors/bounded-exec/cpu-pool.test.ts +18 -0
  71. package/src/executors/bounded-exec/cpu-pool.ts +10 -4
  72. package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
  73. package/src/executors/bounded-exec/executor-host.test.ts +23 -11
  74. package/src/executors/bounded-exec/executor.test.ts +189 -63
  75. package/src/executors/bounded-exec/executor.ts +36 -11
  76. package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
  77. package/src/executors/bounded-exec/no-space.ts +40 -0
  78. package/src/executors/bounded-exec/ram-temp-host.test.ts +9 -8
  79. package/src/executors/bounded-exec/ram-temp.test.ts +32 -18
  80. package/src/executors/bounded-exec/ram-temp.ts +17 -4
  81. package/src/executors/bounded-exec/verdict.test.ts +125 -25
  82. package/src/executors/bounded-exec/verdict.ts +78 -3
  83. package/src/graph-input-contract.test.ts +8 -0
  84. package/src/graph-input-contract.ts +26 -4
  85. package/src/nextest-extraction.test.ts +114 -4
  86. package/src/nx-daemon-claim.test.ts +5 -3
  87. package/src/nx-daemon-idle-policy.test.ts +22 -18
  88. package/src/nx-daemon-validity.test.ts +5 -13
  89. package/src/owned-installation.ts +174 -0
  90. package/src/producer-receipts.ts +15 -10
  91. package/src/test-backstop.ts +11 -0
  92. package/src/test-clock-policy.test.ts +338 -0
  93. package/src/test-clock-policy.ts +708 -0
  94. package/src/testing.ts +8 -1
  95. package/test-timings.json +3 -0
@@ -0,0 +1,338 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { type ClockOracleKind, findClockOracles, formatClockOracle, TEST_CLOCK_ORACLE } from './test-clock-policy.js';
7
+ import { diffScope } from './test-walk-policy.js';
8
+
9
+ const lines = (...source: string[]): string => `${source.join('\n')}\n`;
10
+ // Assembled so this file's own cases carry no runner flag a scan of it would read as a bound.
11
+ const flag = ['--time', 'out'].join('');
12
+
13
+ describe('test-clock-policy', () => {
14
+ // One walk: each planted site and each control is a step over one fixture directory, then the diff scope.
15
+ it('refuses runner and test-owned deadlines, elapsed-time asserts and clocked bounds, passes the controls, and scopes to changed cases', () => {
16
+ const root = mkdtempSync(join(tmpdir(), 'test-clock-policy-'));
17
+ const write = (file: string, source: string): void => {
18
+ mkdirSync(dirname(join(root, file)), { recursive: true });
19
+ writeFileSync(join(root, file), source);
20
+ };
21
+ const kinds = (file: string) => findClockOracles(root, [file]).map((oracle) => oracle.kind);
22
+ const git = (...args: string[]): string => {
23
+ const result = spawnSync(
24
+ 'git',
25
+ ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', ...args],
26
+ {
27
+ cwd: root,
28
+ encoding: 'utf8',
29
+ env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' },
30
+ },
31
+ );
32
+ if (result.status !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`);
33
+ return result.stdout;
34
+ };
35
+ try {
36
+ const planted: readonly [ClockOracleKind, string, string][] = [
37
+ ['runner-deadline', 'tests/a.test.ts', "test('slow', async () => { await child.exited; }, 60_000);"],
38
+ [
39
+ 'runner-deadline',
40
+ 'tests/a.test.ts',
41
+ "test('slow', async () => { await child.exited; }, { timeout: 60_000 });",
42
+ ],
43
+ ['runner-deadline', 'tests/a.test.ts', "test.each([1])('n %d', async (n) => { await run(n); }, 30_000);"],
44
+ ['runner-deadline', 'tests/a.test.ts', 'setDefaultTimeout(60_000);'],
45
+ [
46
+ 'clock-delta',
47
+ 'tests/a.test.ts',
48
+ "test('fast', async () => { const started = Date.now(); await run(); expect(Date.now() - started).toBeLessThan(5_000); });",
49
+ ],
50
+ [
51
+ 'clock-delta',
52
+ 'tests/a.test.ts',
53
+ "test('fast', () => { const t = performance.now(); work(); const elapsedMs = performance.now() - t; expect(elapsedMs < 1_000).toBe(true); });",
54
+ ],
55
+ [
56
+ 'clock-delta',
57
+ 'tests/a.test.ts',
58
+ "test('deadline', () => { const deadline = Date.now() + 1_000; work(); expect(Date.now()).toBeLessThanOrEqual(deadline); });",
59
+ ],
60
+ [
61
+ 'clock-delta',
62
+ 'tests/a.test.ts',
63
+ "test('close', () => { expect(Math.abs(stamp() - Date.now())).not.toBeGreaterThan(1); });",
64
+ ],
65
+ [
66
+ 'clock-delta',
67
+ 'tests/quick.rs',
68
+ lines(
69
+ '#[test]',
70
+ 'fn quick() {',
71
+ ' let started = Instant::now();',
72
+ ' work();',
73
+ ' assert!(started.elapsed() < Duration::from_secs(10), "slow");',
74
+ '}',
75
+ ),
76
+ ],
77
+ [
78
+ 'clock-delta',
79
+ 'src/quick.rs',
80
+ lines(
81
+ 'fn work() {}',
82
+ '#[cfg(test)]',
83
+ 'mod tests {',
84
+ ' #[test]',
85
+ ' fn quick() {',
86
+ ' let started = Instant::now();',
87
+ ' let elapsed = started.elapsed();',
88
+ ' assert!(Duration::from_millis(500) > elapsed);',
89
+ ' }',
90
+ '}',
91
+ ),
92
+ ],
93
+ [
94
+ 'clocked-bound',
95
+ 'tests/a.test.ts',
96
+ `test('times out', async () => { const result = await runBoundedExec({ command: 'node -e "setTimeout(() => {}, 5000)"', timeoutMs: 50 }); expect(result.success).toBe(false); });`,
97
+ ],
98
+ [
99
+ 'clocked-bound',
100
+ 'tests/a.test.ts',
101
+ lines(
102
+ "const SLOW = `test('slow', async () => { await new Promise((r) => setTimeout(r, 5000)); });`;",
103
+ `test('per-test bound', async () => { expect(await verdictOf('bun test ${flag}=100 ./slow.test.ts', { 'slow.test.ts': SLOW })).toEqual({ outcome: 'bound' }); });`,
104
+ ),
105
+ ],
106
+ [
107
+ 'clocked-bound',
108
+ 'tests/a.test.ts',
109
+ "test('idle', async () => { await run({ argv: ['sleep', '5'], idleTimeoutSeconds: 1 }); });",
110
+ ],
111
+ [
112
+ 'clocked-bound',
113
+ 'tests/a.test.ts',
114
+ "test('short stand-in', async () => { const path = await fakeChild('exec sleep 30'); await openService({ path, lspQueryTimeoutMs: 1_000 }); });",
115
+ ],
116
+ [
117
+ 'clocked-bound',
118
+ 'tests/a.test.ts',
119
+ `test('talking child under a progress bound', async () => { await verdictOf('node -e "setInterval(() => console.log(1), 10)"', { idleTimeoutMs: 100 }); });`,
120
+ ],
121
+ [
122
+ 'clocked-bound',
123
+ 'tests/bound.rs',
124
+ lines(
125
+ '#[test]',
126
+ 'fn bound() {',
127
+ ' let outcome = run(Command::new("sleep").arg("5"), Options { timeout_ms: 50 });',
128
+ ' assert!(outcome.timed_out);',
129
+ '}',
130
+ ),
131
+ ],
132
+ [
133
+ 'test-deadline',
134
+ 'tests/deadline.rs',
135
+ lines(
136
+ '#[test]',
137
+ 'fn event() {',
138
+ ' let (tx, rx) = channel();',
139
+ ' spawn(tx);',
140
+ ' rx.recv_timeout(Duration::from_secs(10)).expect("the event");',
141
+ '}',
142
+ ),
143
+ ],
144
+ [
145
+ 'test-deadline',
146
+ 'tests/deadline.rs',
147
+ lines(
148
+ '#[tokio::test]',
149
+ 'async fn event() {',
150
+ ' tokio::time::timeout(Duration::from_millis(500), served()).await.expect("served");',
151
+ '}',
152
+ ),
153
+ ],
154
+ ];
155
+ for (const [kind, file, source] of planted) {
156
+ write(file, source);
157
+ expect([file, source, kinds(file)]).toEqual([file, source, [kind]]);
158
+ rmSync(join(root, file));
159
+ }
160
+ write('tests/a.test.ts', planted[4]?.[2] ?? '');
161
+ const diagnostic = findClockOracles(root, ['tests/a.test.ts']).map(formatClockOracle)[0] ?? '';
162
+ for (const part of [
163
+ `error[${TEST_CLOCK_ORACLE.id}]: ${TEST_CLOCK_ORACLE.message['clock-delta']}`,
164
+ ' --> tests/a.test.ts:1:',
165
+ ' = help: Elapsed time on a loaded host',
166
+ ])
167
+ expect(diagnostic).toContain(part);
168
+ rmSync(join(root, 'tests/a.test.ts'));
169
+
170
+ const controls: readonly [string, string][] = [
171
+ [
172
+ 'tests/c.test.ts',
173
+ "test('injected clock', () => { const timer = new MemoryTimer(); const started = timer.now(); timer.advance(30); expect(timer.now() - started).toBeLessThan(31); });",
174
+ ],
175
+ [
176
+ 'tests/c.test.ts',
177
+ `test('exit decides', async () => { const run = await onProgressClock(() => false, 0, () => verdictOf('node -e ""', { timeoutMs: 5_000 })); expect(run.result).toEqual({ outcome: 'passed' }); });`,
178
+ ],
179
+ [
180
+ 'tests/c.test.ts',
181
+ `test('subject held off by construction', async () => { const result = await runBoundedExec({ command: 'node -e "process.stdin.resume()"', timeoutMs: 50 }); expect(result.terminalOutput).toContain('timeoutMs=50'); });`,
182
+ ],
183
+ [
184
+ 'tests/c.test.ts',
185
+ `test('bounds that cannot decide', async () => { await runBoundedExec({ command: 'node -e "setTimeout(() => {}, 400)"', idleTimeoutMs: 0, timeoutMs: 180_000 }); });`,
186
+ ],
187
+ [
188
+ 'tests/c.test.ts',
189
+ "test('waited at least', async () => { const started = performance.now(); await lock.acquired; expect(performance.now() - started).toBeGreaterThanOrEqual(100); });",
190
+ ],
191
+ [
192
+ 'tests/c.test.ts',
193
+ "test('stamped after', () => { const before = Date.now(); const record = make(); expect(record.at).toBeGreaterThanOrEqual(before); expect(before).toBeLessThanOrEqual(record.at); });",
194
+ ],
195
+ ['tests/c.test.ts', "test('cpu time', () => { expect(cpuTime.total).toBeLessThanOrEqual(100_000); });"],
196
+ [
197
+ 'tests/c.test.ts',
198
+ "test('stand-in outlasts the leg', async () => { const path = await fakeChild('exec sleep 3600'); await openService({ path, lspQueryTimeoutMs: 1_000 }); });",
199
+ ],
200
+ [
201
+ 'tests/c.test.ts',
202
+ `test('silent child held past the backstop', async () => { await runBoundedExec({ command: 'node -e "setInterval(() => {}, 1 << 30)"', timeoutMs: 50, killAfterMs: 10 }); });`,
203
+ ],
204
+ [
205
+ 'tests/c.test.ts',
206
+ `test('a ceiling and a progress bound', async () => { await verdictOf('node -e "setInterval(() => console.log(1), 10)"', { timeoutMs: 200 }); await verdictOf('node -e "setInterval(() => {}, 1 << 30)"', { idleTimeoutMs: 100 }); });`,
207
+ ],
208
+ [
209
+ 'tests/c.test.ts',
210
+ `test('virtual progress clock', async () => { const script = "setInterval(() => console.error('SLOW'), 50);"; await onProgressClock((chunk) => chunk.includes('SLOW'), 400, () => runBoundedExec({ command: 'node runner.js', idleTimeoutMs: 400 })); expect(verdict).toMatchObject({ outcome: 'wedged', idleMs: 400 }); });`,
211
+ ],
212
+ [
213
+ 'tests/c.rs',
214
+ lines(
215
+ '#[tokio::test]',
216
+ 'async fn parked() {',
217
+ ' let child = Command::new("sleep").arg("1");',
218
+ ' assert!(tokio::time::timeout(Duration::from_millis(500), &mut parked).await.is_err());',
219
+ '}',
220
+ ),
221
+ ],
222
+ [
223
+ 'tests/c.test.ts',
224
+ lines(
225
+ 'const elapsed = Date.now() - t0;',
226
+ "test('shadowed', () => { const elapsed = timer.elapsed(); expect(elapsed).toBeLessThan(5); });",
227
+ ),
228
+ ],
229
+ [
230
+ 'tests/c.rs',
231
+ lines(
232
+ '#[test]',
233
+ 'fn waited() {',
234
+ ' let started = Instant::now();',
235
+ ' acquire();',
236
+ ' assert!(started.elapsed() >= Duration::from_millis(100));',
237
+ ' let clock = ManualClock::new();',
238
+ ' clock.advance(Duration::from_millis(30));',
239
+ ' assert!(clock.elapsed() < Duration::from_millis(31));',
240
+ '}',
241
+ ),
242
+ ],
243
+ [
244
+ 'tests/c.rs',
245
+ lines(
246
+ '#[test]',
247
+ 'fn stamped() {',
248
+ ' let wall_before = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_micros();',
249
+ ' let since_us = start();',
250
+ ' assert!(since_us >= wall_before);',
251
+ ' let config = format!(r#"timeoutMs = 1; cmd = "sleep 5""#);',
252
+ '}',
253
+ ),
254
+ ],
255
+ [
256
+ 'tests/c.rs',
257
+ lines(
258
+ '#[tokio::test]',
259
+ 'async fn quiet() {',
260
+ ' assert!(timeout(Duration::from_millis(50), rx.recv()).await.is_err());',
261
+ ' timeout(NO_PROGRESS, served()).await.expect("served");',
262
+ '}',
263
+ ),
264
+ ],
265
+ [
266
+ 'tests/c.rs',
267
+ lines(
268
+ '#[tokio::test(start_paused = true)]',
269
+ 'async fn virtual_time() {',
270
+ ' let deadline = Instant::now() + Duration::from_secs(5);',
271
+ ' advance().await;',
272
+ ' assert!(Instant::now() < deadline);',
273
+ ' timeout(Duration::from_millis(500), served()).await.expect("served");',
274
+ '}',
275
+ ),
276
+ ],
277
+ ];
278
+ for (const [file, source] of controls) {
279
+ write(file, source);
280
+ expect([source, kinds(file)]).toEqual([source, []]);
281
+ rmSync(join(root, file));
282
+ }
283
+
284
+ // Diff scope: an existing elapsed bound in the upstream refuses nothing until its own case is edited, and then the
285
+ // whole case is examined; the bin judges the same changes.
286
+ const legacy = [
287
+ "test('old elapsed bound', async () => {",
288
+ ' const started = Date.now();',
289
+ ' await run();',
290
+ ' expect(Date.now() - started).toBeLessThan(5_000);',
291
+ '});',
292
+ "test('event case', async () => {",
293
+ ' await child.exited;',
294
+ '});',
295
+ ];
296
+ write('tests/legacy.test.ts', lines(...legacy));
297
+ git('init', '--quiet', '-b', 'main');
298
+ git('add', '.');
299
+ git('commit', '--quiet', '-m', 'base');
300
+ git('checkout', '--quiet', '-b', 'topic');
301
+ const base = git('rev-parse', 'HEAD').trim();
302
+ const judged = () => {
303
+ const scope = diffScope(root, base);
304
+ if (!scope.ok) throw new Error(scope.reason);
305
+ return findClockOracles(root, scope.value.files, scope.value.changes).map((oracle) => [
306
+ oracle.kind,
307
+ oracle.line,
308
+ ]);
309
+ };
310
+ expect(judged()).toEqual([]);
311
+ write('tests/legacy.test.ts', lines(...legacy.slice(0, 6), ' await child.closed;', ...legacy.slice(7)));
312
+ expect(judged()).toEqual([]);
313
+ write(
314
+ 'tests/legacy.test.ts',
315
+ lines(...legacy.slice(0, 2), ' await run({ verbose: true });', ...legacy.slice(3)),
316
+ );
317
+ expect(judged()).toEqual([['clock-delta', 4]]);
318
+ const scope = diffScope(root, base);
319
+ expect(
320
+ (scope.ok ? findClockOracles(root, scope.value.files, scope.value.changes) : [])
321
+ .map(formatClockOracle)
322
+ .map((each) => each.split('\n').slice(0, 2)),
323
+ ).toEqual([
324
+ [
325
+ `error[${TEST_CLOCK_ORACLE.id}]: ${TEST_CLOCK_ORACLE.message['clock-delta']}: expect(Date.now() - started).toBeLessThan(5_000)`,
326
+ ' --> tests/legacy.test.ts:4:3',
327
+ ],
328
+ ]);
329
+ write('tests/new.test.ts', planted[0]?.[2] ?? '');
330
+ expect(judged()).toEqual([
331
+ ['clock-delta', 4],
332
+ ['runner-deadline', 1],
333
+ ]);
334
+ } finally {
335
+ rmSync(root, { recursive: true, force: true });
336
+ }
337
+ });
338
+ });