@smoothbricks/nx-plugin 0.4.27 → 0.4.29

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 (124) hide show
  1. package/README.md +203 -83
  2. package/dist/bounded-test-policy.d.ts +10 -3
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +19 -25
  5. package/dist/cargo-closure-input.d.ts +12 -0
  6. package/dist/cargo-closure-input.d.ts.map +1 -1
  7. package/dist/cargo-closure-input.js +29 -7
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +42 -19
  10. package/dist/ensure-built-receipt.d.ts +34 -6
  11. package/dist/ensure-built-receipt.d.ts.map +1 -1
  12. package/dist/ensure-built-receipt.js +265 -159
  13. package/dist/ensure-built-witness.d.ts +27 -2
  14. package/dist/ensure-built-witness.d.ts.map +1 -1
  15. package/dist/ensure-built-witness.js +2176 -15
  16. package/dist/ensure-built.d.ts +99 -1
  17. package/dist/ensure-built.d.ts.map +1 -1
  18. package/dist/ensure-built.js +34 -53
  19. package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
  20. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/cpu-pool.js +43 -19
  22. package/dist/executors/bounded-exec/executor.d.ts +11 -2
  23. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/executor.js +139 -39
  25. package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
  26. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/ram-temp.js +27 -13
  28. package/dist/generators/bun-test-tracing/generator.js +2 -2
  29. package/dist/graph-input-contract.d.ts +98 -0
  30. package/dist/graph-input-contract.d.ts.map +1 -0
  31. package/dist/graph-input-contract.js +624 -0
  32. package/dist/index.d.ts +12 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +17 -3
  35. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  36. package/dist/managed-files/ci-workflow.js +5 -2
  37. package/dist/managed-files/publish-workflow.d.ts +11 -1
  38. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  39. package/dist/producer-receipts.d.ts +19 -0
  40. package/dist/producer-receipts.d.ts.map +1 -0
  41. package/dist/producer-receipts.js +921 -0
  42. package/dist/testing.d.ts +8 -0
  43. package/dist/testing.d.ts.map +1 -1
  44. package/dist/testing.js +58 -0
  45. package/managed/raw/patches/nx@23.2.1.patch +328 -50
  46. package/managed/raw/tooling/direnv/developer-links.ts +147 -21
  47. package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
  48. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
  49. package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
  50. package/managed/raw/tooling/direnv/repo-path +15 -2
  51. package/managed/raw/tooling/direnv/setup-environment.ts +363 -125
  52. package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
  53. package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
  54. package/nextest.toml +1 -1
  55. package/package.json +11 -6
  56. package/src/__tests__/fixture-nx-env.ts +7 -0
  57. package/src/__tests__/owned-installation.ts +174 -0
  58. package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
  59. package/src/bounded-test-policy.test.ts +36 -22
  60. package/src/bounded-test-policy.ts +19 -27
  61. package/src/bun-bootstrap.test.ts +1 -1
  62. package/src/cargo-closure-input.test.ts +60 -11
  63. package/src/cargo-closure-input.ts +28 -6
  64. package/src/cargo-resolve-cache.test.ts +140 -25
  65. package/src/cargo-source-hash.test.ts +78 -3
  66. package/src/cargo-source-hash.ts +48 -30
  67. package/src/cross-check-policy.test.ts +2 -2
  68. package/src/ensure-built-receipt.test.ts +111 -16
  69. package/src/ensure-built-receipt.ts +251 -149
  70. package/src/ensure-built-witness.test.ts +197 -13
  71. package/src/ensure-built-witness.ts +187 -15
  72. package/src/ensure-built.test.ts +156 -102
  73. package/src/ensure-built.ts +114 -64
  74. package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
  75. package/src/executors/bounded-exec/cpu-pool.ts +55 -17
  76. package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
  77. package/src/executors/bounded-exec/executor-host.test.ts +51 -41
  78. package/src/executors/bounded-exec/executor.test.ts +155 -35
  79. package/src/executors/bounded-exec/executor.ts +156 -45
  80. package/src/executors/bounded-exec/progress.test.ts +1 -1
  81. package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
  82. package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
  83. package/src/executors/bounded-exec/ram-temp.ts +32 -16
  84. package/src/executors/bounded-exec/verdict.test.ts +17 -12
  85. package/src/generators/bounded-test-targets/generator.test.ts +1 -3
  86. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  87. package/src/generators/bun-test-tracing/generator.ts +2 -2
  88. package/src/graph-input-contract.test.ts +371 -0
  89. package/src/graph-input-contract.ts +605 -0
  90. package/src/index.test.ts +3 -3
  91. package/src/index.ts +24 -3
  92. package/src/linked-snapshots.nx.test.ts +112 -30
  93. package/src/managed-files/ci-workflow.ts +5 -2
  94. package/src/managed-files/publish-workflow.ts +12 -1
  95. package/src/managed-files/repo-path.test.ts +44 -1
  96. package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
  97. package/src/nextest-code-bound.test.ts +23 -17
  98. package/src/nextest-partitions.test.ts +7 -1
  99. package/src/nx-cache-restore-mtime.test.ts +2 -2
  100. package/src/nx-daemon-claim.test.ts +5 -5
  101. package/src/nx-daemon-idle-cpu.test.ts +0 -1
  102. package/src/nx-daemon-idle-policy.test.ts +56 -0
  103. package/src/nx-daemon-ignore-files.test.ts +2 -2
  104. package/src/nx-daemon-validity.test.ts +31 -9
  105. package/src/nx-dot-input-policy.test.ts +5 -5
  106. package/src/nx-files-archive-racy.test.ts +1 -1
  107. package/src/nx-incomplete-run-summary.test.ts +1 -1
  108. package/src/nx-plugin-load-errors.test.ts +2 -2
  109. package/src/nx-project-graph-errors.test.ts +70 -0
  110. package/src/nx-skipped-task-exit.test.ts +2 -2
  111. package/src/nx-store-resolution.test.ts +7 -25
  112. package/src/nx-task-output-lease.test.ts +3 -3
  113. package/src/nx-use-local.test.ts +7 -5
  114. package/src/producer-receipts.test.ts +164 -0
  115. package/src/producer-receipts.ts +631 -0
  116. package/src/runtime-input.test.ts +1 -1
  117. package/src/serial-group-wiring.test.ts +4 -4
  118. package/src/task-results.test.ts +18 -16
  119. package/src/test-timings.test.ts +2 -2
  120. package/src/testing.test.ts +5 -5
  121. package/src/testing.ts +59 -0
  122. package/src/typecheck-test-policy.test.ts +1 -1
  123. package/src/typescript-resolution.test.ts +76 -0
  124. package/test-timings.json +5 -0
