@smoothbricks/nx-plugin 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -46
- 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/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 +33 -14
- package/dist/executors/bounded-exec/cpu-pool.d.ts +14 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +297 -38
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +19 -7
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-tokens.js +21 -7
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +12 -6
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +5 -4
- 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/producer-receipts.d.ts +10 -0
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +30 -5
- 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 +14 -3
- package/managed/raw/tooling/direnv/developer-links.ts +37 -10
- package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -3
- package/managed/raw/tooling/direnv/linked-snapshots.ts +49 -12
- package/managed/raw/tooling/direnv/repo-path +1 -1
- 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__/counted-cargo.ts +1 -1
- 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 +2 -2
- 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/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 +79 -5
- package/src/ensure-built.ts +51 -15
- package/src/executors/bounded-exec/cpu-pool.test.ts +132 -4
- package/src/executors/bounded-exec/cpu-pool.ts +300 -46
- package/src/executors/bounded-exec/cpu-tokens.test.ts +60 -15
- package/src/executors/bounded-exec/cpu-tokens.ts +34 -11
- package/src/executors/bounded-exec/executor.test.ts +72 -4
- package/src/executors/bounded-exec/executor.ts +12 -6
- package/src/executors/bounded-exec/run-cpu-pool.test.ts +3 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
- 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-validity.test.ts +51 -0
- package/src/owned-installation.test.ts +105 -0
- package/src/owned-installation.ts +335 -93
- package/src/producer-receipts.test.ts +37 -15
- package/src/producer-receipts.ts +29 -5
- 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 +94 -92
|
@@ -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.2",
|
|
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
|
+
}
|
|
@@ -558,7 +558,7 @@ async function shim(
|
|
|
558
558
|
join(bin, 'cargo'),
|
|
559
559
|
[
|
|
560
560
|
'#!/bin/sh',
|
|
561
|
-
// Delegate with the caller's original search path:
|
|
561
|
+
// Delegate with the caller's original search path: nothing the real Cargo starts may resolve this shim again.
|
|
562
562
|
`export PATH=${quote(path)}`,
|
|
563
563
|
`real=${quote(real)}`,
|
|
564
564
|
`if [ "$1" != metadata ]; then ${forward}; fi`,
|
|
@@ -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 () => {
|
|
@@ -254,7 +254,7 @@ function leafControls(workspace: string, edit: (path: string, text: string) => P
|
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
it(
|
|
257
|
+
it("delegates counted Cargo to the caller's own cargo without re-entering its broker", async () => {
|
|
258
258
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-counted-delegate-')));
|
|
259
259
|
let fixtureCargo: CountedCargo | undefined;
|
|
260
260
|
try {
|
|
@@ -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
|
/*
|
|
@@ -220,13 +220,23 @@ describe('Linux cross-check policy', () => {
|
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
222
|
* The managed pre-push hook, run for real in a fixture repository whose `tooling/direnv/repo-path` puts stand-ins
|
|
223
|
-
* first on PATH: `uname` says Darwin, `smoo` passes the denylist,
|
|
224
|
-
*
|
|
223
|
+
* first on PATH: `uname` says Darwin, `smoo` passes the denylist, `direnv` enters the checkout's environment, and `nx`
|
|
224
|
+
* prints what a cross run printed and exits with its status, refusing to run in any environment but the checkout's.
|
|
225
|
+
* The hook must ask in the checkout's environment and call a miss a miss and every other failure what it is.
|
|
225
226
|
*/
|
|
226
227
|
describe('managed pre-push cross probe', () => {
|
|
227
228
|
const hook = join(import.meta.dir, '../managed/raw/tooling/git-hooks/pre-push.sh');
|
|
229
|
+
/** The SDK the checkout's environment names; the caller's shell names another. */
|
|
230
|
+
const CHECKOUT_SDK = '/checkout/MacOSX.sdk';
|
|
228
231
|
|
|
229
|
-
|
|
232
|
+
interface Push {
|
|
233
|
+
readonly nxOutput: string;
|
|
234
|
+
readonly nxStatus: number;
|
|
235
|
+
/** Whether direnv is on the hook's PATH. */
|
|
236
|
+
readonly direnv?: boolean;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function push({ nxOutput, nxStatus, direnv = true }: Push): Promise<{ status: number | null; stderr: string }> {
|
|
230
240
|
const root = await mkdtemp(join(tmpdir(), 'pre-push-cross-'));
|
|
231
241
|
try {
|
|
232
242
|
const bin = join(root, 'bin');
|
|
@@ -238,14 +248,29 @@ describe('managed pre-push cross probe', () => {
|
|
|
238
248
|
};
|
|
239
249
|
await stub('uname', 'echo Darwin');
|
|
240
250
|
await stub('smoo', 'exit 0');
|
|
241
|
-
|
|
242
|
-
await
|
|
251
|
+
// Nx keys on the environment it runs in: outside the checkout's, it is not the gate's run.
|
|
252
|
+
await stub(
|
|
253
|
+
'nx',
|
|
254
|
+
`[ "$SDKROOT" = '${CHECKOUT_SDK}' ] || { echo "nx stub: keyed on the caller's SDKROOT $SDKROOT" >&2; exit 1; }\nprintf '%s\\n' "$NX_STUB_OUTPUT"; exit ${nxStatus}`,
|
|
255
|
+
);
|
|
256
|
+
if (direnv) {
|
|
257
|
+
// The checkout's .envrc: `direnv exec <checkout>` enters the environment that checkout declares.
|
|
258
|
+
await stub(
|
|
259
|
+
'direnv',
|
|
260
|
+
`[ "$1" = exec ] && [ "$2" = "$PWD" ] || { echo "direnv stub: unexpected $*" >&2; exit 64; }\nexport SDKROOT='${CHECKOUT_SDK}'\nshift 2\nexec "$@"`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
// Without direnv, PATH holds the stand-ins alone: no host direnv is found, and no coreutils either, as on a
|
|
264
|
+
// Nix-built Linux host whose /usr/bin and /bin hold none. The refusal must still be said.
|
|
265
|
+
const path = direnv ? `${bin}:$PATH` : bin;
|
|
266
|
+
await writeFile(join(root, 'repo', 'tooling', 'direnv', 'repo-path'), `#!/bin/sh\necho "${path}"\n`);
|
|
243
267
|
await chmod(join(root, 'repo', 'tooling', 'direnv', 'repo-path'), 0o755);
|
|
244
268
|
await writeFile(join(root, 'repo', 'tooling', 'direnv', 'ttsc-env.sh'), '');
|
|
245
269
|
expect(spawnSync('git', ['init', '-q', join(root, 'repo')]).status).toBe(0);
|
|
246
270
|
const run = spawnSync('bash', [hook, 'origin'], {
|
|
247
271
|
cwd: join(root, 'repo'),
|
|
248
|
-
|
|
272
|
+
// The caller's shell carries another directory's SDK, as a shell inside a parent directory's devenv does.
|
|
273
|
+
env: { ...process.env, NX_STUB_OUTPUT: nxOutput, SDKROOT: '/nix/store/caller-apple-sdk/MacOSX.sdk' },
|
|
249
274
|
input: '',
|
|
250
275
|
encoding: 'utf8',
|
|
251
276
|
});
|
|
@@ -255,21 +280,37 @@ describe('managed pre-push cross probe', () => {
|
|
|
255
280
|
}
|
|
256
281
|
}
|
|
257
282
|
|
|
258
|
-
it(
|
|
259
|
-
|
|
283
|
+
it("passes a hit, asked in the checkout's environment rather than the caller's", async () => {
|
|
284
|
+
const { status, stderr } = await push({ nxOutput: 'Successfully ran target cargo-lint-cross', nxStatus: 0 });
|
|
285
|
+
expect(stderr).not.toContain("keyed on the caller's SDKROOT");
|
|
286
|
+
expect(status).toBe(0);
|
|
260
287
|
});
|
|
261
288
|
|
|
262
289
|
it('names a miss when the cross target refused to compile', async () => {
|
|
263
|
-
const { status, stderr } = await push(CARGO_CROSS_LINT_REFUSAL, 1);
|
|
290
|
+
const { status, stderr } = await push({ nxOutput: CARGO_CROSS_LINT_REFUSAL, nxStatus: 1 });
|
|
264
291
|
expect(status).toBe(1);
|
|
265
292
|
expect(stderr).toContain('NOT cached for this tree');
|
|
266
293
|
expect(stderr).toContain('bun run check:linux');
|
|
267
294
|
});
|
|
268
295
|
|
|
269
|
-
it('names any other
|
|
270
|
-
const { status, stderr } = await push(
|
|
296
|
+
it('names any other failure as that, never as a cache miss', async () => {
|
|
297
|
+
const { status, stderr } = await push({
|
|
298
|
+
nxOutput: 'NX NX_WORKSPACE_ROOT_PATH names another workspace',
|
|
299
|
+
nxStatus: 1,
|
|
300
|
+
});
|
|
301
|
+
expect(status).toBe(1);
|
|
302
|
+
expect(stderr).toContain('failed (exit 1) before it reached');
|
|
303
|
+
expect(stderr).not.toContain('NOT cached');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("refuses, naming direnv, when it cannot enter the checkout's environment", async () => {
|
|
307
|
+
const { status, stderr } = await push({
|
|
308
|
+
nxOutput: 'Successfully ran target cargo-lint-cross',
|
|
309
|
+
nxStatus: 0,
|
|
310
|
+
direnv: false,
|
|
311
|
+
});
|
|
271
312
|
expect(status).toBe(1);
|
|
272
|
-
expect(stderr).toContain('
|
|
313
|
+
expect(stderr).toContain('direnv is not on PATH');
|
|
273
314
|
expect(stderr).not.toContain('NOT cached');
|
|
274
315
|
});
|
|
275
316
|
});
|