@smoothbricks/nx-plugin 0.4.28 → 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 (158) hide show
  1. package/README.md +277 -89
  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 +8 -8
  6. package/dist/bounded-test-policy.d.ts.map +1 -1
  7. package/dist/bounded-test-policy.js +18 -30
  8. package/dist/cargo-closure-input.d.ts +23 -0
  9. package/dist/cargo-closure-input.d.ts.map +1 -1
  10. package/dist/cargo-closure-input.js +41 -9
  11. package/dist/cargo-source-hash.d.ts.map +1 -1
  12. package/dist/cargo-source-hash.js +42 -19
  13. package/dist/ensure-built-receipt.d.ts +40 -6
  14. package/dist/ensure-built-receipt.d.ts.map +1 -1
  15. package/dist/ensure-built-receipt.js +297 -159
  16. package/dist/ensure-built-witness.d.ts +65 -4
  17. package/dist/ensure-built-witness.d.ts.map +1 -1
  18. package/dist/ensure-built-witness.js +2237 -23
  19. package/dist/ensure-built.d.ts +99 -1
  20. package/dist/ensure-built.d.ts.map +1 -1
  21. package/dist/ensure-built.js +45 -56
  22. package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
  23. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/cpu-pool.js +51 -22
  25. package/dist/executors/bounded-exec/executor.d.ts +12 -3
  26. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/executor.js +174 -51
  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 +20 -11
  32. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  33. package/dist/executors/bounded-exec/ram-temp.js +42 -17
  34. package/dist/executors/bounded-exec/verdict.d.ts +34 -4
  35. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  36. package/dist/executors/bounded-exec/verdict.js +54 -3
  37. package/dist/generators/bun-test-tracing/generator.js +2 -2
  38. package/dist/graph-input-contract.d.ts +102 -0
  39. package/dist/graph-input-contract.d.ts.map +1 -0
  40. package/dist/graph-input-contract.js +637 -0
  41. package/dist/index.d.ts +12 -5
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +17 -3
  44. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  45. package/dist/managed-files/ci-workflow.js +5 -2
  46. package/dist/managed-files/publish-workflow.d.ts +11 -1
  47. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  48. package/dist/owned-installation.d.ts +14 -0
  49. package/dist/owned-installation.d.ts.map +1 -0
  50. package/dist/owned-installation.js +324 -0
  51. package/dist/producer-receipts.d.ts +19 -0
  52. package/dist/producer-receipts.d.ts.map +1 -0
  53. package/dist/producer-receipts.js +926 -0
  54. package/dist/test-backstop.d.ts +9 -0
  55. package/dist/test-backstop.d.ts.map +1 -0
  56. package/dist/test-backstop.js +10 -0
  57. package/dist/test-clock-policy.d.ts +30 -0
  58. package/dist/test-clock-policy.d.ts.map +1 -0
  59. package/dist/test-clock-policy.js +686 -0
  60. package/dist/testing.d.ts +8 -0
  61. package/dist/testing.d.ts.map +1 -1
  62. package/dist/testing.js +66 -1
  63. package/managed/raw/patches/nx@23.2.1.patch +328 -50
  64. package/managed/raw/tooling/direnv/developer-links.ts +148 -29
  65. package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
  66. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
  67. package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
  68. package/managed/raw/tooling/direnv/repo-path +15 -2
  69. package/managed/raw/tooling/direnv/setup-environment.ts +179 -115
  70. package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
  71. package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
  72. package/nextest.toml +1 -1
  73. package/package.json +25 -9
  74. package/src/__tests__/cargo-closure-fixture.ts +113 -0
  75. package/src/__tests__/counted-cargo.ts +8 -25
  76. package/src/__tests__/directory-change.ts +27 -0
  77. package/src/__tests__/fixture-nx-env.ts +7 -0
  78. package/src/__tests__/owned-installation.ts +14 -0
  79. package/src/__tests__/past-tick.ts +12 -0
  80. package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
  81. package/src/bin/smoo-nx-test-clocks.ts +29 -0
  82. package/src/bounded-test-policy.test.ts +36 -22
  83. package/src/bounded-test-policy.ts +18 -32
  84. package/src/bun-bootstrap.test.ts +1 -1
  85. package/src/cargo-closure-input.property.test.ts +50 -0
  86. package/src/cargo-closure-input.test.ts +73 -121
  87. package/src/cargo-closure-input.ts +47 -8
  88. package/src/cargo-closure-key.test.ts +239 -0
  89. package/src/cargo-resolve-cache.test.ts +168 -31
  90. package/src/cargo-source-hash.test.ts +78 -3
  91. package/src/cargo-source-hash.ts +48 -30
  92. package/src/cross-check-policy.test.ts +2 -2
  93. package/src/ensure-built-receipt.test.ts +111 -16
  94. package/src/ensure-built-receipt.ts +294 -149
  95. package/src/ensure-built-witness.test.ts +306 -13
  96. package/src/ensure-built-witness.ts +255 -24
  97. package/src/ensure-built.test.ts +228 -102
  98. package/src/ensure-built.ts +127 -66
  99. package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
  100. package/src/executors/bounded-exec/cpu-pool.ts +64 -20
  101. package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
  102. package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
  103. package/src/executors/bounded-exec/executor-host.test.ts +74 -52
  104. package/src/executors/bounded-exec/executor.test.ts +343 -97
  105. package/src/executors/bounded-exec/executor.ts +192 -56
  106. package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
  107. package/src/executors/bounded-exec/no-space.ts +40 -0
  108. package/src/executors/bounded-exec/progress.test.ts +1 -1
  109. package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
  110. package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
  111. package/src/executors/bounded-exec/ram-temp.ts +49 -20
  112. package/src/executors/bounded-exec/verdict.test.ts +127 -22
  113. package/src/executors/bounded-exec/verdict.ts +78 -3
  114. package/src/generators/bounded-test-targets/generator.test.ts +1 -3
  115. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  116. package/src/generators/bun-test-tracing/generator.ts +2 -2
  117. package/src/graph-input-contract.test.ts +379 -0
  118. package/src/graph-input-contract.ts +627 -0
  119. package/src/index.test.ts +3 -3
  120. package/src/index.ts +24 -3
  121. package/src/linked-snapshots.nx.test.ts +112 -30
  122. package/src/managed-files/ci-workflow.ts +5 -2
  123. package/src/managed-files/publish-workflow.ts +12 -1
  124. package/src/managed-files/repo-path.test.ts +44 -1
  125. package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
  126. package/src/nextest-code-bound.test.ts +23 -17
  127. package/src/nextest-extraction.test.ts +114 -4
  128. package/src/nextest-partitions.test.ts +7 -1
  129. package/src/nx-cache-restore-mtime.test.ts +2 -2
  130. package/src/nx-daemon-claim.test.ts +10 -8
  131. package/src/nx-daemon-idle-cpu.test.ts +0 -1
  132. package/src/nx-daemon-idle-policy.test.ts +61 -1
  133. package/src/nx-daemon-ignore-files.test.ts +2 -2
  134. package/src/nx-daemon-validity.test.ts +36 -22
  135. package/src/nx-dot-input-policy.test.ts +5 -5
  136. package/src/nx-files-archive-racy.test.ts +1 -1
  137. package/src/nx-incomplete-run-summary.test.ts +1 -1
  138. package/src/nx-plugin-load-errors.test.ts +2 -2
  139. package/src/nx-project-graph-errors.test.ts +70 -0
  140. package/src/nx-skipped-task-exit.test.ts +2 -2
  141. package/src/nx-store-resolution.test.ts +7 -25
  142. package/src/nx-task-output-lease.test.ts +3 -3
  143. package/src/nx-use-local.test.ts +7 -5
  144. package/src/owned-installation.ts +174 -0
  145. package/src/producer-receipts.test.ts +164 -0
  146. package/src/producer-receipts.ts +636 -0
  147. package/src/runtime-input.test.ts +1 -1
  148. package/src/serial-group-wiring.test.ts +4 -4
  149. package/src/task-results.test.ts +18 -16
  150. package/src/test-backstop.ts +11 -0
  151. package/src/test-clock-policy.test.ts +338 -0
  152. package/src/test-clock-policy.ts +708 -0
  153. package/src/test-timings.test.ts +2 -2
  154. package/src/testing.test.ts +5 -5
  155. package/src/testing.ts +67 -1
  156. package/src/typecheck-test-policy.test.ts +1 -1
  157. package/src/typescript-resolution.test.ts +76 -0
  158. package/test-timings.json +8 -0
