@smoothbricks/nx-plugin 0.4.28 → 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 +179 -114
  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
@@ -48,7 +48,7 @@ export async function indexedCargoManifests(workspaceRoot) {
48
48
  export async function resolveCargoClosureSource(manifest, workspaceRoot, indexed, compiledFilesCache) {
49
49
  const [root, index] = await Promise.all([realpath(workspaceRoot), indexed]);
50
50
  const cargo = await readCargoResolve(join(root, manifest), root, index);
51
- return { manifest, root, cargo, indexed: index, compiledFilesCache };
51
+ return { manifest, workspaceRoot, root, cargo, indexed: index, compiledFilesCache };
52
52
  }
53
53
  /**
54
54
  * The `cargoClosure` definition for the project at `projectRoot`: for each
@@ -69,6 +69,16 @@ export async function resolveCargoClosureSource(manifest, workspaceRoot, indexed
69
69
  * An in-workspace member missing from Nx's file index is a typed refusal,
70
70
  * never a whole-workspace runtime hash. Only outside-workspace members need
71
71
  * the external-only runtime input.
72
+ *
73
+ * A compiled-in file is named only when Nx's file index holds both it and the
74
+ * source that includes it. An ignored one is a build output: no fileset can
75
+ * hash its bytes, which reach a consumer through its producer's dependency
76
+ * outputs instead, so naming it would add nothing to any task's key except
77
+ * the names of whatever output last ran. That state is exactly what a project
78
+ * graph must not read (`globIndexedFiles`): a producer that regenerates
79
+ * content-named files would otherwise move every key of the graph it was
80
+ * hashed under, and the run that compiled a tree would leave its verdict
81
+ * under a key no later run of the same tree computes.
72
82
  */
73
83
  export async function cargoClosureInputs(projectRoot, sources) {
74
84
  const inputs = [];
@@ -91,6 +101,7 @@ async function workspaceClosureInputs(projectRoot, source) {
91
101
  const { root, cargo, indexed } = source;
92
102
  const packageDirectories = [];
93
103
  const files = [];
104
+ const compiledIn = [];
94
105
  const compiledFiles = new Set();
95
106
  let external = false;
96
107
  try {
@@ -106,11 +117,15 @@ async function workspaceClosureInputs(projectRoot, source) {
106
117
  if (!indexed.has(posix.join(directory, 'Cargo.toml'))) {
107
118
  throw new Error(`the Cargo package ${directory} is not in Nx's file index (an ignored directory)`);
108
119
  }
109
- for (const { file } of compiledInFiles(pkg.directory, source.compiledFilesCache)) {
110
- const path = indexablePath(root, file);
111
- if (path === null)
112
- throw new Error(`${directory} compiles ${file}, which Nx's file index cannot hold`);
113
- compiledFiles.add(path);
120
+ for (const compiled of compiledInFiles(pkg.directory, source.compiledFilesCache)) {
121
+ const file = indexablePath(root, compiled.file);
122
+ if (file === null)
123
+ throw new Error(`${directory} compiles ${compiled.file}, which Nx's file index cannot hold`);
124
+ // The scan starts inside this package's indexable directory, so its sources can always be named.
125
+ const declaring = indexablePath(root, compiled.source);
126
+ if (declaring === null)
127
+ throw new Error(`${compiled.source} was scanned outside ${directory}`);
128
+ compiledIn.push({ declaring, file });
114
129
  }
115
130
  packageDirectories.push(directory);
116
131
  for (const file of [...pkg.sources, pkg.governingManifest]) {
@@ -120,9 +135,16 @@ async function workspaceClosureInputs(projectRoot, source) {
120
135
  files.push(path);
121
136
  }
122
137
  }
123
- const unglobbable = [...packageDirectories, ...files, ...compiledFiles].find((path) => GLOB_SYNTAX.test(path));
138
+ const compiledPaths = [...new Set(compiledIn.flatMap(({ declaring, file }) => [declaring, file]))];
139
+ const unglobbable = [...packageDirectories, ...files, ...compiledPaths].find((path) => GLOB_SYNTAX.test(path));
124
140
  if (unglobbable !== undefined)
125
141
  throw new Error(`${unglobbable} contains glob syntax, so no fileset can name it`);
142
+ // Literal paths, so each matches exactly itself in the index.
143
+ const held = new Set(compiledPaths.length === 0 ? [] : await globIndexedFiles(source.workspaceRoot, compiledPaths));
144
+ for (const { declaring, file } of compiledIn) {
145
+ if (held.has(declaring) && held.has(file))
146
+ compiledFiles.add(file);
147
+ }
126
148
  }
127
149
  catch (error) {
128
150
  throw new CargoClosureInputError(projectRoot, error);
@@ -1 +1 @@
1
- {"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AAiGA,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iHAAiH;IACjH,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,kGAAkG;AAClG,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;CAC/D;AAED,MAAM,WAAW,sBAAsB;IACrC,oHAAoH;IACpH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAkJD,2GAA2G;AAC3G,eAAO,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AAG,SAAS;IAJxC,YACW,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAOvC;CACF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAmF7D;AAoCD,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,CA6HjB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAc5G;AAoGD,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAOD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,EAAE,CA0C5G"}
@@ -1,8 +1,8 @@
1
1
  import { execFileSync, spawn, spawnSync } from 'node:child_process';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
3
  import { channel } from 'node:diagnostics_channel';
4
- import { constants, existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
5
- import { access, lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile, } from 'node:fs/promises';
4
+ import { accessSync, constants, existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
5
+ import { lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
6
6
  import { createRequire } from 'node:module';
7
7
  import { homedir } from 'node:os';
8
8
  import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
@@ -299,16 +299,16 @@ function resolutionFiles(root, manifest, cargo, indexed) {
299
299
  const directories = new Set([root]);
300
300
  for (const file of paths)
301
301
  directories.add(dirname(file));
302
+ const ancestors = new Set();
302
303
  for (const directory of directories) {
303
304
  paths.add(join(directory, 'Cargo.lock'));
304
- for (let ancestor = directory;; ancestor = dirname(ancestor)) {
305
+ for (let ancestor = directory; !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
306
+ ancestors.add(ancestor);
305
307
  paths.add(join(ancestor, '.cargo/config'));
306
308
  paths.add(join(ancestor, '.cargo/config.toml'));
307
309
  paths.add(join(ancestor, 'rust-toolchain'));
308
310
  paths.add(join(ancestor, 'rust-toolchain.toml'));
309
311
  paths.add(join(ancestor, 'Cargo.toml'));
310
- if (dirname(ancestor) === ancestor)
311
- break;
312
312
  }
313
313
  }
314
314
  for (const pin of CARGO_TOOLCHAIN_PIN_INPUTS)
@@ -319,12 +319,12 @@ function resolutionFiles(root, manifest, cargo, indexed) {
319
319
  return paths;
320
320
  }
321
321
  /** Toolchain selection can change even while the declared pin's bytes do not. */
322
- async function cargoExecutable() {
322
+ function cargoExecutable() {
323
323
  for (const directory of (process.env.PATH ?? '').split(delimiter)) {
324
324
  const executable = resolve(directory, process.platform === 'win32' ? 'cargo.exe' : 'cargo');
325
325
  try {
326
- await access(executable, constants.X_OK);
327
- return await realpath(executable);
326
+ accessSync(executable, constants.X_OK);
327
+ return realpathSync.native(executable);
328
328
  }
329
329
  catch (error) {
330
330
  if (!(error instanceof Error &&
@@ -335,14 +335,17 @@ async function cargoExecutable() {
335
335
  }
336
336
  return '<cargo-not-on-PATH>';
337
337
  }
338
- async function resolutionKey(root, manifest, cargo, indexed) {
338
+ function resolutionKey(root, manifest, cargo, indexed) {
339
339
  const cargoHome = resolve(process.env.CARGO_HOME ?? join(homedir(), '.cargo'));
340
- const executable = await cargoExecutable();
340
+ const executable = cargoExecutable();
341
341
  const hash = createHash('sha256').update(`${RESOLVE_CACHE_SCHEMA}\0${root}\0${manifest}\0${cargoHome}\0${executable}\0${process.env.RUSTUP_TOOLCHAIN ?? ''}\0${process.env.RUSTUP_HOME ?? ''}\0`);
342
342
  for (const file of [...resolutionFiles(root, manifest, cargo, indexed)].sort()) {
343
343
  hash.update(file).update('\0');
344
344
  try {
345
- const [bytes, canonical] = await Promise.all([readFile(file), realpath(file)]);
345
+ // Most ancestor inputs are absent. Read first so those paths need no
346
+ // canonical lookup; small resolution files need no per-file async dispatch.
347
+ const bytes = readFileSync(file);
348
+ const canonical = realpathSync.native(file);
346
349
  hash.update(`${canonical}\0${bytes.length}\0`).update(bytes);
347
350
  }
348
351
  catch (error) {
@@ -435,7 +438,7 @@ export async function readCargoResolve(manifestPath, cwd, indexed, boundMs = CAR
435
438
  else
436
439
  await state.ready;
437
440
  for (let joined = 0; joined <= 3; joined += 1) {
438
- const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, index);
441
+ const key = resolutionKey(root, manifest, state.cached?.cargo ?? null, index);
439
442
  const pending = state.pending;
440
443
  if (pending !== undefined) {
441
444
  if (joined === 3)
@@ -478,6 +481,21 @@ export async function readCargoResolve(manifestPath, cwd, indexed, boundMs = CAR
478
481
  throw new CargoMetadataError(manifest, error);
479
482
  }
480
483
  }
484
+ async function observeCacheParent(directory) {
485
+ try {
486
+ const parent = await stat(directory, { bigint: true });
487
+ return { state: 'present', dev: parent.dev.toString(), ino: parent.ino.toString() };
488
+ }
489
+ catch (error) {
490
+ if (!(error instanceof Error))
491
+ throw error;
492
+ return {
493
+ state: 'unavailable',
494
+ code: 'code' in error && typeof error.code === 'string' ? error.code : error.name,
495
+ detail: error.message,
496
+ };
497
+ }
498
+ }
481
499
  async function resolveAndCache(root, manifest, indexed, directory, file, state, boundMs = CARGO_RESOLVE_BOUND_MS) {
482
500
  if (IS_WASM)
483
501
  throw new Error('Cargo resolution requires the native Nx file lock; a WASM Nx host cannot own Cargo children');
@@ -485,19 +503,18 @@ async function resolveAndCache(root, manifest, indexed, directory, file, state,
485
503
  // A warm cache answers with no lock: reading it and keying it spawns nothing and
486
504
  // waits for nobody, so an unchanged workspace never queues behind a foreign flight.
487
505
  state.cached = await loadResolveCache(file);
488
- {
489
- const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, indexed);
490
- if (state.cached?.key === key)
491
- return state.cached.cargo;
506
+ if (state.cached !== null && state.cached.key === resolutionKey(root, manifest, state.cached.cargo, indexed)) {
507
+ return state.cached.cargo;
492
508
  }
493
509
  const lockFile = join(directory, 'resolve.lock');
510
+ const parentBeforeLock = await observeCacheParent(directory);
494
511
  const lock = await acquireCargoResolveLock(lockFile, boundMs);
495
512
  try {
496
513
  // Another worker may have populated it while this worker waited.
497
514
  state.cached = await loadResolveCache(file);
498
515
  let inputs = state.cached?.cargo ?? null;
499
516
  for (let attempt = 0; attempt < 3; attempt += 1) {
500
- const before = await resolutionKey(root, manifest, inputs, indexed);
517
+ const before = resolutionKey(root, manifest, inputs, indexed);
501
518
  if (state.cached?.key === before)
502
519
  return state.cached.cargo;
503
520
  const knownFiles = resolutionFiles(root, manifest, inputs, indexed);
@@ -509,8 +526,8 @@ async function resolveAndCache(root, manifest, indexed, directory, file, state,
509
526
  const cargo = cargoFromMetadata(metadata);
510
527
  // Capture the published key before validation. Reading it afterwards
511
528
  // could pair a post-edit key with Cargo's pre-edit answer.
512
- const key = await resolutionKey(root, manifest, cargo, indexed);
513
- let changed = before !== (await resolutionKey(root, manifest, inputs, indexed));
529
+ const key = resolutionKey(root, manifest, cargo, indexed);
530
+ let changed = before !== resolutionKey(root, manifest, inputs, indexed);
514
531
  for (const added of resolutionFiles(root, manifest, cargo, indexed)) {
515
532
  if (knownFiles.has(added))
516
533
  continue;
@@ -528,10 +545,16 @@ async function resolveAndCache(root, manifest, indexed, directory, file, state,
528
545
  continue;
529
546
  }
530
547
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
548
+ const parentAtTmpOpen = await observeCacheParent(directory);
531
549
  try {
532
550
  await writeFile(temporary, `${key}\n${JSON.stringify(metadata)}\n`);
533
551
  await rename(temporary, file);
534
552
  }
553
+ catch (error) {
554
+ const parentAfterFailure = await observeCacheParent(directory);
555
+ const cause = error instanceof Error ? error.message : String(error);
556
+ throw new Error(`Cargo resolution cache publication failed: ${JSON.stringify({ directory, lockFile, temporary, parentBeforeLock, parentAtTmpOpen, parentAfterFailure })}; ${cause}`, { cause: error });
557
+ }
535
558
  finally {
536
559
  await rm(temporary, { force: true });
537
560
  }
@@ -1,6 +1,14 @@
1
1
  import type { Task } from 'nx/src/config/task-graph';
2
2
  import type { expandOutputs, HashInputs } from 'nx/src/native';
3
- import type { EnsureBuiltProbeFailure, EnsureBuiltReceipt } from './ensure-built.js';
3
+ import type { EnsureBuiltOutputReceipt, EnsureBuiltProbeFailure, EnsureBuiltProducerFileInput, EnsureBuiltProducerReceipt, EnsureBuiltReceipt } from './ensure-built.js';
4
+ import { type NodeWitness } from './ensure-built-witness.js';
5
+ export type ReceiptEvidence<T> = {
6
+ readonly ok: true;
7
+ readonly value: T;
8
+ } | {
9
+ readonly ok: false;
10
+ readonly detail: string;
11
+ };
4
12
  export interface ProviderInputProof {
5
13
  readonly kind: 'exact-file-inputs' | 'conservative-provider-source';
6
14
  readonly files: readonly string[];
@@ -12,14 +20,34 @@ export interface ProviderInputProof {
12
20
  readonly detail: string;
13
21
  };
14
22
  }
15
- /** NUL-delimited Git paths preserve whitespace, rename sources and index-only changes. */
23
+ export interface ProducerSourceWitness {
24
+ readonly head: string;
25
+ readonly headTree: string;
26
+ readonly files: readonly EnsureBuiltProducerFileInput[];
27
+ readonly nodes: readonly NodeWitness[];
28
+ readonly outputs: readonly string[];
29
+ }
30
+ /**
31
+ * Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in whichever process
32
+ * Nx runs plugins in, a workspace's sandboxed daemon included, which adopts a host client's HOME; git with that HOME
33
+ * reads the operator's global configuration, the sandbox denies it, and git dies (specs/cowshed/04_sandbox.md, the
34
+ * runtime-input contract). A receipt's tree, HEAD and tracked-file status are read under the repository's own
35
+ * configuration alone, so a host run and a sandboxed run agree on them.
36
+ */
37
+ export declare function receiptGit(root: string, args: string[]): ReceiptEvidence<string>;
38
+ /** NUL-delimited paths preserve whitespace, rename sources and index-only changes. */
16
39
  export declare function dirtyProviderPaths(status: string): string[];
17
- export declare function providerReceipt(workspaceRoot: string, taskId: string, tasks: readonly Task[], proof: ProviderInputProof, expand: typeof expandOutputs): {
40
+ /** One independently read node; absolute paths also serve tool/package closures. */
41
+ export declare function receiptNode(path: string, name: string, observed: NodeWitness[]): EnsureBuiltOutputReceipt;
42
+ /** Capture every tracked source byte at pre. Unrelated untracked files are not source basis. */
43
+ export declare function captureProducerSource(root: string, outputs: readonly string[]): ReceiptEvidence<ProducerSourceWitness>;
44
+ export declare function producerSourceUnchanged(root: string, before: ProducerSourceWitness): ReceiptEvidence<true>;
45
+ /** Enumerate exact public nodes; never exempt a broad directory of tracked source. */
46
+ export declare function producerOutputPaths(root: string, tasks: readonly Task[], expand: typeof expandOutputs): string[];
47
+ export declare function providerReceipt(root: string, taskId: string, tasks: readonly Task[], proof: ProviderInputProof, expand: typeof expandOutputs, source: ProducerSourceWitness, producer: Omit<EnsureBuiltProducerReceipt, 'outputSha256'>): {
18
48
  readonly disposition: 'hit';
19
49
  readonly receipt: EnsureBuiltReceipt;
20
50
  } | EnsureBuiltProbeFailure;
21
- /** Admit only recipes emitted by the same owning toolchain generator.
22
- * No shell parsing or keyword approximation confers file-source provenance.
23
- */
51
+ /** Admit only version recipes emitted by the owning generator and declared toolchain pins. */
24
52
  export declare function boundedReceiptRuntimes(inputs: Readonly<Record<string, HashInputs>>, directories: readonly string[], files: readonly string[], installationProved: boolean): ProviderInputProof['runtimeSource'];
25
53
  //# sourceMappingURL=ensure-built-receipt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensure-built-receipt.d.ts","sourceRoot":"","sources":["../src/ensure-built-receipt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,KAAK,EAA4B,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAK/G,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,GAAG,8BAA8B,CAAC;IACpE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,aAAa,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7G;AA0BD,0FAA0F;AAC1F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAa3D;AAED,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,OAAO,aAAa,GAC3B;IAAE,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAAG,uBAAuB,CAqKjG;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE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