@smoothbricks/nx-plugin 0.5.1 → 0.5.3

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 (60) hide show
  1. package/README.md +74 -13
  2. package/dist/bin/smoo-nx-test-clocks.js +2 -2
  3. package/dist/bin/smoo-nx-test-walks.js +6 -9
  4. package/dist/cargo-closure-input.d.ts.map +1 -1
  5. package/dist/cargo-closure-input.js +25 -15
  6. package/dist/cargo-source-hash.d.ts +2 -2
  7. package/dist/cargo-source-hash.d.ts.map +1 -1
  8. package/dist/cargo-source-hash.js +106 -46
  9. package/dist/ensure-built-witness.d.ts +33 -5
  10. package/dist/ensure-built-witness.d.ts.map +1 -1
  11. package/dist/ensure-built-witness.js +84 -18
  12. package/dist/ensure-built.d.ts.map +1 -1
  13. package/dist/ensure-built.js +19 -5
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +4 -0
  16. package/dist/owned-installation.d.ts +6 -5
  17. package/dist/owned-installation.d.ts.map +1 -1
  18. package/dist/owned-installation.js +324 -201
  19. package/dist/test-walk-policy.d.ts +8 -0
  20. package/dist/test-walk-policy.d.ts.map +1 -1
  21. package/dist/test-walk-policy.js +34 -0
  22. package/dist/workspace-manifest.d.ts +5 -5
  23. package/dist/workspace-manifest.d.ts.map +1 -1
  24. package/managed/raw/patches/nx@23.2.1.patch +196 -48
  25. package/managed/raw/tooling/direnv/developer-links.ts +37 -10
  26. package/managed/raw/tooling/direnv/linked-snapshots.ts +31 -4
  27. package/managed/raw/tooling/direnv/setup-environment.ts +2 -0
  28. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -11
  29. package/package.json +3 -3
  30. package/runtime-input.sh +21 -9
  31. package/src/__tests__/cargo-closure-filesets.ts +94 -0
  32. package/src/__tests__/owned-installation.ts +5 -6
  33. package/src/bin/smoo-nx-test-clocks.ts +2 -2
  34. package/src/bin/smoo-nx-test-walks.ts +6 -9
  35. package/src/cargo-closure-filesets.test.ts +63 -0
  36. package/src/cargo-closure-input.test.ts +1 -1
  37. package/src/cargo-closure-input.ts +23 -15
  38. package/src/cargo-closure-key.test.ts +1 -1
  39. package/src/cargo-resolve-cache.test.ts +1 -1
  40. package/src/cargo-source-hash.test.ts +143 -2
  41. package/src/cargo-source-hash.ts +108 -44
  42. package/src/cross-check-policy.test.ts +53 -12
  43. package/src/ensure-built-witness.test.ts +53 -2
  44. package/src/ensure-built-witness.ts +103 -18
  45. package/src/ensure-built.test.ts +40 -5
  46. package/src/ensure-built.ts +28 -6
  47. package/src/index.ts +4 -0
  48. package/src/linked-snapshots.nx.test.ts +1 -1
  49. package/src/nextest-partitions.test.ts +1 -1
  50. package/src/nx-daemon-start-never.test.ts +126 -0
  51. package/src/nx-daemon-validity.test.ts +51 -0
  52. package/src/nx-task-output-lease.test.ts +136 -0
  53. package/src/owned-installation.test.ts +105 -0
  54. package/src/owned-installation.ts +335 -93
  55. package/src/runtime-input.test.ts +22 -1
  56. package/src/task-results.test.ts +1 -1
  57. package/src/test-walk-policy.test.ts +35 -0
  58. package/src/test-walk-policy.ts +32 -0
  59. package/src/workspace-manifest.ts +5 -5
  60. package/test-timings.json +95 -92
@@ -612,6 +612,19 @@ export function upstreamBase(root) {
612
612
  break;
613
613
  }
614
614
  }
615
+ if (upstream === 'main') {
616
+ // No upstream ref answered: say so as its own reason rather than letting
617
+ // merge-base fail against a local main that may not exist (a fresh shed
618
+ // has none until it fetches).
619
+ const local = exists('main');
620
+ if (!local.ok)
621
+ return local;
622
+ if (!local.value)
623
+ return {
624
+ ok: false,
625
+ reason: 'no main ref in this shed: neither refs/remotes/main/main, refs/remotes/origin/main nor a local main exists (fetch main, set refs/remotes/main/main, or export NX_BASE)',
626
+ };
627
+ }
615
628
  }
616
629
  const args = ['merge-base', 'HEAD', upstream];
617
630
  const result = git(root, args);
@@ -622,6 +635,27 @@ export function upstreamBase(root) {
622
635
  };
623
636
  return { ok: true, value: result.stdout.trim() };
624
637
  }