@@ -12,6 +12,9 @@ import { getExecutorNameForTask } from 'nx/src/tasks-runner/utils';
12
12
  import { signalToCode } from 'nx/src/utils/exit-codes';
13
13
  import typia from 'typia';
14
14
  import { nxFixtureRoot, withNxFixture } from './__tests__/fixture-nx-env.js';
15
+ import { testFileInstallation } from './__tests__/owned-installation.js';
16
+ import { pastTick } from './__tests__/past-tick.js';
17
+ import type { EnsureBuiltProbeResult } from './ensure-built.js';
15
18
  import {
16
19
  assignEnvironment,
17
20
  callerOwnsWorkspace,
@@ -244,7 +247,9 @@ describe('unvouched', () => {
244
247
  });
245
248
 
246
249
  describe('compareWithArtifacts', () => {
247
- it('reuses a verified two-tree inventory without expanding or rereading artifact bytes', () => {
250
+ it('reuses a verified two-tree inventory without expanding or rereading artifact bytes', async () => {
251
+ // An inventory recorded in the tick its fixture was written in is unproven, and the next comparison is a full one.
252
+ await pastTick();
248
253
  const path = join(root, 'verified.json');
249
254
  let walks = 0;
250
255
  const expand: typeof expandOutputs = (...args) => {
@@ -562,10 +567,10 @@ describe('the environment Nx runs under', () => {
562
567
  });
563
568
 
564
569
  const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
565
- const repoRoot = dirname(dirname(packageRoot));
566
570
  const binEntry = join(packageRoot, 'src', 'bin', 'smoo-nx-exec.ts');
567
571
  const builtBinEntry = join(packageRoot, 'dist', 'bin', 'smoo-nx-exec.js');
568
- const nxEntry = join(repoRoot, 'node_modules', '.bin', 'nx');
572
+ /** The Nx CLI of a fixture workspace's own installation. */
573
+ const nxEntry = (workspace: string) => join(workspace, 'node_modules', '.bin', 'nx');
569
574
  const MARKER = 'EXEC_OK';
570
575
  /**
571
576
  * Reports what the exec'd process inherited: the marker proves execve
@@ -716,7 +721,14 @@ describe('smoo-nx-exec without a daemon', () => {
716
721
  });
717
722
 
718
723
  /** Fixture Nx configuration: its cache and database stay under its removable root. */
719
- const FIXTURE_NX_JSON = { useDaemonProcess: true, cacheDirectory: '.nx/cache' };
724
+ const FIXTURE_NX_JSON = {
725
+ useDaemonProcess: true,
726
+ cacheDirectory: '.nx/cache',
727
+ plugins: ['@smoothbricks/nx-plugin'],
728
+ };
729
+
730
+ /** The Nx installation this file's fixtures share: one copy per run of the file, not one per fixture. */
731
+ const installation = testFileInstallation('ensure-built-installation-');
720
732
 
721
733
  /**
722
734
  * Two projects, `app:build` reading `lib:build`'s outputs through
@@ -726,7 +738,7 @@ const FIXTURE_NX_JSON = { useDaemonProcess: true, cacheDirectory: '.nx/cache' };
726
738
  * outside the workspace: a log inside it would be an undeclared output the
727
739
  * snapshot diff rightly reports as a changed input.
728
740
  */
729
- async function writeTwoProjectWorkspace(workspace: string, builds: string): Promise<void> {
741
+ async function writeTwoProjectWorkspace(workspace: string, builds: string, publishReceipts = false): Promise<void> {
730
742
  // Cowshed's scratch is ignored by its enclosing Git checkout. This is an
731
743
  // independent Nx workspace: its own Git boundary keeps the daemon's
732
744
  // ignore-aware watcher from dropping all of its source changes.
@@ -734,9 +746,14 @@ async function writeTwoProjectWorkspace(workspace: string, builds: string): Prom
734
746
  await writeFile(join(workspace, '.gitignore'), '.nx\nnode_modules\npackages/*/dist\n');
735
747
  await mkdir(join(workspace, 'packages', 'app'), { recursive: true });
736
748
  await mkdir(join(workspace, 'packages', 'lib'), { recursive: true });
737
- // The repository's own node_modules, so the fixture resolves the Nx this package is written against.
738
- await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
739
- await writeFile(join(workspace, 'nx.json'), JSON.stringify(FIXTURE_NX_JSON));
749
+ await symlink(await installation.nodeModules(), join(workspace, 'node_modules'), 'dir');
750
+ const nxJson = publishReceipts
751
+ ? {
752
+ ...FIXTURE_NX_JSON,
753
+ plugins: [{ plugin: '@smoothbricks/nx-plugin', options: { producerReceipts: { targets: ['app:build'] } } }],
754
+ }
755
+ : FIXTURE_NX_JSON;
756
+ await writeFile(join(workspace, 'nx.json'), JSON.stringify(nxJson));
740
757
  await writeFile(
741
758
  join(workspace, 'packages', 'lib', 'project.json'),
742
759
  JSON.stringify({
@@ -781,6 +798,10 @@ async function writeTwoProjectWorkspace(workspace: string, builds: string): Prom
781
798
  }
782
799
 
783
800
  describe('smoo-nx-exec with a fresh daemon', () => {
801
+ // The fixtures share one installation because none writes into it; otherwise one fixture's write would be
802
+ // another's input. Its identity when retired must be the one it was made with.
803
+ afterAll(() => installation.retire());
804
+
784
805
  /**
785
806
  * The socket directory a call entered from another workspace's shell is given for `workspace`, or null where the
786
807
  * packaged socket owner has no managed shell runtime to bind in (`DEVENV_RUNTIME` unset), and Nx keeps its own
@@ -815,7 +836,7 @@ describe('smoo-nx-exec with a fresh daemon', () => {
815
836
  await writeTwoProjectWorkspace(workspace, builds);
816
837
  const built = await run(
817
838
  'node',
818
- nxEntry,
839
+ nxEntry(workspace),
819
840
  workspace,
820
841
  ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
821
842
  { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
@@ -931,76 +952,29 @@ await writeFile(${JSON.stringify(resultsPath)}, JSON.stringify(results));
931
952
  },
932
953
  'workspace',
933
954
  );
934
- }, 60_000);
955
+ });
935
956
 
936
- it('replays current outputs and refreshes stale snapshots without running unrelated edits', async () => {
937
- // A socket path has a 95 character budget and macOS's temp directory spends most of it, so the
938
- // socket directory is made in the short socket namespace the sandbox admits.
939
- const socketDir = await ownedSocketDirectory('eb-sock-', NX_LONGEST_SOCKET_NAME);
940
- let root = '';
941
- let failure: { readonly error: unknown } | null = null;
942
- const providerDirectories: string[] = [];
957
+ // Publication is opt-in only for the receipt case. Graph/exec probes below
958
+ // keep ordinary plugin hooks but have no producer source/tool prepass.
959
+ it('publishes real completion receipts and reuses their original basis for the same tree', async () => {
960
+ let providerSockets: string | null = null;
943
961
  try {
944
962
  await withNxFixture(
945
- 'ensure-built-daemon-',
946
- async (fixture) => {
947
- root = fixture.root;
948
- const { workspace } = fixture;
963
+ 'ensure-built-producer-',
964
+ async ({ root, workspace }) => {
949
965
  const builds = join(root, 'lib-builds.log');
950
- await writeTwoProjectWorkspace(workspace, builds);
951
- // What the provider binds for this workspace when the call is entered from another one's shell.
952
- const providerSockets = providerSocketDirectory(workspace);
953
- if (providerSockets !== null) providerDirectories.push(providerSockets);
966
+ await writeTwoProjectWorkspace(workspace, builds, true);
967
+ providerSockets = providerSocketDirectory(workspace);
954
968
  const ownEnv: Record<string, string> = providerSockets === null ? {} : { NX_SOCKET_DIR: providerSockets };
955
-
956
- // Built by daemonless Nx, as CI or a restarted daemon leaves a tree:
957
- // cached and on disk, recorded by no daemon.
958
969
  const built = await run(
959
970
  'node',
960
- nxEntry,
971
+ nxEntry(workspace),
961
972
  workspace,
962
973
  ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
963
974
  { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
964
975
  );
965
976
  expect(built.code, built.stdout + built.stderr).toBe(0);
966
977
  expect(await readFile(builds, 'utf-8')).toBe('lib\n');
967
-
968
- // Entered from outside the root by a shell set up for another
969
- // workspace, as a managed devenv's is: its socket directory belongs to
970
- // that workspace's daemon, and a second daemon listening there would
971
- // take the socket from it.
972
- const caller = join(root, 'caller');
973
- await mkdir(caller);
974
- const hit = await run(
975
- 'bun',
976
- binEntry,
977
- caller,
978
- ['app:build', '--workspace-root', workspace, '--', join(workspace, 'report')],
979
- { NX_DAEMON: 'true', NX_USE_LOCAL: 'true', NX_SOCKET_DIR: socketDir },
980
- );
981
- expect(hit.code, hit.stdout + hit.stderr).toBe(0);
982
- expect(hit.stderr).toBe('');
983
- expect(hit.stdout.split('\n')[0], hit.stdout).toBe(MARKER);
984
- expect(await readFile(builds, 'utf-8')).toBe('lib\n');
985
- expect(await readdir(socketDir)).toEqual([]);
986
- const record = await readFile(join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json'), 'utf-8');
987
- expect(record).not.toContain(socketDir);
988
- // The daemon it started binds in the directory the provider named, not the caller's nor Nx's default.
989
- const daemon = typia.json.assertParse<DaemonProcessJson>(record);
990
- if (providerSockets !== null) {
991
- expect(daemon.socketPath.startsWith(`${providerSockets}/`), record).toBe(true);
992
- }
993
-
994
- // That hit re-armed the daemon's records. The emitted wrapper, under
995
- // Node and with nothing to exec, is as silent.
996
- const again = await run('node', builtBinEntry, workspace, ['app:build'], {
997
- NX_DAEMON: 'true',
998
- NX_USE_LOCAL: 'true',
999
- ...ownEnv,
1000
- });
1001
- expect(again).toEqual({ code: 0, signal: null, stdout: '', stderr: '' });
1002
- expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1003
-
1004
978
  // Probe-only receipts use the real Nx keys/cache and independently
1005
979
  // census public output bytes without starting a task runner.
1006
980
  const committed = spawnSync(
@@ -1036,6 +1010,28 @@ await writeFile(${JSON.stringify(resultsPath)}, JSON.stringify(results));
1036
1010
  { encoding: 'utf8' },
1037
1011
  );
1038
1012
  expect(sourceCommit.status, sourceCommit.stdout + sourceCommit.stderr).toBe(0);
1013
+ // The receipt binds the producer's executables. A `git` this fixture owns lets the consumer case below move
1014
+ // one tool node's ctime alone, as a same-mode chmod by another checkout's install moves a shared store file.
1015
+ const realGit = Bun.which('git');
1016
+ if (realGit === null) throw new Error('git is not on PATH');
1017
+ const fixtureBin = join(root, 'bin');
1018
+ await mkdir(fixtureBin);
1019
+ const fixtureGit = join(fixtureBin, 'git');
1020
+ await writeExecutable(fixtureGit, `#!/bin/sh\nexec ${JSON.stringify(realGit)} "$@"\n`);
1021
+ const published = await run(
1022
+ 'node',
1023
+ nxEntry(workspace),
1024
+ workspace,
1025
+ ['run', 'app:build', '--outputStyle=static-failures-only'],
1026
+ {
1027
+ NX_DAEMON: 'true',
1028
+ NX_WORKSPACE_ROOT_PATH: workspace,
1029
+ ...ownEnv,
1030
+ PATH: `${fixtureBin}:${process.env.PATH ?? ''}`,
1031
+ },
1032
+ );
1033
+ expect(published.code, published.stdout + published.stderr).toBe(0);
1034
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1039
1035
  const probeEntry = join(root, 'probe-receipt.ts');
1040
1036
  await writeFile(
1041
1037
  probeEntry,
@@ -1060,7 +1056,7 @@ await writeFile(source, 'new uncached source');
1060
1056
  const uncached = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1061
1057
  const outputAfterMiss = await readFile(output, 'utf8');
1062
1058
  await writeFile(source, originalSource);
1063
- console.log(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten: before.ino === after.ino && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs, outputAfterMiss }));
1059
+ await new Promise<void>((resolve, reject) => process.stdout.write(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten: before.ino === after.ino && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs, outputAfterMiss }) + "\\n", error => error ? reject(error) : resolve()));
1064
1060
  `,
1065
1061
  );
1066
1062
  const probed = await run('bun', probeEntry, workspace, [], {
@@ -1071,10 +1067,10 @@ console.log(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten:
1071
1067
  });
1072
1068
  expect(probed.code, probed.stdout + probed.stderr).toBe(0);
1073
1069
  const receipts = typia.json.assertParse<{
1074
- hit: import('./ensure-built.js').EnsureBuiltProbeResult;
1075
- daemonless: import('./ensure-built.js').EnsureBuiltProbeResult;
1076
- stale: import('./ensure-built.js').EnsureBuiltProbeResult;
1077
- uncached: import('./ensure-built.js').EnsureBuiltProbeResult;
1070
+ hit: EnsureBuiltProbeResult;
1071
+ daemonless: EnsureBuiltProbeResult;
1072
+ stale: EnsureBuiltProbeResult;
1073
+ uncached: EnsureBuiltProbeResult;
1078
1074
  outputUnwritten: boolean;
1079
1075
  outputAfterMiss: string;
1080
1076
  }>(probed.stdout);
@@ -1087,55 +1083,185 @@ console.log(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten:
1087
1083
  .find(({ path }) => path === 'packages/app/dist/marker.txt'),
1088
1084
  ).toMatchObject({ type: 'file', sha256: expect.stringMatching(/^[a-f0-9]{64}$/) });
1089
1085
  }
1090
- expect(receipts.daemonless).toEqual({
1091
- disposition: 'miss',
1092
- reason: { kind: 'no-daemon', taskId: 'app:build' },
1093
- });
1094
- expect(receipts.stale).toEqual({
1095
- disposition: 'miss',
1096
- reason: { kind: 'stale-outputs', taskId: 'app:build' },
1097
- });
1098
- expect(receipts.uncached.disposition).toBe('miss');
1086
+ expect(receipts.daemonless.disposition).toBe('hit');
1087
+ expect(receipts.stale).toMatchObject({ disposition: 'failed', reason: { kind: 'provider-proof' } });
1088
+ expect(receipts.uncached.disposition).toBe('failed');
1099
1089
  expect(receipts.outputUnwritten).toBe(true);
1100
1090
  expect(receipts.outputAfterMiss).toBe('built\nlib\n');
1101
1091
  expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1102
1092
 
1103
- const sourceRaceEntry = join(root, 'receipt-source-race.ts');
1093
+ const producerEnvironmentEntry = join(root, 'producer-environment-independence.ts');
1104
1094
  await writeFile(
1105
- sourceRaceEntry,
1095
+ producerEnvironmentEntry,
1106
1096
  `
1107
1097
  import { createRequire } from 'node:module';
1108
- import { readFile, writeFile } from 'node:fs/promises';
1109
- import { join } from 'node:path';
1098
+ import { spawnSync } from 'node:child_process';
1110
1099
  import { probeBuilt } from ${JSON.stringify(join(packageRoot, 'dist', 'ensure-built.js'))};
1111
- const source = join(process.cwd(), 'packages/lib/source.txt');
1112
- const text = await readFile(source, 'utf8');
1113
1100
  const { daemonClient } = createRequire(process.cwd() + '/package.json')('nx/src/daemon/client/client');
1114
- const hash = daemonClient.hashTasks.bind(daemonClient);
1115
- daemonClient.hashTasks = async (...args) => {
1116
- const result = await hash(...args);
1117
- await writeFile(source, 'transient source');
1118
- await writeFile(source, text);
1119
- return result;
1120
- };
1121
- console.log(JSON.stringify(await probeBuilt({ target: 'app:build', cwd: process.cwd() })));
1101
+ daemonClient.hashTasks = async () => { throw new Error('readonly consumer must not hash its own environment'); };
1102
+ const packageJson = createRequire(process.cwd() + '/package.json')('nx/src/utils/package-json');
1103
+ const readModulePackageJson = packageJson.readModulePackageJson;
1104
+ let moduleInspections = 0;
1105
+ packageJson.readModulePackageJson = (...args) => { moduleInspections += 1; return readModulePackageJson(...args); };
1106
+ process.env.PRODUCER_CONSUMER_DIFFERENCE = 'consumer-only';
1107
+ const first = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1108
+ const empty = spawnSync('git', ['-c', 'user.name=Receipt fixture', '-c', 'user.email=receipt@example.invalid', 'commit', '--allow-empty', '-qm', 'same tree'], { encoding: 'utf8' });
1109
+ if (empty.status !== 0) throw new Error(empty.stderr);
1110
+ const sameTree = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1111
+ await new Promise<void>((resolve, reject) => process.stdout.write(JSON.stringify({ first, sameTree, moduleInspections }) + "\\n", error => error ? reject(error) : resolve()));
1122
1112
  `,
1123
1113
  );
1124
- const sourceRace = await run('bun', sourceRaceEntry, workspace, [], {
1114
+ const producerEnvironment = await run('bun', producerEnvironmentEntry, workspace, [], {
1125
1115
  NX_DAEMON: 'true',
1126
1116
  NX_USE_LOCAL: 'true',
1127
1117
  NX_WORKSPACE_ROOT_PATH: workspace,
1128
1118
  ...ownEnv,
1129
1119
  });
1130
- expect(sourceRace.code, sourceRace.stdout + sourceRace.stderr).toBe(0);
1131
- const sourceRaceResult = typia.json.assertParse<import('./ensure-built.js').EnsureBuiltProbeResult>(
1132
- sourceRace.stdout,
1120
+ expect(producerEnvironment.code, producerEnvironment.stdout + producerEnvironment.stderr).toBe(0);
1121
+ const environmentResults = typia.json.assertParse<{
1122
+ first: EnsureBuiltProbeResult;
1123
+ sameTree: EnsureBuiltProbeResult;
1124
+ moduleInspections: number;
1125
+ }>(producerEnvironment.stdout);
1126
+ expect(environmentResults.first.disposition, producerEnvironment.stderr).toBe('hit');
1127
+ expect(environmentResults.sameTree).toEqual(environmentResults.first);
1128
+ expect(environmentResults.moduleInspections).toBe(0);
1129
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1130
+
1131
+ // Between its readonly read of the receipt's tools and its last check of them, the consumer censuses the
1132
+ // public outputs through Nx's expandOutputs. Moving the fixture `git` there is a tool node moving under the
1133
+ // readonly validation: a same-mode chmod moves its ctime alone and keeps the hit, a byte change refuses and
1134
+ // names the node.
1135
+ const toolMoveEntry = join(root, 'tool-node-move.ts');
1136
+ await writeFile(
1137
+ toolMoveEntry,
1138
+ `
1139
+ import { chmodSync, statSync, writeFileSync } from 'node:fs';
1140
+ import { createRequire } from 'node:module';
1141
+ import { probeBuilt } from ${JSON.stringify(join(packageRoot, 'dist', 'ensure-built.js'))};
1142
+ const git = ${JSON.stringify(fixtureGit)};
1143
+ const native = createRequire(process.cwd() + '/package.json')('nx/src/native');
1144
+ const expand = native.expandOutputs;
1145
+ let move = () => {};
1146
+ let moves = 0;
1147
+ native.expandOutputs = (...args) => {
1148
+ move();
1149
+ moves += 1;
1150
+ return expand(...args);
1151
+ };
1152
+ const before = statSync(git, { bigint: true });
1153
+ move = () => chmodSync(git, 0o755);
1154
+ const chmodded = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1155
+ const after = statSync(git, { bigint: true });
1156
+ const ctimeAlone = before.ino === after.ino && before.mode === after.mode && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs !== after.ctimeNs;
1157
+ const chmodMoves = moves;
1158
+ move = () => writeFileSync(git, '#!/bin/sh\\nexit 1\\n');
1159
+ const rewritten = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1160
+ await new Promise<void>((resolve, reject) => process.stdout.write(JSON.stringify({ chmodded, ctimeAlone, chmodMoves, rewritten }) + "\\n", error => error ? reject(error) : resolve()));
1161
+ `,
1133
1162
  );
1134
- expect(sourceRaceResult).toMatchObject({
1163
+ const toolMove = await run('bun', toolMoveEntry, workspace, [], {
1164
+ NX_DAEMON: 'true',
1165
+ NX_USE_LOCAL: 'true',
1166
+ NX_WORKSPACE_ROOT_PATH: workspace,
1167
+ ...ownEnv,
1168
+ });
1169
+ expect(toolMove.code, toolMove.stdout + toolMove.stderr).toBe(0);
1170
+ const toolMoves = typia.json.assertParse<{
1171
+ chmodded: EnsureBuiltProbeResult;
1172
+ ctimeAlone: boolean;
1173
+ chmodMoves: number;
1174
+ rewritten: EnsureBuiltProbeResult;
1175
+ }>(toolMove.stdout);
1176
+ expect(toolMoves.chmodMoves).toBeGreaterThan(0);
1177
+ expect(toolMoves.ctimeAlone).toBe(true);
1178
+ expect(toolMoves.chmodded, toolMove.stderr).toEqual(environmentResults.first);
1179
+ expect(toolMoves.rewritten).toMatchObject({
1135
1180
  disposition: 'failed',
1136
- reason: { kind: 'provider-proof', detail: expect.stringContaining('across Nx hashing') },
1181
+ reason: {
1182
+ kind: 'provider-proof',
1183
+ detail: `Producer tool namespace changed during independent product validation: ${fixtureGit}`,
1184
+ },
1185
+ });
1186
+ },
1187
+ 'workspace',
1188
+ );
1189
+ } finally {
1190
+ if (providerSockets !== null) await rm(providerSockets, { recursive: true, force: true });
1191
+ }
1192
+ });
1193
+
1194
+ // The graph/exec case runs real Nx because its subject is the daemon:
1195
+ // the daemon a probe starts holds no output records, so every output must be
1196
+ // vouched for by comparing the working tree with Nx's cache artifact. The
1197
+ // daemon it starts is also the one whose socket is in question, so the same
1198
+ // lifetime answers where a root entered from another workspace's shell binds.
1199
+ it('replays current outputs and refreshes stale snapshots without running unrelated edits', async () => {
1200
+ // A socket path has a 95 character budget and macOS's temp directory spends most of it, so the
1201
+ // socket directory is made in the short socket namespace the sandbox admits.
1202
+ const socketDir = await ownedSocketDirectory('eb-sock-', NX_LONGEST_SOCKET_NAME);
1203
+ let root = '';
1204
+ let failure: { readonly error: unknown } | null = null;
1205
+ const providerDirectories: string[] = [];
1206
+ try {
1207
+ await withNxFixture(
1208
+ 'ensure-built-daemon-',
1209
+ async (fixture) => {
1210
+ root = fixture.root;
1211
+ const { workspace } = fixture;
1212
+ const builds = join(root, 'lib-builds.log');
1213
+ await writeTwoProjectWorkspace(workspace, builds);
1214
+ // What the provider binds for this workspace when the call is entered from another one's shell.
1215
+ const providerSockets = providerSocketDirectory(workspace);
1216
+ if (providerSockets !== null) providerDirectories.push(providerSockets);
1217
+ const ownEnv: Record<string, string> = providerSockets === null ? {} : { NX_SOCKET_DIR: providerSockets };
1218
+
1219
+ // Built by daemonless Nx, as CI or a restarted daemon leaves a tree:
1220
+ // cached and on disk, recorded by no daemon.
1221
+ const built = await run(
1222
+ 'node',
1223
+ nxEntry(workspace),
1224
+ workspace,
1225
+ ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
1226
+ { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
1227
+ );
1228
+ expect(built.code, built.stdout + built.stderr).toBe(0);
1229
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1230
+
1231
+ // Entered from outside the root by a shell set up for another
1232
+ // workspace, as a managed devenv's is: its socket directory belongs to
1233
+ // that workspace's daemon, and a second daemon listening there would
1234
+ // take the socket from it.
1235
+ const caller = join(root, 'caller');
1236
+ await mkdir(caller);
1237
+ const hit = await run(
1238
+ 'bun',
1239
+ binEntry,
1240
+ caller,
1241
+ ['app:build', '--workspace-root', workspace, '--', join(workspace, 'report')],
1242
+ { NX_DAEMON: 'true', NX_USE_LOCAL: 'true', NX_SOCKET_DIR: socketDir },
1243
+ );
1244
+ expect(hit.code, hit.stdout + hit.stderr).toBe(0);
1245
+ expect(hit.stderr).toBe('');
1246
+ expect(hit.stdout.split('\n')[0], hit.stdout).toBe(MARKER);
1247
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1248
+ expect(await readdir(socketDir)).toEqual([]);
1249
+ const record = await readFile(join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json'), 'utf-8');
1250
+ expect(record).not.toContain(socketDir);
1251
+ // The daemon it started binds in the directory the provider named, not the caller's nor Nx's default.
1252
+ const daemon = typia.json.assertParse<DaemonProcessJson>(record);
1253
+ if (providerSockets !== null) {
1254
+ expect(daemon.socketPath.startsWith(`${providerSockets}/`), record).toBe(true);
1255
+ }
1256
+
1257
+ // That hit re-armed the daemon's records. The emitted wrapper, under
1258
+ // Node and with nothing to exec, is as silent.
1259
+ const again = await run('node', builtBinEntry, workspace, ['app:build'], {
1260
+ NX_DAEMON: 'true',
1261
+ NX_USE_LOCAL: 'true',
1262
+ ...ownEnv,
1137
1263
  });
1138
- expect(sourceRace.stderr).toContain('Provider source');
1264
+ expect(again).toEqual({ code: 0, signal: null, stdout: '', stderr: '' });
1139
1265
  expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1140
1266
 
1141
1267
  // An awaited daemon graph can see B while both disk snapshots see
@@ -1258,5 +1384,5 @@ console.log(JSON.stringify(await ensureBuilt({ target: 'app:build', cwd: process
1258
1384
  cause: failure.error,
1259
1385
  });
1260
1386
  }
1261
- }, 60_000);
1387
+ });
1262
1388
  });