@smoothbricks/nx-plugin 0.6.2 → 0.6.3-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +281 -73
  2. package/dist/.build-inputs.json +20 -14
  3. package/dist/bin/smoo-nx-publish.d.ts +3 -0
  4. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-publish.js +3 -0
  6. package/dist/cargo-retention-hook.d.ts +6 -2
  7. package/dist/cargo-retention-hook.d.ts.map +1 -1
  8. package/dist/cargo-retention-hook.js +13 -7
  9. package/dist/eslint-file-set.d.ts +4 -1
  10. package/dist/eslint-file-set.d.ts.map +1 -1
  11. package/dist/eslint-sources.d.ts +25 -0
  12. package/dist/eslint-sources.d.ts.map +1 -0
  13. package/dist/eslint-sources.js +99 -0
  14. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  15. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  16. package/dist/executors/all-verdicts/executor.js +48 -2
  17. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  18. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  19. package/dist/executors/all-verdicts/schema.js +7 -0
  20. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  21. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  22. package/dist/executors/bounded-exec/bounds.js +100 -11
  23. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  24. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/executor.js +270 -27
  26. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  27. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  28. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  29. package/dist/executors/bounded-exec/mbx-pool.d.ts +20 -3
  30. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  31. package/dist/executors/bounded-exec/mbx-pool.js +84 -4
  32. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  33. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  34. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  35. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  36. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/progress.js +148 -22
  38. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  39. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  40. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  41. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  42. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  43. package/dist/executors/bounded-exec/test-results.js +33 -0
  44. package/dist/executors/bounded-exec/verdict.d.ts +20 -2
  45. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  46. package/dist/executors/bounded-exec/verdict.js +102 -4
  47. package/dist/index.d.ts +3 -2
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +67 -65
  50. package/dist/nx-publish.d.ts +24 -0
  51. package/dist/nx-publish.d.ts.map +1 -0
  52. package/dist/nx-publish.js +150 -0
  53. package/dist/runtime-input-policy.d.ts +14 -0
  54. package/dist/runtime-input-policy.d.ts.map +1 -1
  55. package/dist/runtime-input-policy.js +1 -1
  56. package/dist/tool-bins.d.ts +6 -8
  57. package/dist/tool-bins.d.ts.map +1 -1
  58. package/dist/tool-bins.js +7 -5
  59. package/dist/workspace-index.d.ts +7 -0
  60. package/dist/workspace-index.d.ts.map +1 -1
  61. package/dist/workspace-index.js +11 -0
  62. package/executors.json +1 -1
  63. package/managed/raw/patches/ttsc@0.34.1.patch +75 -0
  64. package/managed/raw/tooling/devenv +1 -2
  65. package/managed/raw/tooling/direnv/developer-links.ts +3 -0
  66. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  67. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  68. package/managed/raw/tooling/direnv/setup-environment.ts +35 -20
  69. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  70. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  71. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  72. package/package.json +223 -7
  73. package/runtime/nx-publish/cache_adapter.js +45 -0
  74. package/runtime/nx-publish/nx_publish.js +60 -0
  75. package/runtime-input.sh +12 -3
  76. package/src/bin/smoo-nx-publish.ts +4 -0
  77. package/src/cargo-retention-hook.ts +16 -10
  78. package/src/eslint-file-set.ts +4 -1
  79. package/src/eslint-sources.ts +134 -0
  80. package/src/executors/all-verdicts/executor.ts +58 -3
  81. package/src/executors/all-verdicts/schema.json +4 -0
  82. package/src/executors/all-verdicts/schema.ts +14 -0
  83. package/src/executors/bounded-exec/bounds.ts +132 -15
  84. package/src/executors/bounded-exec/executor.ts +303 -27
  85. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  86. package/src/executors/bounded-exec/mbx-pool.ts +82 -5
  87. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  88. package/src/executors/bounded-exec/progress.ts +168 -15
  89. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  90. package/src/executors/bounded-exec/test-results.ts +39 -0
  91. package/src/executors/bounded-exec/verdict.ts +108 -5
  92. package/src/index.ts +74 -70
  93. package/src/nx-publish.ts +157 -0
  94. package/src/runtime-input-policy.ts +1 -1
  95. package/src/tool-bins.ts +13 -9
  96. package/src/workspace-index.ts +12 -0
  97. package/test-timings.json +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.6.2",