@@ -12,6 +12,8 @@ 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 type { EnsureBuiltProbeResult } from './ensure-built.js';
15
17
  import {
16
18
  assignEnvironment,
17
19
  callerOwnsWorkspace,
@@ -562,10 +564,10 @@ describe('the environment Nx runs under', () => {
562
564
  });
563
565
 
564
566
  const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
565
- const repoRoot = dirname(dirname(packageRoot));
566
567
  const binEntry = join(packageRoot, 'src', 'bin', 'smoo-nx-exec.ts');
567
568
  const builtBinEntry = join(packageRoot, 'dist', 'bin', 'smoo-nx-exec.js');
568
- const nxEntry = join(repoRoot, 'node_modules', '.bin', 'nx');
569
+ /** The Nx CLI of a fixture workspace's own installation. */
570
+ const nxEntry = (workspace: string) => join(workspace, 'node_modules', '.bin', 'nx');
569
571
  const MARKER = 'EXEC_OK';
570
572
  /**
571
573
  * Reports what the exec'd process inherited: the marker proves execve
@@ -716,7 +718,14 @@ describe('smoo-nx-exec without a daemon', () => {
716
718
  });
717
719
 
718
720
  /** Fixture Nx configuration: its cache and database stay under its removable root. */
719
- const FIXTURE_NX_JSON = { useDaemonProcess: true, cacheDirectory: '.nx/cache' };
721
+ const FIXTURE_NX_JSON = {
722
+ useDaemonProcess: true,
723
+ cacheDirectory: '.nx/cache',
724
+ plugins: ['@smoothbricks/nx-plugin'],
725
+ };
726
+
727
+ /** The Nx installation this file's fixtures share: one copy per run of the file, not one per fixture. */
728
+ const installation = testFileInstallation('ensure-built-installation-');
720
729
 
721
730
  /**
722
731
  * Two projects, `app:build` reading `lib:build`'s outputs through
@@ -726,7 +735,7 @@ const FIXTURE_NX_JSON = { useDaemonProcess: true, cacheDirectory: '.nx/cache' };
726
735
  * outside the workspace: a log inside it would be an undeclared output the
727
736
  * snapshot diff rightly reports as a changed input.
728
737
  */
729
- async function writeTwoProjectWorkspace(workspace: string, builds: string): Promise<void> {
738
+ async function writeTwoProjectWorkspace(workspace: string, builds: string, publishReceipts = false): Promise<void> {
730
739
  // Cowshed's scratch is ignored by its enclosing Git checkout. This is an
731
740
  // independent Nx workspace: its own Git boundary keeps the daemon's
732
741
  // ignore-aware watcher from dropping all of its source changes.
@@ -734,9 +743,14 @@ async function writeTwoProjectWorkspace(workspace: string, builds: string): Prom
734
743
  await writeFile(join(workspace, '.gitignore'), '.nx\nnode_modules\npackages/*/dist\n');
735
744
  await mkdir(join(workspace, 'packages', 'app'), { recursive: true });
736
745
  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));
746
+ await symlink(await installation.nodeModules(), join(workspace, 'node_modules'), 'dir');
747
+ const nxJson = publishReceipts
748
+ ? {
749
+ ...FIXTURE_NX_JSON,
750
+ plugins: [{ plugin: '@smoothbricks/nx-plugin', options: { producerReceipts: { targets: ['app:build'] } } }],
751
+ }
752
+ : FIXTURE_NX_JSON;
753
+ await writeFile(join(workspace, 'nx.json'), JSON.stringify(nxJson));
740
754
  await writeFile(
741
755
  join(workspace, 'packages', 'lib', 'project.json'),
742
756
  JSON.stringify({
@@ -781,6 +795,10 @@ async function writeTwoProjectWorkspace(workspace: string, builds: string): Prom
781
795
  }
782
796
 
783
797
  describe('smoo-nx-exec with a fresh daemon', () => {
798
+ // The fixtures share one installation because none writes into it; otherwise one fixture's write would be
799
+ // another's input. Its identity when retired must be the one it was made with.
800
+ afterAll(() => installation.retire());
801
+
784
802
  /**
785
803
  * The socket directory a call entered from another workspace's shell is given for `workspace`, or null where the
786
804
  * packaged socket owner has no managed shell runtime to bind in (`DEVENV_RUNTIME` unset), and Nx keeps its own
@@ -815,7 +833,7 @@ describe('smoo-nx-exec with a fresh daemon', () => {
815
833
  await writeTwoProjectWorkspace(workspace, builds);
816
834
  const built = await run(
817
835
  'node',
818
- nxEntry,
836
+ nxEntry(workspace),
819
837
  workspace,
820
838
  ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
821
839
  { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
@@ -931,76 +949,29 @@ await writeFile(${JSON.stringify(resultsPath)}, JSON.stringify(results));
931
949
  },
932
950
  'workspace',
933
951
  );
934
- }, 60_000);
952
+ });
935
953
 
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[] = [];
954
+ // Publication is opt-in only for the receipt case. Graph/exec probes below
955
+ // keep ordinary plugin hooks but have no producer source/tool prepass.
956
+ it('publishes real completion receipts and reuses their original basis for the same tree', async () => {
957
+ let providerSockets: string | null = null;
943
958
  try {
944
959
  await withNxFixture(
945
- 'ensure-built-daemon-',
946
- async (fixture) => {
947
- root = fixture.root;
948
- const { workspace } = fixture;
960
+ 'ensure-built-producer-',
961
+ async ({ root, workspace }) => {
949
962
  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);
963
+ await writeTwoProjectWorkspace(workspace, builds, true);
964
+ providerSockets = providerSocketDirectory(workspace);
954
965
  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
966
  const built = await run(
959
967
  'node',
960
- nxEntry,
968
+ nxEntry(workspace),
961
969
  workspace,
962
970
  ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
963
971
  { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
964
972
  );
965
973
  expect(built.code, built.stdout + built.stderr).toBe(0);
966
974
  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
975
  // Probe-only receipts use the real Nx keys/cache and independently
1005
976
  // census public output bytes without starting a task runner.
1006
977
  const committed = spawnSync(
@@ -1036,6 +1007,15 @@ await writeFile(${JSON.stringify(resultsPath)}, JSON.stringify(results));
1036
1007
  { encoding: 'utf8' },
1037
1008
  );
1038
1009
  expect(sourceCommit.status, sourceCommit.stdout + sourceCommit.stderr).toBe(0);
1010
+ const published = await run(
1011
+ 'node',
1012
+ nxEntry(workspace),
1013
+ workspace,
1014
+ ['run', 'app:build', '--outputStyle=static-failures-only'],
1015
+ { NX_DAEMON: 'true', NX_WORKSPACE_ROOT_PATH: workspace, ...ownEnv },
1016
+ );
1017
+ expect(published.code, published.stdout + published.stderr).toBe(0);
1018
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1039
1019
  const probeEntry = join(root, 'probe-receipt.ts');
1040
1020
  await writeFile(
1041
1021
  probeEntry,
@@ -1060,7 +1040,7 @@ await writeFile(source, 'new uncached source');
1060
1040
  const uncached = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1061
1041
  const outputAfterMiss = await readFile(output, 'utf8');
1062
1042
  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 }));
1043
+ 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
1044
  `,
1065
1045
  );
1066
1046
  const probed = await run('bun', probeEntry, workspace, [], {
@@ -1071,10 +1051,10 @@ console.log(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten:
1071
1051
  });
1072
1052
  expect(probed.code, probed.stdout + probed.stderr).toBe(0);
1073
1053
  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;
1054
+ hit: EnsureBuiltProbeResult;
1055
+ daemonless: EnsureBuiltProbeResult;
1056
+ stale: EnsureBuiltProbeResult;
1057
+ uncached: EnsureBuiltProbeResult;
1078
1058
  outputUnwritten: boolean;
1079
1059
  outputAfterMiss: string;
1080
1060
  }>(probed.stdout);
@@ -1087,55 +1067,129 @@ console.log(JSON.stringify({ hit, daemonless, stale, uncached, outputUnwritten:
1087
1067
  .find(({ path }) => path === 'packages/app/dist/marker.txt'),
1088
1068
  ).toMatchObject({ type: 'file', sha256: expect.stringMatching(/^[a-f0-9]{64}$/) });
1089
1069
  }
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');
1070
+ expect(receipts.daemonless.disposition).toBe('hit');
1071
+ expect(receipts.stale).toMatchObject({ disposition: 'failed', reason: { kind: 'provider-proof' } });
1072
+ expect(receipts.uncached.disposition).toBe('failed');
1099
1073
  expect(receipts.outputUnwritten).toBe(true);
1100
1074
  expect(receipts.outputAfterMiss).toBe('built\nlib\n');
1101
1075
  expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1102
1076
 
1103
- const sourceRaceEntry = join(root, 'receipt-source-race.ts');
1077
+ const producerEnvironmentEntry = join(root, 'producer-environment-independence.ts');
1104
1078
  await writeFile(
1105
- sourceRaceEntry,
1079
+ producerEnvironmentEntry,
1106
1080
  `
1107
1081
  import { createRequire } from 'node:module';
1108
- import { readFile, writeFile } from 'node:fs/promises';
1109
- import { join } from 'node:path';
1082
+ import { spawnSync } from 'node:child_process';
1110
1083
  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
1084
  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() })));
1085
+ daemonClient.hashTasks = async () => { throw new Error('readonly consumer must not hash its own environment'); };
1086
+ const packageJson = createRequire(process.cwd() + '/package.json')('nx/src/utils/package-json');
1087
+ const readModulePackageJson = packageJson.readModulePackageJson;
1088
+ let moduleInspections = 0;
1089
+ packageJson.readModulePackageJson = (...args) => { moduleInspections += 1; return readModulePackageJson(...args); };
1090
+ process.env.PRODUCER_CONSUMER_DIFFERENCE = 'consumer-only';
1091
+ const first = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1092
+ const empty = spawnSync('git', ['-c', 'user.name=Receipt fixture', '-c', 'user.email=receipt@example.invalid', 'commit', '--allow-empty', '-qm', 'same tree'], { encoding: 'utf8' });
1093
+ if (empty.status !== 0) throw new Error(empty.stderr);
1094
+ const sameTree = await probeBuilt({ target: 'app:build', cwd: process.cwd() });
1095
+ await new Promise<void>((resolve, reject) => process.stdout.write(JSON.stringify({ first, sameTree, moduleInspections }) + "\\n", error => error ? reject(error) : resolve()));
1122
1096
  `,
1123
1097
  );
1124
- const sourceRace = await run('bun', sourceRaceEntry, workspace, [], {
1098
+ const producerEnvironment = await run('bun', producerEnvironmentEntry, workspace, [], {
1125
1099
  NX_DAEMON: 'true',
1126
1100
  NX_USE_LOCAL: 'true',
1127
1101
  NX_WORKSPACE_ROOT_PATH: workspace,
1128
1102
  ...ownEnv,
1129
1103
  });
1130
- expect(sourceRace.code, sourceRace.stdout + sourceRace.stderr).toBe(0);
1131
- const sourceRaceResult = typia.json.assertParse<import('./ensure-built.js').EnsureBuiltProbeResult>(
1132
- sourceRace.stdout,
1104
+ expect(producerEnvironment.code, producerEnvironment.stdout + producerEnvironment.stderr).toBe(0);
1105
+ const environmentResults = typia.json.assertParse<{
1106
+ first: EnsureBuiltProbeResult;
1107
+ sameTree: EnsureBuiltProbeResult;
1108
+ moduleInspections: number;
1109
+ }>(producerEnvironment.stdout);
1110
+ expect(environmentResults.first.disposition, producerEnvironment.stderr).toBe('hit');
1111
+ expect(environmentResults.sameTree).toEqual(environmentResults.first);
1112
+ expect(environmentResults.moduleInspections).toBe(0);
1113
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1114
+ },
1115
+ 'workspace',
1116
+ );
1117
+ } finally {
1118
+ if (providerSockets !== null) await rm(providerSockets, { recursive: true, force: true });
1119
+ }
1120
+ });
1121
+
1122
+ // The graph/exec case runs real Nx because its subject is the daemon:
1123
+ // the daemon a probe starts holds no output records, so every output must be
1124
+ // vouched for by comparing the working tree with Nx's cache artifact. The
1125
+ // daemon it starts is also the one whose socket is in question, so the same
1126
+ // lifetime answers where a root entered from another workspace's shell binds.
1127
+ it('replays current outputs and refreshes stale snapshots without running unrelated edits', async () => {
1128
+ // A socket path has a 95 character budget and macOS's temp directory spends most of it, so the
1129
+ // socket directory is made in the short socket namespace the sandbox admits.
1130
+ const socketDir = await ownedSocketDirectory('eb-sock-', NX_LONGEST_SOCKET_NAME);
1131
+ let root = '';
1132
+ let failure: { readonly error: unknown } | null = null;
1133
+ const providerDirectories: string[] = [];
1134
+ try {
1135
+ await withNxFixture(
1136
+ 'ensure-built-daemon-',
1137
+ async (fixture) => {
1138
+ root = fixture.root;
1139
+ const { workspace } = fixture;
1140
+ const builds = join(root, 'lib-builds.log');
1141
+ await writeTwoProjectWorkspace(workspace, builds);
1142
+ // What the provider binds for this workspace when the call is entered from another one's shell.
1143
+ const providerSockets = providerSocketDirectory(workspace);
1144
+ if (providerSockets !== null) providerDirectories.push(providerSockets);
1145
+ const ownEnv: Record<string, string> = providerSockets === null ? {} : { NX_SOCKET_DIR: providerSockets };
1146
+
1147
+ // Built by daemonless Nx, as CI or a restarted daemon leaves a tree:
1148
+ // cached and on disk, recorded by no daemon.
1149
+ const built = await run(
1150
+ 'node',
1151
+ nxEntry(workspace),
1152
+ workspace,
1153
+ ['run-many', '-t', 'build', '-p', 'app', '--outputStyle=static-failures-only'],
1154
+ { NX_DAEMON: 'false', NX_WORKSPACE_ROOT_PATH: workspace },
1133
1155
  );
1134
- expect(sourceRaceResult).toMatchObject({
1135
- disposition: 'failed',
1136
- reason: { kind: 'provider-proof', detail: expect.stringContaining('across Nx hashing') },
1156
+ expect(built.code, built.stdout + built.stderr).toBe(0);
1157
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1158
+
1159
+ // Entered from outside the root by a shell set up for another
1160
+ // workspace, as a managed devenv's is: its socket directory belongs to
1161
+ // that workspace's daemon, and a second daemon listening there would
1162
+ // take the socket from it.
1163
+ const caller = join(root, 'caller');
1164
+ await mkdir(caller);
1165
+ const hit = await run(
1166
+ 'bun',
1167
+ binEntry,
1168
+ caller,
1169
+ ['app:build', '--workspace-root', workspace, '--', join(workspace, 'report')],
1170
+ { NX_DAEMON: 'true', NX_USE_LOCAL: 'true', NX_SOCKET_DIR: socketDir },
1171
+ );
1172
+ expect(hit.code, hit.stdout + hit.stderr).toBe(0);
1173
+ expect(hit.stderr).toBe('');
1174
+ expect(hit.stdout.split('\n')[0], hit.stdout).toBe(MARKER);
1175
+ expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1176
+ expect(await readdir(socketDir)).toEqual([]);
1177
+ const record = await readFile(join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json'), 'utf-8');
1178
+ expect(record).not.toContain(socketDir);
1179
+ // The daemon it started binds in the directory the provider named, not the caller's nor Nx's default.
1180
+ const daemon = typia.json.assertParse<DaemonProcessJson>(record);
1181
+ if (providerSockets !== null) {
1182
+ expect(daemon.socketPath.startsWith(`${providerSockets}/`), record).toBe(true);
1183
+ }
1184
+
1185
+ // That hit re-armed the daemon's records. The emitted wrapper, under
1186
+ // Node and with nothing to exec, is as silent.
1187
+ const again = await run('node', builtBinEntry, workspace, ['app:build'], {
1188
+ NX_DAEMON: 'true',
1189
+ NX_USE_LOCAL: 'true',
1190
+ ...ownEnv,
1137
1191
  });
1138
- expect(sourceRace.stderr).toContain('Provider source');
1192
+ expect(again).toEqual({ code: 0, signal: null, stdout: '', stderr: '' });
1139
1193
  expect(await readFile(builds, 'utf-8')).toBe('lib\n');
1140
1194
 
1141
1195
  // An awaited daemon graph can see B while both disk snapshots see
@@ -1258,5 +1312,5 @@ console.log(JSON.stringify(await ensureBuilt({ target: 'app:build', cwd: process
1258
1312
  cause: failure.error,
1259
1313
  });
1260
1314
  }
1261
- }, 60_000);
1315
+ });
1262
1316
  });