@smoothbricks/nx-plugin 0.5.0 → 0.5.2

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 (79) hide show
  1. package/README.md +107 -46
  2. package/dist/bin/smoo-nx-test-clocks.js +2 -2
  3. package/dist/bin/smoo-nx-test-walks.js +6 -9
  4. package/dist/cargo-closure-input.d.ts.map +1 -1
  5. package/dist/cargo-closure-input.js +25 -15
  6. package/dist/ensure-built-witness.d.ts +33 -5
  7. package/dist/ensure-built-witness.d.ts.map +1 -1
  8. package/dist/ensure-built-witness.js +84 -18
  9. package/dist/ensure-built.d.ts.map +1 -1
  10. package/dist/ensure-built.js +33 -14
  11. package/dist/executors/bounded-exec/cpu-pool.d.ts +14 -7
  12. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  13. package/dist/executors/bounded-exec/cpu-pool.js +297 -38
  14. package/dist/executors/bounded-exec/cpu-tokens.d.ts +19 -7
  15. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  16. package/dist/executors/bounded-exec/cpu-tokens.js +21 -7
  17. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  18. package/dist/executors/bounded-exec/executor.js +12 -6
  19. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  20. package/dist/executors/bounded-exec/run-cpu-pool.js +5 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +4 -0
  23. package/dist/owned-installation.d.ts +6 -5
  24. package/dist/owned-installation.d.ts.map +1 -1
  25. package/dist/owned-installation.js +324 -201
  26. package/dist/producer-receipts.d.ts +10 -0
  27. package/dist/producer-receipts.d.ts.map +1 -1
  28. package/dist/producer-receipts.js +30 -5
  29. package/dist/test-walk-policy.d.ts +8 -0
  30. package/dist/test-walk-policy.d.ts.map +1 -1
  31. package/dist/test-walk-policy.js +34 -0
  32. package/dist/workspace-manifest.d.ts +5 -5
  33. package/dist/workspace-manifest.d.ts.map +1 -1
  34. package/managed/raw/patches/nx@23.2.1.patch +14 -3
  35. package/managed/raw/tooling/direnv/developer-links.ts +37 -10
  36. package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -3
  37. package/managed/raw/tooling/direnv/linked-snapshots.ts +49 -12
  38. package/managed/raw/tooling/direnv/repo-path +1 -1
  39. package/managed/raw/tooling/direnv/setup-environment.ts +2 -0
  40. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -11
  41. package/package.json +3 -3
  42. package/runtime-input.sh +21 -9
  43. package/src/__tests__/cargo-closure-filesets.ts +94 -0
  44. package/src/__tests__/counted-cargo.ts +1 -1
  45. package/src/__tests__/owned-installation.ts +5 -6
  46. package/src/bin/smoo-nx-test-clocks.ts +2 -2
  47. package/src/bin/smoo-nx-test-walks.ts +6 -9
  48. package/src/cargo-closure-filesets.test.ts +63 -0
  49. package/src/cargo-closure-input.test.ts +2 -2
  50. package/src/cargo-closure-input.ts +23 -15
  51. package/src/cargo-closure-key.test.ts +1 -1
  52. package/src/cargo-resolve-cache.test.ts +1 -1
  53. package/src/cross-check-policy.test.ts +53 -12
  54. package/src/ensure-built-witness.test.ts +53 -2
  55. package/src/ensure-built-witness.ts +103 -18
  56. package/src/ensure-built.test.ts +79 -5
  57. package/src/ensure-built.ts +51 -15
  58. package/src/executors/bounded-exec/cpu-pool.test.ts +132 -4
  59. package/src/executors/bounded-exec/cpu-pool.ts +300 -46
  60. package/src/executors/bounded-exec/cpu-tokens.test.ts +60 -15
  61. package/src/executors/bounded-exec/cpu-tokens.ts +34 -11
  62. package/src/executors/bounded-exec/executor.test.ts +72 -4
  63. package/src/executors/bounded-exec/executor.ts +12 -6
  64. package/src/executors/bounded-exec/run-cpu-pool.test.ts +3 -0
  65. package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
  66. package/src/index.ts +4 -0
  67. package/src/linked-snapshots.nx.test.ts +1 -1
  68. package/src/nextest-partitions.test.ts +1 -1
  69. package/src/nx-daemon-validity.test.ts +51 -0
  70. package/src/owned-installation.test.ts +105 -0
  71. package/src/owned-installation.ts +335 -93
  72. package/src/producer-receipts.test.ts +37 -15
  73. package/src/producer-receipts.ts +29 -5
  74. package/src/runtime-input.test.ts +22 -1
  75. package/src/task-results.test.ts +1 -1
  76. package/src/test-walk-policy.test.ts +35 -0
  77. package/src/test-walk-policy.ts +32 -0
  78. package/src/workspace-manifest.ts +5 -5
  79. package/test-timings.json +94 -92
@@ -2,7 +2,7 @@ import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
2
2
  import * as _accessExpressionAsString_1 from "typia/lib/internal/_accessExpressionAsString";
3
3
  const __typia_transform__accessExpressionAsString = _accessExpressionAsString_1._accessExpressionAsString;
