@smoothbricks/nx-plugin 0.5.1 → 0.5.3
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 +74 -13
- package/dist/bin/smoo-nx-test-clocks.js +2 -2
- package/dist/bin/smoo-nx-test-walks.js +6 -9
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +25 -15
- package/dist/cargo-source-hash.d.ts +2 -2
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +106 -46
- package/dist/ensure-built-witness.d.ts +33 -5
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +84 -18
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +19 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/owned-installation.d.ts +6 -5
- package/dist/owned-installation.d.ts.map +1 -1
- package/dist/owned-installation.js +324 -201
- package/dist/test-walk-policy.d.ts +8 -0
- package/dist/test-walk-policy.d.ts.map +1 -1
- package/dist/test-walk-policy.js +34 -0
- package/dist/workspace-manifest.d.ts +5 -5
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/patches/nx@23.2.1.patch +196 -48
- package/managed/raw/tooling/direnv/developer-links.ts +37 -10
- package/managed/raw/tooling/direnv/linked-snapshots.ts +31 -4
- package/managed/raw/tooling/direnv/setup-environment.ts +2 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +34 -11
- package/package.json +3 -3
- package/runtime-input.sh +21 -9
- package/src/__tests__/cargo-closure-filesets.ts +94 -0
- package/src/__tests__/owned-installation.ts +5 -6
- package/src/bin/smoo-nx-test-clocks.ts +2 -2
- package/src/bin/smoo-nx-test-walks.ts +6 -9
- package/src/cargo-closure-filesets.test.ts +63 -0
- package/src/cargo-closure-input.test.ts +1 -1
- package/src/cargo-closure-input.ts +23 -15
- package/src/cargo-closure-key.test.ts +1 -1
- package/src/cargo-resolve-cache.test.ts +1 -1
- package/src/cargo-source-hash.test.ts +143 -2
- package/src/cargo-source-hash.ts +108 -44
- package/src/cross-check-policy.test.ts +53 -12
- package/src/ensure-built-witness.test.ts +53 -2
- package/src/ensure-built-witness.ts +103 -18
- package/src/ensure-built.test.ts +40 -5
- package/src/ensure-built.ts +28 -6
- package/src/index.ts +4 -0
- package/src/linked-snapshots.nx.test.ts +1 -1
- package/src/nextest-partitions.test.ts +1 -1
- package/src/nx-daemon-start-never.test.ts +126 -0
- package/src/nx-daemon-validity.test.ts +51 -0
- package/src/nx-task-output-lease.test.ts +136 -0
- package/src/owned-installation.test.ts +105 -0
- package/src/owned-installation.ts +335 -93
- package/src/runtime-input.test.ts +22 -1
- package/src/task-results.test.ts +1 -1
- package/src/test-walk-policy.test.ts +35 -0
- package/src/test-walk-policy.ts +32 -0
- package/src/workspace-manifest.ts +5 -5
- package/test-timings.json +95 -92
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* resolved the live directory would then read bytes no key of it describes. A
|
|
9
9
|
* snapshot is copied from one provider state and never changes: a provider
|
|
10
10
|
* change reaches the consumer only as another snapshot under another name.
|
|
11
|
+
* An explicit snapshot ID resolves only from the consumer's existing store;
|
|
12
|
+
* provider HEAD changes are informational and never select another snapshot.
|
|
13
|
+
* Only a capture declaration opts into the provider's current state.
|
|
11
14
|
*
|
|
12
15
|
* What a snapshot holds, laid out as in the provider checkout so relative
|
|
13
16
|
* resolution means what it meant there (exports, tsconfig `paths`, and the
|
|
@@ -140,6 +143,8 @@ export interface SealedSnapshot {
|
|
|
140
143
|
readonly kind: 'snapshot';
|
|
141
144
|
readonly id: string;
|
|
142
145
|
readonly directory: string;
|
|
146
|
+
/** Informational pin freshness only; never a request to recapture or refuse a verified pin. */
|
|
147
|
+
readonly report?: string;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
export type SnapshotBinding = SealedSnapshot | { readonly kind: 'refused'; readonly reason: string };
|
|
@@ -174,18 +179,18 @@ type ProducerRecord = Extract<EnsureBuiltProbeResult, { readonly disposition: 'h
|
|
|
174
179
|
const PRODUCER_VERSION = 1;
|
|
175
180
|
|
|
176
181
|
/**
|
|
177
|
-
*
|
|
178
|
-
* the
|
|
179
|
-
* refusal names its cause and leaves every binding as it was.
|
|
182
|
+
* A snapshot ID resolves only from the consumer's store. A capture declaration instead probes, copies and attests
|
|
183
|
+
* the provider's current state. A refusal names its cause and leaves every binding as it was.
|
|
180
184
|
*/
|
|
181
185
|
export async function snapshotBinding(
|
|
182
186
|
root: string,
|
|
183
187
|
name: string,
|
|
184
188
|
source: string,
|
|
185
|
-
declaration: SnapshotDeclaration,
|
|
189
|
+
declaration: SnapshotDeclaration | string,
|
|
186
190
|
probe: ProducerProbe,
|
|
187
191
|
): Promise<SnapshotBinding> {
|
|
188
192
|
try {
|
|
193
|
+
if (typeof declaration === 'string') return pinnedSnapshot(root, name, source, declaration);
|
|
189
194
|
const store = snapshotStore(root);
|
|
190
195
|
const plan = planSnapshot(source, name, declaration, bunCacheRoot(root));
|
|
191
196
|
const id = await capture(store, plan, declaration, probe, fingerprintOf(plan));
|
|
@@ -199,6 +204,28 @@ export async function snapshotBinding(
|
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
|
|
207
|
+
/** Resolve an explicit content pin, never reading provider bytes or asking its producer to run. */
|
|
208
|
+
export function pinnedSnapshot(root: string, name: string, source: string, id: string): SealedSnapshot {
|
|
209
|
+
if (!/^[0-9a-f]{64}$/.test(id)) throw new SnapshotRefusal(`snapshot pin ${id} must be 64 lowercase hex digits`);
|
|
210
|
+
const sealed = path.resolve(root, SNAPSHOT_STORE, id);
|
|
211
|
+
const receipt = verifySnapshot(sealed);
|
|
212
|
+
if (receipt.name !== name) throw new SnapshotRefusal(`snapshot ${id} contains ${receipt.name}, not ${name}`);
|
|
213
|
+
if (!contained(receipt.packagePath))
|
|
214
|
+
throw new SnapshotRefusal(`snapshot ${id} has an invalid package path ${receipt.packagePath}`);
|
|
215
|
+
const directory = path.join(sealed, receipt.packagePath);
|
|
216
|
+
const head = spawnSync('git', ['-C', source, 'rev-parse', '--verify', 'HEAD'], {
|
|
217
|
+
encoding: 'utf8',
|
|
218
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' },
|
|
219
|
+
});
|
|
220
|
+
const report =
|
|
221
|
+
head.error !== undefined || head.status !== 0
|
|
222
|
+
? `cannot inspect ${source} HEAD for snapshot pin ${id}: ${head.error?.message ?? head.stderr.trim()}; continuing with the pin`
|
|
223
|
+
: head.stdout.trim() !== receipt.provenance.head
|
|
224
|
+
? `stale pin ${id}: captured HEAD ${receipt.provenance.head} differs from ${source} HEAD ${head.stdout.trim()}; continuing with the pin; move snapshot explicitly to select another build`
|
|
225
|
+
: undefined;
|
|
226
|
+
return { kind: 'snapshot', id, directory, ...(report === undefined ? {} : { report }) };
|
|
227
|
+
}
|
|
228
|
+
|
|
202
229
|
/**
|
|
203
230
|
* The store under `root`. A cowshed checkout keeps it on its build volume: until a refresh has linked it there,
|
|
204
231
|
* an empty directory is left for that refresh to adopt and the capture refuses.
|
|
@@ -249,6 +249,8 @@ try {
|
|
|
249
249
|
// A refused or unclaimed snapshot is current only when said: the exec that follows names its cause.
|
|
250
250
|
const current =
|
|
251
251
|
plan.changes.length === 0 && plan.unavailable.every((unavailable) => unavailable.kind === 'absent');
|
|
252
|
+
// A stale pin is informational, not a stale install: say it even when devenv skips the exec.
|
|
253
|
+
if (current && plan.reports.length > 0) applyDeclaredLinks(projectRoot, plan);
|
|
252
254
|
process.exit(
|
|
253
255
|
current && !hasStaleDeveloperLinks(projectRoot, ['nx']) && danglingStoreLinks(projectRoot).length === 0 ? 0 : 1,
|
|
254
256
|
);
|
|
@@ -14,15 +14,25 @@
|
|
|
14
14
|
# present. From a plain shell the cross target itself never compiles here: on
|
|
15
15
|
# a miss its guard refuses. Its dependencies are ordinary Nx tasks whose outputs
|
|
16
16
|
# the cross key reads, so Nx restores them from the cache or, for a tree no gate
|
|
17
|
-
# ran, builds them. A refusal names the one command that fixes it; any other
|
|
17
|
+
# ran, builds them. A refusal names the one command that fixes it; any other
|
|
18
18
|
# failure is said as that, never as a cache miss.
|
|
19
19
|
#
|
|
20
|
+
# Nx runs in this checkout's environment, `direnv exec <checkout>`, which is the
|
|
21
|
+
# environment the land gate runs in, never in the environment of whatever shell
|
|
22
|
+
# ran `git push`. devenv declares this checkout's tooling and the environment it
|
|
23
|
+
# builds with (the macOS SDK it links against among it), and tasks key on that
|
|
24
|
+
# environment as well as on the tree: a push from a shell carrying another
|
|
25
|
+
# directory's devenv keyed the gate's tasks on that shell's SDKROOT and
|
|
26
|
+
# DEVELOPER_DIR, missed every one of them, and then built them against the wrong
|
|
27
|
+
# SDK. Under the checkout's environment the keys are the gate's, and a dependency
|
|
28
|
+
# that does miss builds the way the gate builds it.
|
|
29
|
+
#
|
|
20
30
|
# Why the cross target never compiles here. The cross-clippy needs zig and
|
|
21
31
|
# cargo-zigbuild, which a macOS host carries only in the linux-cross devenv
|
|
22
|
-
# profile
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
32
|
+
# profile, not in the default shell `direnv exec` enters. A hook that entered
|
|
33
|
+
# that profile spent minutes compiling on a push the user expected to take a
|
|
34
|
+
# second. Pushing is not the place to discover that the tree has not been
|
|
35
|
+
# compiled for Linux: the land gate, or `bun run check:linux`, is.
|
|
26
36
|
#
|
|
27
37
|
# The target's own guard refuses to start when cargo-zigbuild is not on PATH,
|
|
28
38
|
# which is what turns a miss into a refusal here. A push made from a shell that
|
|
@@ -30,8 +40,9 @@
|
|
|
30
40
|
# guard, so there a miss runs the check itself: the same clippy `check:linux`
|
|
31
41
|
# runs, in the toolchain the user entered for it.
|
|
32
42
|
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
43
|
+
# The denylist gate needs only tooling/direnv/repo-path's PATH; the cross gate
|
|
44
|
+
# needs direnv on the caller's PATH, and the checkout's own devenv through it,
|
|
45
|
+
# not a devenv the caller entered. It must never pretend a check ran that did not.
|
|
35
46
|
|
|
36
47
|
cd "$(git rev-parse --show-toplevel)"
|
|
37
48
|
TOOLING="$PWD/tooling"
|
|
@@ -66,13 +77,24 @@ case "$(uname -s)" in
|
|
|
66
77
|
*) exit 0 ;;
|
|
67
78
|
esac
|
|
68
79
|
|
|
80
|
+
# The refusal uses shell builtins alone: without direnv nothing proves the
|
|
81
|
+
# caller's PATH carries coreutils, and a Nix-built host's /usr/bin and /bin
|
|
82
|
+
# hold none of them.
|
|
83
|
+
if ! command -v direnv >/dev/null; then
|
|
84
|
+
printf '%s\n' \
|
|
85
|
+
'pre-push: direnv is not on PATH, so the Linux cross-compile check cannot run in' \
|
|
86
|
+
"this checkout's environment, and a check run in any other environment keys on" \
|
|
87
|
+
'values the land gate never used. Put direnv on PATH, then push again.' >&2
|
|
88
|
+
exit 1
|
|
89
|
+
fi
|
|
90
|
+
|
|
69
91
|
# The guard's refusal (nx-plugin cross-check-policy.ts CARGO_CROSS_LINT_REFUSAL)
|
|
70
92
|
# is the one line that means the key missed. Nx exits 1 for every task failure,
|
|
71
93
|
# so the hook reads the output for it rather than guessing from the status.
|
|
72
94
|
output=$(mktemp "${TMPDIR:-/tmp}/pre-push-cross.XXXXXX") || exit 1
|
|
73
95
|
trap 'rm -f "$output"' EXIT
|
|
74
96
|
set -o pipefail
|
|
75
|
-
nx run-many -t cargo-lint-cross --output-style=static 2>&1 | tee "$output"
|
|
97
|
+
direnv exec "$PWD" nx run-many -t cargo-lint-cross --output-style=static 2>&1 | tee "$output"
|
|
76
98
|
status=$?
|
|
77
99
|
[ "$status" -eq 0 ] && exit 0
|
|
78
100
|
|
|
@@ -90,9 +112,10 @@ EOF
|
|
|
90
112
|
else
|
|
91
113
|
cat >&2 <<EOF
|
|
92
114
|
|
|
93
|
-
pre-push:
|
|
94
|
-
a cache verdict
|
|
95
|
-
bun run check:linux will
|
|
115
|
+
pre-push: the Linux cross-compile check failed (exit $status) before it reached
|
|
116
|
+
a cache verdict, in Nx or in direnv entering this checkout's environment; the
|
|
117
|
+
output above names why. This is not a cache miss, and bun run check:linux will
|
|
118
|
+
not fix it.
|
|
96
119
|
EOF
|
|
97
120
|
fi
|
|
98
121
|
exit 1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -312,8 +312,8 @@
|
|
|
312
312
|
"yaml": "^2.9.0"
|
|
313
313
|
},
|
|
314
314
|
"devDependencies": {
|
|
315
|
-
"@smoothbricks/lmao": "0.5.
|
|
316
|
-
"@smoothbricks/validation": "0.1.
|
|
315
|
+
"@smoothbricks/lmao": "0.5.6",
|
|
316
|
+
"@smoothbricks/validation": "0.1.12",
|
|
317
317
|
"fast-check": "^4.4.0"
|
|
318
318
|
}
|
|
319
319
|
}
|
package/runtime-input.sh
CHANGED
|
@@ -20,10 +20,17 @@
|
|
|
20
20
|
# exit status, the byte is redundant and can go.
|
|
21
21
|
#
|
|
22
22
|
# Nx drops runtime stderr, so it is not a reliable diagnostic channel. Failures
|
|
23
|
-
# retain private argv, byte-exact stderr, status and a readable
|
|
24
|
-
# $PWD/.runtime-input-failures/, outside Nx and temporary state.
|
|
25
|
-
# `cat .runtime-input-failures/*/report` after a decoder error.
|
|
26
|
-
# controlling /dev/tty also name the failure where those channels
|
|
23
|
+
# retain private argv, byte-exact stdout and stderr, status and a readable
|
|
24
|
+
# report below $PWD/.runtime-input-failures/, outside Nx and temporary state.
|
|
25
|
+
# Read them with `cat .runtime-input-failures/*/report` after a decoder error.
|
|
26
|
+
# Stderr and a controlling /dev/tty also name the failure where those channels
|
|
27
|
+
# are visible.
|
|
28
|
+
#
|
|
29
|
+
# A failed command's own stdout never reaches the hasher either: it is
|
|
30
|
+
# captured to a file from the start, retained in the failure record, and the
|
|
31
|
+
# only byte this script emits on failure is the 0xFF poison above. Nothing
|
|
32
|
+
# from a failure path flows into the hash as input bytes. Successful stdout
|
|
33
|
+
# is replayed from the capture file byte-exact.
|
|
27
34
|
#
|
|
28
35
|
# The command's stderr is not part of the value; it surfaces only on failure.
|
|
29
36
|
# Diagnostics name temp paths, process ids and the boundary the input ran in
|
|
@@ -35,15 +42,17 @@ if [ "$#" -eq 0 ]; then
|
|
|
35
42
|
printf '\377'
|
|
36
43
|
exit 64
|
|
37
44
|
fi
|
|
38
|
-
if diagnostic=$(mktemp "${TMPDIR:-/tmp}/nx-runtime-input.XXXXXXXXXX")
|
|
45
|
+
if diagnostic=$(mktemp "${TMPDIR:-/tmp}/nx-runtime-input-stderr.XXXXXXXXXX") &&
|
|
46
|
+
captured=$(mktemp "${TMPDIR:-/tmp}/nx-runtime-input-stdout.XXXXXXXXXX"); then
|
|
39
47
|
:
|
|
40
48
|
else
|
|
41
|
-
printf 'runtime input could not capture
|
|
49
|
+
printf 'runtime input could not capture streams: %s\n' "$*" >&2
|
|
42
50
|
printf '\377'
|
|
43
51
|
exit 73
|
|
44
52
|
fi
|
|
45
|
-
if "$@" 2>"$diagnostic"; then
|
|
46
|
-
|
|
53
|
+
if "$@" >"$captured" 2>"$diagnostic"; then
|
|
54
|
+
cat "$captured"
|
|
55
|
+
rm -f "$diagnostic" "$captured"
|
|
47
56
|
exit 0
|
|
48
57
|
else
|
|
49
58
|
status=$?
|
|
@@ -53,7 +62,8 @@ if record=$(umask 077; mkdir -p "$PWD/.runtime-input-failures" &&
|
|
|
53
62
|
mktemp -d "$PWD/.runtime-input-failures/failure.XXXXXXXXXX"); then
|
|
54
63
|
if printf '%s\000' "$@" >"$record/argv" &&
|
|
55
64
|
printf '%s\n' "$status" >"$record/exit-status" &&
|
|
56
|
-
mv "$diagnostic" "$record/stderr" &&
|
|
65
|
+
mv "$diagnostic" "$record/stderr" &&
|
|
66
|
+
mv "$captured" "$record/stdout" && {
|
|
57
67
|
printf 'runtime input exited %s: %s\n' "$status" "$*"
|
|
58
68
|
printf 'working directory: %s\n' "$PWD"
|
|
59
69
|
index=0
|
|
@@ -64,6 +74,8 @@ if record=$(umask 077; mkdir -p "$PWD/.runtime-input-failures" &&
|
|
|
64
74
|
done
|
|
65
75
|
printf 'original stderr:\n'
|
|
66
76
|
cat "$record/stderr"
|
|
77
|
+
printf 'original stdout (never hashed):\n'
|
|
78
|
+
cat "$record/stdout"
|
|
67
79
|
} >"$record/report"; then
|
|
68
80
|
printf '\nruntime input exited %s: %s; evidence: %s/report\n' "$status" "$*" "$record" >&2
|
|
69
81
|
# A detached daemon may have no terminal. Preserve that error too, rather
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { join, posix } from 'node:path';
|
|
2
|
+
import type { CargoClosureSource } from '../cargo-closure-input.js';
|
|
3
|
+
import { CARGO_ANCESTOR_INPUTS, HASH_SKIPPED_DIRECTORIES } from '../cargo-source-hash.js';
|
|
4
|
+
|
|
5
|
+
/** Resolved metadata with the per-graph source scans already cached, as on later project visits. */
|
|
6
|
+
export function filesetSource(
|
|
7
|
+
root: string,
|
|
8
|
+
directories: readonly string[],
|
|
9
|
+
files: readonly string[],
|
|
10
|
+
): CargoClosureSource {
|
|
11
|
+
const local = directories.map((directory, index) => ({
|
|
12
|
+
id: String(index),
|
|
13
|
+
name: `package-${index}`,
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
directory: join(root, directory),
|
|
16
|
+
manifest: join(root, directory, 'Cargo.toml'),
|
|
17
|
+
sources: [join(root, directory, 'src/lib.rs'), ...files.map((file) => join(root, file))],
|
|
18
|
+
governingManifest: join(root, 'Cargo.toml'),
|
|
19
|
+
}));
|
|
20
|
+
return {
|
|
21
|
+
manifest: 'Cargo.toml',
|
|
22
|
+
workspaceRoot: root,
|
|
23
|
+
root,
|
|
24
|
+
cargo: {
|
|
25
|
+
root,
|
|
26
|
+
members: new Set(local.map(({ id }) => id)),
|
|
27
|
+
local,
|
|
28
|
+
edges: new Map(local.map(({ id }) => [id, []])),
|
|
29
|
+
},
|
|
30
|
+
indexed: new Set(directories.map((directory) => posix.join(directory, 'Cargo.toml'))),
|
|
31
|
+
compiledFilesCache: new Map(local.map(({ directory }) => [directory, []])),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ExpansionCopies {
|
|
36
|
+
directoryEntries: number;
|
|
37
|
+
siblingNames: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The pre-cutover fileset reduction, retained only as a differential oracle. */
|
|
41
|
+
export function expandedFilesets(
|
|
42
|
+
packageDirectories: readonly string[],
|
|
43
|
+
files: readonly string[],
|
|
44
|
+
copies?: ExpansionCopies,
|
|
45
|
+
): string[] {
|
|
46
|
+
const parent = (path: string): string | null => {
|
|
47
|
+
if (path === '') return null;
|
|
48
|
+
const directory = posix.dirname(path);
|
|
49
|
+
return directory === '.' ? '' : directory;
|
|
50
|
+
};
|
|
51
|
+
const contains = (directory: string, path: string) =>
|
|
52
|
+
directory === '' || path === directory || path.startsWith(`${directory}/`);
|
|
53
|
+
const directories = [...new Set(packageDirectories)].sort().filter((directory, index, sorted) => {
|
|
54
|
+
if (copies !== undefined) copies.directoryEntries += index;
|
|
55
|
+
return !sorted.slice(0, index).some((outer) => contains(outer, directory));
|
|
56
|
+
});
|
|
57
|
+
const ancestors = new Set<string>();
|
|
58
|
+
for (const directory of directories) {
|
|
59
|
+
for (let ancestor = parent(directory); ancestor !== null; ancestor = parent(ancestor)) {
|
|
60
|
+
const candidate = ancestor;
|
|
61
|
+
if (!directories.some((outer) => contains(outer, candidate))) ancestors.add(candidate);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const loose = new Set(
|
|
65
|
+
files.filter(
|
|
66
|
+
(file) =>
|
|
67
|
+
!directories.some((directory) => contains(directory, file)) &&
|
|
68
|
+
!(posix.basename(file) === 'Cargo.toml' && ancestors.has(parent(file) ?? '')),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
const siblings = new Map<string, string[]>();
|
|
72
|
+
for (const directory of directories) {
|
|
73
|
+
const key = parent(directory);
|
|
74
|
+
if (key === null) continue;
|
|
75
|
+
if (copies !== undefined) copies.siblingNames += siblings.get(key)?.length ?? 0;
|
|
76
|
+
siblings.set(key, [...(siblings.get(key) ?? []), posix.basename(directory)]);
|
|
77
|
+
}
|
|
78
|
+
const packageGlobs = directories.includes('')
|
|
79
|
+
? ['']
|
|
80
|
+
: [...siblings].map(([under, names]) =>
|
|
81
|
+
posix.join(under, names.length === 1 ? names.join('') : `{${names.join(',')}}`),
|
|
82
|
+
);
|
|
83
|
+
const anchored = (path: string, pattern = '') => posix.join('{workspaceRoot}', path, pattern);
|
|
84
|
+
// cargoClosureInputs removes duplicate inputs, including a loose lockfile.
|
|
85
|
+
return [
|
|
86
|
+
...new Set([
|
|
87
|
+
'{workspaceRoot}/Cargo.lock',
|
|
88
|
+
...packageGlobs.map((glob) => anchored(glob, '**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}')),
|
|
89
|
+
...packageGlobs.map((glob) => `!${anchored(glob, `**/{${HASH_SKIPPED_DIRECTORIES.join(',')}}/**`)}`),
|
|
90
|
+
...[...ancestors].sort().map((ancestor) => anchored(ancestor, `{${CARGO_ANCESTOR_INPUTS.join(',')}}`)),
|
|
91
|
+
...[...loose].sort().map((file) => anchored(file)),
|
|
92
|
+
]),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
/** This repository's fixtures own a copy of its Nx installation (`../owned-installation.ts`) in
|
|
1
|
+
/** This repository's fixtures own a copy of its Nx installation (`../owned-installation.ts`), kept in its tool cache. */
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { ownedInstallation, type TestFileInstallation } from '../owned-installation.js';
|
|
4
|
-
import { nxFixtureRoot } from './fixture-nx-env.js';
|
|
5
4
|
|
|
6
5
|
const repositoryRoot = join(import.meta.dir, '../../../..');
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
* The installation one test file owns,
|
|
10
|
-
* Bun runs many test files in one process, and each must own its copy.
|
|
8
|
+
* The installation one test file owns, kept as `name`. Call once per file, at module scope, with a name no other file
|
|
9
|
+
* uses: Bun runs many test files in one process, and each must own its copy.
|
|
11
10
|
*/
|
|
12
|
-
export function testFileInstallation(
|
|
13
|
-
return ownedInstallation(repositoryRoot,
|
|
11
|
+
export function testFileInstallation(name: string): TestFileInstallation {
|
|
12
|
+
return ownedInstallation(repositoryRoot, name);
|
|
14
13
|
}
|
|
@@ -3,8 +3,8 @@ import { findClockOracles, formatClockOracle, TEST_CLOCK_ORACLE } from '../test-
|
|
|
3
3
|
import { diffScope, upstreamBase } from '../test-walk-policy.js';
|
|
4
4
|
|
|
5
5
|
// TEST-CLOCK-ORACLE over the current directory's repository, judged on the cases changed since the upstream merge base
|
|
6
|
-
// (`upstreamBase`,
|
|
7
|
-
//
|
|
6
|
+
// (`upstreamBase`, resolved as a run precondition before Nx hashes anything). Every finding prints `error[…]` and
|
|
7
|
+
// exits 1. Exit 2 when git cannot answer.
|
|
8
8
|
if (process.argv.length > 2) {
|
|
9
9
|
process.stderr.write('usage: smoo-nx-test-clocks\n');
|
|
10
10
|
process.exit(2);
|
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
} from '../test-walk-policy.js';
|
|
10
10
|
|
|
11
11
|
// TEST-ONE-WALK over the current directory's repository, judged on the cases changed since the upstream merge base
|
|
12
|
-
// (`upstreamBase`).
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// (`upstreamBase`). The base is repository state, not task data: the plugin resolves it as a run precondition
|
|
13
|
+
// before Nx hashes anything (assertUpstreamBasePrecondition), so it is never carried by a runtime input.
|
|
14
|
+
// Refusing kinds print `error[…]` and exit 1; advisory kinds print `warning[…]` for the writer and reviewer and
|
|
15
|
+
// leave the exit at 0. Exit 2 when git cannot answer.
|
|
15
16
|
const args = process.argv.slice(2);
|
|
16
|
-
if (args.length >
|
|
17
|
-
process.stderr.write('usage: smoo-nx-test-walks
|
|
17
|
+
if (args.length > 0) {
|
|
18
|
+
process.stderr.write('usage: smoo-nx-test-walks\n');
|
|
18
19
|
process.exit(2);
|
|
19
20
|
}
|
|
20
21
|
const root = process.cwd();
|
|
@@ -23,10 +24,6 @@ if (!base.ok) {
|
|
|
23
24
|
process.stderr.write(`${TEST_ONE_WALK.id} cannot find the upstream base: ${base.reason}\n`);
|
|
24
25
|
process.exit(2);
|
|
25
26
|
}
|
|
26
|
-
if (args[0] === '--base') {
|
|
27
|
-
process.stdout.write(`${base.value}\n`);
|
|
28
|
-
process.exit(0);
|
|
29
|
-
}
|
|
30
27
|
const scope = diffScope(root, base.value);
|
|
31
28
|
if (!scope.ok) {
|
|
32
29
|
process.stderr.write(`${TEST_ONE_WALK.id} cannot read the changes since ${base.value}: ${scope.reason}\n`);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { posix } from 'node:path';
|
|
4
|
+
import { expandedFilesets, filesetSource } from './__tests__/cargo-closure-filesets.js';
|
|
5
|
+
import { cargoClosureInputs } from './cargo-closure-input.js';
|
|
6
|
+
|
|
7
|
+
const root = await realpath(import.meta.dir);
|
|
8
|
+
|
|
9
|
+
async function equivalent(directories: readonly string[], files: readonly string[]): Promise<void> {
|
|
10
|
+
const expected = expandedFilesets(directories, [
|
|
11
|
+
'Cargo.toml',
|
|
12
|
+
...directories.map((directory) => posix.join(directory, 'src/lib.rs')),
|
|
13
|
+
...files,
|
|
14
|
+
]);
|
|
15
|
+
expect(await cargoClosureInputs('', [filesetSource(root, directories, files)])).toEqual(expected);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
it('preserves ordered inputs for roots, nested packages, prefix siblings, and loose targets', async () => {
|
|
19
|
+
for (const directories of [
|
|
20
|
+
[''],
|
|
21
|
+
['', 'crates/a', 'crates/a/nested'],
|
|
22
|
+
['crates/a', 'crates/a-', 'crates/a/nested', 'crates/a./child', 'crates/a0', 'crates/ab'],
|
|
23
|
+
['crates/z/deep/member', 'crates/a/member', 'crates/z/other', 'crates/a/member'],
|
|
24
|
+
['a/b', 'a/b/c', 'a/b/c/d', 'a/b-', 'a/b-/d', 'a/b0'],
|
|
25
|
+
['é/a', 'é/a-b', 'é/a/b', 'a b/c', 'a b/c/d'],
|
|
26
|
+
]) {
|
|
27
|
+
await equivalent(directories, [
|
|
28
|
+
'Cargo.toml',
|
|
29
|
+
'Cargo.lock',
|
|
30
|
+
'shared.rs',
|
|
31
|
+
'crates/Cargo.toml',
|
|
32
|
+
'crates/a/src/lib.rs',
|
|
33
|
+
'crates/a-/outside.rs',
|
|
34
|
+
'crates/a0/src/lib.rs',
|
|
35
|
+
'crates/a/loose.rs',
|
|
36
|
+
'elsewhere/Cargo.toml',
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('matches the expansion oracle over generated directory trees and repeated source ownership', async () => {
|
|
42
|
+
let state = 0x9e3779b9;
|
|
43
|
+
const next = (bound: number): number => {
|
|
44
|
+
state ^= state << 13;
|
|
45
|
+
state ^= state >>> 17;
|
|
46
|
+
state ^= state << 5;
|
|
47
|
+
return (state >>> 0) % bound;
|
|
48
|
+
};
|
|
49
|
+
const names = ['a', 'a-', 'a.', 'a0', 'b', 'z'];
|
|
50
|
+
for (let trial = 0; trial < 256; trial += 1) {
|
|
51
|
+
const path = (): string => Array.from({ length: next(4) }, () => names[next(names.length)]).join('/');
|
|
52
|
+
const directories = Array.from({ length: 1 + next(32) }, path);
|
|
53
|
+
const files = Array.from({ length: 1 + next(8) }, () =>
|
|
54
|
+
posix.join(path(), next(2) === 0 ? 'Cargo.toml' : 'target.rs'),
|
|
55
|
+
);
|
|
56
|
+
await equivalent(directories, files);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('reduces a large sibling closure to the same few ordered filesets', async () => {
|
|
61
|
+
const directories = Array.from({ length: 1024 }, (_, index) => `crates/package-${index}`);
|
|
62
|
+
await equivalent(directories, ['shared.rs']);
|
|
63
|
+
});
|
|
@@ -31,7 +31,7 @@ const repositoryRoot = join(import.meta.dir, '../../..');
|
|
|
31
31
|
useFixtureCargoHome();
|
|
32
32
|
|
|
33
33
|
/** The Nx installation this file's fixtures share; none may write into it. */
|
|
34
|
-
const installation = testFileInstallation('cargo-closure-installation
|
|
34
|
+
const installation = testFileInstallation('cargo-closure-installation');
|
|
35
35
|
afterAll(() => installation.retire());
|
|
36
36
|
|
|
37
37
|
it('keys a custom target on exactly its Cargo closure, inside the workspace and out', async () => {
|
|
@@ -150,8 +150,8 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
150
150
|
const closureArguments = `--closure ${shellWord(projectRoot)} ${shellWord(source.manifest)}`;
|
|
151
151
|
|
|
152
152
|
const { root, cargo, indexed } = source;
|
|
153
|
-
const packageDirectories
|
|
154
|
-
const files
|
|
153
|
+
const packageDirectories = new Set<string>();
|
|
154
|
+
const files = new Set<string>();
|
|
155
155
|
const compiledIn: CompiledInclusion[] = [];
|
|
156
156
|
let compiledFiles: readonly string[] = [];
|
|
157
157
|
let external = false;
|
|
@@ -175,11 +175,11 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
175
175
|
if (declaring === null) throw new Error(`${compiled.source} was scanned outside ${directory}`);
|
|
176
176
|
compiledIn.push({ declaring, file });
|
|
177
177
|
}
|
|
178
|
-
packageDirectories.
|
|
178
|
+
packageDirectories.add(directory);
|
|
179
179
|
for (const file of [...pkg.sources, pkg.governingManifest]) {
|
|
180
180
|
const path = indexablePath(root, file);
|
|
181
181
|
if (path === null) throw new Error(`${directory} compiles ${file}, which Nx's file index cannot hold`);
|
|
182
|
-
files.
|
|
182
|
+
files.add(path);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
const compiledPaths = [...new Set(compiledIn.flatMap(({ declaring, file }) => [declaring, file]))];
|
|
@@ -192,23 +192,25 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
192
192
|
throw new CargoClosureInputError(projectRoot, error);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
//
|
|
196
|
-
|
|
195
|
+
// Query the directory set by path ancestors, not by expanding all pairs.
|
|
196
|
+
// Removing nested members leaves an antichain with the same covered files.
|
|
197
|
+
const directories = [...packageDirectories]
|
|
197
198
|
.sort()
|
|
198
|
-
.filter((directory
|
|
199
|
+
.filter((directory) => !covered(packageDirectories, parent(directory)));
|
|
199
200
|
const ancestors = new Set<string>();
|
|
200
201
|
for (const directory of directories) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
// An ancestor of an outermost member cannot be inside another member.
|
|
203
|
+
// Once this walk joins an earlier walk, all remaining ancestors are held.
|
|
204
|
+
for (let ancestor = parent(directory); ancestor !== null && !ancestors.has(ancestor); ancestor = parent(ancestor)) {
|
|
205
|
+
ancestors.add(ancestor);
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
// Target sources outside every package directory, and governing manifests
|
|
207
209
|
// that are not already one of the ancestors' manifests.
|
|
208
210
|
const loose = new Set(
|
|
209
|
-
files.filter(
|
|
211
|
+
[...files].filter(
|
|
210
212
|
(file) =>
|
|
211
|
-
!
|
|
213
|
+
!covered(packageDirectories, file) &&
|
|
212
214
|
!(posix.basename(file) === 'Cargo.toml' && ancestors.has(parent(file) ?? '')),
|
|
213
215
|
),
|
|
214
216
|
);
|
|
@@ -218,7 +220,9 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
218
220
|
for (const directory of directories) {
|
|
219
221
|
const key = parent(directory);
|
|
220
222
|
if (key === null) continue;
|
|
221
|
-
|
|
223
|
+
const names = siblings.get(key);
|
|
224
|
+
if (names === undefined) siblings.set(key, [posix.basename(directory)]);
|
|
225
|
+
else names.push(posix.basename(directory));
|
|
222
226
|
}
|
|
223
227
|
const packageGlobs = directories.includes('')
|
|
224
228
|
? ['']
|
|
@@ -275,6 +279,10 @@ function parent(path: string): string | null {
|
|
|
275
279
|
return directory === '.' ? '' : directory;
|
|
276
280
|
}
|
|
277
281
|
|
|
278
|
-
|
|
279
|
-
|
|
282
|
+
/** Membership in the union of package subtrees, bounded by path depth rather than package count. */
|
|
283
|
+
function covered(directories: ReadonlySet<string>, path: string | null): boolean {
|
|
284
|
+
for (let candidate = path; candidate !== null; candidate = parent(candidate)) {
|
|
285
|
+
if (directories.has(candidate)) return true;
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
280
288
|
}
|
|
@@ -30,7 +30,7 @@ import { isRecord } from './type-guards.js';
|
|
|
30
30
|
useFixtureCargoHome();
|
|
31
31
|
|
|
32
32
|
/** The Nx installation this file's fixtures share; none may write into it. */
|
|
33
|
-
const installation = testFileInstallation('cargo-closure-key-installation
|
|
33
|
+
const installation = testFileInstallation('cargo-closure-key-installation');
|
|
34
34
|
afterAll(() => installation.retire());
|
|
35
35
|
|
|
36
36
|
/** The ignored directory the producer owns, inside `leaf`, which every closure of `app` reaches. */
|
|
@@ -48,7 +48,7 @@ import { createNodesV2 } from './index.js';
|
|
|
48
48
|
useFixtureCargoHome();
|
|
49
49
|
|
|
50
50
|
/** The Nx installation this file's graph fixtures share; none may write into it. */
|
|
51
|
-
const installation = testFileInstallation('cargo-resolve-installation
|
|
51
|
+
const installation = testFileInstallation('cargo-resolve-installation');
|
|
52
52
|
afterAll(() => installation.retire());
|
|
53
53
|
|
|
54
54
|
/*
|