3
+ "version": "0.6.3-0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -33,6 +33,16 @@
33
33
  "import": "./dist/bounded-test-policy.js",
34
34
  "default": "./dist/bounded-test-policy.js"
35
35
  },
36
+ "./test-results": {
37
+ "types": "./dist/executors/bounded-exec/test-results.d.ts",
38
+ "import": "./dist/executors/bounded-exec/test-results.js",
39
+ "default": "./dist/executors/bounded-exec/test-results.js"
40
+ },
41
+ "./test-results/host": {
42
+ "types": "./dist/executors/bounded-exec/test-result-writer.d.ts",
43
+ "import": "./dist/executors/bounded-exec/test-result-writer.js",
44
+ "default": "./dist/executors/bounded-exec/test-result-writer.js"
45
+ },
36
46
  "./build-state-output-policy": {
37
47
  "types": "./dist/build-state-output-policy.d.ts",
38
48
  "import": "./dist/build-state-output-policy.js",
@@ -138,6 +148,11 @@
138
148
  "import": "./dist/deploy-policy.js",
139
149
  "default": "./dist/deploy-policy.js"
140
150
  },
151
+ "./nx-publish": {
152
+ "types": "./dist/nx-publish.d.ts",
153
+ "import": "./dist/nx-publish.js",
154
+ "default": "./dist/nx-publish.js"
155
+ },
141
156
  "./managed-assets": {
142
157
  "types": "./dist/managed-assets.d.ts",
143
158
  "import": "./dist/managed-assets.js",
@@ -212,6 +227,7 @@
212
227
  "smoo-nx-bound-failures": "./dist/bin/smoo-nx-bound-failures.js",
213
228
  "smoo-nx-test-walks": "./dist/bin/smoo-nx-test-walks.js",
214
229
  "smoo-nx-test-clocks": "./dist/bin/smoo-nx-test-clocks.js",
230
+ "smoo-nx-publish": "./dist/bin/smoo-nx-publish.js",
215
231
  "smoo-nx-forbidden-spellings": "./dist/bin/smoo-nx-forbidden-spellings.js"
216
232
  },
217
233
  "generators": "./generators.json",
@@ -221,6 +237,67 @@
221
237
  },