638
+ /**
639
+ * The upstream base as a run precondition, checked before Nx hashes anything:
640
+ * only a workspace whose own root package.json declares the test-walk check
641
+ * (this repository) is gated, and a missing main ref fails the run with the
642
+ * check's own reason instead of an error smuggled through a runtime input's
643
+ * byte channel. Workspaces that never declare the check are untouched.
644
+ */
645
+ export function assertUpstreamBasePrecondition(workspaceRoot) {
646
+ let rootPackage;
647
+ try {
648
+ rootPackage = readFileSync(join(workspaceRoot, 'package.json'), 'utf8');
649
+ }
650
+ catch {
651
+ return;
652
+ }
653
+ if (!rootPackage.includes('smoo-nx-test-walks'))
654
+ return;
655
+ const base = upstreamBase(workspaceRoot);
656
+ if (!base.ok)
657
+ throw new Error(`${TEST_ONE_WALK.id} cannot find the upstream base: ${base.reason}`);
658
+ }
625
659
  /**
626
660
  * The files changed since `base`, tracked or untracked, and the new-side line ranges of each change; an untracked
627
661
  * file is changed throughout.
@@ -236,7 +236,8 @@ export interface DeveloperLinkSnapshot {
236
236
  /** A declared checkout whose aliases bind a snapshot of it instead of the live directory. */
237
237
  export interface DeveloperLinkSnapshotDeclaration {
238
238
  directory: DeveloperLinkDirectory;
239
- snapshot: DeveloperLinkSnapshot;
239
+ /** A sealed content ID pins an existing snapshot; a target declaration opts into capture at each entry. */
240
+ snapshot: (string & typia.tags.Pattern<'^[0-9a-f]{64}$'>) | DeveloperLinkSnapshot;
240
241
  }
241
242
  export interface PackageSmooConfig {
242
243
  github?: PackageSmooGithub;
@@ -252,10 +253,9 @@ export interface PackageSmooConfig {
252
253
  * every checkout gets it. Shell entry links each tree that installed the
253
254
  * package, a directory the machine lacks keeps the installed version, and CI
254
255
  * links nothing (tooling/direnv/developer-links.ts, which validates the same
255
- * shape at runtime). A `{ directory, snapshot }` declaration binds a sealed,
256
- * Nx-attested snapshot of that checkout instead, so the provider's own builds
257
- * never change a file a running consumer task resolves. Nx is
258
- * lockfile/patch-owned and cannot be declared here.
256
+ * shape at runtime). A `{ directory, snapshot: "<64-hex ID>" }` declaration pins a sealed,
257
+ * Nx-attested snapshot in the consumer store until explicitly moved, even when the provider changes or disappears.
258
+ * A snapshot object opts into capture from the current provider. Nx is lockfile/patch-owned and cannot be declared here.
259
259
  */
260
260
  developerLinks?: Record<string, DeveloperLinkDirectory | DeveloperLinkSnapshotDeclaration>;
261
261
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-manifest.d.ts","sourceRoot":"","sources":["../src/workspace-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C,2DAA2D;AAC3D,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAE3C,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,CAEnE;AAED,mHAAmH;AACnH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GACvC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACvB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;AAEvD,oEAAoE;AACpE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEhE,qGAAqG;AACrG,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CAC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tD,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,MAAM;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CAChF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAE3F"}
@@ -343,7 +343,7 @@ index 9bd7b61bf9ad94c72a198dfe6f15fbcb68dfaac3..c552b4b252c2d0496312ddb6ff481699
343
343
  flushSyncGeneratorChangesToDisk(generators: string[]): Promise<FlushSyncGeneratorChangesResult>;
344
344
  getRegisteredSyncGenerators(): Promise<{
345
345
  diff --git a/dist/src/daemon/client/client.js b/dist/src/daemon/client/client.js
346
- index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6a3133399 100644
346
+ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..a1aeb1ac56800af773219df4f55ee95e324f1a26 100644
347
347
  --- a/dist/src/daemon/client/client.js
348
348
  +++ b/dist/src/daemon/client/client.js
349
349
  @@ -40,7 +40,6 @@ const nx_console_1 = require("../message-types/nx-console");
@@ -354,7 +354,23 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
354
354
  const update_workspace_context_1 = require("../message-types/update-workspace-context");
355
355
  const tmp_dir_1 = require("../tmp-dir");
356
356
  const sandbox_socket_hint_1 = require("../sandbox-socket-hint");
357
- @@ -668,27 +667,6 @@ class DaemonClient {
357
+ @@ -135,6 +134,15 @@ class DaemonClient {
358
+ });
359
+ this._enabled = false;
360
+ }
361
+ + else if (process.env.NX_DAEMON_START === 'never' && !recordedDaemonRuns()) {
362
+ + // A client that may never start a daemon (every cowshed job's) and
363
+ + // finds none running computes this command in its own process. A
364
+ + // daemon it started would serve every client of the checkout through
365
+ + // the shared record while belonging to this client's job, and end
366
+ + // with it.
367
+ + logger_1.clientLogger.log(`[Client] NX_DAEMON_START=never and the recorded daemon is not running: running without the daemon`);
368
+ + this._enabled = false;
369
+ + }
370
+ else {
371
+ this._enabled = true;
372
+ }
373
+ @@ -668,27 +676,6 @@ class DaemonClient {
358
374
  };
359
375
  return this.sendToDaemonViaQueue(message);
360
376
  }