4
4
  /**
5
- * A fixture's own copy of a workspace's Nx installation, and the check that nothing wrote into it.
5
+ * A fixture's own copy of a workspace's Nx installation, kept between runs, and the check that nothing wrote into it.
6
6
  *
7
7
  * The graph witness binds node stamps (ctime included) of every file in the closure of Nx, this plugin and
8
8
  * TypeScript (README "Ancestor directories bind..."). Linked from a workspace, that closure is the host's: on CI
@@ -16,48 +16,64 @@ const __typia_transform__accessExpressionAsString = _accessExpressionAsString_1.
16
16
  * its copy as Bun's isolated layout does, the top-level packages' bins in `.bin`. Every copy is a new inode, cloned
17
17
  * where the volume allows and written otherwise, so no link count is shared with anything outside its owner.
18
18
  *
19
- * A test file makes one copy, on first use, shared by its fixtures; retiring it fails, naming the changed nodes, if
20
- * any fixture wrote into it.
19
+ * The copy is kept between runs, in the workspace's own tool cache, because making it is most of what a test file
20
+ * costs: about 21,000 files, which clonefile cannot share across the volume between Bun's global store and any
21
+ * directory a cowshed job may write (specs/cowshed/03_caches.md "Clone-materializing caches"). It is trusted only as
22
+ * its census proves it: on first use in a run, the census of the host closure and the proven census of the copy are
23
+ * compared package by package, by what each holds (resolution edges, node types and modes, file bytes), and a package
24
+ * whose copy no longer holds what the host's holds is copied again. Both censuses take the hashes of files whose
25
+ * stamps have not moved from the ones recorded beside the copy, so a run that changes nothing reads no file bytes.
26
+ *
27
+ * The copy lies beneath `censusRoot`'s `node_modules`, so a census of it that resolves any package outside the copy
28
+ * proves nothing about it, and the copy is made again, whole, in a directory of its own (`installation-<uuid>`, named
29
+ * in the record beside it). A package in the copy that requires a dependency it does not
30
+ * declare still reaches the host's top-level `node_modules` the same way; the census binds declared edges only.
31
+ *
32
+ * A test file uses its copy, on first use, for all its fixtures; retiring it fails, naming the changed nodes, if any
33
+ * fixture wrote into it.
21
34
  */
35
+ import { randomUUID } from 'node:crypto';
22
36
  import { constants } from 'node:fs';
