@smoothbricks/nx-plugin 0.6.0 → 0.6.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 +68 -56
- package/dist/.build-inputs.json +16 -13
- package/dist/cargo-retention-hook.d.ts +8 -1
- package/dist/cargo-retention-hook.d.ts.map +1 -1
- package/dist/cargo-retention-hook.js +12 -1
- package/dist/ensure-built-receipt.d.ts +9 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +42 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +4 -4
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +7 -6
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +20 -2
- package/dist/executors/bounded-exec/gateway-lease.d.ts +3 -2
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +23 -3
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +25 -1
- package/dist/executors/bounded-exec/lease-wait.d.ts +23 -2
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
- package/dist/executors/bounded-exec/lease-wait.js +15 -11
- package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-pool.js +24 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +9 -3
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +109 -12
- package/dist/executors/bounded-exec/verdict.d.ts +8 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +1 -1
- package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
- package/dist/executors/typescript-emit/emit-overrides.js +24 -0
- package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
- package/dist/executors/typescript-emit/executor.js +1 -19
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +6 -0
- package/dist/managed-files/publish-workflow.js +14 -11
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +441 -1
- package/managed/raw/envrc +15 -0
- package/managed/raw/tooling/direnv/developer-links.ts +12 -1
- package/managed/raw/tooling/direnv/devenv.smoo.nix +21 -8
- package/managed/raw/tooling/direnv/linked-snapshots.ts +50 -13
- package/managed/raw/tooling/direnv/setup-environment.ts +23 -11
- package/managed/raw/tooling/git-hooks/pre-push.sh +4 -1
- package/managed/raw/tooling/git-reword-commit +151 -0
- package/package.json +22 -5
- package/src/cargo-retention-hook.ts +12 -1
- package/src/ensure-built-receipt.ts +41 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
- package/src/executors/bounded-exec/cpu-pool.ts +7 -6
- package/src/executors/bounded-exec/executor.ts +20 -2
- package/src/executors/bounded-exec/gateway-lease.ts +17 -7
- package/src/executors/bounded-exec/hang-diagnostics.ts +28 -1
- package/src/executors/bounded-exec/lease-wait.ts +39 -12
- package/src/executors/bounded-exec/mbx-pool.ts +48 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +117 -15
- package/src/executors/bounded-exec/verdict.ts +8 -1
- package/src/executors/typescript-emit/emit-overrides.ts +24 -0
- package/src/executors/typescript-emit/executor.ts +1 -20
- package/src/managed-files/files.ts +6 -0
- package/src/managed-files/publish-workflow.ts +20 -15
- package/src/producer-receipts.ts +28 -0
- package/test-timings.json +120 -118
|
@@ -214,13 +214,12 @@ in {
|
|
|
214
214
|
# wants the cache anyway names it in its own nix.conf.
|
|
215
215
|
cachix.enable = false;
|
|
216
216
|
|
|
217
|
-
#
|
|
217
|
+
# No compiler cache is exported from this shell. One shell once exported
|
|
218
218
|
# RUSTC_WRAPPER=sccache as a BARE NAME, which PATH then resolved per project —
|
|
219
|
-
# which is
|
|
220
|
-
#
|
|
221
|
-
#
|
|
222
|
-
#
|
|
223
|
-
# business deciding which compiler cache a host runs.
|
|
219
|
+
# which is how an unpatched binary from one profile came to serve clients from
|
|
220
|
+
# another. Cargo's cache is mbx: a repository pins it in its own devenv, and
|
|
221
|
+
# cowshed proves that pin against the mbx it installs beside itself
|
|
222
|
+
# (specs/cowshed/05_gateway.md, "Pool selection and revision").
|
|
224
223
|
|
|
225
224
|
# One toolchain for every repository and every workspace, pinned by devenv.lock
|
|
226
225
|
# rather than by a rust-toolchain file. devenv resolves the channel through
|
|
@@ -511,8 +510,15 @@ in {
|
|
|
511
510
|
# A runner links nothing.
|
|
512
511
|
#
|
|
513
512
|
# A failed task does not fail shell entry (devenv reports it and the shell
|
|
514
|
-
# still loads, so the tools to repair it stay available)
|
|
515
|
-
#
|
|
513
|
+
# still loads, so the tools to repair it stay available), with one
|
|
514
|
+
# exception: smoo:developer-links refusing the declared links. A shell on
|
|
515
|
+
# links its declaration does not describe runs another build than it says
|
|
516
|
+
# (a live checkout whose build is stale, with no sealed snapshot to serve
|
|
517
|
+
# instead), and the repair is in the provider checkout, not in this shell.
|
|
518
|
+
# The refused exec leaves node_modules/.smoo-links-refused, which the
|
|
519
|
+
# prologue below says and fails on; the next `--links` run that finds the
|
|
520
|
+
# links current removes it. CI runs both with `devenv tasks run`, which
|
|
521
|
+
# does fail; setup-environment.ts is strict there.
|
|
516
522
|
tasks = let
|
|
517
523
|
setup = ''bun "$DEVENV_ROOT/setup-environment.ts"'';
|
|
518
524
|
in {
|
|
@@ -652,6 +658,13 @@ in {
|
|
|
652
658
|
# they run.
|
|
653
659
|
(lib.mkBefore ''
|
|
654
660
|
cd "$DEVENV_ROOT/../.."
|
|
661
|
+
# smoo:developer-links refused the declared links (tasks above): fail
|
|
662
|
+
# shell entry with its reason rather than run on links it refused.
|
|
663
|
+
if [ -f node_modules/.smoo-links-refused ]; then
|
|
664
|
+
echo "smoo:developer-links refused this checkout's declared links; shell entry fails until they are current:" >&2
|
|
665
|
+
cat node_modules/.smoo-links-refused >&2
|
|
666
|
+
exit 1
|
|
667
|
+
fi
|
|
655
668
|
# A bare assignment: export's status would hide repo-path's refusal of a
|
|
656
669
|
# cowshed workspace it could not serve, and the shell would enter with an
|
|
657
670
|
# empty PATH.
|
|
@@ -925,6 +925,56 @@ function copySealed(from: string, to: string): void {
|
|
|
925
925
|
}
|
|
926
926
|
}
|
|
927
927
|
|
|
928
|
+
/**
|
|
929
|
+
* The newest sealed snapshot of `name` this checkout's store, or else its link anchor's (the main checkout's), holds,
|
|
930
|
+
* newest by the commit time of the HEAD it captured, as `source`'s repository knows it; or null when there is none.
|
|
931
|
+
* What a live developer link serves while the live checkout's build does not describe its sources (developer-links.ts):
|
|
932
|
+
* the last revision that was built and sealed, never the stale build, and never a refusal that stops shell entry.
|
|
933
|
+
*/
|
|
934
|
+
export function newestSealedSnapshot(
|
|
935
|
+
root: string,
|
|
936
|
+
name: string,
|
|
937
|
+
source: string,
|
|
938
|
+
): (SealedSnapshot & { readonly head: string }) | null {
|
|
939
|
+
const stores = [...new Set([path.join(root, SNAPSHOT_STORE), path.join(linkAnchor(root), SNAPSHOT_STORE)])];
|
|
940
|
+
const candidates: { readonly directory: string; readonly receipt: SnapshotReceipt; readonly time: number }[] = [];
|
|
941
|
+
for (const store of stores) {
|
|
942
|
+
let entries: string[];
|
|
943
|
+
try {
|
|
944
|
+
entries = readdirSync(store);
|
|
945
|
+
} catch {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
for (const entry of entries) {
|
|
949
|
+
const directory = path.join(store, entry);
|
|
950
|
+
const receipt = readSealed(directory);
|
|
951
|
+
if (receipt === null || receipt.name !== name || !contained(receipt.packagePath)) continue;
|
|
952
|
+
const committed = spawnSync('git', ['-C', source, 'log', '-1', '--format=%ct', receipt.provenance.head], {
|
|
953
|
+
encoding: 'utf8',
|
|
954
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' },
|
|
955
|
+
});
|
|
956
|
+
const time = Number.parseInt(committed.stdout.trim(), 10);
|
|
957
|
+
if (committed.status === 0 && Number.isFinite(time)) candidates.push({ directory, receipt, time });
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
candidates.sort((left, right) => right.time - left.time);
|
|
961
|
+
for (const { directory, receipt } of candidates) {
|
|
962
|
+
try {
|
|
963
|
+
verifySnapshot(directory);
|
|
964
|
+
} catch (error) {
|
|
965
|
+
if (error instanceof SnapshotRefusal) continue;
|
|
966
|
+
throw error;
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
kind: 'snapshot',
|
|
970
|
+
id: receipt.id,
|
|
971
|
+
directory: path.join(directory, receipt.packagePath),
|
|
972
|
+
head: receipt.provenance.head,
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
|
|
928
978
|
/** A sealed snapshot's receipt, or null when `directory` holds none. Its census is not verified here. */
|
|
929
979
|
export function readSealed(directory: string): SnapshotReceipt | null {
|
|
930
980
|
let input: unknown;
|
|
@@ -941,19 +991,6 @@ export function readSealed(directory: string): SnapshotReceipt | null {
|
|
|
941
991
|
return receipt;
|
|
942
992
|
}
|
|
943
993
|
|
|
944
|
-
/** The sealed snapshot `target` lies in, found by its receipt above it, or null. */
|
|
945
|
-
export function sealedSnapshotOf(
|
|
946
|
-
target: string,
|
|
947
|
-
): { readonly directory: string; readonly receipt: SnapshotReceipt } | null {
|
|
948
|
-
for (let at = path.dirname(target); ; at = path.dirname(at)) {
|
|
949
|
-
if (lstatSync(path.join(at, SNAPSHOT_RECEIPT), { throwIfNoEntry: false }) !== undefined) {
|
|
950
|
-
const receipt = readSealed(at);
|
|
951
|
-
return receipt === null ? null : { directory: at, receipt };
|
|
952
|
-
}
|
|
953
|
-
if (path.dirname(at) === at) return null;
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
994
|
/**
|
|
958
995
|
* The sealed snapshot of `name` in this checkout's store that `linkText`, an alias's recorded link at `entry`, binds,
|
|
959
996
|
* once it verifies; or null when that text names no snapshot left in the store. When no new snapshot can be made the
|
|
@@ -223,6 +223,11 @@ const { values: flags } = parseArgs({
|
|
|
223
223
|
},
|
|
224
224
|
});
|
|
225
225
|
const cargoMode = flags.cargo === true;
|
|
226
|
+
// What a `--links` exec that refused leaves for the enterShell prologue (devenv.smoo.nix), which then fails shell entry
|
|
227
|
+
// with its reason: a shell must not run on links the declaration does not describe (a live checkout whose build is
|
|
228
|
+
// stale with no sealed snapshot to serve, a declaration smoo refuses), and the repair is in the provider checkout, not
|
|
229
|
+
// in this shell. Every `--links` run that finds the links current, or makes them so, removes it.
|
|
230
|
+
const linksRefusal = path.join(projectRoot, 'node_modules', '.smoo-links-refused');
|
|
226
231
|
|
|
227
232
|
// The Nx plugin's test for a Cargo workspace root manifest (CARGO_WORKSPACE_PATTERN), which
|
|
228
233
|
// cargoWorkspaces applies during the bootstrap block; declared above it for the same reason.
|
|
@@ -253,13 +258,12 @@ try {
|
|
|
253
258
|
plan.changes.length === 0 && plan.unavailable.every((unavailable) => unavailable.kind === 'absent');
|
|
254
259
|
// A stale pin is informational, not a stale install: say it even when devenv skips the exec.
|
|
255
260
|
if (current && plan.reports.length > 0) applyDeclaredLinks(projectRoot, plan);
|
|
256
|
-
|
|
261
|
+
const linked =
|
|
257
262
|
current &&
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
);
|
|
263
|
+
!hasStaleDeveloperLinks(projectRoot, ['nx']) &&
|
|
264
|
+
danglingStoreLinks(projectRoot, () => workspaceMemberModules(projectRoot)).length === 0;
|
|
265
|
+
if (linked) rmSync(linksRefusal, { force: true });
|
|
266
|
+
process.exit(linked ? 0 : 1);
|
|
263
267
|
}
|
|
264
268
|
// Planning reads, apart from a snapshot it may capture, which seals by an atomic rename (linked-snapshots.ts),
|
|
265
269
|
// and applying a plan with no changes only says what this machine cannot honour. So an entry with nothing to
|
|
@@ -272,6 +276,7 @@ try {
|
|
|
272
276
|
!hasStaleDeveloperLinks(projectRoot, ['nx'])
|
|
273
277
|
) {
|
|
274
278
|
applyDeclaredLinks(projectRoot, plan);
|
|
279
|
+
rmSync(linksRefusal, { force: true });
|
|
275
280
|
process.exit(0);
|
|
276
281
|
}
|
|
277
282
|
await withInstallLock(async () => {
|
|
@@ -290,6 +295,7 @@ try {
|
|
|
290
295
|
}
|
|
291
296
|
applyDeclaredLinks(projectRoot, await planDeclaredLinks(projectRoot));
|
|
292
297
|
});
|
|
298
|
+
rmSync(linksRefusal, { force: true });
|
|
293
299
|
process.exit(0);
|
|
294
300
|
}
|
|
295
301
|
// Bootstrap only: install deps + wire local git hooks/config.
|
|
@@ -410,6 +416,11 @@ try {
|
|
|
410
416
|
}
|
|
411
417
|
}
|
|
412
418
|
} catch (error) {
|
|
419
|
+
// Thrown out of a `--links` exec, an error is the links refused (an install failure reports itself and exits).
|
|
420
|
+
if (flags.links === true && flags.check !== true) {
|
|
421
|
+
mkdirSync(path.dirname(linksRefusal), { recursive: true });
|
|
422
|
+
writeFileSync(linksRefusal, `${error instanceof Error ? error.message : String(error)}\n`);
|
|
423
|
+
}
|
|
413
424
|
reportSetupFailure(error);
|
|
414
425
|
}
|
|
415
426
|
|
|
@@ -1427,14 +1438,15 @@ async function applyWorkspaceGitConfig(root: string): Promise<void> {
|
|
|
1427
1438
|
|
|
1428
1439
|
const gitDir = path.resolve(root, new TextDecoder().decode(gitDirResult.stdout).trim());
|
|
1429
1440
|
const tooling = path.join(root, 'tooling');
|
|
1430
|
-
linkHook(gitDir, tooling, 'pre-commit');
|
|
1441
|
+
linkHook(gitDir, path.join(tooling, 'git-hooks', 'pre-commit.sh'));
|
|
1431
1442
|
installPostCommitHook(gitDir, tooling);
|
|
1432
|
-
linkHook(gitDir, tooling, 'commit-msg');
|
|
1433
|
-
linkHook(gitDir, tooling, 'pre-push');
|
|
1443
|
+
linkHook(gitDir, path.join(tooling, 'git-hooks', 'commit-msg.sh'));
|
|
1444
|
+
linkHook(gitDir, path.join(tooling, 'git-hooks', 'pre-push.sh'));
|
|
1434
1445
|
}
|
|
1435
1446
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1447
|
+
/** Links `.git/hooks/<name>` to the hook source `<name>.sh`. */
|
|
1448
|
+
function linkHook(gitDir: string, source: string): void {
|
|
1449
|
+
const name = path.basename(source, '.sh');
|
|
1438
1450
|
if (!existsSync(source)) {
|
|
1439
1451
|
throw new Error(`Missing ${name} hook source: ${source}`);
|
|
1440
1452
|
}
|
|
@@ -70,7 +70,10 @@ while read -r _local_ref local_sha _remote_ref _remote_sha; do
|
|
|
70
70
|
esac
|
|
71
71
|
done
|
|
72
72
|
if [ "${#pushed[@]}" -gt 0 ]; then
|
|
73
|
-
smoo monorepo check-public-denylist --remote "$1" "${pushed[@]}" ||
|
|
73
|
+
smoo monorepo check-public-denylist --remote "$1" "${pushed[@]}" || {
|
|
74
|
+
echo 'pre-push: rewrite a refused commit message in place with tooling/git-reword-commit <commit> (the new message on stdin), then push again' >&2
|
|
75
|
+
exit 1
|
|
76
|
+
}
|
|
74
77
|
fi
|
|
75
78
|
|
|
76
79
|
case "$(uname -s)" in
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# git-reword-commit - Rewrite a commit message without affecting worktree
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# echo "new message" | git-reword-commit <commit-hash>
|
|
7
|
+
# echo "prepend this" | git-reword-commit <commit-hash> --prepend
|
|
8
|
+
# echo "append this" | git-reword-commit <commit-hash> --append
|
|
9
|
+
# ... | git-reword-commit <commit-hash> --rewrite-published
|
|
10
|
+
#
|
|
11
|
+
# Examples:
|
|
12
|
+
# # Replace the entire commit message
|
|
13
|
+
# echo "feat: new message here" | git-reword-commit abc123
|
|
14
|
+
#
|
|
15
|
+
# # Prepend to existing message (adds newline between)
|
|
16
|
+
# cat msg.txt | git-reword-commit abc123 --prepend
|
|
17
|
+
#
|
|
18
|
+
# # Append to existing message (adds newline between)
|
|
19
|
+
# echo "Co-authored-by: Someone" | git-reword-commit abc123 --append
|
|
20
|
+
#
|
|
21
|
+
# The commit is rebuilt with `git commit-tree` from its own tree, parents, author and
|
|
22
|
+
# committer, and so is every commit between it and HEAD that descends from it; nothing else
|
|
23
|
+
# changes. HEAD -- a branch, or a detached HEAD -- moves once, with `git update-ref`, and only
|
|
24
|
+
# if it still names the commit it named when the rewrite began. The trees are the same, so the
|
|
25
|
+
# worktree and index are untouched, and no backup ref is left behind.
|
|
26
|
+
#
|
|
27
|
+
# A commit any remote-tracking ref already holds is published: rewriting it forks history
|
|
28
|
+
# others have. That is refused unless --rewrite-published says it is meant.
|
|
29
|
+
#
|
|
30
|
+
|
|
31
|
+
set -euo pipefail
|
|
32
|
+
|
|
33
|
+
usage() {
|
|
34
|
+
echo "Usage: <message> | git-reword-commit <commit-hash> [--prepend|--append] [--rewrite-published]"
|
|
35
|
+
echo ""
|
|
36
|
+
echo "Reads new commit message from stdin."
|
|
37
|
+
echo ""
|
|
38
|
+
echo "Modes:"
|
|
39
|
+
echo " (default) Replace the entire commit message"
|
|
40
|
+
echo " --prepend Prepend to existing message (adds newline between)"
|
|
41
|
+
echo " --append Append to existing message (adds newline between)"
|
|
42
|
+
echo " --rewrite-published Rewrite even though a remote-tracking ref holds the commit"
|
|
43
|
+
exit 1
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if [ $# -lt 1 ]; then
|
|
47
|
+
usage
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
COMMIT_SHORT="$1"
|
|
51
|
+
shift
|
|
52
|
+
|
|
53
|
+
COMMIT_FULL=$(git rev-parse --verify --quiet "$COMMIT_SHORT^{commit}") || {
|
|
54
|
+
echo "Error: Invalid commit reference: $COMMIT_SHORT" >&2
|
|
55
|
+
exit 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
MODE="replace"
|
|
59
|
+
REWRITE_PUBLISHED=0
|
|
60
|
+
for option in "$@"; do
|
|
61
|
+
case "$option" in
|
|
62
|
+
--prepend) MODE="prepend" ;;
|
|
63
|
+
--append) MODE="append" ;;
|
|
64
|
+
--rewrite-published) REWRITE_PUBLISHED=1 ;;
|
|
65
|
+
*)
|
|
66
|
+
echo "Error: Unknown option: $option" >&2
|
|
67
|
+
usage
|
|
68
|
+
;;
|
|
69
|
+
esac
|
|
70
|
+
done
|
|
71
|
+
|
|
72
|
+
HEAD_BEFORE=$(git rev-parse --verify HEAD)
|
|
73
|
+
if ! git merge-base --is-ancestor "$COMMIT_FULL" "$HEAD_BEFORE"; then
|
|
74
|
+
echo "Error: $COMMIT_SHORT is not an ancestor of HEAD; there is nothing of it to rewrite here" >&2
|
|
75
|
+
exit 1
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
PUBLISHED=$(git for-each-ref --contains "$COMMIT_FULL" --format='%(refname)' refs/remotes)
|
|
79
|
+
if [ -n "$PUBLISHED" ] && [ "$REWRITE_PUBLISHED" -ne 1 ]; then
|
|
80
|
+
echo "Error: $COMMIT_SHORT is already published; these remote-tracking refs hold it:" >&2
|
|
81
|
+
printf ' %s\n' $PUBLISHED >&2
|
|
82
|
+
echo "Rewriting it forks history others have. Pass --rewrite-published if that is meant." >&2
|
|
83
|
+
exit 1
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
WORK=$(mktemp -d)
|
|
87
|
+
trap 'rm -rf "$WORK"' EXIT
|
|
88
|
+
cat > "$WORK/new"
|
|
89
|
+
if [ ! -s "$WORK/new" ]; then
|
|
90
|
+
echo "Error: Message cannot be empty (nothing on stdin)" >&2
|
|
91
|
+
usage
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
# The message bytes of commit $1: everything after the header's terminating blank line.
|
|
95
|
+
# Continuation lines of a multi-line header (a signature) start with a space, never empty.
|
|
96
|
+
message_of() {
|
|
97
|
+
git cat-file commit "$1" | sed '1,/^$/d'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case "$MODE" in
|
|
101
|
+
replace) cp "$WORK/new" "$WORK/message" ;;
|
|
102
|
+
prepend) { cat "$WORK/new"; echo ''; echo ''; message_of "$COMMIT_FULL"; } > "$WORK/message" ;;
|
|
103
|
+
append) { message_of "$COMMIT_FULL"; echo ''; echo ''; cat "$WORK/new"; } > "$WORK/message" ;;
|
|
104
|
+
esac
|
|
105
|
+
|
|
106
|
+
# old -> new for every rebuilt commit, one "old new" pair per line; a parent not listed is kept.
|
|
107
|
+
: > "$WORK/map"
|
|
108
|
+
rebuilt() {
|
|
109
|
+
awk -v old="$1" '$1 == old { print $2; found = 1 } END { if (!found) print old }' "$WORK/map"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# Rebuild $1 on its rebuilt parents with the message in file $2, keeping tree, author and
|
|
113
|
+
# committer.
|
|
114
|
+
rebuild() {
|
|
115
|
+
local commit="$1" message="$2" parents=() parent listed
|
|
116
|
+
listed=$(git rev-parse "$commit^@")
|
|
117
|
+
for parent in $listed; do
|
|
118
|
+
parents+=(-p "$(rebuilt "$parent")")
|
|
119
|
+
done
|
|
120
|
+
local an ae ad cn ce cd
|
|
121
|
+
{
|
|
122
|
+
IFS= read -r an
|
|
123
|
+
IFS= read -r ae
|
|
124
|
+
IFS= read -r ad
|
|
125
|
+
IFS= read -r cn
|
|
126
|
+
IFS= read -r ce
|
|
127
|
+
IFS= read -r cd
|
|
128
|
+
} < <(git log --no-walk --format='%an%n%ae%n%ad%n%cn%n%ce%n%cd' --date=raw "$commit")
|
|
129
|
+
GIT_AUTHOR_NAME="$an" GIT_AUTHOR_EMAIL="$ae" GIT_AUTHOR_DATE="$ad" \
|
|
130
|
+
GIT_COMMITTER_NAME="$cn" GIT_COMMITTER_EMAIL="$ce" GIT_COMMITTER_DATE="$cd" \
|
|
131
|
+
git commit-tree "$commit^{tree}" ${parents[@]+"${parents[@]}"} < "$message"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
echo "Rewriting commit $COMMIT_SHORT ($MODE mode)..."
|
|
135
|
+
|
|
136
|
+
NEW_COMMIT=$(rebuild "$COMMIT_FULL" "$WORK/message")
|
|
137
|
+
echo "$COMMIT_FULL $NEW_COMMIT" >> "$WORK/map"
|
|
138
|
+
DESCENDANTS=$(git rev-list --reverse --topo-order --ancestry-path "$COMMIT_FULL..$HEAD_BEFORE")
|
|
139
|
+
for descendant in $DESCENDANTS; do
|
|
140
|
+
message_of "$descendant" > "$WORK/descendant"
|
|
141
|
+
rebuilt_descendant=$(rebuild "$descendant" "$WORK/descendant")
|
|
142
|
+
echo "$descendant $rebuilt_descendant" >> "$WORK/map"
|
|
143
|
+
done
|
|
144
|
+
|
|
145
|
+
HEAD_AFTER=$(rebuilt "$HEAD_BEFORE")
|
|
146
|
+
git update-ref -m "git-reword-commit: reword $COMMIT_FULL" HEAD "$HEAD_AFTER" "$HEAD_BEFORE"
|
|
147
|
+
|
|
148
|
+
echo "Done. Commit message rewritten."
|
|
149
|
+
echo ""
|
|
150
|
+
echo "New commit: $NEW_COMMIT"
|
|
151
|
+
echo "New HEAD: $HEAD_AFTER"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -229,9 +229,26 @@
|
|
|
229
229
|
"test-shard2",
|
|
230
230
|
"test-shard3",
|
|
231
231
|
"test-shard4",
|
|
232
|
-
"test-host"
|
|
232
|
+
"test-host",
|
|
233
|
+
"test-pool-silence"
|
|
233
234
|
]
|
|
234
235
|
},
|
|
236
|
+
"test-pool-silence": {
|
|
237
|
+
"executor": "@smoothbricks/nx-plugin:bounded-exec",
|
|
238
|
+
"cache": true,
|
|
239
|
+
"inputs": [
|
|
240
|
+
"default",
|
|
241
|
+
"^dependencyDefault",
|
|
242
|
+
"bunToolchain",
|
|
243
|
+
"{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs"
|
|
244
|
+
],
|
|
245
|
+
"options": {
|
|
246
|
+
"command": "bun test --timeout=0 ./src/executors/bounded-exec/__tests__/cpu-pool.silence.ts",
|
|
247
|
+
"cwd": "{projectRoot}",
|
|
248
|
+
"idleTimeoutMs": 180000,
|
|
249
|
+
"killAfterMs": 10000
|
|
250
|
+
}
|
|
251
|
+
},
|
|
235
252
|
"test-shard1": {
|
|
236
253
|
"executor": "@smoothbricks/nx-plugin:bounded-exec",
|
|
237
254
|
"cache": true,
|
|
@@ -367,9 +384,9 @@
|
|
|
367
384
|
},
|
|
368
385
|
"dependencies": {
|
|
369
386
|
"@nx/js": "23.2.1",
|
|
370
|
-
"@smoothbricks/build-inputs": "0.0.1
|
|
371
|
-
"@smoothbricks/cargo-retain": "0.0.1
|
|
372
|
-
"@smoothbricks/nextest-extract": "0.0.1
|
|
387
|
+
"@smoothbricks/build-inputs": "0.0.1",
|
|
388
|
+
"@smoothbricks/cargo-retain": "0.0.1",
|
|
389
|
+
"@smoothbricks/nextest-extract": "0.0.1",
|
|
373
390
|
"jsonc-parser": "^3.3.1",
|
|
374
391
|
"minimatch": "10.2.5",
|
|
375
392
|
"nx": "latest",
|
|
@@ -40,13 +40,24 @@ function ran(status: TaskStatus): boolean {
|
|
|
40
40
|
*/
|
|
41
41
|
export const CARGO_PRODUCER_METADATA = { cargoProducer: true } as const;
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Whether the run's environment is an mbx project's canonical one, which names the shared store beside mbx-managed
|
|
45
|
+
* target views (specs/cowshed/11_shell.md, "Canonical mbx environment"). Such a project's targets are mbx's to collect,
|
|
46
|
+
* so the plugin retains and purges nothing in them (specs/cowshed/16_build_volumes.md, "Migration" step 4).
|
|
47
|
+
*/
|
|
48
|
+
export function mbxManagesTargets(environment: Readonly<NodeJS.ProcessEnv>): boolean {
|
|
49
|
+
return Boolean(environment.MBX_CACHE_DIR) && environment.MBX_TARGET_VIEWS === '1';
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
/**
|
|
44
53
|
* After a run that executed a Cargo producer task ({@link CARGO_PRODUCER_METADATA}), check whether
|
|
45
54
|
* each Cargo workspace is due for its daily maintenance. A successful receipt schedules only;
|
|
46
55
|
* every due pass reads the current graph under Cargo's locks and is awaited by this Nx process.
|
|
47
|
-
* Maintenance never fails the run it follows: every outcome, a refused or busy pass included, is only reported.
|
|
56
|
+
* Maintenance never fails the run it follows: every outcome, a refused or busy pass included, is only reported. In an
|
|
57
|
+
* mbx project ({@link mbxManagesTargets}) it does nothing.
|
|
48
58
|
*/
|
|
49
59
|
export async function postTasksExecution(_options: unknown, context: PostTasksExecutionContext): Promise<void> {
|
|
60
|
+
if (mbxManagesTargets(process.env)) return;
|
|
50
61
|
const executed = Object.values(context.taskResults).filter(({ status }) => ran(status));
|
|
51
62
|
if (executed.length === 0) return;
|
|
52
63
|
let graph: ProjectGraph;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
readlinkSync,
|
|
11
11
|
readSync,
|
|
12
12
|
realpathSync,
|
|
13
|
+
rmSync,
|
|
13
14
|
} from 'node:fs';
|
|
14
15
|
import { isAbsolute, join, relative } from 'node:path';
|
|
15
16
|
import type { Task } from 'nx/src/config/task-graph';
|
|
@@ -378,6 +379,46 @@ export function producerOutputPaths(root: string, tasks: readonly Task[], expand
|
|
|
378
379
|
for (const task of tasks) for (const path of expand(root, task.outputs)) visit(path);
|
|
379
380
|
return [...paths].sort();
|
|
380
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Remove what a producer's previous receipt declared as task outputs and its current task graph no longer declares,
|
|
384
|
+
* inside the declaring task's project root. A layout change (an output moved, a target renamed) otherwise leaves the
|
|
385
|
+
* old layout's files where a package's published `files` still packs them, so a consumer's capture hashes them as the
|
|
386
|
+
* producer's tools and ships them. A previously declared directory that holds a currently declared output loses only
|
|
387
|
+
* its other entries. A previous task that left this graph while its target still exists is not this producer's to
|
|
388
|
+
* clean: `defined` says whether a task's target still exists. Returns the removed paths, relative to `root`.
|
|
389
|
+
*/
|
|
390
|
+
export function removeOrphanedOutputs(
|
|
391
|
+
root: string,
|
|
392
|
+
previous: readonly Task[],
|
|
393
|
+
current: readonly Task[],
|
|
394
|
+
expand: typeof expandOutputs,
|
|
395
|
+
defined: (task: Task) => boolean,
|
|
396
|
+
): string[] {
|
|
397
|
+
const declared = current.flatMap((task) => expand(root, task.outputs));
|
|
398
|
+
const currentIds = new Set(current.map((task) => task.id));
|
|
399
|
+
const removed: string[] = [];
|
|
400
|
+
function prune(path: string): void {
|
|
401
|
+
if (declared.some((output) => path === output || path.startsWith(`${output}/`))) return;
|
|
402
|
+
const stats = lstatSync(join(root, path), { throwIfNoEntry: false });
|
|
403
|
+
if (stats === undefined) return;
|
|
404
|
+
if (!declared.some((output) => output.startsWith(`${path}/`))) {
|
|
405
|
+
rmSync(join(root, path), { recursive: true, force: true });
|
|
406
|
+
removed.push(path);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (stats.isDirectory()) for (const name of readdirSync(join(root, path))) prune(join(path, name));
|
|
410
|
+
}
|
|
411
|
+
for (const task of previous) {
|
|
412
|
+
if (!currentIds.has(task.id) && defined(task)) continue;
|
|
413
|
+
const project = task.projectRoot ?? '';
|
|
414
|
+
for (const output of expand(root, task.outputs)) {
|
|
415
|
+
if (isAbsolute(output) || output.split('/').includes('..')) continue;
|
|
416
|
+
if (project !== '' && project !== '.' && output !== project && !output.startsWith(`${project}/`)) continue;
|
|
417
|
+
prune(output);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return removed.sort();
|
|
421
|
+
}
|
|
381
422
|
export function providerReceipt(
|
|
382
423
|
root: string,
|
|
383
424
|
taskId: string,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { type CloseOutcome, createCpuPool } from './cpu-pool.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The thread an Nx run's CPU pool runs on (`run-cpu-pool.ts`; specs/cowshed/05_gateway.md, "Every Nx run budgets
|
|
6
|
+
* itself"). The process that serves a run's pool, the Nx daemon when installed plugins load in it or the Nx CLI without
|
|
7
|
+
* one, hashes tasks and builds the project graph in synchronous calls on its main thread. A pool there writes no
|
|
8
|
+
* heartbeat while one runs, and every runner queued on it fails `SILENT` while it still works. Here the pool's socket,
|
|
9
|
+
* jobserver fifo and heartbeat share an event loop that runs nothing else, so the heartbeat proves that the actor which
|
|
10
|
+
* admits and grants is turning.
|
|
11
|
+
*
|
|
12
|
+
* The thread is started with the pool's count. It says once that the pool serves, with the environment a task inherits,
|
|
13
|
+
* or why it cannot; the host's one message is its close, after which the thread says how the pool closed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** What the thread is started with. */
|
|
17
|
+
export interface CpuPoolThreadData {
|
|
18
|
+
readonly tokens: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What the thread says, in order: the pool serves or failed; after the host's close, how the pool closed. */
|
|
22
|
+
export type CpuPoolThreadReport =
|
|
23
|
+
| { readonly kind: 'serving'; readonly environment: Record<string, string> }
|
|
24
|
+
| { readonly kind: 'failed'; readonly error: string }
|
|
25
|
+
| { readonly kind: 'closed'; readonly outcome: CloseOutcome };
|
|
26
|
+
|
|
27
|
+
const host = parentPort;
|
|
28
|
+
if (host === null) {
|
|
29
|
+
throw new Error('cpu-pool-thread runs as the worker thread run-cpu-pool starts, never as a module of its own');
|
|
30
|
+
}
|
|
31
|
+
const report = (message: CpuPoolThreadReport): void => host.postMessage(message);
|
|
32
|
+
const data: CpuPoolThreadData = workerData;
|
|
33
|
+
// The pool lives until its host closes it, or with the thread.
|
|
34
|
+
const made = await createCpuPool(data.tokens, new Promise<void>(() => {}));
|
|
35
|
+
if (made.ok) {
|
|
36
|
+
const { pool } = made;
|
|
37
|
+
host.once('message', () => {
|
|
38
|
+
void pool.close().then((outcome) => report({ kind: 'closed', outcome }));
|
|
39
|
+
});
|
|
40
|
+
report({ kind: 'serving', environment: pool.environment });
|
|
41
|
+
} else {
|
|
42
|
+
report({ kind: 'failed', error: made.error });
|
|
43
|
+
}
|
|
@@ -7,14 +7,15 @@ import { promisify } from 'node:util';
|
|
|
7
7
|
import typia from 'typia';
|
|
8
8
|
import { ownedSocketDirectory } from '../../testing.js';
|
|
9
9
|
import { holdLease, type Unleased } from './gateway-lease.js';
|
|
10
|
-
import { type CpuLeaseProgress, CpuLeaseWait, HEARTBEAT_MS } from './lease-wait.js';
|
|
10
|
+
import { type CpuLeaseProgress, type CpuLeaseQueued, CpuLeaseWait, HEARTBEAT_MS } from './lease-wait.js';
|
|
11
11
|
import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A CPU pool: the tokens a process lends the runners it starts, held live rather than inherited as a
|
|
15
15
|
* bare count (specs/cowshed/05_gateway.md, "Host scheduling", "Parallelism inside a job"). An Nx run
|
|
16
|
-
* serves one (`run-cpu-pool.ts`), and every granted bounded-exec serves a
|
|
17
|
-
* its own descendants, so the runners of one build tree together stay
|
|
16
|
+
* serves one on a thread of its own (`run-cpu-pool.ts`), and every granted bounded-exec serves a
|
|
17
|
+
* sub-pool of its grant to its own descendants, so the runners of one build tree together stay
|
|
18
|
+
* within the tree's count.
|
|
18
19
|
*
|
|
19
20
|
* The pool is a private Unix socket in a directory the process owns: the directory 0700, the socket
|
|
20
21
|
* 0600. A child asks it for a count with one request line, in `holdLease`'s framing. The pool
|
|
@@ -52,7 +53,7 @@ export interface CpuPool {
|
|
|
52
53
|
close(): Promise<CloseOutcome>;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
type CloseOutcome = { ok: true } | { ok: false; error: string };
|
|
56
|
+
export type CloseOutcome = { ok: true } | { ok: false; error: string };
|
|
56
57
|
|
|
57
58
|
/** The one line a child sends: a count of whole tokens, at least one. */
|
|
58
59
|
interface CpuPoolRequest {
|
|
@@ -63,7 +64,7 @@ interface CpuPoolRequest {
|
|
|
63
64
|
/** The pool's answers, in `holdLease`'s framing. */
|
|
64
65
|
type CpuPoolReply =
|
|
65
66
|
| CpuLeaseProgress
|
|
66
|
-
|
|
|
67
|
+
| CpuLeaseQueued
|
|
67
68
|
| { ok: true; lease: 'granted'; tokens: number }
|
|
68
69
|
| { ok: false; code: 'invalid-request'; error: string };
|
|
69
70
|
|
|
@@ -528,7 +529,7 @@ export async function createCpuPool(
|
|
|
528
529
|
const request = parsed;
|
|
529
530
|
child.phase = { kind: 'queued' };
|
|
530
531
|
queue.push({ child, want: request.want });
|
|
531
|
-
socket.write(frame({ ok: true, lease: 'queued' }));
|
|
532
|
+
socket.write(frame({ ok: true, lease: 'queued', server: process.pid }));
|
|
532
533
|
drain(0);
|
|
533
534
|
});
|
|
534
535
|
};
|
|
@@ -26,7 +26,9 @@ import {
|
|
|
26
26
|
import { GATEWAY_SOCKET } from './gateway-lease.js';
|
|
27
27
|
import type { HangDiagnostics } from './hang-diagnostics.js';
|
|
28
28
|
import { captureHangDiagnostics, HANG_CAPTURE_MS } from './hang-diagnostics.js';
|
|
29
|
+
import type { CpuWaitRow } from './lease-wait.js';
|
|
29
30
|
import type { LockWait } from './lock-wait.js';
|
|
31
|
+
import { mbxLeaf, mbxPool, withMbxLeaf } from './mbx-pool.js';
|
|
30
32
|
import { createNoSpaceWatch } from './no-space.js';
|
|
31
33
|
import {
|
|
32
34
|
COWSHED_EXECUTABLE_ENV,
|
|
@@ -515,6 +517,7 @@ export async function runBoundedExec(
|
|
|
515
517
|
// instead. A pool whose endpoint is gone (its holder exited) lends nothing, and the run goes on as asked.
|
|
516
518
|
let grant: GrantedTokens | null = null;
|
|
517
519
|
let parentRefusal: string | null = null;
|
|
520
|
+
let parentWait: CpuWaitRow | undefined;
|
|
518
521
|
if (inherited !== null) {
|
|
519
522
|
const fromParent = await takeParentCpuTokens(inherited, demand.want);
|
|
520
523
|
if (fromParent.granted) {
|
|
@@ -523,17 +526,25 @@ export async function runBoundedExec(
|
|
|
523
526
|
appendStderr(`cowshed: cpu-pool parent pool absent: ${fromParent.reason}; running the command as asked\n`);
|
|
524
527
|
} else {
|
|
525
528
|
parentRefusal = fromParent.reason;
|
|
529
|
+
parentWait = fromParent.wait;
|
|
526
530
|
}
|
|
527
531
|
}
|
|
528
532
|
const waitedMs = Date.now() - asked;
|
|
529
533
|
let cpu: BoundedExecRecord['cpu'];
|
|
530
534
|
let sized: { command: string; env: Record<string, string> } = { command: requested, env: {} };
|
|
535
|
+
// With mbx the leaf's admission is mbx's one pool, not a parent's tokens: its runner is sized to the job's count,
|
|
536
|
+
// and a non-Cargo leaf holds that much of the pool for its run (specs/cowshed/05_gateway.md, "Parallelism inside a
|
|
537
|
+
// job"). No grant and no sub-pool beside it.
|
|
538
|
+
const mbx = mbxPool(process.env);
|
|
539
|
+
const leaf = mbx === null ? null : mbxLeaf(mbx, demand.kind, demand.want);
|
|
531
540
|
if (grant !== null) {
|
|
532
541
|
sized = sizeRunner(demand, requested, grant.tokens);
|
|
533
542
|
cpu = { tokens: grant.tokens, want: demand.want, waitedMs };
|
|
534
543
|
appendStderr(
|
|
535
544
|
`cowshed: cpu-pool wait done elapsed=${waitedMs}ms status=ok tokens=${grant.tokens}/${demand.want} runner=${demand.kind}\n`,
|
|
536
545
|
);
|
|
546
|
+
} else if (leaf !== null) {
|
|
547
|
+
sized = sizeRunner(demand, requested, demand.want);
|
|
537
548
|
}
|
|
538
549
|
// The run's sub-pool and grant are given back exactly once, however the run ends. The sub-pool closes first, so no
|
|
539
550
|
// descendant still draws on tokens the grant has returned.
|
|
@@ -575,7 +586,13 @@ export async function runBoundedExec(
|
|
|
575
586
|
if (verdict.outcome === 'bound' && verdict.bound === 'test') {
|
|
576
587
|
appendStderr(`Every failing test failed only on its per-test timeout: ${verdict.tests.join(', ')}\n`);
|
|
577
588
|
}
|
|
578
|
-
await writeRecord(recordDirectory, {
|
|
589
|
+
await writeRecord(recordDirectory, {
|
|
590
|
+
task: task.id,
|
|
591
|
+
hash: task.hash,
|
|
592
|
+
verdict,
|
|
593
|
+
...(cpu ? { cpu } : {}),
|
|
594
|
+
...(parentWait ? { cpuWait: parentWait } : {}),
|
|
595
|
+
});
|
|
579
596
|
};
|
|
580
597
|
// A run refused before its command starts says why, gives back its grant and RAM, and records the failure.
|
|
581
598
|
const refuse = async (message: string): Promise<BoundedExecResult> => {
|
|
@@ -627,7 +644,8 @@ export async function runBoundedExec(
|
|
|
627
644
|
const startedAt = Date.now();
|
|
628
645
|
// With a supervisor, `cowshed subtree-root` asks it for a handle on itself, writes the answer to the handle
|
|
629
646
|
// descriptor, and execs `/bin/sh -c command` in the same process: the command's pid, group and life are unchanged.
|
|
630
|
-
const
|
|
647
|
+
const unadmitted = hooked?.command ?? (fixture === null ? command : `${fixture.command} && ${command}`);
|
|
648
|
+
const shellCommand = leaf === null ? unadmitted : withMbxLeaf(unadmitted, leaf);
|
|
631
649
|
const root = owner?.rootArgv(shellCommand);
|
|
632
650
|
let child: ChildProcess;
|
|
633
651
|
try {
|