@@ -382,7 +398,33 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
382
398
  getSyncGeneratorChanges(generators) {
383
399
  const message = {
384
400
  type: get_sync_generator_changes_1.GET_SYNC_GENERATOR_CHANGES,
385
- @@ -831,13 +809,24 @@ class DaemonClient {
401
+ @@ -813,8 +800,23 @@ class DaemonClient {
402
+ }
403
+ }
404
+ if (!probe.available) {
405
+ - // Carried as a value so no other caller's probe can substitute for it.
406
+ - daemonPid = await this.startInBackground(probe.refusal);
407
+ + if (process.env.NX_DAEMON_START === 'never') {
408
+ + // The daemon enabled() found running has stopped since. Its
409
+ + // successor is its starter's (cowshed's keeper) to start, never
410
+ + // this client's. The stop belongs to that owner, not to the
411
+ + // workspace, so the daemon is off for this process alone: no
412
+ + // marker that an ordinary terminal would inherit.
413
+ + const reason = 'The Nx daemon this client was using stopped, and NX_DAEMON_START=never: this client never starts a daemon.';
414
+ + (0, tmp_dir_1.disableDaemonForThisProcess)(reason);
415
+ + this._daemonStatus = DaemonStatus.DISCONNECTED;
416
+ + const error = new Error(reason);
417
+ + error.daemonStartForbidden = true;
418
+ + throw error;
419
+ + }
420
+ + else {
421
+ + // Carried as a value so no other caller's probe can substitute for it.
422
+ + daemonPid = await this.startInBackground(probe.refusal);
423
+ + }
424
+ }
425
+ this.setUpConnection();
426
+ this._daemonStatus = DaemonStatus.CONNECTED;
427
+ @@ -831,13 +833,24 @@ class DaemonClient {
386
428
  }
387
429
  }
388
430
  async sendToDaemonViaQueue(messageToDaemon, parser) {
@@ -414,7 +456,7 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
414
456
  }
415
457
  setUpConnection() {
416
458
  const socketPath = this.getSocketPath();
417
- @@ -846,7 +835,13 @@ class DaemonClient {
459
+ @@ -846,7 +859,13 @@ class DaemonClient {
418
460
  // sendMessageToDaemon method uses a keep-alive setTimeout to
419
461
  // explicitly hold the event loop open while awaiting a response.
420
462
  socket.unref();
@@ -429,7 +471,7 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
429
471
  // it's ok for the daemon to terminate if the client doesn't wait on
430
472
  // any messages from the daemon
431
473
  if (this.queue.isEmpty()) {
432
- @@ -1132,8 +1127,11 @@ class DaemonClient {
474
+ @@ -1132,8 +1151,11 @@ class DaemonClient {
433
475
  */
434
476
  const { available, refusal: polled } = await this.waitForServerToBeAvailable({ ignoreVersionMismatch: true });
435
477
  if (available) {
@@ -443,6 +485,33 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
443
485
  }
444
486
  else {
445
487
  // A permission refusal from either source wins, then the poll's errno,
488
+ @@ -1200,6 +1222,26 @@ function isDocker() {
489
+ function nxJsonIsNotPresent() {
490
+ return !(0, nx_json_1.hasNxJson)(workspace_root_1.workspaceRoot);
491
+ }
492
+ +/**
493
+ + * Whether the process the daemon record names still runs. Read only under
494
+ + * NX_DAEMON_START=never, before any request, to choose between that daemon and
495
+ + * none: a record whose daemon has gone is a reason to run without one, never to
496
+ + * start one.
497
+ + */
498
+ +function recordedDaemonRuns() {
499
+ + const pid = (0, cache_1.getDaemonProcessIdSync)();
500
+ + if (!Number.isInteger(pid) || pid < 1) {
501
+ + return false;
502
+ + }
503
+ + try {
504
+ + process.kill(pid, 0);
505
+ + return true;
506
+ + }
507
+ + catch (err) {
508
+ + // EPERM: a process this one may not signal holds the pid, so it runs.
509
+ + return err.code === 'EPERM';
510
+ + }
511
+ +}
512
+ /**
513
+ * The operating system refused the connection. Most often the socket belongs to
514
+ * another user, which is the guarantee the owner-only socket directory buys —
446
515
  diff --git a/dist/src/daemon/message-types/daemon-message.d.ts b/dist/src/daemon/message-types/daemon-message.d.ts
447
516
  index 9dd6123ad6d9adb20a07f7db56fc476be78cbcca..0b1ee217729d63a29806cf6c38d0fc5d4a2161a5 100644
448
517
  --- a/dist/src/daemon/message-types/daemon-message.d.ts
@@ -694,10 +763,10 @@ index 0000000000000000000000000000000000000000..28f263f82b7b698ec1bf88943924696b
694
763
  +export declare function stopDaemonIfWorkspaceGone(): boolean;
695
764
  diff --git a/dist/src/daemon/server/restart-checks.js b/dist/src/daemon/server/restart-checks.js
696
765
  new file mode 100644
697
- index 0000000000000000000000000000000000000000..5f7aa0aa874dfe389388169c8acb0c0ab45f5180
766
+ index 0000000000000000000000000000000000000000..6bd6df6e26cdbc306b33c01b363dc4b3d4475ada
698
767
  --- /dev/null
699
768
  +++ b/dist/src/daemon/server/restart-checks.js
700
- @@ -0,0 +1,295 @@
769
+ @@ -0,0 +1,306 @@
701
770
  +"use strict";
702
771
  +Object.defineProperty(exports, "__esModule", { value: true });
703
772
  +exports.relativeServerProcess = exports.DAEMON_VALIDITY_SAFETY_INTERVAL_MS = void 0;
@@ -721,6 +790,12 @@ index 0000000000000000000000000000000000000000..5f7aa0aa874dfe389388169c8acb0c0a
721
790
  +// Adapted from nrwl/nx#37113. Kept apart from server.js: importing it starts a server.
722
791
  +let daemon;
723
792
  +let terminating = false;
793
+ +// The process that starts a daemon owns its restart. A supervisor that keeps
794
+ +// this daemon (cowshed's keeper job) starts it as `start.js --kept` and starts
795
+ +// its successor itself; a successor spawned here would run outside that job,
796
+ +// where its owner cannot prove it. argv, read once at boot, is the launcher's
797
+ +// own word: no client's environment, which this daemon adopts, can change it.
798
+ +const keptByLauncher = process.argv.slice(2).includes('--kept');
724
799
  +function registerDaemonForRestartChecks(server, sockets, socketPath) {
725
800
  + daemon = { server, sockets, socketPath };
726
801
  + terminating = false;
@@ -986,10 +1061,15 @@ index 0000000000000000000000000000000000000000..5f7aa0aa874dfe389388169c8acb0c0a
986
1061
  +}
987
1062
  +function restartDaemon(reason) {
988
1063
  + if (!daemon || terminating) return;
1064
+ + logger_1.serverLogger.log(`[Server] Daemon outdated: ${reason}`);
1065
+ + if (keptByLauncher) {
1066
+ + logger_1.serverLogger.log('[Server] Stopping: the process that started this daemon (--kept) starts its successor');
1067
+ + stopDaemon(reason);
1068
+ + return;
1069
+ + }
989
1070
  + // Do not spawn multiple replacements or answer queued requests while the
990
1071
  + // asynchronous restart releases ownership and starts the successor.
991
1072
  + terminating = true;
992
- + logger_1.serverLogger.log(`[Server] Daemon outdated: ${reason}`);
993
1073
  + logger_1.serverLogger.log('[Server] Restarting daemon...');
994
1074
  + (0, shutdown_utils_1.handleServerProcessTerminationWithRestart)({ server: daemon.server, reason, sockets: daemon.sockets });
995
1075
  +}
@@ -2110,7 +2190,7 @@ index 3659fdd1955d56e60cc0158d19ac55d59916d78e..92e6700adfc52a380b3e9e37b655fbc9
2110
2190
  /**
2111
2191
  * Returns the current session count for a phase. Useful for testing.
2112
2192
  diff --git a/dist/src/project-graph/project-graph.js b/dist/src/project-graph/project-graph.js
2113
- index a23de7d0f27d7bc222ee09f4904f5d236510d01d..247ed0fe9f7a1a1a3d8d91d0d772763e9068b1be 100644
2193
+ index a23de7d0f27d7bc222ee09f4904f5d236510d01d..0d8514be79f2ed03c7cc2410ea0d91f7c885d634 100644
2114
2194
  --- a/dist/src/project-graph/project-graph.js
2115
2195
  +++ b/dist/src/project-graph/project-graph.js
2116
2196
  @@ -149,14 +149,7 @@ function handleProjectGraphError(opts, e) {
@@ -2129,6 +2209,21 @@ index a23de7d0f27d7bc222ee09f4904f5d236510d01d..247ed0fe9f7a1a1a3d8d91d0d772763e
2129
2209
  }
2130
2210
  else if (typeof e.message === 'string') {
2131
2211
  const lines = e.message.split('\n');
2212
+ @@ -356,6 +349,14 @@ async function createProjectGraphAndSourceMapsAsync(opts = {
2213
+ (0, tmp_dir_1.markDaemonAsDisabled)(e.message);
2214
+ return buildProjectGraphAndSourceMapsWithoutDaemon();
2215
+ }
2216
+ + if (e.daemonStartForbidden) {
2217
+ + // The daemon stopped under a client that may not start one
2218
+ + // (NX_DAEMON_START=never). The client already turned the daemon off
2219
+ + // for this process alone; the command continues without it.
2220
+ + output_1.output.note({ title: `${e.message} Continuing without the daemon.` });
2221
+ + client_1.daemonClient.reset();
2222
+ + return buildProjectGraphAndSourceMapsWithoutDaemon();
2223
+ + }
2224
+ if (e.daemonPermissionError) {
2225
+ // Deliberately not disabled: unlike the inotify limit above, a socket
2226
+ // owned by someone else stops being there when it is removed or the
2132
2227
  diff --git a/dist/src/tasks-runner/cache.d.ts b/dist/src/tasks-runner/cache.d.ts
2133
2228
  index 34aa44f81f1df63c5d33e58d8b55d15fcf1d7619..edf41406f465726828fa447bd10d71a49a2ede8a 100644
2134
2229
  --- a/dist/src/tasks-runner/cache.d.ts
@@ -3251,10 +3346,10 @@ index 0000000000000000000000000000000000000000..ab141ad0de874122b363f2fd1894dcbd
3251
3346
  +}
3252
3347
  diff --git a/dist/src/tasks-runner/task-output-lease.js b/dist/src/tasks-runner/task-output-lease.js
3253
3348
  new file mode 100644
3254
- index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a264ff2485c
3349
+ index 0000000000000000000000000000000000000000..df3e705647a8a38b28125df16ef0c73472b20df3
3255
3350
  --- /dev/null
3256
3351
  +++ b/dist/src/tasks-runner/task-output-lease.js
3257
- @@ -0,0 +1,180 @@
3352
+ @@ -0,0 +1,233 @@
3258
3353
  +"use strict";
3259
3354
  +const { channel } = require("node:diagnostics_channel");
3260
3355
  +const { writeFileSync } = require("node:fs");
@@ -3270,12 +3365,20 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
3270
3365
  +// lock files are never unlinked or replaced.
3271
3366
  +if (process.argv[2] === "--nx-task-output-lease-worker") {
3272
3367
  + let held = [];
3368
+ + // One FileLock, so one descriptor, per lock file for the helper's life:
3369
+ + // FileLock has no close, and a fresh one per acquire kept every descriptor
3370
+ + // until garbage collection.
3371
+ + const locks = new Map();
3273
3372
  + process.on("disconnect", () => process.exit(0));
3274
3373
  + process.on("message", (message) => {
3275
3374
  + try {
3276
3375
  + if (message.type === "acquire") {
3277
3376
  + for (const path of message.paths) {
3278
- + const lock = new FileLock(path);
3377
+ + let lock = locks.get(path);
3378
+ + if (!lock) {
3379
+ + lock = new FileLock(path);
3380
+ + locks.set(path, lock);
3381
+ + }
3279
3382
  + lock.lock();
3280
3383
  + held.push({ lock, path });
3281
3384
  + writeFileSync(path, JSON.stringify({ pid: process.pid, clientPid: process.ppid, purpose: message.purpose, targets: message.targets }));
@@ -3301,12 +3404,21 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
3301
3404
  + });
3302
3405
  +}
3303
3406
  +else {
3407
+ + // The pool's slots. A slot is held by a live helper in `workers`; an acquire
3408
+ + // that finds none free waits in `waiters` for one of exactly two events:
3409
+ + // a release hands it the released helper, or a helper leaves the pool
3410
+ + // (exit, failed spawn, failed send, or an error reply, after which it is
3411
+ + // killed) and `retire` hands it that helper's slot to fork a successor.
3412
+ + // Every way a helper can stop serving goes through `retire`, so no waiter
3413
+ + // waits for a slot nothing will free.
3304
3414
  + class TaskOutputLeases {
3305
3415
  + constructor(parallelism, invocationTracker, purpose) {
3306
3416
  + this.purpose = purpose;
3307
3417
  + this.invocationTracker = invocationTracker;
3308
3418
  + this.parallelism = Math.max(1, parallelism);
3309
3419
  + this.workers = new Set();
3420
+ + this.children = new Set();
3421
+ + this.reserved = 0;
3310
3422
  + this.idle = [];
3311
3423
  + this.waiters = [];
3312
3424
  + this.stopping = false;
@@ -3336,43 +3448,17 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
3336
3448
  + const paths = targets.map((target) => join(workspaceDataDirectory, "task-output-leases", `${hashArray([this.purpose, target])}.lock`));
3337
3449
  + events.publish({ phase: "waiting", purpose: this.purpose, targets, paths, pid: process.pid });
3338
3450
  + let entry = this.idle.pop();
3339
- + if (!entry && this.workers.size >= this.parallelism) {
3451
+ + if (!entry && this.workers.size + this.reserved >= this.parallelism) {
3452
+ + // An entry from a release, or null: a retired helper's slot, reserved for this acquire.
3340
3453
  + entry = await new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
3454
+ + if (!entry) this.reserved--;
3455
+ + if (this.stopping) {
3456
+ + if (entry) this.idle.push(entry);
3457
+ + throw new Error(`Task output lease acquisition cancelled during runner cleanup: ${targets.join(", ")}`);
3458
+ + }
3341
3459
  + }
3342
3460
  + if (!entry) {
3343
- + const worker = fork(__filename, ["--nx-task-output-lease-worker"], {
3344
- + execPath: process.execPath,
3345
- + execArgv: [],
3346
- + stdio: ["ignore", "inherit", "inherit", "ipc"],
3347
- + });
3348
- + entry = { worker, pending: null, failed: null, phase: "idle", exited: null };
3349
- + entry.exited = new Promise((resolve) => worker.once("exit", resolve));
3350
- + this.workers.add(entry);
3351
- + worker.on("message", (message) => {
3352
- + const pending = entry.pending;
3353
- + entry.pending = null;
3354
- + if (message.type === "error") {
3355
- + const error = new Error(`Task output lease for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} failed: ${message.message}`);
3356
- + error.stack += `\nCaused by lease helper:\n${message.stack}`;
3357
- + entry.failed = error;
3358
- + pending?.reject(error);
3359
- + }
3360
- + else {
3361
- + pending?.resolve();
3362
- + }
3363
- + });
3364
- + worker.on("error", (cause) => {
3365
- + const error = new Error(`Task output lease helper failed for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`, { cause });
3366
- + entry.failed = error;
3367
- + entry.pending?.reject(error);
3368
- + entry.pending = null;
3369
- + });
3370
- + worker.on("exit", (code, signal) => {
3371
- + entry.failed ??= new Error(`Task output lease worker exited (code ${code}, signal ${signal ?? "none"}) for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`);
3372
- + entry.pending?.reject(entry.failed);
3373
- + entry.pending = null;
3374
- + this.workers.delete(entry);
3375
- + });
3461
+ + entry = this.spawn();
3376
3462
  + }
3377
3463
  + entry.targets = targets;
3378
3464
  + entry.paths = paths;
@@ -3393,11 +3479,73 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
3393
3479
  + else this.idle.push(entry);
3394
3480
  + };
3395
3481
  + }
3482
+ + spawn() {
3483
+ + const worker = fork(__filename, ["--nx-task-output-lease-worker"], {
3484
+ + execPath: process.execPath,
3485
+ + execArgv: [],
3486
+ + stdio: ["ignore", "inherit", "inherit", "ipc"],
3487
+ + });
3488
+ + const exited = Promise.withResolvers();
3489
+ + const entry = { worker, pending: null, failed: null, retired: false, phase: "idle", exited: exited.promise, targets: [], paths: [] };
3490
+ + const gone = () => {
3491
+ + this.children.delete(entry);
3492
+ + exited.resolve();
3493
+ + };
3494
+ + this.workers.add(entry);
3495
+ + this.children.add(entry);
3496
+ + worker.on("message", (message) => {
3497
+ + const pending = entry.pending;
3498
+ + entry.pending = null;
3499
+ + if (message.type === "error") {
3500
+ + // The helper unlocked what it held before replying; it no longer serves.
3501
+ + const error = new Error(`Task output lease for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} failed: ${message.message}`);
3502
+ + error.stack += `\nCaused by lease helper:\n${message.stack}`;
3503
+ + pending?.reject(error);
3504
+ + this.retire(entry, error);
3505
+ + }
3506
+ + else {
3507
+ + pending?.resolve();
3508
+ + }
3509
+ + });
3510
+ + worker.on("error", (cause) => {
3511
+ + this.retire(entry, new Error(`Task output lease helper failed for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`, { cause }));
3512
+ + // A helper that never started emits no exit.
3513
+ + if (worker.pid === undefined) gone();
3514
+ + });
3515
+ + worker.on("exit", (code, signal) => {
3516
+ + this.retire(entry, new Error(`Task output lease worker exited (code ${code}, signal ${signal ?? "none"}) for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`));
3517
+ + gone();
3518
+ + });
3519
+ + return entry;
3520
+ + }
3521
+ + // Takes a helper that no longer serves out of the pool, once: its
3522
+ + // pending exchange fails with the reason, and its slot goes to the
3523
+ + // oldest waiter, which forks a successor.
3524
+ + retire(entry, error) {
3525
+ + if (entry.retired) return;
3526
+ + entry.retired = true;
3527
+ + entry.failed ??= error;
3528
+ + entry.pending?.reject(entry.failed);
3529
+ + entry.pending = null;
3530
+ + // A live helper that stopped serving holds no lease: its error reply unlocked them, or a failed send left
3531
+ + // it unreachable. Killing it releases whatever the kernel still records.
3532
+ + entry.worker.kill("SIGKILL");
3533
+ + this.workers.delete(entry);
3534
+ + const index = this.idle.indexOf(entry);
3535
+ + if (index !== -1) this.idle.splice(index, 1);
3536
+ + const waiter = this.waiters.shift();
3537
+ + if (waiter) {
3538
+ + this.reserved++;
3539
+ + waiter.resolve(null);
3540
+ + }
3541
+ + }
3396
3542
  + exchange(entry, message) {
3397
3543
  + if (entry.failed) return Promise.reject(entry.failed);
3398
3544
  + return new Promise((resolve, reject) => {
3399
3545
  + entry.pending = { resolve, reject };
3400
- + entry.worker.send(message);
3546
+ + entry.worker.send(message, (error) => {
3547
+ + if (error) this.retire(entry, new Error(`Task output lease helper for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} could not be sent ${message.type}`, { cause: error }));
3548
+ + });
3401
3549
  + });
3402
3550
  + }
3403
3551
  + async withTasks(tasks, action) {
@@ -3426,7 +3574,7 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
3426
3574
  + async close() {
3427
3575
  + await this.cancelPending();
3428
3576
  + this.closed = true;
3429
- + await Promise.all([...this.workers].map((entry) => {
3577
+ + await Promise.all([...this.children].map((entry) => {
3430
3578
  + entry.worker.kill("SIGKILL");
3431
3579
  + return entry.exited;
3432
3580
  + }));
@@ -66,6 +66,11 @@
66
66
  * CI never applies them: it builds against the published packages the
67
67
  * lockfile names (setup-environment.ts `--links`).
68
68
  *
69
+ * A stable declaration names `{ "directory": …, "snapshot": "<64-hex ID>" }`:
70
+ * only the consumer's verified sealed snapshot resolves. Provider HEAD drift
71
+ * is reported and continues with the pin; a missing or invalid pin refuses.
72
+ * The directory is a freshness hint, never an input to pinned execution.
73
+ *
69
74
  * A declaration may also ask for a snapshot: `{ "directory": …, "snapshot":
70
75
  * { "targets": [...], "artifactModules": [...] } }` binds every alias to a
71
76
  * sealed copy of that checkout instead of the live directory, so the
@@ -118,6 +123,8 @@ import {
118
123
  import path from 'node:path';
119
124
  import type { KeepDeveloperLinksOptions } from '@smoothbricks/nx-plugin/managed-assets';
120
125
  import {
126
+ type ProducerProbe,
127
+ pinnedSnapshot,
121
128
  pluginProbe,
122
129
  recordedSnapshot,
123
130
  type SealedSnapshot,
@@ -415,6 +422,8 @@ export type UnavailableDeclaredLink =
415
422
  export interface DeclaredLinksPlan {
416
423
  readonly changes: readonly DeclaredLinkChange[];
417
424
  readonly unavailable: readonly UnavailableDeclaredLink[];
425
+ /** Verified pins whose provider HEAD differs or cannot be inspected; linking still succeeds. */
426
+ readonly reports: readonly string[];
418
427
  }
419
428
 
420
429
  /**
@@ -435,22 +444,24 @@ export interface DeclaredLinksPlan {
435
444
  export async function planDeclaredLinks(root: string): Promise<DeclaredLinksPlan> {
436
445
  const declared = readDeclaredLinks(root);
437
446
  if (declared.length === 0) {
438
- return { changes: [], unavailable: [] };
447
+ return { changes: [], unavailable: [], reports: [] };
439
448
  }
440
449
  const anchor = linkAnchor(root);
441
450
  const canonicalRoot = realpathSync(root);
442
451
  const trees = nodeModulesTrees(root);
443
452
  const recorded = readDeclaredRecord(root);
444
- const probe = pluginProbe(snapshotPluginRoot(root, anchor, declared));
453
+ const probe: ProducerProbe = (target, providerRoot) =>
454
+ pluginProbe(snapshotPluginRoot(root, anchor, declared))(target, providerRoot);
445
455
  const changes: DeclaredLinkChange[] = [];
446
456
  const unavailable: UnavailableDeclaredLink[] = [];
457
+ const reports: string[] = [];
447
458
  for (const { name, directory: relative, snapshot } of declared) {
448
459
  const source = declaredTarget(root, anchor, relative);
449
460
  const contained = containsPath(path.resolve(root), source);
450
- if (contained) {
461
+ if (contained && typeof snapshot !== 'string') {
451
462
  assertOwnedPath(canonicalRoot, path.resolve(canonicalRoot, path.relative(path.resolve(root), source)));
452
463
  }
453
- const reason = unavailableReason(source);
464
+ const reason = typeof snapshot === 'string' ? null : unavailableReason(source);
454
465
  if (reason !== null) {
455
466
  if (contained) assertNoInheritedBinding(root, anchor, name, relative, source);
456
467
  unavailable.push({ kind: 'absent', name, target: source, reason });
@@ -460,16 +471,20 @@ export async function planDeclaredLinks(root: string): Promise<DeclaredLinksPlan
460
471
  if (snapshot !== undefined) {
461
472
  const outcome = await snapshotBinding(root, name, source, snapshot, probe);
462
473
  if (outcome.kind === 'refused') {
474
+ if (typeof snapshot === 'string')
475
+ throw new Error(`smoo.developerLinks ${name}: cannot resolve pinned snapshot ${snapshot}: ${outcome.reason}`);
463
476
  const kept = keptSnapshots(root, trees, name, recorded);
464
477
  changes.push(...kept.changes);
465
478
  unavailable.push({ kind: 'snapshot-refused', name, source, reason: outcome.reason, ...kept.said });
466
479
  continue;
467
480
  }
468
481
  binding = { kind: 'snapshot', target: outcome.directory, id: outcome.id };
482
+ if (outcome.report !== undefined) reports.push(`! smoo.developerLinks ${name}: ${outcome.report}`);
469
483
  }
470
484
  const target = binding.target;
471
485
  // The live checkout a snapshot replaces, by physical identity: a link spelled through another path is the same one.
472
- const sourcePhysical = binding.kind === 'snapshot' ? realpathSync(source) : undefined;
486
+ const sourcePhysical =
487
+ binding.kind === 'snapshot' && typeof snapshot !== 'string' ? realpathSync(source) : undefined;
473
488
  for (const tree of trees) {
474
489
  const entry = path.join(tree, name);
475
490
  const at = path.join(root, entry);
@@ -488,8 +503,13 @@ export async function planDeclaredLinks(root: string): Promise<DeclaredLinksPlan
488
503
  const inherited = inheritedContainedBinding(anchor, relative, current);
489
504
  const managed = recorded.get(entry)?.target === text;
490
505
  if (current === target && text === packageAliasTarget(root, at, target)) continue;
491
- const physical = sourcePhysical === undefined ? undefined : realpathOrNull(current);
492
- if (binding.kind === 'snapshot' && foreign && !inherited && !managed && physical === sourcePhysical) {
506
+ if (
507
+ sourcePhysical !== undefined &&
508
+ foreign &&
509
+ !inherited &&
510
+ !managed &&
511
+ realpathOrNull(current) === sourcePhysical
512
+ ) {
493
513
  unavailable.push({ kind: 'snapshot-unclaimed', name, path: entry, source });
494
514
  continue;
495
515
  }
@@ -498,7 +518,7 @@ export async function planDeclaredLinks(root: string): Promise<DeclaredLinksPlan
498
518
  changes.push({ path: entry, binding });
499
519
  }
500
520
  }
501
- return { changes, unavailable };
521
+ return { changes, unavailable, reports };
502
522
  }
503
523
 
504
524
  /**
@@ -560,6 +580,7 @@ function snapshotPluginRoot(root: string, anchor: string, declared: readonly Dec
560
580
  const plugin = declared.find(({ name }) => name === '@smoothbricks/nx-plugin');
561
581
  if (plugin === undefined) return root;
562
582
  const source = declaredTarget(root, anchor, plugin.directory);
583
+ if (typeof plugin.snapshot === 'string') return pinnedSnapshot(root, plugin.name, source, plugin.snapshot).directory;
563
584
  return unavailableReason(source) === null ? source : root;
564
585
  }
565
586
 
@@ -586,6 +607,7 @@ function assertNoInheritedBinding(root: string, anchor: string, name: string, re
586
607
  * which declarations this machine cannot honour.
587
608
  */
588
609
  export function applyDeclaredLinks(root: string, plan: DeclaredLinksPlan): void {
610
+ for (const report of plan.reports) console.error(report);
589
611
  for (const unavailable of plan.unavailable) {
590
612
  switch (unavailable.kind) {
591
613
  case 'absent':
@@ -732,13 +754,13 @@ const TARGET = /^[^:\s]+:[^:\s]+(?::[^:\s]+)?$/;
732
754
  interface DeclaredLink {
733
755
  readonly name: string;
734
756
  readonly directory: string;
735
- readonly snapshot: SnapshotDeclaration | undefined;
757
+ readonly snapshot: SnapshotDeclaration | string | undefined;
736
758
  }
737
759
 
738
760
  /**
739
761
  * `smoo.developerLinks` from the root manifest: each package name with its
740
762
  * checkout directory, relative, given alone or as `{ directory, snapshot }`
741
- * where `snapshot` names the provider targets that build it and its native
763
+ * where `snapshot` names a sealed snapshot ID or the provider targets that build it and its native
742
764
  * artifact modules (linked-snapshots.ts). Hand-validated, like
743
765
  * secret-references.ts validates `smoo.secrets`: this runs before anything is
744
766
  * installed. The shape is `PackageSmooConfig.developerLinks` in the
@@ -773,6 +795,11 @@ function readDeclaredLinks(root: string): DeclaredLink[] {
773
795
  }
774
796
  if (!object) return { name, directory, snapshot: undefined };
775
797
  const snapshot: unknown = Reflect.get(declaration, 'snapshot');
798
+ if (typeof snapshot === 'string') {
799
+ if (!/^[0-9a-f]{64}$/.test(snapshot))
800
+ throw new Error(`${manifestPath}: smoo.developerLinks ${name}.snapshot must be 64 lowercase hex digits`);
801
+ return { name, directory, snapshot };
802
+ }
776
803
  const targets: unknown =
777
804
  typeof snapshot === 'object' && snapshot !== null ? Reflect.get(snapshot, 'targets') : undefined;
778
805
  const artifactModules: unknown =