@smoothbricks/nx-plugin 0.4.28 → 0.4.30
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 +277 -89
- package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-clocks.js +28 -0
- package/dist/bounded-test-policy.d.ts +8 -8
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +18 -30
- package/dist/cargo-closure-input.d.ts +23 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +41 -9
- 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 +40 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +297 -159
- package/dist/ensure-built-witness.d.ts +65 -4
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2237 -23
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +45 -56
- package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +51 -22
- package/dist/executors/bounded-exec/executor.d.ts +12 -3
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +174 -51
- package/dist/executors/bounded-exec/no-space.d.ts +8 -0
- package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
- package/dist/executors/bounded-exec/no-space.js +31 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +20 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +42 -17
- package/dist/executors/bounded-exec/verdict.d.ts +34 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +54 -3
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +102 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +637 -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/owned-installation.d.ts +14 -0
- package/dist/owned-installation.d.ts.map +1 -0
- package/dist/owned-installation.js +324 -0
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +926 -0
- package/dist/test-backstop.d.ts +9 -0
- package/dist/test-backstop.d.ts.map +1 -0
- package/dist/test-backstop.js +10 -0
- package/dist/test-clock-policy.d.ts +30 -0
- package/dist/test-clock-policy.d.ts.map +1 -0
- package/dist/test-clock-policy.js +686 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +66 -1
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +148 -29
- 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 +179 -115
- 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 +25 -9
- package/src/__tests__/cargo-closure-fixture.ts +113 -0
- package/src/__tests__/counted-cargo.ts +8 -25
- package/src/__tests__/directory-change.ts +27 -0
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +14 -0
- package/src/__tests__/past-tick.ts +12 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bin/smoo-nx-test-clocks.ts +29 -0
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +18 -32
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.property.test.ts +50 -0
- package/src/cargo-closure-input.test.ts +73 -121
- package/src/cargo-closure-input.ts +47 -8
- package/src/cargo-closure-key.test.ts +239 -0
- package/src/cargo-resolve-cache.test.ts +168 -31
- 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 +294 -149
- package/src/ensure-built-witness.test.ts +306 -13
- package/src/ensure-built-witness.ts +255 -24
- package/src/ensure-built.test.ts +228 -102
- package/src/ensure-built.ts +127 -66
- package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
- package/src/executors/bounded-exec/cpu-pool.ts +64 -20
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
- package/src/executors/bounded-exec/executor-host.test.ts +74 -52
- package/src/executors/bounded-exec/executor.test.ts +343 -97
- package/src/executors/bounded-exec/executor.ts +192 -56
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
- package/src/executors/bounded-exec/no-space.ts +40 -0
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
- package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
- package/src/executors/bounded-exec/ram-temp.ts +49 -20
- package/src/executors/bounded-exec/verdict.test.ts +127 -22
- package/src/executors/bounded-exec/verdict.ts +78 -3
- 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 +379 -0
- package/src/graph-input-contract.ts +627 -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-extraction.test.ts +114 -4
- 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 +10 -8
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +61 -1
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +36 -22
- 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/owned-installation.ts +174 -0
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +636 -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-backstop.ts +11 -0
- package/src/test-clock-policy.test.ts +338 -0
- package/src/test-clock-policy.ts +708 -0
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +67 -1
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +8 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
+
import { chmodSync, lstatSync, readFileSync, utimesSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import {
|
|
4
5
|
chmod,
|
|
5
6
|
mkdir,
|
|
@@ -15,19 +16,26 @@ import {
|
|
|
15
16
|
} from 'node:fs/promises';
|
|
16
17
|
import { tmpdir } from 'node:os';
|
|
17
18
|
import { join } from 'node:path';
|
|
19
|
+
import fc from 'fast-check';
|
|
18
20
|
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
19
|
-
import { WorkspaceContext } from 'nx/src/native';
|
|
21
|
+
import { expandOutputs, WorkspaceContext } from 'nx/src/native';
|
|
20
22
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory';
|
|
21
23
|
import type { readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
22
24
|
import typia from 'typia';
|
|
23
25
|
import {
|
|
26
|
+
censusStart,
|
|
24
27
|
type GraphWitness,
|
|
25
28
|
graphInstallationIdentity,
|
|
29
|
+
movedNodes,
|
|
26
30
|
type NodeWitness,
|
|
31
|
+
nodeStamp,
|
|
27
32
|
nodesUnchanged,
|
|
28
33
|
readGraphWitness,
|
|
34
|
+
recordedStamp,
|
|
29
35
|
reusableGraph,
|
|
36
|
+
SAME_TICK_NS,
|
|
30
37
|
snapshotsEqual,
|
|
38
|
+
stampMove,
|
|
31
39
|
workspaceSnapshot,
|
|
32
40
|
writeWitness,
|
|
33
41
|
} from './ensure-built-witness.js';
|
|
@@ -148,6 +156,53 @@ describe('authoritative graph witness', () => {
|
|
|
148
156
|
});
|
|
149
157
|
});
|
|
150
158
|
|
|
159
|
+
// A filesystem dates a change by the kernel's clock, and ZFS on Linux by its coarse tick (1 ms on CI's runner), so a
|
|
160
|
+
// same-size rewrite in the tick a stamp was read in leaves the whole stamp as it was: git's racily clean entries. No
|
|
161
|
+
// call sets a ctime, so the tick is constructed rather than raced for: each write is dated ahead with utimes, so every
|
|
162
|
+
// census reads it inside its change's tick however long the census takes, and the rewrite keeps that date and size.
|
|
163
|
+
// On a coarse clock the rewrite then leaves the stamp as recorded in most rounds, and a reader that trusts it reads
|
|
164
|
+
// the node as unchanged; on a fine one (APFS, ext4) its ctime still moves, and only there would trusting it pass.
|
|
165
|
+
describe('a stamp read in the tick its node changed in', () => {
|
|
166
|
+
const rounds = 16;
|
|
167
|
+
const source = 'packages/app/source.txt';
|
|
168
|
+
|
|
169
|
+
it('is re-hashed by the next capture, which a same-size rewrite in that tick would otherwise escape', () => {
|
|
170
|
+
const path = join(root, source);
|
|
171
|
+
const context = new WorkspaceContext(root, data());
|
|
172
|
+
const hashOf = ({ files }: GraphWitness['snapshot']) => files.find(({ file }) => file === source)?.hash;
|
|
173
|
+
for (let round = 0; round < rounds; round++) {
|
|
174
|
+
const ahead = new Date(Date.now() + 60_000);
|
|
175
|
+
writeFileSync(path, `before ${round}`);
|
|
176
|
+
utimesSync(path, ahead, ahead);
|
|
177
|
+
const recorded = workspaceSnapshot(root, context, undefined);
|
|
178
|
+
writeFileSync(path, `after! ${round}`);
|
|
179
|
+
utimesSync(path, ahead, ahead);
|
|
180
|
+
const current = workspaceSnapshot(root, context, recorded);
|
|
181
|
+
// Its own stability check compares what it read; only a later capture distrusts the stamp.
|
|
182
|
+
expect(recorded.stable).toBe(true);
|
|
183
|
+
expect(hashOf(current)).not.toBe(hashOf(recorded));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('is recorded unproven, so a reader re-reads the node and finds the rewrite', () => {
|
|
188
|
+
const path = join(root, 'stamped');
|
|
189
|
+
const reread = (node: string) => readFileSync(node, 'utf8') === 'before';
|
|
190
|
+
for (let round = 0; round < rounds; round++) {
|
|
191
|
+
const ahead = new Date(Date.now() + 60_000);
|
|
192
|
+
writeFileSync(path, 'before');
|
|
193
|
+
utimesSync(path, ahead, ahead);
|
|
194
|
+
const recorded: NodeWitness[] = [
|
|
195
|
+
{ path, stamp: recordedStamp(lstatSync(path, { bigint: true }), censusStart()) },
|
|
196
|
+
];
|
|
197
|
+
expect(movedNodes(recorded, reread)).toBeNull();
|
|
198
|
+
writeFileSync(path, 'after!');
|
|
199
|
+
utimesSync(path, ahead, ahead);
|
|
200
|
+
expect(nodesUnchanged(recorded)).toBe(false);
|
|
201
|
+
expect(movedNodes(recorded, reread)).toBe(path);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
151
206
|
describe('runtime graph witness storage', () => {
|
|
152
207
|
it.each(['relative', 'absolute'])(
|
|
153
208
|
'uses the %s workspace-data binding for missing and unreadable witnesses',
|
|
@@ -219,7 +274,8 @@ describe('installed graph input identity', () => {
|
|
|
219
274
|
const { nx, plugin, dependency, resolver } = await packages();
|
|
220
275
|
const output = join(plugin, 'dist', 'index.js');
|
|
221
276
|
await utimes(output, 1_600_000_000, 1_600_000_000);
|
|
222
|
-
const identity = () =>
|
|
277
|
+
const identity = () =>
|
|
278
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
223
279
|
const original = identity();
|
|
224
280
|
expect(original).not.toBeNull();
|
|
225
281
|
expect(identity()).toBe(original);
|
|
@@ -263,7 +319,8 @@ describe('installed graph input identity', () => {
|
|
|
263
319
|
const output = join(dependency, 'dist', 'payload.bin');
|
|
264
320
|
const bytes = Buffer.alloc(2 * 64 * 1024 + 17, 0x61);
|
|
265
321
|
await writeFile(output, bytes);
|
|
266
|
-
const identity = () =>
|
|
322
|
+
const identity = () =>
|
|
323
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
267
324
|
const original = parsed(identity());
|
|
268
325
|
expect(original.files.find(({ path }) => path === output)?.sha256).toBe(
|
|
269
326
|
createHash('sha256').update(bytes).digest('hex'),
|
|
@@ -287,7 +344,8 @@ describe('installed graph input identity', () => {
|
|
|
287
344
|
const published = join(root, 'published-build-volume');
|
|
288
345
|
await rename(join(plugin, 'dist'), published);
|
|
289
346
|
await symlink(published, join(plugin, 'dist'), 'dir');
|
|
290
|
-
const identity = () =>
|
|
347
|
+
const identity = () =>
|
|
348
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
291
349
|
const original = identity();
|
|
292
350
|
expect(original).not.toBeNull();
|
|
293
351
|
expect(identity()).toBe(original);
|
|
@@ -307,38 +365,273 @@ describe('installed graph input identity', () => {
|
|
|
307
365
|
const alternative = join(root, 'alternative-dependency');
|
|
308
366
|
await mkdir(alternative);
|
|
309
367
|
await writeFile(join(alternative, 'package.json'), '{"name":"owned","version":"1"}');
|
|
310
|
-
const original = graphInstallationIdentity(
|
|
368
|
+
const original = graphInstallationIdentity(
|
|
369
|
+
root,
|
|
370
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
371
|
+
resolver,
|
|
372
|
+
expandOutputs,
|
|
373
|
+
null,
|
|
374
|
+
);
|
|
311
375
|
const changed: typeof resolver = (name, from) => {
|
|
312
376
|
const result = resolver(name, from);
|
|
313
377
|
return name === 'alias' ? { ...result, path: join(alternative, 'package.json') } : result;
|
|
314
378
|
};
|
|
315
|
-
expect(
|
|
379
|
+
expect(
|
|
380
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, changed, expandOutputs, null),
|
|
381
|
+
).not.toBe(original);
|
|
316
382
|
expect(dependency).not.toBe(alternative);
|
|
317
383
|
});
|
|
318
384
|
|
|
385
|
+
it('binds an installed dependency exposing only public subpaths, without inventing a main entry', async () => {
|
|
386
|
+
const { plugin, dependency, resolver } = await packages();
|
|
387
|
+
await mkdir(join(plugin, 'node_modules'), { recursive: true });
|
|
388
|
+
await symlink(dependency, join(plugin, 'node_modules/alias'), 'dir');
|
|
389
|
+
await writeFile(
|
|
390
|
+
join(dependency, 'package.json'),
|
|
391
|
+
JSON.stringify({ name: 'owned', version: '1', exports: { './data': './data.json' } }),
|
|
392
|
+
);
|
|
393
|
+
await writeFile(join(dependency, 'data.json'), '{"value":1}');
|
|
394
|
+
const subpaths: typeof resolver = (name, paths) => {
|
|
395
|
+
if (name === 'alias')
|
|
396
|
+
throw Object.assign(new Error('No exports main defined'), { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' });
|
|
397
|
+
return resolver(name, paths);
|
|
398
|
+
};
|
|
399
|
+
const identity = () =>
|
|
400
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, subpaths, expandOutputs, null);
|
|
401
|
+
const original = identity();
|
|
402
|
+
expect(original).not.toBeNull();
|
|
403
|
+
await writeFile(join(dependency, 'data.json'), '{"value":2}');
|
|
404
|
+
expect(identity()).not.toBe(original);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('uses package-root anchored publication patterns and Nx exclusions without dropping directory members', async () => {
|
|
408
|
+
const { plugin, resolver } = await packages();
|
|
409
|
+
const excluded = join(plugin, 'dist', 'state.tsbuildinfo');
|
|
410
|
+
await writeFile(excluded, 'before');
|
|
411
|
+
const anchored: typeof resolver = (name, paths) => {
|
|
412
|
+
const resolved = resolver(name, paths);
|
|
413
|
+
return { ...resolved, packageJson: { ...resolved.packageJson, files: ['/dist', '!**/*.tsbuildinfo'] } };
|
|
414
|
+
};
|
|
415
|
+
const identity = () =>
|
|
416
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, anchored, expandOutputs, null);
|
|
417
|
+
const original = identity();
|
|
418
|
+
expect(original).not.toBeNull();
|
|
419
|
+
await writeFile(excluded, 'after');
|
|
420
|
+
expect(identity()).toBe(original);
|
|
421
|
+
await writeFile(join(plugin, 'dist', 'index.js'), 'exports.value = 2;');
|
|
422
|
+
expect(identity()).not.toBe(original);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('does not bind an unpublished cache marker but names a public marker changed during census', async () => {
|
|
426
|
+
const { plugin, resolver } = await packages();
|
|
427
|
+
await mkdir(join(plugin, '.cache'));
|
|
428
|
+
const privateMarker = join(plugin, '.cache', 'marker');
|
|
429
|
+
const publicMarker = join(plugin, 'dist', 'index.js');
|
|
430
|
+
await writeFile(privateMarker, 'before');
|
|
431
|
+
const during = (marker: string) => {
|
|
432
|
+
let changed = false;
|
|
433
|
+
let detail = '';
|
|
434
|
+
const mutate: typeof resolver = (name, paths) => {
|
|
435
|
+
const resolved = resolver(name, paths);
|
|
436
|
+
if (name === 'alias' && !changed) {
|
|
437
|
+
writeFileSync(marker, 'after');
|
|
438
|
+
changed = true;
|
|
439
|
+
}
|
|
440
|
+
return resolved;
|
|
441
|
+
};
|
|
442
|
+
const proof = graphInstallationIdentity(
|
|
443
|
+
root,
|
|
444
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
445
|
+
mutate,
|
|
446
|
+
expandOutputs,
|
|
447
|
+
null,
|
|
448
|
+
(reason) => {
|
|
449
|
+
detail = reason;
|
|
450
|
+
},
|
|
451
|
+
);
|
|
452
|
+
return { proof, changed, detail };
|
|
453
|
+
};
|
|
454
|
+
const unrelated = during(privateMarker);
|
|
455
|
+
expect(unrelated.changed).toBe(true);
|
|
456
|
+
expect(unrelated.proof).not.toBeNull();
|
|
457
|
+
expect(unrelated.detail).toBe('');
|
|
458
|
+
const changed = during(publicMarker);
|
|
459
|
+
expect(changed.changed).toBe(true);
|
|
460
|
+
expect(changed.proof).toBeNull();
|
|
461
|
+
expect(changed.detail).toContain(publicMarker);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('retains the full tree without a publication declaration and names its changed marker', async () => {
|
|
465
|
+
const { plugin, resolver } = await packages();
|
|
466
|
+
await mkdir(join(plugin, '.cache'));
|
|
467
|
+
const marker = join(plugin, '.cache', 'marker');
|
|
468
|
+
await writeFile(marker, 'before');
|
|
469
|
+
let changed = false;
|
|
470
|
+
let detail = '';
|
|
471
|
+
const undeclared: typeof resolver = (name, paths) => {
|
|
472
|
+
const resolved = resolver(name, paths);
|
|
473
|
+
if (name === 'alias' && !changed) {
|
|
474
|
+
writeFileSync(marker, 'after');
|
|
475
|
+
changed = true;
|
|
476
|
+
}
|
|
477
|
+
const { files, ...packageJson } = resolved.packageJson;
|
|
478
|
+
expect(files).toEqual(['dist']);
|
|
479
|
+
return { ...resolved, packageJson };
|
|
480
|
+
};
|
|
481
|
+
expect(
|
|
482
|
+
graphInstallationIdentity(
|
|
483
|
+
root,
|
|
484
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
485
|
+
undeclared,
|
|
486
|
+
expandOutputs,
|
|
487
|
+
null,
|
|
488
|
+
(reason) => {
|
|
489
|
+
detail = reason;
|
|
490
|
+
},
|
|
491
|
+
),
|
|
492
|
+
).toBeNull();
|
|
493
|
+
expect(changed).toBe(true);
|
|
494
|
+
expect(detail).toContain(marker);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it("re-hashes a public file whose ctime alone moved during census, as Bun's bin linking moves a shared store file", async () => {
|
|
498
|
+
const { plugin, resolver } = await packages();
|
|
499
|
+
const output = join(plugin, 'dist/index.js');
|
|
500
|
+
const mode = (await stat(output)).mode & 0o7777;
|
|
501
|
+
let rechmodded = false;
|
|
502
|
+
let detail = '';
|
|
503
|
+
// Any checkout's install that links a bin re-chmods its store target to the mode it already has.
|
|
504
|
+
const sameMode: typeof resolver = (name, paths) => {
|
|
505
|
+
const resolved = resolver(name, paths);
|
|
506
|
+
if (name === 'alias' && !rechmodded) {
|
|
507
|
+
chmodSync(output, mode);
|
|
508
|
+
rechmodded = true;
|
|
509
|
+
}
|
|
510
|
+
return resolved;
|
|
511
|
+
};
|
|
512
|
+
const proof = graphInstallationIdentity(
|
|
513
|
+
root,
|
|
514
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
515
|
+
sameMode,
|
|
516
|
+
expandOutputs,
|
|
517
|
+
null,
|
|
518
|
+
(reason) => {
|
|
519
|
+
detail = reason;
|
|
520
|
+
},
|
|
521
|
+
);
|
|
522
|
+
expect(rechmodded).toBe(true);
|
|
523
|
+
expect(detail).toBe('');
|
|
524
|
+
// Bound, with the bytes it read: the identity carries the stamps of that census, not a later one's.
|
|
525
|
+
expect(parsed(proof).files.find(({ path }) => path === output)?.sha256).toBe(
|
|
526
|
+
createHash('sha256').update('exports.value = 1;').digest('hex'),
|
|
527
|
+
);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it('names every moved node, and re-reads only one whose ctime alone moved', async () => {
|
|
531
|
+
const file = join(root, 'stamped');
|
|
532
|
+
await writeFile(file, 'before');
|
|
533
|
+
// A filesystem that stamps from the kernel's coarse tick (ZFS on Linux: 1 ms) keeps the stamp of a chmod or a
|
|
534
|
+
// same-size rewrite that lands in the tick of the last change. No call sets a ctime, so the file is dated a second
|
|
535
|
+
// back and recorded as it was then, when its ctime was its mtime: each change below moves it on every filesystem.
|
|
536
|
+
const past = new Date(Date.now() - 1000);
|
|
537
|
+
await utimes(file, past, past);
|
|
538
|
+
const recorded = lstatSync(file, { bigint: true });
|
|
539
|
+
const chmodded: NodeWitness[] = [
|
|
540
|
+
{ path: file, stamp: nodeStamp(Object.assign(recorded, { ctimeNs: recorded.mtimeNs })) },
|
|
541
|
+
];
|
|
542
|
+
chmodSync(file, (await stat(file)).mode & 0o7777);
|
|
543
|
+
expect(movedNodes(chmodded)).toBe(file);
|
|
544
|
+
expect(movedNodes(chmodded, () => true)).toBeNull();
|
|
545
|
+
const written: NodeWitness[] = [{ path: file, stamp: nodeStamp(lstatSync(file, { bigint: true })) }];
|
|
546
|
+
await writeFile(file, 'after!');
|
|
547
|
+
expect(movedNodes(written, () => true)).toBe(file);
|
|
548
|
+
await rm(file);
|
|
549
|
+
expect(movedNodes(written)).toBe(`${file} (ENOENT)`);
|
|
550
|
+
});
|
|
551
|
+
|
|
319
552
|
it('fails loudly for unreadable required module bytes rather than publishing an installation witness', async () => {
|
|
320
553
|
const { plugin, resolver } = await packages();
|
|
321
554
|
const output = join(plugin, 'dist/index.js');
|
|
322
555
|
await chmod(output, 0);
|
|
323
556
|
try {
|
|
324
|
-
expect(() =>
|
|
557
|
+
expect(() =>
|
|
558
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null),
|
|
559
|
+
).toThrow();
|
|
325
560
|
} finally {
|
|
326
561
|
await chmod(output, 0o600);
|
|
327
562
|
}
|
|
328
563
|
});
|
|
329
564
|
it('does not invent an input contract for unknown plugins or unresolved required dependencies', async () => {
|
|
330
565
|
const { resolver } = await packages();
|
|
331
|
-
expect(graphInstallationIdentity(root, { plugins: ['opaque-plugin'] }, resolver)).toBeNull();
|
|
566
|
+
expect(graphInstallationIdentity(root, { plugins: ['opaque-plugin'] }, resolver, expandOutputs, null)).toBeNull();
|
|
332
567
|
expect(
|
|
333
|
-
graphInstallationIdentity(
|
|
334
|
-
|
|
335
|
-
|
|
568
|
+
graphInstallationIdentity(
|
|
569
|
+
root,
|
|
570
|
+
{},
|
|
571
|
+
() => {
|
|
572
|
+
throw Object.assign(new Error('missing'), { code: 'MODULE_NOT_FOUND' });
|
|
573
|
+
},
|
|
574
|
+
expandOutputs,
|
|
575
|
+
null,
|
|
576
|
+
),
|
|
336
577
|
).toBeNull();
|
|
337
578
|
});
|
|
338
579
|
|
|
339
580
|
it('refuses an unproved directory link instead of overlooking external plugin files', async () => {
|
|
340
581
|
const { plugin, dependency, resolver } = await packages();
|
|
341
|
-
await symlink(dependency, join(plugin, 'external'), 'dir');
|
|
342
|
-
expect(
|
|
582
|
+
await symlink(dependency, join(plugin, 'dist/external'), 'dir');
|
|
583
|
+
expect(
|
|
584
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null),
|
|
585
|
+
).toBeNull();
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// The classification every tool-node reader shares, over generated stat fields rather than a filesystem: no clock
|
|
590
|
+
// tick, timestamp granularity or concurrent install decides these verdicts, so they are the same on every platform.
|
|
591
|
+
describe('a stamp move is judged by the two stamps alone', () => {
|
|
592
|
+
const u64 = fc.bigInt({ min: 0n, max: 2n ** 64n - 1n });
|
|
593
|
+
const fields = fc.record({ dev: u64, ino: u64, mode: u64, size: u64, mtimeNs: u64, ctimeNs: u64 });
|
|
594
|
+
const identity = fc.constantFrom('dev', 'ino', 'mode', 'size', 'mtimeNs');
|
|
595
|
+
|
|
596
|
+
it('reads a node whose stamp is unchanged as the same node', () => {
|
|
597
|
+
fc.assert(fc.property(fields, (stats) => stampMove(nodeStamp(stats), nodeStamp(stats)) === 'same'));
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it('reads a move of the ctime alone as a ctime move, in either direction and at any distance', () => {
|
|
601
|
+
fc.assert(
|
|
602
|
+
fc.property(fields, u64, (stats, ctimeNs) => {
|
|
603
|
+
fc.pre(ctimeNs !== stats.ctimeNs);
|
|
604
|
+
return stampMove(nodeStamp(stats), nodeStamp({ ...stats, ctimeNs })) === 'ctime';
|
|
605
|
+
}),
|
|
606
|
+
);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('reads a move of device, inode, mode, size or mtime as moved, whatever the ctime did', () => {
|
|
610
|
+
fc.assert(
|
|
611
|
+
fc.property(fields, identity, u64, u64, (stats, field, value, ctimeNs) => {
|
|
612
|
+
fc.pre(value !== stats[field]);
|
|
613
|
+
return stampMove(nodeStamp(stats), nodeStamp({ ...stats, [field]: value, ctimeNs })) === 'moved';
|
|
614
|
+
}),
|
|
615
|
+
);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
// The racily clean rule: a stamp read within SAME_TICK_NS of its node's change (the later of ctime and mtime) proves
|
|
619
|
+
// nothing, and only such a stamp costs a reader a re-read.
|
|
620
|
+
it('records a stamp as read exactly when its census started a full tick after its node changed', () => {
|
|
621
|
+
fc.assert(
|
|
622
|
+
fc.property(fields, u64, (stats, start) => {
|
|
623
|
+
const proven = start - (stats.ctimeNs > stats.mtimeNs ? stats.ctimeNs : stats.mtimeNs) >= SAME_TICK_NS;
|
|
624
|
+
return proven === (recordedStamp(stats, start) === nodeStamp(stats));
|
|
625
|
+
}),
|
|
626
|
+
);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it('makes every reader re-read an unproven stamp, whatever the ctime of the node it reads', () => {
|
|
630
|
+
fc.assert(
|
|
631
|
+
fc.property(fields, u64, u64, (stats, start, ctimeNs) => {
|
|
632
|
+
fc.pre(recordedStamp(stats, start) !== nodeStamp(stats));
|
|
633
|
+
return stampMove(recordedStamp(stats, start), nodeStamp({ ...stats, ctimeNs })) === 'ctime';
|
|
634
|
+
}),
|
|
635
|
+
);
|
|
343
636
|
});
|
|
344
637
|
});
|