23
- import { cp, mkdir, readFile, rm, symlink } from 'node:fs/promises';
37
+ import { cp, mkdir, readdir, readFile, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
24
38
  import { basename, dirname, join, relative } from 'node:path';
25
39
  import { expandOutputs } from 'nx/src/native';
26
40
  import { readModulePackageJson } from 'nx/src/utils/package-json';
27
41
  import typia from 'typia';
28
- import { graphInstallationCensus, graphInstallationIdentity, } from './ensure-built-witness.js';
42
+ import { graphInstallationCensus, installationIdentityOf, provenInstallationCensus, stampMode, } from './ensure-built-witness.js';
29
43
  /** The configuration the census resolves: Nx, this plugin and TypeScript. */
30
44
  const CENSUS_NX_JSON = { plugins: ['@smoothbricks/nx-plugin'] };
31
- /** The graph witness's installation identity resolved from `root`; an unproved installation fails loudly. */
32
- function installationIdentity(root) {
33
- let unproved = 'no detail';
34
- const identity = graphInstallationIdentity(root, CENSUS_NX_JSON, readModulePackageJson, expandOutputs, null, (detail) => {
35
- unproved = detail;
36
- });
37
- if (identity === null)
38
- throw new Error(`the Nx installation resolved from ${root} is unproved: ${unproved}`);
39
- return identity;
45
+ /**
46
+ * Where a workspace keeps its test files' copies: its tool cache, `node_modules/.cache`. Nothing sweeps it. A cowshed
47
+ * fork clones it with the build volume and main adopts it at land (specs/cowshed/16_build_volumes.md); it goes cold
48
+ * only when `node_modules` is reinstalled or the build volume reseeded.
49
+ */
50
+ const KEPT = join('node_modules', '.cache', 'smoothbricks-nx-plugin', 'owned-installations');
51
+ /** The proven installation census resolved from `root`, taking unmoved files' hashes from `previous`. */
52
+ function provenCensus(root, previous, onUnproved) {
53
+ return provenInstallationCensus(root, CENSUS_NX_JSON, readModulePackageJson, expandOutputs, null, onUnproved, previous);
40
54
  }
41
- /** Copy the installation closure `censusRoot` resolves into `root/node_modules`; `root` is an empty directory the
42
- * caller owns.
43
- *
44
- * Only the closure is read from `censusRoot`, never its proof: that installation is the host's, whose shared store
45
- * other tasks relink while the census reads it, which changes node stamps and would make every test that copies it
46
- * fail for the host's work rather than its own. The copy, which the fixture owns, is what gets proved.
55
+ /**
56
+ * The proven census of the copy under `root`, or `null`, with `onUnproved` told why, for one that is unproved or
57
+ * that resolves a package outside the copy. The copy lies in `censusRoot`'s `node_modules/.cache`, so where that is a
58
+ * real directory, as on a fresh CI checkout, Node's ancestor lookup from the copy reaches the host's own
59
+ * `node_modules`: a copy that is missing, or lacks a link, would otherwise be proved by a census of host packages.
60
+ * Node also keeps every resolution for the life of the process, so once a census has resolved a host package from a
61
+ * copy's directory, no copy made there again can be proved in that process: a copy made whole goes to a new directory.
47
62
  */
48
- async function makeOwnedInstallation(censusRoot, root) {
49
- let unread = 'no detail';
50
- const census = graphInstallationCensus(censusRoot, CENSUS_NX_JSON, readModulePackageJson, expandOutputs, null, (detail) => {
51
- unread = detail;
52
- });
53
- if (census === null)
54
- throw new Error(`the Nx installation closure of ${censusRoot} cannot be read: ${unread}`);
55
- const { resolutions } = census;
56
- const modules = join(root, 'node_modules');
57
- // Each source package root's copy, inside a store directory whose node_modules also holds its dependency links.
58
- const copies = new Map();
63
+ function copyCensus(root, previous, onUnproved) {
64
+ const census = provenCensus(root, previous, onUnproved);
65
+ const escaped = census?.resolutions.find(([, , manifest]) => manifest !== null && !manifest.startsWith(`${root}/`));
66
+ if (escaped === undefined)
67
+ return census;
68
+ const [from, name, manifest] = escaped;
69
+ onUnproved(`it resolves ${name} from ${from} to ${manifest}, outside the copy`);
70
+ return null;
71
+ }
72
+ /** Where the copy keeps each package root the census of `censusRoot` resolves. */
73
+ async function placements({ resolutions }) {
74
+ const placed = new Map();
59
75
  for (const [, , manifest] of resolutions) {
60
- if (manifest === null || copies.has(dirname(manifest)))
76
+ if (manifest === null || placed.has(dirname(manifest)))
61
77
  continue;
62
78
  const { name, bin } = (() => {
63
79
  const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.name || _assertGuard_1._assertGuard(_exceptionable, {
@@ -120,205 +136,312 @@ async function makeOwnedInstallation(censusRoot, root) {
120
136
  };
121
137
  return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
122
138
  })()(await readFile(manifest, 'utf8'));
123
- const store = join(modules, '.store', String(copies.size), 'node_modules');
124
- copies.set(dirname(manifest), { store, copy: join(store, name), bin });
139
+ const store = join('node_modules', '.store', String(placed.size), 'node_modules');
140
+ placed.set(dirname(manifest), { store, place: join(store, name), bin });
125
141
  }
126
- const copyOf = (source) => {
127
- const copied = copies.get(source);
128
- if (copied === undefined)
129
- throw new Error(`${source} resolves dependencies but is not in the census`);
130
- return copied;
131
- };
132
- await Promise.all([...copies].map(([source, { copy }]) => cp(source, copy, {
133
- recursive: true,
134
- verbatimSymlinks: true,
135
- mode: constants.COPYFILE_FICLONE,
136
- filter: (path) => path === source || !['node_modules', '.git', '.nx'].includes(basename(path)),
137
- })));
138
- for (const [from, name, manifest] of resolutions) {
139
- if (manifest === null)
140
- continue;
141
- const link = join(from === censusRoot ? modules : copyOf(from).store, name);
142
- await mkdir(dirname(link), { recursive: true });
143
- await symlink(relative(dirname(link), copyOf(dirname(manifest)).copy), link, 'dir');
144
- if (from !== censusRoot)
145
- continue;
146
- const { bin } = copyOf(dirname(manifest));
147
- const commands = typeof bin === 'string' ? { [basename(name)]: bin } : (bin ?? {});
148
- for (const [command, path] of Object.entries(commands)) {
149
- await mkdir(join(modules, '.bin'), { recursive: true });
150
- await symlink(relative(join(modules, '.bin'), join(link, path)), join(modules, '.bin', command));
142
+ return placed;
143
+ }
144
+ /**
145
+ * What `census` holds, read from `root` with each package root in `places` named by its place in the copy. A node
146
+ * outside every package root keeps its path, in the place `''` with the root's own edges.
147
+ */
148
+ function holdings(census, root, places) {
149
+ const named = (path) => {
150
+ for (let at = path;; at = dirname(at)) {
151
+ const place = at === root ? '' : places.get(at);
152
+ if (place !== undefined)
153
+ return [place, relative(at, path)];
154
+ if (dirname(at) === at)
155
+ return ['', path];
151
156
  }
152
- }
153
- return { root, identity: installationIdentity(root) };
157
+ };
158
+ const packages = new Map();
159
+ const hold = (path, value) => {
160
+ const [place, inner] = named(path);
161
+ const held = packages.get(place);
162
+ if (held === undefined)
163
+ packages.set(place, [[inner, value]]);
164
+ else
165
+ held.push([inner, value]);
166
+ };
167
+ for (const { path, stamp } of census.nodes)
168
+ hold(path, stampMode(stamp));
169
+ for (const { path, sha256 } of census.files)
170
+ hold(path, sha256);
171
+ return {
172
+ edges: JSON.stringify(census.resolutions.map(([from, name, manifest]) => [
173
+ named(from),
174
+ name,
175
+ manifest === null ? null : named(manifest),
176
+ ])),
177
+ packages: new Map([...packages].map(([place, held]) => [place, JSON.stringify(held)])),
178
+ };
154
179
  }
155
180
  /**
156
- * Remove an installation, failing, with the changed nodes named, if its identity is no longer the one it was made
157
- * with: the proof that its sharers only read it.
181
+ * Each package of `packages` (the first eight) with the first entry in which what the copy holds is not what the host
182
+ * closure holds: a path within the package and its mode or SHA-256, on each side.
158
183
  */
159
- async function retireOwnedInstallation({ root, identity }) {
160
- try {
161
- const retired = installationIdentity(root);
162
- if (retired === identity)
163
- return;
164
- const entries = (census) => {
165
- const { nodes, files } = (() => {
166
- const _ip0 = input => "string" === typeof input["path"];
167
- const _ap0 = (input, _path, _exceptionable = true) => "string" === typeof input["path"] || _assertGuard_1._assertGuard(_exceptionable, {
168
- method: "typia.json.assertParse",
169
- path: _path + ".path",
170
- expected: "string",
171
- value: input["path"]
172
- }, _errorFactory);
173
- const _ao0 = (input, _path, _exceptionable = true) => ((Array.isArray(input.resolutions) || _assertGuard_1._assertGuard(_exceptionable, {
184
+ function differences(packages, host, copy) {
185
+ const entries = (held) => (() => {
186
+ const __is = input => Array.isArray(input) && input.every(elem => Array.isArray(elem) && (elem.length === 2 && "string" === typeof elem[0] && "string" === typeof elem[1]));
187
+ let _errorFactory;
188
+ const __assert = (input, errorFactory) => {
189
+ if (false === __is(input)) {
190
+ _errorFactory = errorFactory;
191
+ ((input, _path, _exceptionable = true) => (Array.isArray(input) || _assertGuard_1._assertGuard(true, {
174
192
  method: "typia.json.assertParse",
175
- path: _path + ".resolutions",
176
- expected: "ReadonlyArray<readonly [string, string, string | null]>",
177
- value: input.resolutions
178
- }, _errorFactory)) && input.resolutions.every((elem, _index4) => (Array.isArray(elem) || _assertGuard_1._assertGuard(_exceptionable, {
193
+ path: _path + "",
194
+ expected: "Array<[string, string]>",
195
+ value: input
196
+ }, _errorFactory)) && input.every((elem, _index2) => (Array.isArray(elem) || _assertGuard_1._assertGuard(true, {
179
197
  method: "typia.json.assertParse",
180
- path: _path + ".resolutions[" + _index4 + "]",
181
- expected: "readonly [string, string, string | null]",
198
+ path: _path + "[" + _index2 + "]",
199
+ expected: "[string, string]",
182
200
  value: elem
183
- }, _errorFactory)) && ((elem.length === 3 || _assertGuard_1._assertGuard(_exceptionable, {
201
+ }, _errorFactory)) && ((elem.length === 2 || _assertGuard_1._assertGuard(true, {
184
202
  method: "typia.json.assertParse",
185
- path: _path + ".resolutions[" + _index4 + "]",
186
- expected: "[string, string, (null | string)]",
203
+ path: _path + "[" + _index2 + "]",
204
+ expected: "[string, string]",
187
205
  value: elem
188
- }, _errorFactory)) && ("string" === typeof elem[0] || _assertGuard_1._assertGuard(_exceptionable, {
206
+ }, _errorFactory)) && ("string" === typeof elem[0] || _assertGuard_1._assertGuard(true, {
189
207
  method: "typia.json.assertParse",
190
- path: _path + ".resolutions[" + _index4 + "][0]",
208
+ path: _path + "[" + _index2 + "][0]",
191
209
  expected: "string",
192
210
  value: elem[0]
193
- }, _errorFactory)) && ("string" === typeof elem[1] || _assertGuard_1._assertGuard(_exceptionable, {
211
+ }, _errorFactory)) && ("string" === typeof elem[1] || _assertGuard_1._assertGuard(true, {
194
212
  method: "typia.json.assertParse",
195
- path: _path + ".resolutions[" + _index4 + "][1]",
213
+ path: _path + "[" + _index2 + "][1]",
196
214
  expected: "string",
197
215
  value: elem[1]
198
- }, _errorFactory)) && (null === elem[2] || "string" === typeof elem[2] || _assertGuard_1._assertGuard(_exceptionable, {
199
- method: "typia.json.assertParse",
200
- path: _path + ".resolutions[" + _index4 + "][2]",
201
- expected: "(null | string)",
202
- value: elem[2]
203
- }, _errorFactory))) || _assertGuard_1._assertGuard(_exceptionable, {
204
- method: "typia.json.assertParse",
205
- path: _path + ".resolutions[" + _index4 + "]",
206
- expected: "readonly [string, string, string | null]",
207
- value: elem
208
- }, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
209
- method: "typia.json.assertParse",
210
- path: _path + ".resolutions",
211
- expected: "ReadonlyArray<readonly [string, string, string | null]>",
212
- value: input.resolutions
213
- }, _errorFactory)) && ((Array.isArray(input.nodes) || _assertGuard_1._assertGuard(_exceptionable, {
214
- method: "typia.json.assertParse",
215
- path: _path + ".nodes",
216
- expected: "ReadonlyArray<NodeWitness>",
217
- value: input.nodes
218
- }, _errorFactory)) && input.nodes.every((elem, _index5) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
219
- method: "typia.json.assertParse",
220
- path: _path + ".nodes[" + _index5 + "]",
221
- expected: "NodeWitness",
222
- value: elem
223
- }, _errorFactory)) && _ao1(elem, _path + ".nodes[" + _index5 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
224
- method: "typia.json.assertParse",
225
- path: _path + ".nodes[" + _index5 + "]",
226
- expected: "NodeWitness",
227
- value: elem
228
- }, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
229
- method: "typia.json.assertParse",
230
- path: _path + ".nodes",
231
- expected: "ReadonlyArray<NodeWitness>",
232
- value: input.nodes
233
- }, _errorFactory)) && ((Array.isArray(input.files) || _assertGuard_1._assertGuard(_exceptionable, {
216
+ }, _errorFactory))) || _assertGuard_1._assertGuard(true, {
234
217
  method: "typia.json.assertParse",
235
- path: _path + ".files",
236
- expected: "readonly { readonly path: string; readonly sha256: string; }[]",
237
- value: input.files
238
- }, _errorFactory)) && input.files.every((elem, _index6) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
239
- method: "typia.json.assertParse",
240
- path: _path + ".files[" + _index6 + "]",
241
- expected: "{ readonly path: string; readonly sha256: string; }",
242
- value: elem
243
- }, _errorFactory)) && _ao2(elem, _path + ".files[" + _index6 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
244
- method: "typia.json.assertParse",
245
- path: _path + ".files[" + _index6 + "]",
246
- expected: "{ readonly path: string; readonly sha256: string; }",
218
+ path: _path + "[" + _index2 + "]",
219
+ expected: "[string, string]",
247
220
  value: elem
248
- }, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
249
- method: "typia.json.assertParse",
250
- path: _path + ".files",
251
- expected: "readonly { readonly path: string; readonly sha256: string; }[]",
252
- value: input.files
253
- }, _errorFactory));
254
- const _ao1 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && ("string" === typeof input.stamp || _assertGuard_1._assertGuard(_exceptionable, {
221
+ }, _errorFactory)) || _assertGuard_1._assertGuard(true, {
255
222
  method: "typia.json.assertParse",
256
- path: _path + ".stamp",
257
- expected: "string",
258
- value: input.stamp
259
- }, _errorFactory));
260
- const _ao2 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && ("string" === typeof input.sha256 || _assertGuard_1._assertGuard(_exceptionable, {
261
- method: "typia.json.assertParse",
262
- path: _path + ".sha256",
263
- expected: "string",
264
- value: input.sha256
265
- }, _errorFactory));
266
- const _io0 = input => Array.isArray(input.resolutions) && input.resolutions.every(elem => Array.isArray(elem) && (elem.length === 3 && "string" === typeof elem[0] && "string" === typeof elem[1] && (null === elem[2] || "string" === typeof elem[2]))) && (Array.isArray(input.nodes) && input.nodes.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && (Array.isArray(input.files) && input.files.every(elem => "object" === typeof elem && null !== elem && _io2(elem)));
267
- const _io1 = input => _ip0(input) && "string" === typeof input.stamp;
268
- const _io2 = input => _ip0(input) && "string" === typeof input.sha256;
269
- const __is = input => "object" === typeof input && null !== input && _io0(input);
270
- let _errorFactory;
271
- const __assert = (input, errorFactory) => {
272
- if (false === __is(input)) {
273
- _errorFactory = errorFactory;
274
- ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _assertGuard_1._assertGuard(true, {
275
- method: "typia.json.assertParse",
276
- path: _path + "",
277
- expected: "GraphInstallationCensus",
278
- value: input
279
- }, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard_1._assertGuard(true, {
280
- method: "typia.json.assertParse",
281
- path: _path + "",
282
- expected: "GraphInstallationCensus",
283
- value: input
284
- }, _errorFactory))(input, "$input", true);
285
- }
286
- return input;
287
- };
288
- return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
289
- })()(census);
290
- return new Set([
291
- ...nodes.map(({ path, stamp }) => `${path} ${stamp}`),
292
- ...files.map(({ path, sha256 }) => `${path} ${sha256}`),
293
- ]);
223
+ path: _path + "",
224
+ expected: "Array<[string, string]>",
225
+ value: input
226
+ }, _errorFactory))(input, "$input", true);
227
+ }
228
+ return input;
294
229
  };
295
- const made = entries(identity);
296
- const now = entries(retired);
297
- const changed = [
298
- ...[...made].filter((entry) => !now.has(entry)).map((entry) => `- ${entry}`),
299
- ...[...now].filter((entry) => !made.has(entry)).map((entry) => `+ ${entry}`),
300
- ];
301
- throw new Error(`a fixture changed the installation it shares, in ${root}:\n${changed.slice(0, 20).join('\n')}`);
230
+ return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
231
+ })()(held ?? '[]');
232
+ const entry = (held) => held === undefined ? 'nothing' : `${held[0] || '.'} ${held[1]}`;
233
+ const named = packages.slice(0, 8).map(([source, { place }]) => {
234
+ const wanted = entries(host.packages.get(place));
235
+ const found = entries(copy.packages.get(place));
236
+ let at = 0;
237
+ while (at < Math.max(wanted.length, found.length) && entry(wanted[at]) === entry(found[at]))
238
+ at += 1;
239
+ return `${source} (host: ${entry(wanted[at])}; copy: ${entry(found[at])})`;
240
+ });
241
+ return `${named.join(', ')}${packages.length > 8 ? ` and ${packages.length - 8} more` : ''}`;
242
+ }
243
+ async function readKept(path) {
244
+ try {
245
+ return (() => {
246
+ const _ip0 = input => "string" === typeof input["path"];
247
+ const _io0 = input => 2 === input.version && "string" === typeof input.installation && ("object" === typeof input.host && null !== input.host && _io1(input.host)) && ("object" === typeof input.copy && null !== input.copy && _io1(input.copy));
248
+ const _io1 = input => Array.isArray(input.resolutions) && input.resolutions.every(elem => Array.isArray(elem) && (elem.length === 3 && "string" === typeof elem[0] && "string" === typeof elem[1] && (null === elem[2] || "string" === typeof elem[2]))) && (Array.isArray(input.nodes) && input.nodes.every(elem => "object" === typeof elem && null !== elem && _io2(elem))) && (Array.isArray(input.files) && input.files.every(elem => "object" === typeof elem && null !== elem && _io3(elem))) && (Array.isArray(input.unproven) && input.unproven.every(elem => "string" === typeof elem));
249
+ const _io2 = input => _ip0(input) && "string" === typeof input.stamp;
250
+ const _io3 = input => _ip0(input) && "string" === typeof input.sha256;
251
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
252
+ return input => { input = JSON.parse(input); return __is(input) ? input : null; };
253
+ })()(await readFile(path, 'utf8'));
254
+ }
255
+ catch (error) {
256
+ if (error instanceof SyntaxError || (error instanceof Error && 'code' in error && error.code === 'ENOENT')) {
257
+ return null;
258
+ }
259
+ throw error;
260
+ }
261
+ }
262
+ async function writeKept(path, kept) {
263
+ const temporary = `${path}.${randomUUID()}`;
264
+ try {
265
+ await writeFile(temporary, JSON.stringify(kept), { flag: 'wx', mode: 0o600 });
266
+ await rename(temporary, path);
302
267
  }
303
268
  finally {
304
- await rm(root, { recursive: true, force: true });
269
+ await rm(temporary, { force: true });
270
+ }
271
+ }
272
+ /** Copy the host package root `source` to its place under `root`, with the census's own exclusions. */
273
+ function copyPackage(source, root, { place }) {
274
+ return cp(source, join(root, place), {
275
+ recursive: true,
276
+ verbatimSymlinks: true,
277
+ mode: constants.COPYFILE_FICLONE,
278
+ filter: (path) => path === source || !['node_modules', '.git', '.nx'].includes(basename(path)),
279
+ });
280
+ }
281
+ /** Link every resolution edge of `host` beside its copy under `root`, and the top-level packages' bins in `.bin`. */
282
+ async function linkCopies(censusRoot, root, { resolutions }, placed) {
283
+ const placementOf = (source) => {
284
+ const placement = placed.get(source);
285
+ if (placement === undefined)
286
+ throw new Error(`${source} resolves dependencies but is not in the census`);
287
+ return placement;
288
+ };
289
+ const modules = join(root, 'node_modules');
290
+ for (const [from, name, manifest] of resolutions) {
291
+ if (manifest === null)
292
+ continue;
293
+ const link = join(from === censusRoot ? modules : join(root, placementOf(from).store), name);
294
+ const { place, bin } = placementOf(dirname(manifest));
295
+ await mkdir(dirname(link), { recursive: true });
296
+ await symlink(relative(dirname(link), join(root, place)), link, 'dir');
297
+ if (from !== censusRoot)
298
+ continue;
299
+ const commands = typeof bin === 'string' ? { [basename(name)]: bin } : (bin ?? {});
300
+ for (const [command, path] of Object.entries(commands)) {
301
+ await mkdir(join(modules, '.bin'), { recursive: true });
302
+ await symlink(relative(join(modules, '.bin'), join(link, path)), join(modules, '.bin', command));
303
+ }
304
+ }
305
+ }
306
+ /**
307
+ * Remove whatever sits in the copy's `node_modules` beside its store, bins and top-level links: a census binds none
308
+ * of it, and a run starts with the layout alone, as a fresh copy would.
309
+ */
310
+ async function clearLeftovers(censusRoot, root, { resolutions }) {
311
+ const own = new Set(['.store', '.bin']);
312
+ for (const [from, name, manifest] of resolutions) {
313
+ if (from === censusRoot && manifest !== null)
314
+ own.add(name.split('/')[0]);
315
+ }
316
+ const modules = join(root, 'node_modules');
317
+ for (const entry of await readdir(modules)) {
318
+ if (!own.has(entry))
319
+ await rm(join(modules, entry), { recursive: true, force: true });
320
+ }
321
+ }
322
+ /**
323
+ * The copy of the closure `censusRoot` resolves kept as `name`, proved to hold what the host closure holds, copying
324
+ * again each package whose copy does not, and every package when the resolution edges moved or the copy is unproved.
325
+ * Says so on stderr when a copy that was there fails its proof: a closure that keeps changing is itself worth knowing.
326
+ *
327
+ * Only the closure is read from `censusRoot`, never its proof: that installation is the host's, whose shared store
328
+ * other tasks relink while the census reads it, which changes node stamps and would make every test that copies it
329
+ * fail for the host's work rather than its own. The copy, which the fixture owns, is what gets proved.
330
+ */
331
+ async function keptInstallation(censusRoot, name) {
332
+ await mkdir(join(censusRoot, KEPT, name), { recursive: true });
333
+ const kept = await realpath(join(censusRoot, KEPT, name));
334
+ const record = join(kept, 'censuses.json');
335
+ const recorded = await readKept(record);
336
+ let unread = 'no detail';
337
+ const host = graphInstallationCensus(censusRoot, CENSUS_NX_JSON, readModulePackageJson, expandOutputs, null, (detail) => {
338
+ unread = detail;
339
+ }, recorded?.host);
340
+ if (host === null)
341
+ throw new Error(`the Nx installation closure of ${censusRoot} cannot be read: ${unread}`);
342
+ const placed = await placements(host);
343
+ const wanted = holdings(host, censusRoot, new Map([...placed].map(([source, { place }]) => [source, place])));
344
+ const placesIn = (root) => new Map([...placed.values()].map(({ place }) => [join(root, place), place]));
345
+ // Only a recorded copy is censused: a census of none would resolve the host's packages through the ancestor lookup.
346
+ const current = recorded === null ? null : join(kept, recorded.installation);
347
+ let unproved = 'no detail';
348
+ const found = current === null
349
+ ? null
350
+ : copyCensus(current, recorded?.copy, (detail) => {
351
+ unproved = detail;
352
+ });
353
+ const held = current === null || found === null ? null : holdings(found, current, placesIn(current));
354
+ const stale = held === null || held.edges !== wanted.edges || held.packages.get('') !== wanted.packages.get('')
355
+ ? null
356
+ : [...placed].filter(([, { place }]) => held.packages.get(place) !== wanted.packages.get(place));
357
+ if (current !== null && stale !== null) {
358
+ await clearLeftovers(censusRoot, current, host);
359
+ if (stale.length === 0 && found !== null) {
360
+ await writeKept(record, { version: 2, installation: basename(current), host, copy: found });
361
+ return { root: current, census: found };
362
+ }
363
+ }
364
+ if (current !== null) {
365
+ const why = held === null
366
+ ? `its census is unproved (${unproved})`
367
+ : stale === null
368
+ ? 'its resolution edges are not the host closure’s'
369
+ : `${stale.length} of ${placed.size} packages no longer hold what the host closure holds: ${differences(stale, wanted, held)}`;
370
+ process.stderr.write(`kept Nx installation ${current} failed its proof, copying again: ${why}\n`);
371
+ }
372
+ // A copy made whole goes to a directory no census in this process has resolved from (copyCensus).
373
+ const root = current !== null && stale !== null ? current : join(kept, `installation-${randomUUID()}`);
374
+ if (root === current && stale !== null) {
375
+ for (const [, { place }] of stale)
376
+ await rm(join(root, place), { recursive: true, force: true });
377
+ await Promise.all(stale.map(([source, placement]) => copyPackage(source, root, placement)));
378
+ }
379
+ else {
380
+ for (const entry of await readdir(kept)) {
381
+ if (entry !== 'censuses.json')
382
+ await rm(join(kept, entry), { recursive: true, force: true });
383
+ }
384
+ await Promise.all([...placed].map(([source, placement]) => copyPackage(source, root, placement)));
385
+ await linkCopies(censusRoot, root, host, placed);
386
+ }
387
+ const census = copyCensus(root, root === current ? (found ?? undefined) : undefined, (detail) => {
388
+ unproved = detail;
389
+ });
390
+ if (census === null)
391
+ throw new Error(`the Nx installation copied to ${root} is unproved: ${unproved}`);
392
+ const copied = holdings(census, root, placesIn(root));
393
+ const moved = [...placed].filter(([, { place }]) => copied.packages.get(place) !== wanted.packages.get(place));
394
+ if (copied.edges !== wanted.edges || moved.length > 0) {
395
+ // The host's own installs relink its shared store while it is read: the copy is proved as made, and the next run
396
+ // compares it with the host closure again.
397
+ process.stderr.write(`the Nx installation closure of ${censusRoot} moved while ${root} copied it: ${differences(moved, wanted, copied)}\n`);
305
398
  }
399
+ await writeKept(record, { version: 2, installation: basename(root), host, copy: census });
400
+ return { root, census };
401
+ }
402
+ /**
403
+ * End a test file's use of its installation, failing, with the changed nodes named, if its identity is no longer the
404
+ * one it was taken with: the proof that its sharers only read it. A write moves a node's stamp, which the identity
405
+ * binds, so the census that proves it reads again only the files whose stamps moved. The copy stays for the next run,
406
+ * which proves it against the host closure before using it.
407
+ */
408
+ function retireOwnedInstallation({ root, census }) {
409
+ let unproved = 'no detail';
410
+ const retired = provenCensus(root, census, (detail) => {
411
+ unproved = detail;
412
+ });
413
+ if (retired === null)
414
+ throw new Error(`a fixture left the installation it shares unproved, in ${root}: ${unproved}`);
415
+ if (installationIdentityOf(retired, null) === installationIdentityOf(census, null))
416
+ return;
417
+ const entries = ({ nodes, files }) => new Set([
418
+ ...nodes.map(({ path, stamp }) => `${path} ${stamp}`),
419
+ ...files.map(({ path, sha256 }) => `${path} ${sha256}`),
420
+ ]);
421
+ const taken = entries(census);
422
+ const now = entries(retired);
423
+ const changed = [
424
+ ...[...taken].filter((entry) => !now.has(entry)).map((entry) => `- ${entry}`),
425
+ ...[...now].filter((entry) => !taken.has(entry)).map((entry) => `+ ${entry}`),
426
+ ];
427
+ throw new Error(`a fixture changed the installation it shares, in ${root}:\n${changed.slice(0, 20).join('\n')}`);
306
428
  }
307
429
  /**
308
- * The installation one test file owns: a copy of the closure `censusRoot` (the workspace whose Nx, plugin and
309
- * TypeScript the fixtures stand for) resolves, made in the empty directory `makeRoot` creates on first use. Call once
310
- * per file, at module scope: Bun runs many test files in one process, and each must own its copy.
430
+ * The installation one test file owns: the copy of the closure `censusRoot` (the workspace whose Nx, plugin and
431
+ * TypeScript the fixtures stand for) resolves, kept as `name` in `censusRoot`'s tool cache and proved on first use.
432
+ * Call once per file, at module scope, with a name no other file uses: Bun runs many test files in one process, and
433
+ * each must own its copy. Two runs of one file at once share it, and a copy one of them makes again fails the other.
311
434
  */
312
- export function ownedInstallation(censusRoot, makeRoot) {
313
- let made;
435
+ export function ownedInstallation(censusRoot, name) {
436
+ let taken;
314
437
  return {
315
438
  nodeModules: async () => {
316
- made ??= makeRoot().then((root) => makeOwnedInstallation(censusRoot, root));
317
- return join((await made).root, 'node_modules');
439
+ taken ??= keptInstallation(censusRoot, name);
440
+ return join((await taken).root, 'node_modules');
318
441
  },
319
442
  retire: async () => {
320
- if (made !== undefined)
321
- await retireOwnedInstallation(await made);
443
+ if (taken !== undefined)
444
+ retireOwnedInstallation(await taken);
322
445
  },
323
446
  };
324
447
  }
@@ -7,6 +7,16 @@ export interface ProducerReceiptsOptions {
7
7
  readonly targets: readonly string[];
8
8
  };
9
9
  }
10
+ /**
11
+ * Where a checkout keeps its producer records, relative to its root: in its own source tree, never in Nx's
12
+ * workspace-data. Under cowshed that directory is build state on the checkout's build volume
13
+ * (specs/cowshed/16_build_volumes.md), and a consumer's read grant of the provider checkout does not reach a volume
14
+ * the checkout only links to (specs/cowshed/04_sandbox.md, "Read grants have one narrow meaning"), so a consumer
15
+ * could never read the receipt it is asked to validate. The directory ignores itself (a `.gitignore` of `*` written
16
+ * with its first record), so in any checkout git never tracks a record and Nx's file walk never hashes one: a record
17
+ * is no source or input of the run that publishes it.
18
+ */
19
+ export declare const PRODUCER_RECORDS: string;
10
20
  export declare function completedProducerTasks(graph: TaskGraph, results: PostTasksExecutionContext['taskResults']): ReceiptEvidence<readonly Task[]>;
11
21
  export declare function producerEnvironmentIdentity(inputs: EnsureBuiltProducerReceipt['inputs']): string;
12
22
  export declare function preTasksExecution(options: ProducerReceiptsOptions | undefined, context: PreTasksExecutionContext): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"producer-receipts.d.ts","sourceRoot":"","sources":["../src/producer-receipts.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAEnH,OAAO,EAEL,KAAK,0BAA0B,EAE/B,KAAK,kBAAkB,EAIxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAUnC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,gBAAgB,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;CACrE;AAyQD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,yBAAyB,CAAC,aAAa,CAAC,GAChD,eAAe,CAAC,SAAS,IAAI,EAAE,CAAC,CAqBlC;AACD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC,GAAG,MAAM,CAShG;AACD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAyCf;AACD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoIf;AACD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAOrG"}
1
+ {"version":3,"file":"producer-receipts.d.ts","sourceRoot":"","sources":["../src/producer-receipts.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAEnH,OAAO,EAEL,KAAK,0BAA0B,EAE/B,KAAK,kBAAkB,EAIxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAUnC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,gBAAgB,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;CACrE;AACD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,QAAsC,CAAC;AA2QpE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,yBAAyB,CAAC,aAAa,CAAC,GAChD,eAAe,CAAC,SAAS,IAAI,EAAE,CAAC,CAqBlC;AACD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC,GAAG,MAAM,CAShG;AACD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAyCf;AACD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoIf;AACD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAOrG"}