@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
@@ -0,0 +1,624 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { accessSync, constants, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
6
+ import typia from 'typia';
7
+ import { nodeStamp, nodesUnchanged, workspaceSnapshot } from './ensure-built-witness.js';
8
+ function digest(value) {
9
+ return createHash('sha256').update(value).digest('hex');
10
+ }
11
+ function systemError(error) {
12
+ return error instanceof Error && 'code' in error && typeof error.code === 'string';
13
+ }
14
+ function nativeIdentity(files) {
15
+ return digest(JSON.stringify(files.map(({ file, hash }) => [file, hash]).sort(([left], [right]) => (left ?? '').localeCompare(right ?? ''))));
16
+ }
17
+ function pathStamp(stats) {
18
+ return `${stats.dev}:${stats.ino}:${stats.mode}`;
19
+ }
20
+ function readNodesUnchanged(nodes) {
21
+ for (const node of nodes) {
22
+ try {
23
+ const stats = lstatSync(node.path, { bigint: true });
24
+ if ((node.scope === 'path' ? pathStamp(stats) : nodeStamp(stats)) !== node.stamp)
25
+ return false;
26
+ }
27
+ catch (error) {
28
+ if (systemError(error))
29
+ return false;
30
+ throw error;
31
+ }
32
+ }
33
+ return true;
34
+ }
35
+ function workspaceRequire(root) {
36
+ return createRequire(join(root, 'package.json'));
37
+ }
38
+ function dataDirectory(root) {
39
+ const module = workspaceRequire(root)('nx/src/utils/cache-directory');
40
+ return module.workspaceDataDirectoryForWorkspace(root);
41
+ }
42
+ function captureNative(root, previous) {
43
+ const module = workspaceRequire(root)('nx/src/native');
44
+ return workspaceSnapshot(root, new module.WorkspaceContext(root, dataDirectory(root)), previous);
45
+ }
46
+ function environmentIdentity(root) {
47
+ const module = workspaceRequire(root)('nx/src/daemon/client/daemon-environment');
48
+ return digest(JSON.stringify(Object.entries(module.normalizeDaemonEnvironmentForGraph(module.getDaemonEnv())).sort(([left], [right]) => left.localeCompare(right))));
49
+ }
50
+ function contractOf(options) {
51
+ if (typeof options !== 'object' || options === null || !('graphInputContract' in options))
52
+ return null;
53
+ const contract = options.graphInputContract;
54
+ return (() => {
55
+ const _io0 = input => 1 === input.version && ("native-only" === input.kind || "reference-scan" === input.kind || "tsconfig-extends" === input.kind) && (Array.isArray(input.modules) && input.modules.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && (Array.isArray(input.packages) && input.packages.every(elem => "string" === typeof elem));
56
+ const _io1 = input => "string" === typeof input.path && "string" === typeof input.sha256;
57
+ return input => "object" === typeof input && null !== input && _io0(input);
58
+ })()(contract) &&
59
+ contract.version === 1 &&
60
+ contract.modules.length > 0 &&
61
+ contract.modules.every(({ sha256 }) => /^[a-f0-9]{64}$/.test(sha256))
62
+ ? contract
63
+ : null;
64
+ }
65
+ function witnessPath(root, plugin) {
66
+ return join(dataDirectory(root), `graph-input-${digest(plugin)}.json`);
67
+ }
68
+ function gitEnvironment() {
69
+ return { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
70
+ }
71
+ function gitQuery(path, query) {
72
+ return execFileSync(path, ['-c', 'core.excludesFile=/dev/null', ...query.args], {
73
+ cwd: query.cwd,
74
+ env: gitEnvironment(),
75
+ input: query.stdin,
76
+ encoding: 'utf8',
77
+ maxBuffer: 64 * 1024 * 1024,
78
+ });
79
+ }
80
+ /** Retain read/resolution byproducts at the reader; never reconstruct its extends/import algorithm. */
81
+ export class GraphInputReadCollector {
82
+ workspaceRoot;
83
+ plugin;
84
+ contract;
85
+ before;
86
+ environment;
87
+ nodes = new Map();
88
+ missing = new Set();
89
+ resolutions = [];
90
+ tools = new Map();
91
+ gitQueries = [];
92
+ scanned = new Set();
93
+ gitScopes = new Set();
94
+ detail;
95
+ constructor(workspaceRoot, plugin, options) {
96
+ this.workspaceRoot = workspaceRoot;
97
+ this.plugin = plugin;
98
+ this.contract = contractOf(options);
99
+ if (this.contract === null)
100
+ return;
101
+ try {
102
+ this.before = captureNative(workspaceRoot);
103
+ this.environment = environmentIdentity(workspaceRoot);
104
+ if (process.versions.bun === undefined)
105
+ this.executable('node', process.execPath);
106
+ else {
107
+ const executable = this.executable('bun');
108
+ this.file(process.execPath);
109
+ if (executable !== realpathSync(process.execPath))
110
+ this.refuse('Bun runtime is not the PATH-selected executable');
111
+ }
112
+ if (!this.before.stable)
113
+ this.refuse('native file list contains an unproved node');
114
+ for (const name of ['NODE_OPTIONS', 'BUN_OPTIONS', 'LD_PRELOAD', 'DYLD_INSERT_LIBRARIES']) {
115
+ if (process.env[name])
116
+ this.refuse(`unbounded loader environment: ${name}`);
117
+ }
118
+ }
119
+ catch (error) {
120
+ this.refuse(error instanceof Error ? error.message : String(error));
121
+ }
122
+ }
123
+ refuse(detail) {
124
+ this.detail ??= detail;
125
+ }
126
+ protect(work) {
127
+ if (this.contract === null || this.detail !== undefined)
128
+ return;
129
+ try {
130
+ work();
131
+ }
132
+ catch (error) {
133
+ this.refuse(error instanceof Error ? error.message : String(error));
134
+ }
135
+ }
136
+ /** Observe each alias and its physical target, including a missing candidate's exact path. */
137
+ file(path) {
138
+ this.protect(() => this.observe(resolve(path)));
139
+ }
140
+ observe(path, membership = false) {
141
+ // Every ancestor binds the path, without treating unrelated siblings as reads.
142
+ const parent = dirname(path);
143
+ if (parent !== path && !this.nodes.has(parent) && !this.missing.has(parent))
144
+ this.observe(parent);
145
+ let stats;
146
+ try {
147
+ stats = lstatSync(path, { bigint: true });
148
+ }
149
+ catch (error) {
150
+ if (systemError(error) && ['ENOENT', 'ENOTDIR'].includes(error.code)) {
151
+ this.missing.add(path);
152
+ return;
153
+ }
154
+ throw error;
155
+ }
156
+ const previous = this.nodes.get(path);
157
+ const scope = previous?.scope === 'node' || !stats.isDirectory() || membership ? 'node' : 'path';
158
+ const stamp = scope === 'path' ? pathStamp(stats) : nodeStamp(stats);
159
+ if (previous !== undefined && previous.stamp !== (previous.scope === scope ? stamp : pathStamp(stats)))
160
+ this.refuse(`input changed during read: ${path}`);
161
+ if (previous === undefined || previous.scope !== scope)
162
+ this.nodes.set(path, { path, scope, stamp });
163
+ if (stats.isSymbolicLink())
164
+ this.observe(realpathSync(path), membership);
165
+ else if (stats.isFile())
166
+ accessSync(path, constants.R_OK);
167
+ else if (!stats.isDirectory())
168
+ this.refuse(`unproved filesystem node: ${path}`);
169
+ }
170
+ read(path, reader) {
171
+ this.file(path);
172
+ return reader();
173
+ }
174
+ exists(path) {
175
+ this.file(path);
176
+ return existsSync(path);
177
+ }
178
+ /** The whole immediate candidate directory, including absent/alternative extensions and alias nodes. */
179
+ directory(path) {
180
+ this.protect(() => {
181
+ this.observe(resolve(path), true);
182
+ if (this.missing.has(resolve(path)))
183
+ return;
184
+ for (const name of readdirSync(path).sort())
185
+ this.observe(join(path, name));
186
+ });
187
+ }
188
+ /** A finite candidate namespace: every node and alias, not only the previously selected file. */
189
+ namespace(path) {
190
+ this.protect(() => this.walk(resolve(path)));
191
+ }
192
+ walk(path) {
193
+ this.observe(path, true);
194
+ if (this.missing.has(path))
195
+ return;
196
+ const physical = realpathSync(path);
197
+ if (this.scanned.has(physical))
198
+ return;
199
+ this.scanned.add(physical);
200
+ const stats = lstatSync(physical);
201
+ if (stats.isDirectory()) {
202
+ for (const name of readdirSync(physical).sort())
203
+ this.walk(join(physical, name));
204
+ }
205
+ }
206
+ resolve(from, specifier, resolver, kind = 'node') {
207
+ this.protect(() => {
208
+ const require = createRequire(join(from, 'package.json'));
209
+ if (specifier.startsWith('.') || isAbsolute(specifier)) {
210
+ // Census the literal candidate's directory, independent of which extension/index the resolver selects.
211
+ const base = resolve(from, specifier);
212
+ this.directory(dirname(base));
213
+ if (existsSync(base) && lstatSync(base).isDirectory())
214
+ this.walk(base);
215
+ }
216
+ else {
217
+ const name = specifier.startsWith('@')
218
+ ? specifier.split('/').slice(0, 2).join('/')
219
+ : (specifier.split('/')[0] ?? specifier);
220
+ for (const search of require.resolve.paths(specifier) ?? [])
221
+ this.walk(join(search, name));
222
+ }
223
+ for (let directory = resolve(from);; directory = dirname(directory)) {
224
+ this.observe(join(directory, 'package.json'));
225
+ this.observe(join(directory, 'tsconfig.json'));
226
+ this.observe(join(directory, 'jsconfig.json'));
227
+ if (directory === dirname(directory))
228
+ break;
229
+ }
230
+ });
231
+ try {
232
+ const target = resolver();
233
+ this.file(target);
234
+ this.protect(() => this.resolutions.push({ kind, from, specifier, target: realpathSync(target) }));
235
+ return target;
236
+ }
237
+ catch (error) {
238
+ this.protect(() => this.resolutions.push({ kind, from, specifier, target: null }));
239
+ throw error;
240
+ }
241
+ }
242
+ executable(name, actual) {
243
+ let found;
244
+ this.protect(() => {
245
+ if (actual !== undefined) {
246
+ this.observe(actual);
247
+ found = realpathSync(actual);
248
+ }
249
+ else {
250
+ for (const directory of (process.env.PATH ?? '').split(delimiter)) {
251
+ const candidate = resolve(directory || '.', name);
252
+ this.observe(candidate);
253
+ if (this.missing.has(candidate))
254
+ continue;
255
+ try {
256
+ accessSync(candidate, constants.X_OK);
257
+ }
258
+ catch {
259
+ continue;
260
+ }
261
+ found = realpathSync(candidate);
262
+ break;
263
+ }
264
+ }
265
+ if (found === undefined)
266
+ this.refuse(`unresolved executable: ${name}`);
267
+ else
268
+ this.tools.set(name, { name, path: found });
269
+ });
270
+ return found;
271
+ }
272
+ /** Git itself supplies effective config/include origins, membership and attributes; no config reparser. */
273
+ git(root, paths) {
274
+ this.protect(() => {
275
+ const scope = realpathSync(root);
276
+ if (this.gitScopes.has(scope))
277
+ return;
278
+ this.gitScopes.add(scope);
279
+ const tool = this.executable('git');
280
+ if (tool === undefined)
281
+ return;
282
+ const config = {
283
+ cwd: scope,
284
+ args: ['config', '--show-origin', '--null', '--list'],
285
+ stdin: '',
286
+ };
287
+ const output = gitQuery(tool, config);
288
+ this.gitQueries.push({ ...config, sha256: digest(output) });
289
+ const fields = output.split('\0');
290
+ for (let index = 0; index + 1 < fields.length; index += 2) {
291
+ const origin = fields[index] ?? '';
292
+ const entry = fields[index + 1] ?? '';
293
+ if (origin.startsWith('file:'))
294
+ this.observe(resolve(scope, origin.slice(5)));
295
+ if (/^(?:core\.fsmonitor|core\.attributesfile)\n/iu.test(entry)) {
296
+ const value = entry.slice(entry.indexOf('\n') + 1);
297
+ if (entry.startsWith('core.fsmonitor\n') && value !== '' && value !== 'false')
298
+ this.refuse('Git fsmonitor has an unbounded external input closure');
299
+ if (entry.startsWith('core.attributesfile\n'))
300
+ this.observe(isAbsolute(value) ? value : resolve(scope, value));
301
+ }
302
+ }
303
+ for (const variable of ['GIT_ATTR_SYSTEM', 'GIT_ATTR_GLOBAL']) {
304
+ const query = {
305
+ cwd: scope,
306
+ args: ['var', variable],
307
+ stdin: '',
308
+ };
309
+ const output = gitQuery(tool, query);
310
+ this.gitQueries.push({ ...query, sha256: digest(output) });
311
+ const path = output.trim();
312
+ if (path !== '')
313
+ this.observe(resolve(scope, path));
314
+ }
315
+ const splitIndex = {
316
+ cwd: scope,
317
+ args: ['rev-parse', '--shared-index-path'],
318
+ stdin: '',
319
+ };
320
+ const sharedIndex = gitQuery(tool, splitIndex);
321
+ this.gitQueries.push({ ...splitIndex, sha256: digest(sharedIndex) });
322
+ if (sharedIndex.trim() !== '')
323
+ this.observe(resolve(scope, sharedIndex.trim()));
324
+ for (const name of ['index', 'info/exclude', 'info/attributes']) {
325
+ const path = execFileSync(tool, ['-c', 'core.excludesFile=/dev/null', 'rev-parse', '--git-path', name], {
326
+ cwd: scope,
327
+ env: gitEnvironment(),
328
+ encoding: 'utf8',
329
+ }).trim();
330
+ this.observe(resolve(scope, path));
331
+ }
332
+ const membership = {
333
+ cwd: scope,
334
+ args: ['ls-files', '-z', '--cached', '--others', '--exclude-standard'],
335
+ stdin: '',
336
+ };
337
+ const members = gitQuery(tool, membership);
338
+ this.gitQueries.push({ ...membership, sha256: digest(members) });
339
+ const names = [...new Set([...members.split('\0').filter(Boolean), ...paths])].sort();
340
+ for (const path of names)
341
+ this.observe(resolve(scope, path));
342
+ const attributes = {
343
+ cwd: scope,
344
+ args: ['check-attr', '--all', '-z', '--stdin'],
345
+ stdin: names.map((path) => path + '\0').join(''),
346
+ };
347
+ this.gitQueries.push({ ...attributes, sha256: digest(gitQuery(tool, attributes)) });
348
+ });
349
+ }
350
+ finish() {
351
+ const basis = {
352
+ version: 1,
353
+ workspaceRoot: this.workspaceRoot,
354
+ plugin: this.plugin,
355
+ contractSha256: digest(JSON.stringify(this.contract)),
356
+ };
357
+ this.protect(() => {
358
+ if (this.before === undefined)
359
+ return;
360
+ const after = captureNative(this.workspaceRoot, this.before);
361
+ if (!after.stable ||
362
+ nativeIdentity(after.files) !== nativeIdentity(this.before.files) ||
363
+ !nodesUnchanged(this.before.nodes) ||
364
+ !readNodesUnchanged([...this.nodes.values()]))
365
+ this.refuse('graph inputs changed during the owning reader');
366
+ if (environmentIdentity(this.workspaceRoot) !== this.environment)
367
+ this.refuse('graph environment changed during the owning reader');
368
+ if (!missingStillMissing([...this.missing]))
369
+ this.refuse('a missing resolution candidate appeared during the owning reader');
370
+ });
371
+ const witness = this.detail === undefined && this.before !== undefined && this.environment !== undefined
372
+ ? {
373
+ ...basis,
374
+ status: 'complete',
375
+ nativeIdentity: nativeIdentity(this.before.files),
376
+ nativeNodes: this.before.nodes,
377
+ nodes: [...this.nodes.values()],
378
+ missing: [...this.missing].sort(),
379
+ resolutions: this.resolutions,
380
+ tools: [...this.tools.values()],
381
+ gitQueries: this.gitQueries,
382
+ environmentIdentity: this.environment,
383
+ }
384
+ : { ...basis, status: 'unproved', detail: this.detail ?? 'no owner-approved graphInputContract' };
385
+ if (this.contract !== null) {
386
+ try {
387
+ const path = witnessPath(this.workspaceRoot, this.plugin);
388
+ mkdirSync(dirname(path), { recursive: true });
389
+ const temporary = `${path}.${randomUUID()}`;
390
+ try {
391
+ writeFileSync(temporary, JSON.stringify(witness), { flag: 'wx', mode: 0o600 });
392
+ renameSync(temporary, path);
393
+ }
394
+ finally {
395
+ rmSync(temporary, { force: true });
396
+ }
397
+ }
398
+ catch (error) {
399
+ if (!systemError(error))
400
+ throw error;
401
+ return {
402
+ ...basis,
403
+ status: 'unproved',
404
+ detail: `Cannot publish optional graph-input evidence: ${error.message}`,
405
+ };
406
+ }
407
+ }
408
+ return witness;
409
+ }
410
+ }
411
+ function readInputWitness(path) {
412
+ try {
413
+ return (() => {
414
+ const _ip0 = input => "string" === typeof input["path"];
415
+ const _ip1 = input => "string" === typeof input["stamp"];
416
+ const _ip2 = input => {
417
+ const array = input;
418
+ const tuplePredicators = [
419
+ [
420
+ top => top.length === 2 && "rev-parse" === top[0] && "--shared-index-path" === top[1],
421
+ entire => entire.length === 2 && "rev-parse" === entire[0] && "--shared-index-path" === entire[1]
422
+ ],
423
+ [
424
+ top => top.length === 2 && "var" === top[0] && "GIT_ATTR_GLOBAL" === top[1],
425
+ entire => entire.length === 2 && "var" === entire[0] && "GIT_ATTR_GLOBAL" === entire[1]
426
+ ],
427
+ [
428
+ top => top.length === 2 && "var" === top[0] && "GIT_ATTR_SYSTEM" === top[1],
429
+ entire => entire.length === 2 && "var" === entire[0] && "GIT_ATTR_SYSTEM" === entire[1]
430
+ ],
431
+ [
432
+ top => top.length === 4 && "check-attr" === top[0] && "--all" === top[1] && "-z" === top[2] && "--stdin" === top[3],
433
+ entire => entire.length === 4 && "check-attr" === entire[0] && "--all" === entire[1] && "-z" === entire[2] && "--stdin" === entire[3]
434
+ ],
435
+ [
436
+ top => top.length === 4 && "config" === top[0] && "--show-origin" === top[1] && "--null" === top[2] && "--list" === top[3],
437
+ entire => entire.length === 4 && "config" === entire[0] && "--show-origin" === entire[1] && "--null" === entire[2] && "--list" === entire[3]
438
+ ],
439
+ [
440
+ top => top.length === 5 && "ls-files" === top[0] && "-z" === top[1] && "--cached" === top[2] && "--others" === top[3] && "--exclude-standard" === top[4],
441
+ entire => entire.length === 5 && "ls-files" === entire[0] && "-z" === entire[1] && "--cached" === entire[2] && "--others" === entire[3] && "--exclude-standard" === entire[4]
442
+ ]
443
+ ];
444
+ for (const pred of tuplePredicators)
445
+ if (pred[0](array))
446
+ return pred[1](array);
447
+ return false;
448
+ };
449
+ const _io0 = input => _io1(input) && ("complete" === input.status && "string" === typeof input.nativeIdentity && (Array.isArray(input.nativeNodes) && input.nativeNodes.every(elem => "object" === typeof elem && null !== elem && _io2(elem))) && (Array.isArray(input.nodes) && input.nodes.every(elem => "object" === typeof elem && null !== elem && _io3(elem))) && (Array.isArray(input.missing) && input.missing.every(elem => "string" === typeof elem)) && (Array.isArray(input.resolutions) && input.resolutions.every(elem => "object" === typeof elem && null !== elem && _io4(elem))) && (Array.isArray(input.tools) && input.tools.every(elem => "object" === typeof elem && null !== elem && _io5(elem))) && (Array.isArray(input.gitQueries) && input.gitQueries.every(elem => "object" === typeof elem && null !== elem && _io6(elem))) && "string" === typeof input.environmentIdentity);
450
+ const _io1 = input => 1 === input.version && "string" === typeof input.workspaceRoot && "string" === typeof input.plugin && "string" === typeof input.contractSha256;
451
+ const _io2 = input => _ip0(input) && _ip1(input);
452
+ const _io3 = input => ("node" === input.scope || "path" === input.scope) && _ip0(input) && _ip1(input);
453
+ const _io4 = input => ("bun" === input.kind || "node" === input.kind) && "string" === typeof input.from && "string" === typeof input.specifier && (null === input.target || "string" === typeof input.target);
454
+ const _io5 = input => ("bun" === input.name || "git" === input.name || "node" === input.name) && _ip0(input);
455
+ const _io6 = input => "string" === typeof input.cwd && (Array.isArray(input.args) && (_ip2(input.args) || false)) && "string" === typeof input.stdin && "string" === typeof input.sha256;
456
+ const _io7 = input => _io1(input) && ("unproved" === input.status && "string" === typeof input.detail);
457
+ const _iu0 = input => (() => {
458
+ if ("complete" === input.status)
459
+ return _io0(input);
460
+ else if ("unproved" === input.status)
461
+ return _io7(input);
462
+ else
463
+ return false;
464
+ })();
465
+ const __is = input => "object" === typeof input && null !== input && _iu0(input);
466
+ return input => { input = JSON.parse(input); return __is(input) ? input : null; };
467
+ })()(readFileSync(path, 'utf8'));
468
+ }
469
+ catch (error) {
470
+ if (error instanceof SyntaxError || systemError(error))
471
+ return null;
472
+ throw error;
473
+ }
474
+ }
475
+ function missingStillMissing(paths) {
476
+ return paths.every((path) => {
477
+ try {
478
+ lstatSync(path);
479
+ return false;
480
+ }
481
+ catch (error) {
482
+ if (systemError(error) && ['ENOENT', 'ENOTDIR'].includes(error.code))
483
+ return true;
484
+ throw error;
485
+ }
486
+ });
487
+ }
488
+ /** Every local plugin must prove its own approved code and actual outside-input byproducts. */
489
+ export function graphInputContractIdentity(root, nxJson, snapshot) {
490
+ const plugins = [];
491
+ const packages = [];
492
+ const identities = [];
493
+ if (!snapshot.stable)
494
+ return null;
495
+ try {
496
+ for (const configured of nxJson.plugins ?? []) {
497
+ const plugin = typeof configured === 'string' ? configured : configured.plugin;
498
+ if (plugin === '@smoothbricks/nx-plugin')
499
+ continue;
500
+ if (typeof configured === 'string' || !plugin.startsWith('./'))
501
+ return null;
502
+ const contract = contractOf(configured.options);
503
+ if (contract === null || contract.modules[0]?.path !== plugin.slice(2))
504
+ return null;
505
+ const nodes = [];
506
+ const paths = new Set(contract.modules.map(({ path }) => resolve(root, path)));
507
+ const require = workspaceRequire(root);
508
+ const ts = require('typescript');
509
+ for (const module of contract.modules) {
510
+ const path = resolve(root, module.path);
511
+ if (isAbsolute(module.path) || relative(root, path).startsWith('..'))
512
+ return null;
513
+ const before = lstatSync(path, { bigint: true });
514
+ const text = readFileSync(path, 'utf8');
515
+ if (digest(text) !== module.sha256)
516
+ return null;
517
+ nodes.push({ path, stamp: nodeStamp(before) });
518
+ const physical = realpathSync(path);
519
+ nodes.push({ path: physical, stamp: nodeStamp(lstatSync(physical, { bigint: true })) });
520
+ for (const imported of ts.preProcessFile(text, true, true).importedFiles) {
521
+ const specifier = imported.fileName;
522
+ if (specifier.startsWith('node:'))
523
+ continue;
524
+ if (specifier.startsWith('.')) {
525
+ const base = resolve(dirname(path), specifier);
526
+ const candidates = [
527
+ base,
528
+ base.replace(/\.js$/u, '.ts'),
529
+ `${base}.ts`,
530
+ `${base}.js`,
531
+ join(base, 'index.ts'),
532
+ join(base, 'index.js'),
533
+ ];
534
+ if (!candidates.some((candidate) => paths.has(candidate)))
535
+ return null;
536
+ }
537
+ else {
538
+ const name = specifier.startsWith('@')
539
+ ? specifier.split('/').slice(0, 2).join('/')
540
+ : (specifier.split('/')[0] ?? specifier);
541
+ if (!contract.packages.includes(name))
542
+ return null;
543
+ packages.push({ name, from: dirname(physical) });
544
+ }
545
+ }
546
+ }
547
+ if (!nodesUnchanged(nodes))
548
+ return null;
549
+ let witness = null;
550
+ if (contract.kind !== 'native-only') {
551
+ witness = readInputWitness(witnessPath(root, plugin));
552
+ if (witness === null ||
553
+ witness.status !== 'complete' ||
554
+ witness.workspaceRoot !== root ||
555
+ witness.plugin !== plugin ||
556
+ witness.contractSha256 !== digest(JSON.stringify(contract)) ||
557
+ witness.nativeIdentity !== nativeIdentity(snapshot.files) ||
558
+ witness.environmentIdentity !== environmentIdentity(root) ||
559
+ !nodesUnchanged(witness.nativeNodes) ||
560
+ !readNodesUnchanged(witness.nodes) ||
561
+ !missingStillMissing(witness.missing))
562
+ return null;
563
+ for (const tool of witness.tools) {
564
+ if (realpathSync(tool.path) !== tool.path)
565
+ return null;
566
+ }
567
+ const bunResolutions = witness.resolutions.filter(({ kind }) => kind === 'bun');
568
+ if (bunResolutions.length > 0) {
569
+ const bun = witness.tools.find(({ name }) => name === 'bun');
570
+ if (bun === undefined)
571
+ return null;
572
+ const recipe = "console.log(JSON.stringify(JSON.parse(require('node:fs').readFileSync(0,'utf8')).map(({from,specifier})=>{try{return require('node:fs').realpathSync(Bun.resolveSync(specifier,from))}catch{return null}})))";
573
+ const actual = execFileSync(bun.path, ['--eval', recipe], {
574
+ input: JSON.stringify(bunResolutions),
575
+ cwd: root,
576
+ encoding: 'utf8',
577
+ maxBuffer: 64 * 1024 * 1024,
578
+ });
579
+ const targets = (() => {
580
+ const __is = input => Array.isArray(input) && input.every(elem => null === elem || "string" === typeof elem);
581
+ return input => { input = JSON.parse(input); return __is(input) ? input : null; };
582
+ })()(actual);
583
+ if (targets === null ||
584
+ targets.length !== bunResolutions.length ||
585
+ targets.some((target, index) => target !== bunResolutions[index]?.target))
586
+ return null;
587
+ }
588
+ for (const resolution of witness.resolutions) {
589
+ if (resolution.kind !== 'node')
590
+ continue;
591
+ let target;
592
+ try {
593
+ target = realpathSync(createRequire(join(resolution.from, 'package.json')).resolve(resolution.specifier));
594
+ }
595
+ catch {
596
+ target = null;
597
+ }
598
+ if (target !== resolution.target)
599
+ return null;
600
+ }
601
+ const git = witness.tools.find(({ name }) => name === 'git');
602
+ for (const query of witness.gitQueries) {
603
+ if (git === undefined || digest(gitQuery(git.path, query)) !== query.sha256)
604
+ return null;
605
+ }
606
+ if (!nodesUnchanged(witness.nativeNodes) ||
607
+ !readNodesUnchanged(witness.nodes) ||
608
+ !missingStillMissing(witness.missing))
609
+ return null;
610
+ }
611
+ plugins.push(plugin);
612
+ identities.push({ plugin, contract, nodes, witness });
613
+ }
614
+ return { plugins, packages, identity: JSON.stringify(identities) };
615
+ }
616
+ catch (error) {
617
+ if (systemError(error) && ['EACCES', 'EPERM', 'EIO'].includes(error.code))
618
+ throw error;
619
+ // Optional evidence never hides uncertainty behind a guessed local-plugin contract.
620
+ if (error instanceof Error)
621
+ return null;
622
+ throw error;
623
+ }
624
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { type CreateNodesV2, type TargetConfiguration } from 'nx/src/devkit-exports.js';
1
+ import { type CreateNodesV2, type PostTasksExecution, type PreTasksExecution, type TargetConfiguration } from 'nx/src/devkit-exports.js';
2
2
  import { CARGO_TEST_COMPILE_TARGET } from './cargo-workspace.js';
3
- import { postTasksExecution, preTasksExecution } from './task-results.js';
4
- export { CARGO_TEST_COMPILE_TARGET, postTasksExecution, preTasksExecution };
3
+ import { type ProducerReceiptsOptions } from './producer-receipts.js';
4
+ export { CARGO_TEST_COMPILE_TARGET };
5
5
  /** Makes a version live and proves it answers; never cached. */
6
6
  export declare const DEPLOY_TARGET = "deploy";
7
7
  /** The purely file-derived half a deploy needs built first; cached. */
@@ -32,10 +32,17 @@ export declare function napiToolchainTargetName(convention: NapiTargetConvention
32
32
  export declare function cargoCommandNpmPackages(target: TargetConfiguration, commandText: string, installed?: boolean): string[];
33
33
  export declare function createNodesV2ForPlatform(platform: NodeJS.Platform, architecture: string): CreateNodesV2;
34
34
  export declare const createNodesV2: CreateNodesV2;
35
+ /**
36
+ * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
37
+ * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
38
+ * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
39
+ */
40
+ export declare const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions>;
41
+ export declare const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions>;
35
42
  declare const _default: {
36
43
  createNodesV2: CreateNodesV2;
37
- postTasksExecution: typeof postTasksExecution;
38
- preTasksExecution: typeof preTasksExecution;
44
+ postTasksExecution: PostTasksExecution<ProducerReceiptsOptions>;
45
+ preTasksExecution: PreTasksExecution<ProducerReceiptsOptions>;
39
46
  };
40
47
  export default _default;
41
48
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAuB9B,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAU1E,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;AAE5E,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA2VlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AA4ID,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAoRD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,UAAsB,GAC9B,MAAM,EAAE,CAKV;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAqB9B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA2VlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AA4ID,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAoRD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,UAAsB,GAC9B,MAAM,EAAE,CAKV;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC;AAeF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,uBAAuB,CAGxE,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,uBAAuB,CAG1E,CAAC"}