@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.
- package/README.md +203 -83
- package/dist/bounded-test-policy.d.ts +10 -3
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +19 -25
- package/dist/cargo-closure-input.d.ts +12 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +34 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +265 -159
- package/dist/ensure-built-witness.d.ts +27 -2
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2176 -15
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +34 -53
- package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +43 -19
- package/dist/executors/bounded-exec/executor.d.ts +11 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +139 -39
- package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +27 -13
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +98 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +624 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +921 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +58 -0
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +147 -21
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +363 -125
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +11 -6
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +174 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +19 -27
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.test.ts +60 -11
- package/src/cargo-closure-input.ts +28 -6
- package/src/cargo-resolve-cache.test.ts +140 -25
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +251 -149
- package/src/ensure-built-witness.test.ts +197 -13
- package/src/ensure-built-witness.ts +187 -15
- package/src/ensure-built.test.ts +156 -102
- package/src/ensure-built.ts +114 -64
- package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
- package/src/executors/bounded-exec/cpu-pool.ts +55 -17
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/executor-host.test.ts +51 -41
- package/src/executors/bounded-exec/executor.test.ts +155 -35
- package/src/executors/bounded-exec/executor.ts +156 -45
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
- package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
- package/src/executors/bounded-exec/ram-temp.ts +32 -16
- package/src/executors/bounded-exec/verdict.test.ts +17 -12
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +371 -0
- package/src/graph-input-contract.ts +605 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +5 -5
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +56 -0
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +31 -9
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +631 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +59 -0
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +5 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { closeSync, lstatSync, openSync, readdirSync, readlinkSync, readSync, realpathSync } from 'node:fs';
|
|
4
|
-
import { isAbsolute, join
|
|
4
|
+
import { isAbsolute, join } from 'node:path';
|
|
5
5
|
import { CARGO_TOOLCHAIN_PIN_INPUTS, cargoRuntimeInput } from './cargo-toolchain-policy.js';
|
|
6
|
-
import { nodeStamp, nodesUnchanged } from './ensure-built-witness.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import { movedNodes, nodeStamp, nodesUnchanged } from './ensure-built-witness.js';
|
|
7
|
+
/**
|
|
8
|
+
* Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in whichever process
|
|
9
|
+
* Nx runs plugins in, a workspace's sandboxed daemon included, which adopts a host client's HOME; git with that HOME
|
|
10
|
+
* reads the operator's global configuration, the sandbox denies it, and git dies (specs/cowshed/04_sandbox.md, the
|
|
11
|
+
* runtime-input contract). A receipt's tree, HEAD and tracked-file status are read under the repository's own
|
|
12
|
+
* configuration alone, so a host run and a sandboxed run agree on them.
|
|
13
|
+
*/
|
|
14
|
+
export function receiptGit(root, args) {
|
|
15
|
+
const env = { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
|
|
12
16
|
for (const key of [
|
|
13
17
|
'GIT_DIR',
|
|
14
18
|
'GIT_COMMON_DIR',
|
|
@@ -27,7 +31,7 @@ function git(root, args) {
|
|
|
27
31
|
detail: `git ${args.join(' ')}: ${child.error?.message ?? child.stderr.trim()} (exit ${child.status}, signal ${child.signal})`,
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
|
-
/** NUL-delimited
|
|
34
|
+
/** NUL-delimited paths preserve whitespace, rename sources and index-only changes. */
|
|
31
35
|
export function dirtyProviderPaths(status) {
|
|
32
36
|
const entries = status.split('\0');
|
|
33
37
|
const paths = [];
|
|
@@ -44,8 +48,215 @@ export function dirtyProviderPaths(status) {
|
|
|
44
48
|
}
|
|
45
49
|
return paths;
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
51
|
+
function graphConfiguration(path) {
|
|
52
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
53
|
+
return [
|
|
54
|
+
'nx.json',
|
|
55
|
+
'project.json',
|
|
56
|
+
'package.json',
|
|
57
|
+
'bun.lock',
|
|
58
|
+
'bun.lockb',
|
|
59
|
+
'package-lock.json',
|
|
60
|
+
'pnpm-lock.yaml',
|
|
61
|
+
'yarn.lock',
|
|
62
|
+
].includes(name);
|
|
63
|
+
}
|
|
64
|
+
let readBuffer;
|
|
65
|
+
function fileReadBuffer() {
|
|
66
|
+
if (readBuffer === undefined)
|
|
67
|
+
readBuffer = Buffer.allocUnsafe(1 << 20);
|
|
68
|
+
return readBuffer;
|
|
69
|
+
}
|
|
70
|
+
function hashFile(path, size, algorithms, blob) {
|
|
71
|
+
const hashes = algorithms.map((algorithm) => createHash(algorithm));
|
|
72
|
+
if (blob)
|
|
73
|
+
for (const hash of hashes)
|
|
74
|
+
hash.update(`blob ${size}\0`);
|
|
75
|
+
const buffer = fileReadBuffer();
|
|
76
|
+
const descriptor = openSync(path, 'r');
|
|
77
|
+
try {
|
|
78
|
+
for (let offset = 0; offset < size; offset += buffer.length) {
|
|
79
|
+
const length = Math.min(buffer.length, size - offset);
|
|
80
|
+
if (readSync(descriptor, buffer, 0, length, offset) !== length)
|
|
81
|
+
throw new Error(`File moved while reading ${path}`);
|
|
82
|
+
for (const hash of hashes)
|
|
83
|
+
hash.update(buffer.subarray(0, length));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
closeSync(descriptor);
|
|
88
|
+
}
|
|
89
|
+
return hashes.map((hash) => hash.digest('hex'));
|
|
90
|
+
}
|
|
91
|
+
function sourceFileDigests(path, size, algorithm) {
|
|
92
|
+
const blob = createHash(algorithm).update(`blob ${size}\0`);
|
|
93
|
+
const raw = createHash('sha256');
|
|
94
|
+
const buffer = fileReadBuffer();
|
|
95
|
+
const descriptor = openSync(path, 'r');
|
|
96
|
+
try {
|
|
97
|
+
for (let offset = 0; offset < size; offset += buffer.length) {
|
|
98
|
+
const length = Math.min(buffer.length, size - offset);
|
|
99
|
+
if (readSync(descriptor, buffer, 0, length, offset) !== length)
|
|
100
|
+
throw new Error(`Source moved while reading ${path}`);
|
|
101
|
+
const bytes = buffer.subarray(0, length);
|
|
102
|
+
blob.update(bytes);
|
|
103
|
+
raw.update(bytes);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
closeSync(descriptor);
|
|
108
|
+
}
|
|
109
|
+
return { gitBlob: blob.digest('hex'), sha256: raw.digest('hex') };
|
|
110
|
+
}
|
|
111
|
+
/** One independently read node; absolute paths also serve tool/package closures. */
|
|
112
|
+
export function receiptNode(path, name, observed) {
|
|
113
|
+
const stats = lstatSync(path, { bigint: true });
|
|
114
|
+
observed.push({ path, stamp: nodeStamp(stats) });
|
|
115
|
+
const mode = Number(stats.mode & 4095n);
|
|
116
|
+
if (stats.isFile())
|
|
117
|
+
return { path: name, type: 'file', mode, sha256: hashFile(path, Number(stats.size), ['sha256'], false)[0] };
|
|
118
|
+
if (stats.isSymbolicLink())
|
|
119
|
+
return { path: name, type: 'symlink', mode, linkText: readlinkSync(path) };
|
|
120
|
+
if (stats.isDirectory()) {
|
|
121
|
+
const entries = readdirSync(path).sort();
|
|
122
|
+
return {
|
|
123
|
+
path: name,
|
|
124
|
+
type: 'directory',
|
|
125
|
+
mode,
|
|
126
|
+
entries,
|
|
127
|
+
sha256: createHash('sha256').update(JSON.stringify(entries)).digest('hex'),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`Unsupported receipt node ${path}`);
|
|
131
|
+
}
|
|
132
|
+
/** Capture every tracked source byte at pre. Unrelated untracked files are not source basis. */
|
|
133
|
+
export function captureProducerSource(root, outputs) {
|
|
134
|
+
try {
|
|
135
|
+
const revision = receiptGit(root, ['rev-parse', '--verify', 'HEAD']);
|
|
136
|
+
if (!revision.ok)
|
|
137
|
+
return revision;
|
|
138
|
+
const head = revision.value.trim();
|
|
139
|
+
const tree = receiptGit(root, ['rev-parse', '--verify', `${head}^{tree}`]);
|
|
140
|
+
if (!tree.ok)
|
|
141
|
+
return tree;
|
|
142
|
+
const listed = receiptGit(root, ['ls-tree', '-r', '-z', '--full-tree', head]);
|
|
143
|
+
if (!listed.ok)
|
|
144
|
+
return listed;
|
|
145
|
+
const format = receiptGit(root, ['rev-parse', '--show-object-format']);
|
|
146
|
+
if (!format.ok)
|
|
147
|
+
return format;
|
|
148
|
+
const algorithm = format.value.trim();
|
|
149
|
+
if (algorithm !== 'sha1' && algorithm !== 'sha256')
|
|
150
|
+
return { ok: false, detail: `Unproved Git object format ${algorithm}` };
|
|
151
|
+
const excluded = new Set(outputs.filter((path) => !graphConfiguration(path)));
|
|
152
|
+
const nodes = [];
|
|
153
|
+
const files = [];
|
|
154
|
+
for (const entry of listed.value.split('\0')) {
|
|
155
|
+
if (entry === '')
|
|
156
|
+
continue;
|
|
157
|
+
const tab = entry.indexOf('\t');
|
|
158
|
+
const [mode, kind, oid] = entry.slice(0, tab).split(' ');
|
|
159
|
+
if (tab < 0 || oid === undefined || mode === undefined)
|
|
160
|
+
return { ok: false, detail: `Unproved HEAD tree entry ${entry}` };
|
|
161
|
+
if (kind !== 'blob')
|
|
162
|
+
return { ok: false, detail: `Unbound tracked source namespace ${entry}` };
|
|
163
|
+
const file = entry.slice(tab + 1);
|
|
164
|
+
if (excluded.has(file))
|
|
165
|
+
continue;
|
|
166
|
+
const path = join(root, file);
|
|
167
|
+
const stats = lstatSync(path, { bigint: true });
|
|
168
|
+
nodes.push({ path, stamp: nodeStamp(stats) });
|
|
169
|
+
const actualMode = stats.isSymbolicLink() ? '120000' : (stats.mode & 73n) !== 0n ? '100755' : '100644';
|
|
170
|
+
if (actualMode !== mode)
|
|
171
|
+
return { ok: false, detail: `Tracked source mode differs from HEAD: ${file}` };
|
|
172
|
+
let gitBlob;
|
|
173
|
+
let sha256;
|
|
174
|
+
if (stats.isFile()) {
|
|
175
|
+
const digests = sourceFileDigests(path, Number(stats.size), algorithm);
|
|
176
|
+
gitBlob = digests.gitBlob;
|
|
177
|
+
sha256 = digests.sha256;
|
|
178
|
+
}
|
|
179
|
+
else if (stats.isSymbolicLink()) {
|
|
180
|
+
const text = readlinkSync(path);
|
|
181
|
+
gitBlob = createHash(algorithm)
|
|
182
|
+
.update(`blob ${Buffer.byteLength(text)}\0`)
|
|
183
|
+
.update(text)
|
|
184
|
+
.digest('hex');
|
|
185
|
+
sha256 = createHash('sha256').update(text).digest('hex');
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
return { ok: false, detail: `Unbound tracked source node: ${file}` };
|
|
189
|
+
if (gitBlob !== oid)
|
|
190
|
+
return { ok: false, detail: `Tracked source bytes differ from HEAD: ${file}` };
|
|
191
|
+
files.push({ path: file, mode: Number(stats.mode & 4095n), gitBlob, sha256 });
|
|
192
|
+
}
|
|
193
|
+
const status = receiptGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=no']);
|
|
194
|
+
if (!status.ok)
|
|
195
|
+
return status;
|
|
196
|
+
const dirty = dirtyProviderPaths(status.value).filter((path) => !excluded.has(path));
|
|
197
|
+
if (dirty.length !== 0)
|
|
198
|
+
return { ok: false, detail: `Tracked source/index differs from ${head}: ${dirty.join(', ')}` };
|
|
199
|
+
const moved = movedNodes(nodes);
|
|
200
|
+
if (moved !== null)
|
|
201
|
+
return { ok: false, detail: `Tracked source moved during producer pre capture: ${moved}` };
|
|
202
|
+
return { ok: true, value: { head, headTree: tree.value.trim(), files, nodes, outputs } };
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (error instanceof Error)
|
|
206
|
+
return { ok: false, detail: `Cannot prove tracked producer tree: ${error.message}` };
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export function producerSourceUnchanged(root, before) {
|
|
211
|
+
const revision = receiptGit(root, ['rev-parse', '--verify', 'HEAD']);
|
|
212
|
+
if (!revision.ok)
|
|
213
|
+
return revision;
|
|
214
|
+
const status = receiptGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=no']);
|
|
215
|
+
if (!status.ok)
|
|
216
|
+
return status;
|
|
217
|
+
const outputs = new Set(before.outputs.filter((path) => !graphConfiguration(path)));
|
|
218
|
+
const tree = receiptGit(root, ['rev-parse', '--verify', `${revision.value.trim()}^{tree}`]);
|
|
219
|
+
if (!tree.ok)
|
|
220
|
+
return tree;
|
|
221
|
+
const changed = 'Producer HEAD/tracked source nodes changed across actual task execution';
|
|
222
|
+
if (tree.value.trim() !== before.headTree)
|
|
223
|
+
return { ok: false, detail: `${changed}: HEAD's tree is ${tree.value.trim()}, not ${before.headTree}` };
|
|
224
|
+
const dirty = dirtyProviderPaths(status.value).filter((path) => !outputs.has(path));
|
|
225
|
+
if (dirty.length !== 0)
|
|
226
|
+
return { ok: false, detail: `${changed}: ${dirty.join(', ')} differ from HEAD` };
|
|
227
|
+
const moved = movedNodes(before.nodes);
|
|
228
|
+
if (moved !== null)
|
|
229
|
+
return { ok: false, detail: `${changed}: ${moved}` };
|
|
230
|
+
return { ok: true, value: true };
|
|
231
|
+
}
|
|
232
|
+
/** Enumerate exact public nodes; never exempt a broad directory of tracked source. */
|
|
233
|
+
export function producerOutputPaths(root, tasks, expand) {
|
|
234
|
+
const paths = new Set();
|
|
235
|
+
function visit(path) {
|
|
236
|
+
if (isAbsolute(path) || path.split('/').includes('..'))
|
|
237
|
+
throw new Error(`Output escapes provider: ${path}`);
|
|
238
|
+
if (paths.has(path))
|
|
239
|
+
return;
|
|
240
|
+
paths.add(path);
|
|
241
|
+
let stats;
|
|
242
|
+
try {
|
|
243
|
+
stats = lstatSync(join(root, path));
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
247
|
+
return;
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
if (stats.isDirectory())
|
|
251
|
+
for (const name of readdirSync(join(root, path)))
|
|
252
|
+
visit(join(path, name));
|
|
253
|
+
}
|
|
254
|
+
for (const task of tasks)
|
|
255
|
+
for (const path of expand(root, task.outputs))
|
|
256
|
+
visit(path);
|
|
257
|
+
return [...paths].sort();
|
|
258
|
+
}
|
|
259
|
+
export function providerReceipt(root, taskId, tasks, proof, expand, source, producer) {
|
|
49
260
|
const failed = (detail) => ({
|
|
50
261
|
disposition: 'failed',
|
|
51
262
|
reason: { kind: 'provider-proof', taskId, workspaceRoot: root, detail },
|
|
@@ -54,191 +265,86 @@ export function providerReceipt(workspaceRoot, taskId, tasks, proof, expand) {
|
|
|
54
265
|
});
|
|
55
266
|
if (proof.runtimeSource.kind === 'opaque')
|
|
56
267
|
return failed(proof.runtimeSource.detail);
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
return failed(
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const listed = git(root, ['ls-tree', '-r', '-z', '--full-tree', head]);
|
|
68
|
-
if (!listed.ok)
|
|
69
|
-
return failed(listed.detail);
|
|
70
|
-
const format = git(root, ['rev-parse', '--show-object-format']);
|
|
71
|
-
if (!format.ok)
|
|
72
|
-
return failed(format.detail);
|
|
73
|
-
const algorithm = format.value.trim();
|
|
74
|
-
if (algorithm !== 'sha1' && algorithm !== 'sha256')
|
|
75
|
-
return failed(`Unproved Git object format ${algorithm}`);
|
|
76
|
-
const tracked = new Map();
|
|
77
|
-
for (const entry of listed.value.split('\0')) {
|
|
78
|
-
if (entry === '')
|
|
79
|
-
continue;
|
|
80
|
-
const tab = entry.indexOf('\t');
|
|
81
|
-
const [mode, kind, oid] = entry.slice(0, tab).split(' ');
|
|
82
|
-
if (tab < 0 || oid === undefined)
|
|
83
|
-
return failed(`Unproved HEAD tree entry ${entry}`);
|
|
84
|
-
if (kind !== 'blob')
|
|
85
|
-
continue;
|
|
86
|
-
tracked.set(entry.slice(tab + 1), { mode, oid });
|
|
268
|
+
const stable = producerSourceUnchanged(root, source);
|
|
269
|
+
if (!stable.ok)
|
|
270
|
+
return failed(stable.detail);
|
|
271
|
+
const sourceFiles = new Map(source.files.map((file) => [file.path, file]));
|
|
272
|
+
for (const file of proof.files) {
|
|
273
|
+
const record = sourceFiles.get(file);
|
|
274
|
+
if (record === undefined)
|
|
275
|
+
return failed(`Actual Nx FILE input is not bound to provider HEAD: ${file}`);
|
|
276
|
+
if (!lstatSync(join(root, file)).isFile())
|
|
277
|
+
return failed(`Unbound linked/non-file Nx source: ${file}`);
|
|
87
278
|
}
|
|
88
279
|
const observed = [];
|
|
89
|
-
const
|
|
90
|
-
const outputNodes = new Map();
|
|
91
|
-
function observe(path) {
|
|
92
|
-
const stats = lstatSync(path, { bigint: true });
|
|
93
|
-
observed.push({ path, stamp: nodeStamp(stats) });
|
|
94
|
-
return stats;
|
|
95
|
-
}
|
|
96
|
-
function fileDigest(path, size, algorithm, gitBlob) {
|
|
97
|
-
const hash = createHash(algorithm);
|
|
98
|
-
if (gitBlob)
|
|
99
|
-
hash.update(`blob ${size}\0`);
|
|
100
|
-
const fd = openSync(path, 'r');
|
|
101
|
-
try {
|
|
102
|
-
for (let offset = 0; offset < size; offset += buffer.length) {
|
|
103
|
-
const count = Math.min(buffer.length, size - offset);
|
|
104
|
-
if (readSync(fd, buffer, 0, count, offset) !== count)
|
|
105
|
-
throw new Error(`File moved while reading ${path}`);
|
|
106
|
-
hash.update(buffer.subarray(0, count));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
closeSync(fd);
|
|
111
|
-
}
|
|
112
|
-
return hash.digest('hex');
|
|
113
|
-
}
|
|
280
|
+
const outputs = new Map();
|
|
114
281
|
function visit(path) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (stats.isFile()) {
|
|
125
|
-
node = { path: rel, type: 'file', mode, sha256: fileDigest(path, Number(stats.size), 'sha256', false) };
|
|
126
|
-
}
|
|
127
|
-
else if (stats.isSymbolicLink()) {
|
|
128
|
-
node = { path: rel, type: 'symlink', mode, linkText: readlinkSync(path) };
|
|
129
|
-
}
|
|
130
|
-
else if (stats.isDirectory()) {
|
|
131
|
-
const children = readdirSync(path)
|
|
132
|
-
.sort()
|
|
133
|
-
.map((name) => visit(join(path, name)));
|
|
134
|
-
const entries = children.map(({ path: child }) => relative(rel, child));
|
|
135
|
-
node = {
|
|
136
|
-
path: rel,
|
|
137
|
-
type: 'directory',
|
|
138
|
-
mode,
|
|
139
|
-
entries,
|
|
140
|
-
sha256: createHash('sha256').update(JSON.stringify(children)).digest('hex'),
|
|
141
|
-
};
|
|
282
|
+
if (outputs.has(path))
|
|
283
|
+
return;
|
|
284
|
+
const absolute = join(root, path);
|
|
285
|
+
let node = receiptNode(absolute, path, observed);
|
|
286
|
+
if (node.type === 'directory') {
|
|
287
|
+
for (const entry of node.entries)
|
|
288
|
+
visit(join(path, entry));
|
|
289
|
+
const children = node.entries.map((entry) => outputs.get(join(path, entry)));
|
|
290
|
+
node = { ...node, sha256: createHash('sha256').update(JSON.stringify(children)).digest('hex') };
|
|
142
291
|
}
|
|
143
|
-
|
|
144
|
-
throw new Error(`Unsupported public output node ${path}`);
|
|
145
|
-
}
|
|
146
|
-
outputNodes.set(rel, node);
|
|
147
|
-
return node;
|
|
292
|
+
outputs.set(path, node);
|
|
148
293
|
}
|
|
149
294
|
try {
|
|
150
295
|
const receipts = [];
|
|
151
296
|
for (const task of tasks) {
|
|
152
297
|
if (task.hash === undefined)
|
|
153
|
-
return failed(`
|
|
298
|
+
return failed(`Actual completion supplied no hash for ${task.id}`);
|
|
154
299
|
const entries = task.outputs.length === 0 ? [] : expand(root, task.outputs);
|
|
155
|
-
if (task.outputs.length
|
|
300
|
+
if (task.outputs.length !== 0 && entries.length === 0)
|
|
156
301
|
return failed(`No public outputs for ${task.id}`);
|
|
157
|
-
const selected = new Set();
|
|
158
302
|
for (const entry of entries) {
|
|
159
303
|
if (isAbsolute(entry) || entry.split('/').includes('..'))
|
|
160
|
-
return failed(`
|
|
161
|
-
// Root-to-entry parent directories must be real; do not follow a
|
|
162
|
-
// parent link into an unrelated tree and sign its bytes.
|
|
304
|
+
return failed(`Output escapes provider: ${entry}`);
|
|
163
305
|
let parent = root;
|
|
164
306
|
for (const segment of entry.split('/').slice(0, -1)) {
|
|
165
307
|
parent = join(parent, segment);
|
|
166
|
-
|
|
308
|
+
const stats = lstatSync(parent, { bigint: true });
|
|
309
|
+
observed.push({ path: parent, stamp: nodeStamp(stats) });
|
|
310
|
+
if (!stats.isDirectory())
|
|
167
311
|
return failed(`Symlinked public output parent ${parent}`);
|
|
168
312
|
}
|
|
169
|
-
visit(
|
|
170
|
-
for (const path of outputNodes.keys()) {
|
|
171
|
-
if (path === entry || path.startsWith(`${entry}/`))
|
|
172
|
-
selected.add(path);
|
|
173
|
-
}
|
|
313
|
+
visit(entry);
|
|
174
314
|
}
|
|
175
315
|
receipts.push({
|
|
176
316
|
id: task.id,
|
|
177
317
|
hash: task.hash,
|
|
178
|
-
outputs: [...
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return node;
|
|
183
|
-
}),
|
|
318
|
+
outputs: [...outputs]
|
|
319
|
+
.filter(([path]) => entries.some((entry) => path === entry || path.startsWith(`${entry}/`)))
|
|
320
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
321
|
+
.map(([, node]) => node),
|
|
184
322
|
});
|
|
185
323
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
.
|
|
189
|
-
|
|
190
|
-
const effectiveKind = deletedSource ? 'conservative-provider-source' : proof.kind;
|
|
191
|
-
const dirty = dirtyProviderPaths(status.value).filter((path) => (!outputNodes.has(path) || fileInputs.has(path)) &&
|
|
192
|
-
(effectiveKind === 'conservative-provider-source' || fileInputs.has(path)));
|
|
193
|
-
if (dirty.length > 0)
|
|
194
|
-
return failed(`${effectiveKind}: provider source differs from ${head}: ${dirty.join(', ')}`);
|
|
195
|
-
for (const file of fileInputs) {
|
|
196
|
-
const expected = tracked.get(file);
|
|
197
|
-
if (expected === undefined)
|
|
198
|
-
return failed(`Nx file input is not in provider HEAD tree: ${file}`);
|
|
199
|
-
const path = join(root, file);
|
|
200
|
-
const stats = observe(path);
|
|
201
|
-
const mode = stats.isSymbolicLink() ? '120000' : (stats.mode & 73n) !== 0n ? '100755' : '100644';
|
|
202
|
-
if (mode !== expected.mode)
|
|
203
|
-
return failed(`Nx file input mode differs from provider HEAD: ${file}`);
|
|
204
|
-
if (!stats.isFile())
|
|
205
|
-
return failed(`Unproved linked or non-file input source closure: ${file}`);
|
|
206
|
-
const oid = fileDigest(path, Number(stats.size), algorithm, true);
|
|
207
|
-
if (oid !== expected.oid)
|
|
208
|
-
return failed(`Nx file input bytes differ from provider HEAD: ${file}`);
|
|
209
|
-
}
|
|
210
|
-
const finalHead = git(root, ['rev-parse', '--verify', 'HEAD']);
|
|
211
|
-
const finalStatus = git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']);
|
|
212
|
-
if (!finalHead.ok)
|
|
213
|
-
return failed(finalHead.detail);
|
|
214
|
-
if (!finalStatus.ok)
|
|
215
|
-
return failed(finalStatus.detail);
|
|
216
|
-
const newlyDirty = dirtyProviderPaths(finalStatus.value).some((path) => (!outputNodes.has(path) || fileInputs.has(path)) &&
|
|
217
|
-
(effectiveKind === 'conservative-provider-source' || fileInputs.has(path)));
|
|
218
|
-
if (finalHead.value.trim() !== head || newlyDirty || !nodesUnchanged(observed)) {
|
|
219
|
-
return failed('Provider source, revision or public output nodes moved during receipt capture');
|
|
220
|
-
}
|
|
324
|
+
const final = producerSourceUnchanged(root, source);
|
|
325
|
+
if (!final.ok || !nodesUnchanged(observed))
|
|
326
|
+
return failed(final.ok ? 'Public outputs changed during independent census' : final.detail);
|
|
327
|
+
const outputSha256 = createHash('sha256').update(JSON.stringify(receipts)).digest('hex');
|
|
221
328
|
return {
|
|
222
329
|
disposition: 'hit',
|
|
223
330
|
receipt: {
|
|
224
|
-
workspaceRoot: root,
|
|
225
|
-
head,
|
|
226
|
-
headTree:
|
|
227
|
-
|
|
228
|
-
fileInputProvenance: effectiveKind,
|
|
331
|
+
workspaceRoot: realpathSync(root),
|
|
332
|
+
head: source.head,
|
|
333
|
+
headTree: source.headTree,
|
|
334
|
+
fileInputProvenance: proof.kind,
|
|
229
335
|
runtimeEnvironmentProvenance: 'nx-task-hash-only',
|
|
336
|
+
producer: { ...producer, outputSha256 },
|
|
337
|
+
tasks: receipts,
|
|
230
338
|
},
|
|
231
339
|
};
|
|
232
340
|
}
|
|
233
341
|
catch (error) {
|
|
234
342
|
if (error instanceof Error)
|
|
235
|
-
return failed(`Cannot prove
|
|
343
|
+
return failed(`Cannot prove public product census: ${error.message}`);
|
|
236
344
|
throw error;
|
|
237
345
|
}
|
|
238
346
|
}
|
|
239
|
-
/** Admit only recipes emitted by the
|
|
240
|
-
* No shell parsing or keyword approximation confers file-source provenance.
|
|
241
|
-
*/
|
|
347
|
+
/** Admit only version recipes emitted by the owning generator and declared toolchain pins. */
|
|
242
348
|
export function boundedReceiptRuntimes(inputs, directories, files, installationProved) {
|
|
243
349
|
const runtimes = Object.values(inputs).flatMap((input) => input.runtime);
|
|
244
350
|
if (runtimes.length === 0)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { BigIntStats } from 'node:fs';
|
|
2
2
|
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
|
3
3
|
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
4
|
-
import type { FileData, WorkspaceContext } from 'nx/src/native';
|
|
4
|
+
import type { expandOutputs, FileData, WorkspaceContext } from 'nx/src/native';
|
|
5
5
|
import type { readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
6
|
+
import type { GraphInputContractProof } from './graph-input-contract.js';
|
|
6
7
|
/** Identity of a previously read node, not a timestamp freshness threshold. */
|
|
7
8
|
export declare function nodeStamp(stats: BigIntStats): string;
|
|
8
9
|
export interface NodeWitness {
|
|
@@ -32,11 +33,30 @@ export declare function writeWitness(path: string, value: GraphWitness | Artifac
|
|
|
32
33
|
*/
|
|
33
34
|
export declare function workspaceSnapshot(workspaceRoot: string, context: WorkspaceContext, previous: WorkspaceSnapshot | undefined): WorkspaceSnapshot;
|
|
34
35
|
export declare function nodesUnchanged(nodes: readonly NodeWitness[]): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The witnessed nodes whose stamp is no longer the one read, named for a refusal (the first eight in witness order, a
|
|
38
|
+
* gone one with its error code, and how many more), or null when none moved. A node whose device, inode, mode, size
|
|
39
|
+
* and mtime are unchanged and only its ctime moved (a same-mode chmod, which Bun's bin linking does to a shared store
|
|
40
|
+
* file on any checkout's install) asks for a comparison, not a verdict: `same` re-reads it, and one it finds as
|
|
41
|
+
* recorded has not changed. Without `same` every move counts.
|
|
42
|
+
*/
|
|
43
|
+
export declare function movedNodes(nodes: readonly NodeWitness[], same?: (path: string) => boolean): string | null;
|
|
35
44
|
/** Membership and content are exact. Outputs do not exempt manifests or
|
|
36
45
|
* newly created/deleted files; this graph witness has no output exclusions.
|
|
37
46
|
*/
|
|
38
47
|
export declare function snapshotsEqual(left: WorkspaceSnapshot, right: WorkspaceSnapshot): boolean;
|
|
39
48
|
export declare function reusableGraph(witness: GraphWitness | null, workspaceRoot: string, environment: string, installation: string | null, snapshot: WorkspaceSnapshot): ProjectGraph | null;
|
|
49
|
+
/** What {@link graphInstallationIdentity} binds: resolution edges `[from, name, physical manifest]`, node stamps and
|
|
50
|
+
* file hashes, read once.
|
|
51
|
+
*/
|
|
52
|
+
export interface GraphInstallationCensus {
|
|
53
|
+
readonly resolutions: readonly (readonly [string, string, string | null])[];
|
|
54
|
+
readonly nodes: readonly NodeWitness[];
|
|
55
|
+
readonly files: readonly {
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly sha256: string;
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
40
60
|
/** Plugins with opaque external graph inputs cannot borrow this proof.
|
|
41
61
|
* For the repository plugin and Nx, bind the entire owned module/file tree
|
|
42
62
|
* and its dependency/optional/peer resolution closure, including each alias,
|
|
@@ -44,7 +64,12 @@ export declare function reusableGraph(witness: GraphWitness | null, workspaceRoo
|
|
|
44
64
|
* bytes, including manifest metadata; pre/post node stamps still reject a
|
|
45
65
|
* tree that moved while reading. A missing optional dependency is recorded too.
|
|
46
66
|
*/
|
|
47
|
-
export declare function graphInstallationIdentity(workspaceRoot: string, nxJson: NxJsonConfiguration, resolvePackage: typeof readModulePackageJsonWithoutFallbacks): string | null;
|
|
67
|
+
export declare function graphInstallationIdentity(workspaceRoot: string, nxJson: NxJsonConfiguration, resolvePackage: typeof readModulePackageJsonWithoutFallbacks, expand: typeof expandOutputs, localInputs: GraphInputContractProof | null, onUnproved?: (detail: string) => void): string | null;
|
|
68
|
+
/** One read of the installation closure {@link graphInstallationIdentity} binds, without its final check that no node
|
|
69
|
+
* moved while it was read: what a caller that needs the closure, not a proof of it, reads. `null`, with `onUnproved`
|
|
70
|
+
* told why, for a closure that cannot be read.
|
|
71
|
+
*/
|
|
72
|
+
export declare function graphInstallationCensus(workspaceRoot: string, nxJson: NxJsonConfiguration, resolvePackage: typeof readModulePackageJsonWithoutFallbacks, expand: typeof expandOutputs, localInputs: GraphInputContractProof | null, onUnproved?: (detail: string) => void): GraphInstallationCensus | null;
|
|
48
73
|
export interface ArtifactWitness {
|
|
49
74
|
readonly version: 1;
|
|
50
75
|
readonly workspaceRoot: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-built-witness.d.ts","sourceRoot":"","sources":["../src/ensure-built-witness.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ensure-built-witness.d.ts","sourceRoot":"","sources":["../src/ensure-built-witness.ts"],"names":[],"mappings":"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"}
|