@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
@@ -1,20 +1,8 @@
1
1
  import { type ChildProcess, type ChildProcessByStdio, 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 {
6
- access,
7
- lstat,
8
- mkdir,
9
- readdir,
10
- readFile,
11
- readlink,
12
- realpath,
13
- rename,
14
- rm,
15
- stat,
16
- writeFile,
17
- } 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';
18
6
  import { createRequire } from 'node:module';
19
7
  import { homedir } from 'node:os';
20
8
  import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
@@ -390,15 +378,16 @@ function resolutionFiles(
390
378
  if (cargo !== null) paths.add(join(cargo.root, 'Cargo.toml'));
391
379
  const directories = new Set<string>([root]);
392
380
  for (const file of paths) directories.add(dirname(file));
381
+ const ancestors = new Set<string>();
393
382
  for (const directory of directories) {
394
383
  paths.add(join(directory, 'Cargo.lock'));
395
- for (let ancestor = directory; ; ancestor = dirname(ancestor)) {
384
+ for (let ancestor = directory; !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
385
+ ancestors.add(ancestor);
396
386
  paths.add(join(ancestor, '.cargo/config'));
397
387
  paths.add(join(ancestor, '.cargo/config.toml'));
398
388
  paths.add(join(ancestor, 'rust-toolchain'));
399
389
  paths.add(join(ancestor, 'rust-toolchain.toml'));
400
390
  paths.add(join(ancestor, 'Cargo.toml'));
401
- if (dirname(ancestor) === ancestor) break;
402
391
  }
403
392
  }
404
393
  for (const pin of CARGO_TOOLCHAIN_PIN_INPUTS) paths.add(pin.replace('{workspaceRoot}', root));
@@ -409,12 +398,12 @@ function resolutionFiles(
409
398
  }
410
399
 
411
400
  /** Toolchain selection can change even while the declared pin's bytes do not. */
412
- async function cargoExecutable(): Promise<string> {
401
+ function cargoExecutable(): string {
413
402
  for (const directory of (process.env.PATH ?? '').split(delimiter)) {
414
403
  const executable = resolve(directory, process.platform === 'win32' ? 'cargo.exe' : 'cargo');
415
404
  try {
416
- await access(executable, constants.X_OK);
417
- return await realpath(executable);
405
+ accessSync(executable, constants.X_OK);
406
+ return realpathSync.native(executable);
418
407
  } catch (error) {
419
408
  if (
420
409
  !(
@@ -429,21 +418,24 @@ async function cargoExecutable(): Promise<string> {
429
418
  return '<cargo-not-on-PATH>';
430
419
  }
431
420
 
432
- async function resolutionKey(
421
+ function resolutionKey(
433
422
  root: string,
434
423
  manifest: string,
435
424
  cargo: CargoResolve | null,
436
425
  indexed: ReadonlySet<string>,
437
- ): Promise<string> {
426
+ ): string {
438
427
  const cargoHome = resolve(process.env.CARGO_HOME ?? join(homedir(), '.cargo'));
439
- const executable = await cargoExecutable();
428
+ const executable = cargoExecutable();
440
429
  const hash = createHash('sha256').update(
441
430
  `${RESOLVE_CACHE_SCHEMA}\0${root}\0${manifest}\0${cargoHome}\0${executable}\0${process.env.RUSTUP_TOOLCHAIN ?? ''}\0${process.env.RUSTUP_HOME ?? ''}\0`,
442
431
  );
443
432
  for (const file of [...resolutionFiles(root, manifest, cargo, indexed)].sort()) {
444
433
  hash.update(file).update('\0');
445
434
  try {
446
- const [bytes, canonical] = await Promise.all([readFile(file), realpath(file)]);
435
+ // Most ancestor inputs are absent. Read first so those paths need no
436
+ // canonical lookup; small resolution files need no per-file async dispatch.
437
+ const bytes = readFileSync(file);
438
+ const canonical = realpathSync.native(file);
447
439
  hash.update(`${canonical}\0${bytes.length}\0`).update(bytes);
448
440
  } catch (error) {
449
441
  if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) throw error;
@@ -538,7 +530,7 @@ export async function readCargoResolve(
538
530
  }
539
531
  } else await state.ready;
540
532
  for (let joined = 0; joined <= 3; joined += 1) {
541
- const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, index);
533
+ const key = resolutionKey(root, manifest, state.cached?.cargo ?? null, index);
542
534
  const pending = state.pending;
543
535
  if (pending !== undefined) {
544
536
  if (joined === 3) break;
@@ -572,6 +564,24 @@ export async function readCargoResolve(
572
564
  }
573
565
  }
574
566
 
567
+ type CacheParentObservation =
568
+ | { readonly state: 'present'; readonly dev: string; readonly ino: string }
569
+ | { readonly state: 'unavailable'; readonly code: string; readonly detail: string };
570
+
571
+ async function observeCacheParent(directory: string): Promise<CacheParentObservation> {
572
+ try {
573
+ const parent = await stat(directory, { bigint: true });
574
+ return { state: 'present', dev: parent.dev.toString(), ino: parent.ino.toString() };
575
+ } catch (error) {
576
+ if (!(error instanceof Error)) throw error;
577
+ return {
578
+ state: 'unavailable',
579
+ code: 'code' in error && typeof error.code === 'string' ? error.code : error.name,
580
+ detail: error.message,
581
+ };
582
+ }
583
+ }
584
+
575
585
  async function resolveAndCache(
576
586
  root: string,
577
587
  manifest: string,
@@ -587,18 +597,18 @@ async function resolveAndCache(
587
597
  // A warm cache answers with no lock: reading it and keying it spawns nothing and
588
598
  // waits for nobody, so an unchanged workspace never queues behind a foreign flight.
589
599
  state.cached = await loadResolveCache(file);
590
- {
591
- const key = await resolutionKey(root, manifest, state.cached?.cargo ?? null, indexed);
592
- if (state.cached?.key === key) return state.cached.cargo;
600
+ if (state.cached !== null && state.cached.key === resolutionKey(root, manifest, state.cached.cargo, indexed)) {
601
+ return state.cached.cargo;
593
602
  }
594
603
  const lockFile = join(directory, 'resolve.lock');
604
+ const parentBeforeLock = await observeCacheParent(directory);
595
605
  const lock = await acquireCargoResolveLock(lockFile, boundMs);
596
606
  try {
597
607
  // Another worker may have populated it while this worker waited.
598
608
  state.cached = await loadResolveCache(file);
599
609
  let inputs = state.cached?.cargo ?? null;
600
610
  for (let attempt = 0; attempt < 3; attempt += 1) {
601
- const before = await resolutionKey(root, manifest, inputs, indexed);
611
+ const before = resolutionKey(root, manifest, inputs, indexed);
602
612
  if (state.cached?.key === before) return state.cached.cargo;
603
613
  const knownFiles = resolutionFiles(root, manifest, inputs, indexed);
604
614
  // A filesystem timestamp, not a sandbox's wall clock: a newly
@@ -609,8 +619,8 @@ async function resolveAndCache(
609
619
  const cargo = cargoFromMetadata(metadata);
610
620
  // Capture the published key before validation. Reading it afterwards
611
621
  // could pair a post-edit key with Cargo's pre-edit answer.
612
- const key = await resolutionKey(root, manifest, cargo, indexed);
613
- let changed = before !== (await resolutionKey(root, manifest, inputs, indexed));
622
+ const key = resolutionKey(root, manifest, cargo, indexed);
623
+ let changed = before !== resolutionKey(root, manifest, inputs, indexed);
614
624
  for (const added of resolutionFiles(root, manifest, cargo, indexed)) {
615
625
  if (knownFiles.has(added)) continue;
616
626
  try {
@@ -624,9 +634,17 @@ async function resolveAndCache(
624
634
  continue;
625
635
  }
626
636
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
637
+ const parentAtTmpOpen = await observeCacheParent(directory);
627
638
  try {
628
639
  await writeFile(temporary, `${key}\n${JSON.stringify(metadata)}\n`);
629
640
  await rename(temporary, file);
641
+ } catch (error) {
642
+ const parentAfterFailure = await observeCacheParent(directory);
643
+ const cause = error instanceof Error ? error.message : String(error);
644
+ throw new Error(
645
+ `Cargo resolution cache publication failed: ${JSON.stringify({ directory, lockFile, temporary, parentBeforeLock, parentAtTmpOpen, parentAfterFailure })}; ${cause}`,
646
+ { cause: error },
647
+ );
630
648
  } finally {
631
649
  await rm(temporary, { force: true });
632
650
  }
@@ -117,7 +117,7 @@ describe('Linux cross-check policy', () => {
117
117
  } finally {
118
118
  await rm(project, { recursive: true, force: true });
119
119
  }
120
- }, 60_000);
120
+ });
121
121
 
122
122
  it('fails closed on Darwin without the linux-cross compiler instead of compiling', () => {
123
123
  // Without this guard a Darwin cache miss sits in ring's cc-rs looking for
@@ -167,7 +167,7 @@ describe('Linux cross-check policy', () => {
167
167
  } finally {
168
168
  await rm(root, { recursive: true, force: true });
169
169
  }
170
- }, 30_000);
170
+ });
171
171
 
172
172
  it('pins clippy to the committed lockfile and local cache', () => {
173
173
  expect(cargoFrozen('clippy --workspace')).toBe('cargo --frozen clippy --workspace');
@@ -6,14 +6,21 @@ import { join } from 'node:path';
6
6
  import type { Task } from 'nx/src/config/task-graph';
7
7
  import { expandOutputs } from 'nx/src/native';
8
8
  import { cargoRuntimeInput } from './cargo-toolchain-policy.js';
9
+ import type { EnsureBuiltProducerReceipt } from './ensure-built.js';
9
10
  import {
10
11
  boundedReceiptRuntimes,
12
+ captureProducerSource,
11
13
  dirtyProviderPaths,
14
+ type ProducerSourceWitness,
12
15
  type ProviderInputProof,
16
+ producerOutputPaths,
17
+ producerSourceUnchanged,
13
18
  providerReceipt,
14
19
  } from './ensure-built-receipt.js';
15
20
 
16
21
  let root = '';
22
+ let source: ProducerSourceWitness;
23
+ let producer: Omit<EnsureBuiltProducerReceipt, 'outputSha256'>;
17
24
  const task = {
18
25
  id: 'app:build',
19
26
  target: { project: 'app', target: 'build' },
@@ -46,6 +53,28 @@ beforeEach(async () => {
46
53
  await symlink('file', join(root, 'output/link'));
47
54
  await chmod(join(root, 'output/file'), 0o644);
48
55
  await chmod(join(root, 'output/empty'), 0o755);
56
+ const captured = captureProducerSource(root, producerOutputPaths(root, [task], expandOutputs));
57
+ if (!captured.ok) throw new Error(captured.detail);
58
+ source = captured.value;
59
+ producer = {
60
+ version: 1,
61
+ target: task.id,
62
+ argv: ['nx', 'run', task.id],
63
+ trackedTreeClean: true,
64
+ environmentIdentity: 'unit-fixture-nx-hash-identity',
65
+ tools: [],
66
+ wallTimeMs: 0,
67
+ inputs: [
68
+ {
69
+ taskId: task.id,
70
+ overrides: task.overrides,
71
+ declared: [],
72
+ expanded: inputs,
73
+ hashDetails: { command: 'unit-fixture', nodes: {} },
74
+ files: source.files.filter(({ path }) => inputs.files.includes(path)),
75
+ },
76
+ ],
77
+ };
49
78
  });
50
79
  afterEach(async () => {
51
80
  await rm(root, { recursive: true, force: true });
@@ -56,14 +85,36 @@ describe('provider receipt', () => {
56
85
  const saved = process.env.GIT_DIR;
57
86
  process.env.GIT_DIR = join(root, 'not-the-provider-git-directory');
58
87
  try {
59
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('hit');
88
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('hit');
60
89
  } finally {
61
90
  if (saved === undefined) delete process.env.GIT_DIR;
62
91
  else process.env.GIT_DIR = saved;
63
92
  }
64
93
  });
94
+ it("reads provider provenance without the operator's global git configuration", async () => {
95
+ // The cowshed sandbox denies the operator's global git configuration to a workspace's Nx daemon, which runs these
96
+ // hooks under a host client's HOME; git then dies "unable to access". A self-referencing link fails git the same
97
+ // way (ELOOP), where an unreadable file would only warn (EACCES).
98
+ const home = join(root, 'operator-home');
99
+ await mkdir(home);
100
+ await symlink('.gitconfig', join(home, '.gitconfig'));
101
+ const names = ['HOME', 'XDG_CONFIG_HOME', 'GIT_CONFIG_GLOBAL', 'GIT_CONFIG_NOSYSTEM'] as const;
102
+ const saved = names.map((name) => [name, process.env[name]] as const);
103
+ for (const name of names) delete process.env[name];
104
+ process.env.HOME = home;
105
+ try {
106
+ const captured = captureProducerSource(root, producerOutputPaths(root, [task], expandOutputs));
107
+ expect(captured.ok ? 'captured' : captured.detail).toBe('captured');
108
+ expect(producerSourceUnchanged(root, source)).toEqual({ ok: true, value: true });
109
+ } finally {
110
+ for (const [name, value] of saved) {
111
+ if (value === undefined) delete process.env[name];
112
+ else process.env[name] = value;
113
+ }
114
+ }
115
+ });
65
116
  it('names current hashes, HEAD/tree, independent file digests, link text and empty directory modes', async () => {
66
- const result = providerReceipt(root, task.id, [task], proof, expandOutputs);
117
+ const result = providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer);
67
118
  expect(result.disposition).toBe('hit');
68
119
  if (result.disposition !== 'hit') throw new Error(result.reason.detail);
69
120
  expect(result.receipt.head).toMatch(/^[a-f0-9]{40,64}$/);
@@ -91,51 +142,93 @@ describe('provider receipt', () => {
91
142
  });
92
143
  });
93
144
 
94
- it('does not refuse an unrelated untracked source when FILE closure is exactly proven', async () => {
145
+ it('ignores unrelated untracked files while retaining tracked-tree production provenance', async () => {
95
146
  await writeFile(join(root, 'unrelated.ts'), 'unrelated');
96
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('hit');
147
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('hit');
97
148
  expect(
98
- providerReceipt(root, task.id, [task], { ...proof, kind: 'conservative-provider-source' }, expandOutputs)
99
- .disposition,
100
- ).toBe('failed');
149
+ providerReceipt(
150
+ root,
151
+ task.id,
152
+ [task],
153
+ { ...proof, kind: 'conservative-provider-source' },
154
+ expandOutputs,
155
+ source,
156
+ producer,
157
+ ).disposition,
158
+ ).toBe('hit');
101
159
  });
102
160
 
103
161
  it('refuses modified, deleted, newly matched and index-only dirty FILE inputs', async () => {
104
162
  await writeFile(join(root, 'source.txt'), 'changed');
105
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
163
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('failed');
106
164
  git('add', 'source.txt');
107
165
  await writeFile(join(root, 'source.txt'), 'source');
108
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
166
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('failed');
109
167
  git('restore', '--staged', 'source.txt');
110
168
  await writeFile(join(root, 'new-source.txt'), 'new');
111
169
  expect(
112
- providerReceipt(root, task.id, [task], { ...proof, files: [...proof.files, 'new-source.txt'] }, expandOutputs)
113
- .disposition,
170
+ providerReceipt(
171
+ root,
172
+ task.id,
173
+ [task],
174
+ { ...proof, files: [...proof.files, 'new-source.txt'] },
175
+ expandOutputs,
176
+ source,
177
+ producer,
178
+ ).disposition,
114
179
  ).toBe('failed');
115
180
  await rm(join(root, 'source.txt'));
116
- expect(providerReceipt(root, task.id, [task], { ...proof, files: [] }, expandOutputs).disposition).toBe('failed');
181
+ expect(
182
+ providerReceipt(root, task.id, [task], { ...proof, files: [] }, expandOutputs, source, producer).disposition,
183
+ ).toBe('failed');
117
184
  });
118
185
 
119
186
  it('recomputes output byte/directory identities after every public mutation', async () => {
120
- const first = providerReceipt(root, task.id, [task], proof, expandOutputs);
187
+ const first = providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer);
121
188
  if (first.disposition !== 'hit') throw new Error(first.reason.detail);
122
189
  await writeFile(join(root, 'output/file'), 'PUBLIC BYTES');
123
190
  await chmod(join(root, 'output/empty'), 0o700);
124
- const next = providerReceipt(root, task.id, [task], proof, expandOutputs);
191
+ const next = providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer);
125
192
  if (next.disposition !== 'hit') throw new Error(next.reason.detail);
126
193
  expect(next.receipt.tasks[0].outputs).not.toEqual(first.receipt.tasks[0].outputs);
127
194
  expect(next.receipt.tasks[0].outputs.find(({ path }) => path === 'output/empty')).toMatchObject({ mode: 0o700 });
128
195
  });
129
196
 
197
+ it('accepts a new HEAD at the same committed tree without rewriting the producer basis', () => {
198
+ const original = providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer);
199
+ if (original.disposition !== 'hit') throw new Error(original.reason.detail);
200
+ git(
201
+ '-c',
202
+ 'user.name=Receipt fixture',
203
+ '-c',
204
+ 'user.email=receipt@example.invalid',
205
+ 'commit',
206
+ '--allow-empty',
207
+ '-qm',
208
+ 'same tree',
209
+ );
210
+ expect(producerSourceUnchanged(root, source)).toEqual({ ok: true, value: true });
211
+ const next = providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer);
212
+ if (next.disposition !== 'hit') throw new Error(next.reason.detail);
213
+ expect(next.receipt.head).toBe(original.receipt.head);
214
+ expect(next.receipt.headTree).toBe(original.receipt.headTree);
215
+ expect(next.receipt.producer.outputSha256).toBe(original.receipt.producer.outputSha256);
216
+ });
217
+ it('revokes a producer pre-source witness for a write/revert even when final bytes match HEAD', async () => {
218
+ await writeFile(join(root, 'source.txt'), 'edited');
219
+ await writeFile(join(root, 'source.txt'), 'source');
220
+ expect(producerSourceUnchanged(root, source).ok).toBe(false);
221
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('failed');
222
+ });
130
223
  it('refuses unreadable public bytes, missing outputs and opaque runtime closure', async () => {
131
224
  await chmod(join(root, 'output/file'), 0);
132
225
  try {
133
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
226
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('failed');
134
227
  } finally {
135
228
  await chmod(join(root, 'output/file'), 0o600);
136
229
  }
137
230
  await rm(join(root, 'output'), { recursive: true });
138
- expect(providerReceipt(root, task.id, [task], proof, expandOutputs).disposition).toBe('failed');
231
+ expect(providerReceipt(root, task.id, [task], proof, expandOutputs, source, producer).disposition).toBe('failed');
139
232
  expect(
140
233
  providerReceipt(
141
234
  root,
@@ -143,6 +236,8 @@ describe('provider receipt', () => {
143
236
  [task],
144
237
  { ...proof, runtimeSource: { kind: 'opaque', detail: 'unnameable command input closure' } },
145
238
  expandOutputs,
239
+ source,
240
+ producer,
146
241
  ),
147
242
  ).toMatchObject({
148
243
  disposition: 'failed',