222
238
  "nx": {
223
239
  "targets": {
240
+ "build": {
241
+ "dependsOn": [
242
+ "...",
243
+ "copy-nx-publish-assets"
244
+ ]
245
+ },
246
+ "copy-nx-publish-assets": {
247
+ "executor": "nx:run-commands",
248
+ "cache": true,
249
+ "inputs": [
250
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/build_volume/cache_adapter.js",
251
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/build_volume/nx_publish.js",
252
+ {
253
+ "externalDependencies": []
254
+ }
255
+ ],
256
+ "outputs": [
257
+ "{projectRoot}/runtime/nx-publish/"
258
+ ],
259
+ "options": {
260
+ "command": "asset_source=../cowshed/crates/cowshed-core/src/build_volume; if [ -e runtime/nx-publish ]; then rm -r runtime/nx-publish; fi && mkdir -p runtime/nx-publish && cp \"$asset_source/cache_adapter.js\" \"$asset_source/nx_publish.js\" runtime/nx-publish/",
261
+ "cwd": "{projectRoot}"
262
+ }
263
+ },
264
+ "test-nx-publish": {
265
+ "executor": "@smoothbricks/nx-plugin:bounded-exec",
266
+ "cache": true,
267
+ "inputs": [
268
+ "...",
269
+ "default",
270
+ "^dependencyDefault",
271
+ "bunToolchain",
272
+ {
273
+ "runtime": "sh node_modules/@smoothbricks/nx-plugin/runtime-input.sh node --version"
274
+ },
275
+ {
276
+ "dependentTasksOutputFiles": "**/dist/bin/smoo-nx-publish.js",
277
+ "transitive": true
278
+ },
279
+ {
280
+ "dependentTasksOutputFiles": "**/dist/nx-publish.js",
281
+ "transitive": true
282
+ },
283
+ {
284
+ "dependentTasksOutputFiles": "**/runtime/nx-publish/*.js",
285
+ "transitive": true
286
+ }
287
+ ],
288
+ "dependsOn": [
289
+ "...",
290
+ "tsc-js",
291
+ "copy-nx-publish-assets",
292
+ "typecheck-tests"
293
+ ],
294
+ "options": {
295
+ "command": "bun test --timeout=0 ./src/__tests__/nx-publish.cases.ts ./src/__tests__/nx-publish-bin.cases.ts",
296
+ "cwd": "{projectRoot}",
297
+ "idleTimeoutMs": 180000,
298
+ "killAfterMs": 10000
299
+ }
300
+ },
224
301
  "lint": {},
225
302
  "test": {
226
303
  "executor": "nx:noop",
@@ -230,13 +307,77 @@
230
307
  "test-shard3",
231
308
  "test-shard4",
232
309
  "test-host",
233
- "test-pool-silence"
310
+ "test-pool-silence",
311
+ "test-nx-publish",
312
+ "test-results-runtime"
234
313
  ]
235
314
  },
315
+ "closed-results-runtime-bundle": {
316
+ "executor": "nx:run-commands",
317
+ "cache": true,
318
+ "metadata": {
319
+ "smooTaskKind": "test"
320
+ },
321
+ "dependsOn": [
322
+ "tsc-js",
323
+ "typecheck-tests"
324
+ ],
325
+ "inputs": [
326
+ "{projectRoot}/src/__tests__/test-results-runtime.entry.ts",
327
+ "{projectRoot}/package.json",
328
+ "{projectRoot}/tsconfig.json",
329
+ "{workspaceRoot}/tsconfig.base.json",
330
+ "bunToolchain",
331
+ {
332
+ "externalDependencies": [
333
+ "bun-lock:packages/nx-plugin"
334
+ ]
335
+ },
336
+ {
337
+ "dependentTasksOutputFiles": "**/dist/**/*.js",
338
+ "transitive": false
339
+ }
340
+ ],
341
+ "outputs": [
342
+ "{projectRoot}/.cache/test-results-runtime/"
343
+ ],
344
+ "options": {
345
+ "command": "bun build src/__tests__/test-results-runtime.entry.ts --target=bun --conditions=production --outfile=.cache/test-results-runtime/bundle.mjs",
346
+ "cwd": "{projectRoot}"
347
+ }
348
+ },
349
+ "test-results-runtime": {
350
+ "executor": "@smoothbricks/nx-plugin:bounded-exec",
351
+ "cache": true,
352
+ "dependsOn": [
353
+ "...",
354
+ "closed-results-runtime-bundle"
355
+ ],
356
+ "inputs": [
357
+ "...",
358
+ "bunToolchain",
359
+ {
360
+ "externalDependencies": [
361
+ "bun-lock:packages/nx-plugin"
362
+ ]
363
+ },
364
+ {
365
+ "dependentTasksOutputFiles": "**/test-results-runtime/bundle.mjs",
366
+ "transitive": false
367
+ }
368
+ ],
369
+ "options": {
370
+ "command": "bun .cache/test-results-runtime/bundle.mjs",
371
+ "cwd": "{projectRoot}",
372
+ "idleTimeoutMs": 180000,
373
+ "killAfterMs": 10000
374
+ }
375
+ },
236
376
  "test-pool-silence": {
237
377
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
238
378
  "cache": true,
239
379
  "inputs": [
380
+ "...",
240
381
  "default",
241
382
  "^dependencyDefault",
242
383
  "bunToolchain",
@@ -249,14 +390,49 @@
249
390
  "killAfterMs": 10000
250
391
  }
251
392
  },
393
+ "cargo-stream-archive": {
394
+ "executor": "nx:run-commands",
395
+ "cache": true,
396
+ "metadata": {
397
+ "smooTaskKind": "test"
398
+ },
399
+ "inputs": [
400
+ "{projectRoot}/test-fixtures/stream-witness/**/*",
401
+ "!{projectRoot}/test-fixtures/stream-witness/target/**/*",
402
+ "{workspaceRoot}/.cargo/config",
403
+ "{workspaceRoot}/.cargo/config.toml",
404
+ "cargoToolchain",
405
+ {
406
+ "externalDependencies": []
407
+ }
408
+ ],
409
+ "outputs": [
410
+ "{projectRoot}/.cache/test-stream/archive.tar.zst"
411
+ ],
412
+ "options": {
413
+ "command": "mkdir -p .cache/test-stream && cargo --frozen nextest archive --manifest-path test-fixtures/stream-witness/Cargo.toml --archive-file .cache/test-stream/archive.tar.zst --user-config-file none",
414
+ "cwd": "{projectRoot}"
415
+ }
416
+ },
252
417
  "test-shard1": {
253
418
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
254
419
  "cache": true,
255
420
  "inputs": [
421
+ "...",
256
422
  "default",
257
423
  "^dependencyDefault",
258
424
  "bunToolchain",
259
- "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs"
425
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
426
+ {
427
+ "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
428
+ "transitive": false
429
+ }
430
+ ],
431
+ "dependsOn": [
432
+ "...",
433
+ "^build",
434
+ "build",
435
+ "cargo-stream-archive"
260
436
  ],
261
437
  "options": {
262
438
  "command": "bun test --timeout=0 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
@@ -269,10 +445,21 @@
269
445
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
270
446
  "cache": true,
271
447
  "inputs": [
448
+ "...",
272
449
  "default",
273
450
  "^dependencyDefault",
274
451
  "bunToolchain",
275
- "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs"
452
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
453
+ {
454
+ "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
455
+ "transitive": false
456
+ }
457
+ ],
458
+ "dependsOn": [
459
+ "...",
460
+ "^build",
461
+ "build",
462
+ "cargo-stream-archive"
276
463
  ],
277
464
  "options": {
278
465
  "command": "bun test --timeout=0 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
@@ -285,10 +472,21 @@
285
472
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
286
473
  "cache": true,
287
474
  "inputs": [
475
+ "...",
288
476
  "default",
289
477
  "^dependencyDefault",
290
478
  "bunToolchain",
291
- "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs"
479
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
480
+ {
481
+ "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
482
+ "transitive": false
483
+ }
484
+ ],
485
+ "dependsOn": [
486
+ "...",
487
+ "^build",
488
+ "build",
489
+ "cargo-stream-archive"
292
490
  ],
293
491
  "options": {
294
492
  "command": "bun test --timeout=0 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
@@ -301,10 +499,21 @@
301
499
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
302
500
  "cache": true,
303
501
  "inputs": [
502
+ "...",
304
503
  "default",
305
504
  "^dependencyDefault",
306
505
  "bunToolchain",
307
- "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs"
506
+ "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
507
+ {
508
+ "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
509
+ "transitive": false
510
+ }
511
+ ],
512
+ "dependsOn": [
513
+ "...",
514
+ "^build",
515
+ "build",
516
+ "cargo-stream-archive"
308
517
  ],
309
518
  "options": {
310
519
  "command": "bun test --timeout=0 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
@@ -317,6 +526,7 @@
317
526
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
318
527
  "cache": true,
319
528
  "inputs": [
529
+ "...",
320
530
  "default",
321
531
  "^dependencyDefault",
322
532
  "bunToolchain",
@@ -329,6 +539,7 @@
329
539
  }
330
540
  ],
331
541
  "dependsOn": [
542
+ "...",
332
543
  {
333
544
  "projects": [
334
545
  "cowshed"
@@ -356,6 +567,9 @@
356
567
  "tags": [
357
568
  "npm:public"
358
569
  ],
570
+ "implicitDependencies": [
571
+ "!cowshed"
572
+ ],
359
573
  "name": "nx-plugin"
360
574
  },
361
575
  "files": [
@@ -371,7 +585,8 @@
371
585
  "!**/*.tsbuildinfo",
372
586
  "!src/**/*.test.ts",
373
587
  "!src/**/__tests__",
374
- "managed"
588
+ "managed",
589
+ "runtime/nx-publish"
375
590
  ],
376
591
  "license": "MIT",
377
592
  "publishConfig": {
@@ -386,6 +601,7 @@
386
601
  "@nx/js": "23.2.1",
387
602
  "@smoothbricks/build-inputs": "0.0.1",
388
603
  "@smoothbricks/cargo-retain": "0.0.1",
604
+ "@smoothbricks/cowshed": "0.4.2",
389
605
  "@smoothbricks/nextest-extract": "0.0.1",
390
606
  "jsonc-parser": "^3.3.1",
391
607
  "minimatch": "10.2.5",
@@ -0,0 +1,45 @@
1
+ // One version-sensitive boundary for the checkout's own Nx cache (05_gateway.md, "Publication").
2
+ // DbCache and its native cache field are INTERNAL Nx 23.2.1 APIs, not a public stable adapter.
3
+ // biome-ignore lint/correctness/noUnusedVariables: invoked by the bodies cache_adapter::script prefixes (cache_adapter.rs), not from this file.
4
+ function openNxCache(root) {
5
+ const path = require('node:path');
6
+ const { createRequire } = require('node:module');
7
+ if (!root || !path.isAbsolute(root)) {
8
+ throw new Error(`Nx cache adapter requires an absolute checkout root, got ${JSON.stringify(root)}`);
9
+ }
10
+ const requireNx = createRequire(path.join(root, 'package.json'));
11
+ const version = requireNx('nx/package.json').version;
12
+ if (version !== '23.2.1') {
13
+ throw new Error(
14
+ `Nx cache adapter supports exactly Nx 23.2.1, not ${version}; requalify the adapter before upgrading`,
15
+ );
16
+ }
17
+ // Nx fixes these paths at module load. Every root is handled in its own existing job process.
18
+ process.env.NX_WORKSPACE_ROOT_PATH = root;
19
+ process.env.NX_WORKSPACE_DATA_DIRECTORY = path.join(root, '.nx', 'workspace-data');
20
+ process.env.NX_CACHE_DIRECTORY = path.join(root, '.nx', 'cache');
21
+ if (requireNx('nx/src/native').IS_WASM) {
22
+ throw new Error('The Nx cache adapter requires the pinned native database cache, not WASM');
23
+ }
24
+ // Nx resolves its workspace-data directory itself; prove it is this checkout's before any database is opened.
25
+ const { sharedDataDirectory } = requireNx('nx/src/utils/cache-directory');
26
+ const workspaceData = path.join(root, '.nx', 'workspace-data');
27
+ const actualWorkspaceData = sharedDataDirectory(root, 'workspace-data');
28
+ if (path.resolve(actualWorkspaceData) !== path.resolve(workspaceData)) {
29
+ throw new Error(
30
+ `Nx 23.2.1 workspace-data directory changed: expected ${workspaceData}, actual ${actualWorkspaceData}`,
31
+ );
32
+ }
33
+ const { DbCache } = requireNx('nx/src/tasks-runner/cache');
34
+ // Construction, not init(): Nx owns all schema/metadata setup; no remote loader is contacted.
35
+ const cache = new DbCache({ nxCloudRemoteCache: null, skipRemoteCache: true });
36
+ const native = cache.cache;
37
+ if (!native || typeof native.get !== 'function' || typeof native.cacheDirectory !== 'string') {
38
+ throw new Error('Nx 23.2.1 DbCache native cache surface changed; requalify the adapter');
39
+ }
40
+ const expectedCacheDir = path.join(root, '.nx', 'cache');
41
+ if (path.resolve(native.cacheDirectory) !== path.resolve(expectedCacheDir)) {
42
+ throw new Error(`Nx 23.2.1 cache directory changed: expected ${expectedCacheDir}, actual ${native.cacheDirectory}`);
43
+ }
44
+ return { requireNx, cache, cacheDir: native.cacheDirectory, getLocal: (hash) => native.get(hash) };
45
+ }
@@ -0,0 +1,60 @@
1
+ // A land's publish (05_gateway.md "`/nx/v1/cache/{hash}`"): after the gate passed, every task result
2
+ // the gate's Nx runs named is stored to the project's Nx cache from this checkout's own cache, as
3
+ // plain PUTs by the stock native client. Prefixed once by cache_adapter::script.
4
+ // Usage: node - <absolute Nx root> <JSON array of task hashes>; answers one JSON line on stdout.
5
+ const answer = process.stdout.write.bind(process.stdout);
6
+ process.stdout.write = process.stderr.write.bind(process.stderr);
7
+ const fs = require('node:fs');
8
+ const path = require('node:path');
9
+ const [root, hashesJson] = process.argv.slice(2);
10
+ if (!root || !path.isAbsolute(root) || hashesJson === undefined) {
11
+ throw new Error('usage: node - <absolute Nx root> <JSON array of task hashes>');
12
+ }
13
+ const hashes = JSON.parse(hashesJson);
14
+ if (!Array.isArray(hashes) || new Set(hashes).size !== hashes.length) {
15
+ throw new Error('the land must name distinct task hashes');
16
+ }
17
+ // One validated Nx task key (05_gateway.md): the charset the gateway's route and the store accept.
18
+ for (const hash of hashes) {
19
+ if (typeof hash !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(hash)) {
20
+ throw new Error(`invalid Nx task hash ${JSON.stringify(hash)}`);
21
+ }
22
+ }
23
+ const server = process.env.NX_SELF_HOSTED_REMOTE_CACHE_SERVER;
24
+ if (!server) throw new Error('NX_SELF_HOSTED_REMOTE_CACHE_SERVER names no project Nx cache');
25
+
26
+ async function publish() {
27
+ const { requireNx, cacheDir, getLocal } = openNxCache(root);
28
+ const { HttpRemoteCache } = requireNx('nx/src/native');
29
+ const remote = new HttpRemoteCache();
30
+ let published = 0;
31
+ let existing = 0;
32
+ let skipped = 0;
33
+ for (const hash of hashes) {
34
+ const result = getLocal(hash);
35
+ // A task Nx does not cache, or one that failed, has no complete entry to share.
36
+ if (result?.code !== 0 || !fs.statSync(result.outputsPath, { throwIfNoEntry: false })?.isDirectory()) {
37
+ skipped += 1;
38
+ continue;
39
+ }
40
+ if (await remote.store(hash, cacheDir, result.terminalOutput ?? '', 0)) {
41
+ published += 1;
42
+ continue;
43
+ }
44
+ // The native store answers false for an existing key (409) and for a refusal: tell them apart.
45
+ const response = await fetch(`${server}/v1/cache/${hash}`);
46
+ await response.body?.cancel();
47
+ if (response.status !== 200) {
48
+ throw new Error(`task ${hash} was not stored, and the project cache answers GET ${response.status}`);
49
+ }
50
+ existing += 1;
51
+ }
52
+ return { published, existing, skipped };
53
+ }
54
+ publish().then(
55
+ (result) => answer(`${JSON.stringify(result)}\n`),
56
+ (error) => {
57
+ console.error(error);
58
+ process.exitCode = 1;
59
+ },
60
+ );
package/runtime-input.sh CHANGED
@@ -78,9 +78,18 @@ if record=$(umask 077; mkdir -p "$PWD/.runtime-input-failures" &&
78
78
  cat "$record/stdout"
79
79
  } >"$record/report"; then
80
80
  printf '\nruntime input exited %s: %s; evidence: %s/report\n' "$status" "$*" "$record" >&2
81
- # A detached daemon may have no terminal. Preserve that error too, rather
82
- # than sending it into Nx's discarded stderr or swallowing it.
83
- (exec 4>/dev/tty && cat "$record/report" >&4) 2>"$record/terminal-error"
81
+ # Nx discards this stderr, so a controlling terminal is the one live display
82
+ # of the report. Nx's daemon has none (ENXIO) and cowshed's sandbox denies
83
+ # it (EPERM). Having no terminal is no failure of the input: the shell's
84
+ # refusal of the open joins the notice above on stderr, and the record
85
+ # gains nothing. `command` keeps that refusal from exiting the shell. A
86
+ # write that fails on a terminal that did open is retained in the record.
87
+ if command exec 4>/dev/tty; then
88
+ if ! failure=$(cat "$record/report" 2>&1 >&4); then
89
+ printf '%s\n' "$failure" >"$record/terminal-error"
90
+ fi
91
+ exec 4>&-
92
+ fi
84
93
  else
85
94
  printf '\nruntime input exited %s: %s; evidence incomplete: %s; stderr capture: %s\n' \
86
95
  "$status" "$*" "$record" "$diagnostic" >&2
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { runNxPublish } from '../nx-publish.js';
3
+
4
+ process.exitCode = await runNxPublish(process.argv.slice(2));
@@ -1,13 +1,14 @@
1
1
  import { join, relative } from 'node:path';
2
2
  import {
3
- describeRetention,
4
3
  describeRetentionError,
4
+ describeRetentionStart,
5
5
  type Result,
6
6
  type RetentionError,
7
- type RetentionReport,
7
+ type RetentionStart,
8
8
  refusedAnywhere,
9
- retainCargoWorkspace,
9
+ startRetentionPass,
10
10
  } from '@smoothbricks/cargo-retain';
11
+ import { launchNodeCli } from '@smoothbricks/cargo-retain/launch-node';
11
12
  import { nodeLocks } from '@smoothbricks/cargo-retain/locks-node';
12
13
  import { logger, type ProjectGraph, readCachedProjectGraph } from 'nx/src/devkit-exports.js';
13
14
  import type { PostTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
@@ -51,8 +52,12 @@ export function mbxManagesTargets(environment: Readonly<NodeJS.ProcessEnv>): boo
51
52
 
52
53
  /**
53
54
  * After a run that executed a Cargo producer task ({@link CARGO_PRODUCER_METADATA}), check whether
54
- * each Cargo workspace is due for its daily maintenance. A successful receipt schedules only;
55
- * every due pass reads the current graph under Cargo's locks and is awaited by this Nx process.
55
+ * each Cargo workspace is due for its daily maintenance, and start each due pass in a process of its own
56
+ * (`startRetentionPass`). Nx awaits this hook, inside its daemon when one serves the run, so the pass never runs here:
57
+ * its unlinks are synchronous, and one freeing a large trash on a loaded volume held a daemon, and every client waiting
58
+ * on it, for more than thirty minutes. Here only the gate answers (not due, busy, refused); the started pass reads the
59
+ * current graph under Cargo's locks and records its outcome in the target's receipt, and neither this process nor its
60
+ * exit waits on it. A successful receipt schedules only.
56
61
  * Maintenance never fails the run it follows: every outcome, a refused or busy pass included, is only reported. In an
57
62
  * mbx project ({@link mbxManagesTargets}) it does nothing.
58
63
  */
@@ -80,9 +85,9 @@ export async function postTasksExecution(_options: unknown, context: PostTasksEx
80
85
  if (done.some((workspaceRoot) => !relative(workspaceRoot, root).startsWith('..'))) continue;
81
86
  const started = performance.now();
82
87
  const cpu = process.cpuUsage();
83
- let result: Result<RetentionReport, RetentionError>;
88
+ let result: Result<RetentionStart, RetentionError>;
84
89
  try {
85
- result = await retainCargoWorkspace(root, { apply: true, automatic: true, now: Date.now() }, nodeLocks);
90
+ result = await startRetentionPass(root, Date.now(), nodeLocks, launchNodeCli);
86
91
  } catch (error) {
87
92
  // Maintenance never fails the run it follows: say what escaped, then go on to the next workspace.
88
93
  const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
@@ -97,9 +102,10 @@ export async function postTasksExecution(_options: unknown, context: PostTasksEx
97
102
  logger.warn(`Cargo retention for ${root}: ${describeRetentionError(result.error)}`);
98
103
  continue;
99
104
  }
100
- done.push(result.value.workspaceRoot);
101
- const line = describeRetention(result.value);
102
- if (refusedAnywhere(result.value)) logger.warn(line);
105
+ const start = result.value;
106
+ done.push(start.kind === 'answered' ? start.report.workspaceRoot : start.workspaceRoot);
107
+ const line = describeRetentionStart(start);
108
+ if (start.kind === 'answered' && refusedAnywhere(start.report)) logger.warn(line);
103
109
  else logger.info(line);
104
110
  }
105
111
  }
@@ -1,6 +1,9 @@
1
1
  import typia from 'typia';
2
2
 
3
- /** The exact command and sources source-aware ESLint inference retains for cache inspectors. */
3
+ /**
4
+ * What source-aware ESLint inference retains for cache inspectors: the command, which names no file, and the sources
5
+ * the graph that wrote it resolved. The run reads the sources it lints when it starts.
6
+ */
4
7
  export interface EslintFileSet {
5
8
  readonly command: string;
6
9
  readonly files: readonly string[];