@smoothbricks/nx-plugin 0.4.25 → 0.4.27
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 +1078 -98
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +16 -85
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +16 -17
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +37 -44
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +50 -8
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +691 -71
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +108 -12
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +299 -18
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +213 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +624 -177
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +435 -230
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.js +3 -2
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -62
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +607 -17
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -75
- package/package.json +75 -13
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +730 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +157 -2
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +17 -86
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -22
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +432 -62
- package/src/cargo-closure-input.ts +51 -57
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +1044 -0
- package/src/cargo-source-hash.test.ts +203 -93
- package/src/cargo-source-hash.ts +762 -75
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +344 -18
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1043 -483
- package/src/ensure-built.ts +870 -197
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +1070 -360
- package/src/index.ts +524 -255
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-assets.ts +12 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +3 -2
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +495 -0
- package/src/nx-cache-bound.test.ts +109 -0
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +112 -0
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +99 -0
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +181 -0
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -1
- package/test-timings.json +85 -28
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
- package/src/__tests__/in-process-nx-index.ts +0 -9
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { TRACE_DB_DIRECTORY, TRACE_DB_FILENAME } from '@smoothbricks/lmao/sqlite';
|
|
3
|
+
import { TRACE_DB_ARTIFACT_GLOB } from './ci-workflow.js';
|
|
4
|
+
|
|
5
|
+
it('uploads the trace sink from where lmao writes it, WAL sidecars included', () => {
|
|
6
|
+
expect(TRACE_DB_ARTIFACT_GLOB).toBe(`packages/*/${TRACE_DB_DIRECTORY}/${TRACE_DB_FILENAME}*`);
|
|
7
|
+
});
|
|
@@ -11,6 +11,11 @@ export interface ManagedFile {
|
|
|
11
11
|
target: string;
|
|
12
12
|
content: string | null;
|
|
13
13
|
executable?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Why a `null` content is null, when the generator chose not to write a target
|
|
16
|
+
* it would otherwise own. Reported on the `skipped` result; it blocks nothing.
|
|
17
|
+
*/
|
|
18
|
+
skipReason?: string;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
/** Only facts Tree cannot expose. File contents always come from Tree. */
|
|
@@ -64,7 +69,7 @@ export function stageManagedFiles(
|
|
|
64
69
|
const seen = new Set<string>();
|
|
65
70
|
const pending = new Map(tree.listChanges().map((change) => [change.path, change]));
|
|
66
71
|
const targets = new Set(files.map((file) => file.target));
|
|
67
|
-
return files.map(({ target, content, executable = false }): FileResult => {
|
|
72
|
+
return files.map(({ target, content, executable = false, skipReason }): FileResult => {
|
|
68
73
|
const conflict = (reason: string): FileResult => ({ target, action: 'drifted', reason });
|
|
69
74
|
if (!isManagedTarget(target)) return conflict('expected a canonical workspace-relative path');
|
|
70
75
|
if (seen.has(target)) return conflict('duplicate managed target');
|
|
@@ -73,7 +78,10 @@ export function stageManagedFiles(
|
|
|
73
78
|
if (parts.some((_, i) => i > 0 && targets.has(parts.slice(0, i).join('/')))) {
|
|
74
79
|
return conflict('a managed file is also declared as a parent directory');
|
|
75
80
|
}
|
|
76
|
-
if (content === null)
|
|
81
|
+
if (content === null)
|
|
82
|
+
return skipReason === undefined
|
|
83
|
+
? { target, action: 'skipped' }
|
|
84
|
+
: { target, action: 'skipped', reason: skipReason };
|
|
77
85
|
const path = paths.get(target);
|
|
78
86
|
if (path?.error) return conflict(path.error);
|
|
79
87
|
for (let i = 1; i < parts.length; i++) {
|
|
@@ -109,7 +117,7 @@ export function stageManagedFiles(
|
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
export function assertNoManagedConflicts(results: readonly FileResult[]): void {
|
|
112
|
-
const conflicts = results.filter((result) => result.reason !== undefined);
|
|
120
|
+
const conflicts = results.filter((result) => result.action === 'drifted' && result.reason !== undefined);
|
|
113
121
|
if (conflicts.length > 0) {
|
|
114
122
|
throw new ManagedContentConflict(
|
|
115
123
|
`Managed-file update refused before writing:\n${conflicts.map(({ target, reason }) => `${target}: ${reason}`).join('\n')}`,
|
package/src/manifest-hash.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createHash, type Hash } from 'node:crypto';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { join, posix } from 'node:path';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { globIndexedFiles } from './workspace-index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A release rewrites `version` in every manifest it publishes. Those manifests
|
|
@@ -180,7 +180,8 @@ export async function hashVersionlessCrateManifests(projectRoot: string, workspa
|
|
|
180
180
|
*/
|
|
181
181
|
async function listCrateManifests(projectRoot: string, workspaceRoot: string): Promise<string[]> {
|
|
182
182
|
const prefix = projectRoot === '.' ? '' : `${posix.normalize(projectRoot)}/`;
|
|
183
|
-
const
|
|
183
|
+
const pattern = [`${prefix}**/${CARGO_MANIFEST}`];
|
|
184
|
+
const files = await globIndexedFiles(workspaceRoot, pattern);
|
|
184
185
|
return files.map((file) => file.slice(prefix.length)).sort();
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { chmodSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { codeTime, describeCodeTime, parseWaitRecord, type WaitEdge } from './nextest-code-bound.js';
|
|
8
|
+
|
|
9
|
+
const WRAPPER = fileURLToPath(new URL('./nextest-code-bound.ts', import.meta.url));
|
|
10
|
+
|
|
11
|
+
const start = (pid: number, seq: number, atUs: number): WaitEdge => ({
|
|
12
|
+
kind: 'start',
|
|
13
|
+
pid,
|
|
14
|
+
seq,
|
|
15
|
+
atUs,
|
|
16
|
+
diskClass: 'storage',
|
|
17
|
+
});
|
|
18
|
+
const end = (pid: number, seq: number, atUs: number): WaitEdge => ({ kind: 'end', pid, seq, atUs });
|
|
19
|
+
|
|
20
|
+
describe('lease-wait record', () => {
|
|
21
|
+
it('reads both edge shapes as clients write them and refuses anything else', () => {
|
|
22
|
+
expect(parseWaitRecord('start 7 0 100 storage\nend 7 0 250\n')).toEqual({
|
|
23
|
+
ok: true,
|
|
24
|
+
edges: [start(7, 0, 100), end(7, 0, 250)],
|
|
25
|
+
});
|
|
26
|
+
expect(parseWaitRecord('')).toEqual({ ok: true, edges: [] });
|
|
27
|
+
for (const bad of [
|
|
28
|
+
'start 7 0 100',
|
|
29
|
+
'end 7 0',
|
|
30
|
+
'end 7 0 1 x',
|
|
31
|
+
'begin 7 0 1',
|
|
32
|
+
'end 7 -1 5',
|
|
33
|
+
'start 7 0 1.5 storage',
|
|
34
|
+
]) {
|
|
35
|
+
expect(parseWaitRecord(`${bad}\n`).ok).toBe(false);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('code time', () => {
|
|
41
|
+
it('is the wall time less every wait', () => {
|
|
42
|
+
const time = codeTime([start(1, 0, 1_000), end(1, 0, 3_000), start(1, 1, 5_000), end(1, 1, 6_000)], 0, 10_000);
|
|
43
|
+
expect(time).toEqual({ wallUs: 10_000, waitUs: 3_000, codeUs: 7_000, waits: 2, open: [], strayEnds: 0 });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('counts concurrent waits of several processes once, as their union', () => {
|
|
47
|
+
const edges = [
|
|
48
|
+
start(1, 0, 1_000),
|
|
49
|
+
start(2, 0, 2_000),
|
|
50
|
+
end(1, 0, 4_000),
|
|
51
|
+
end(2, 0, 5_000),
|
|
52
|
+
start(1, 1, 4_500),
|
|
53
|
+
end(1, 1, 4_800),
|
|
54
|
+
];
|
|
55
|
+
expect(codeTime(edges, 0, 10_000)).toMatchObject({ waitUs: 4_000, codeUs: 6_000, waits: 3 });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('clips waits to the test run', () => {
|
|
59
|
+
expect(codeTime([start(1, 0, 0), end(1, 0, 3_000)], 1_000, 5_000)).toMatchObject({ waitUs: 2_000, codeUs: 2_000 });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('counts a wait that never ended to the end of the test and names it', () => {
|
|
63
|
+
const time = codeTime([start(1, 0, 1_000), end(1, 0, 2_000), start(9, 3, 8_000)], 0, 10_000);
|
|
64
|
+
expect(time).toMatchObject({ waitUs: 3_000, codeUs: 7_000, open: [{ pid: 9, seq: 3, startedUs: 8_000 }] });
|
|
65
|
+
expect(describeCodeTime(time, 30_000_000)).toContain("pid 9's wait 3 never ended");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('counts an end without a start as code time', () => {
|
|
69
|
+
expect(codeTime([end(1, 0, 2_000)], 0, 10_000)).toMatchObject({ waitUs: 0, codeUs: 10_000, strayEnds: 1 });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('says whether the code time is within its class', () => {
|
|
73
|
+
const time = codeTime([start(1, 0, 0), end(1, 0, 20_000_000)], 0, 45_000_000);
|
|
74
|
+
expect(describeCodeTime(time, 30_000_000)).toBe(
|
|
75
|
+
'nextest-code-bound: code 25.0s of 30.0s, within its class (wall 45.0s less 20.0s waiting for the host disk lease over 1 waits)',
|
|
76
|
+
);
|
|
77
|
+
expect(describeCodeTime(time, 20_000_000)).toStartWith(
|
|
78
|
+
'nextest-code-bound: code 25.0s of 20.0s, OVER its class (a warning)',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('nextest-code-bound wrapper', () => {
|
|
84
|
+
/**
|
|
85
|
+
* A stand-in test binary: it records `wait` seconds of lease wait in the record its wrapper names,
|
|
86
|
+
* from a child process as a disk-lease client in the test's tree would, then works `work` seconds
|
|
87
|
+
* and exits `status`.
|
|
88
|
+
*/
|
|
89
|
+
const runWrapped = (bound: string, wait: number, work: number, status: number) => {
|
|
90
|
+
const root = mkdtempSync(join(tmpdir(), 'nextest-code-bound-'));
|
|
91
|
+
try {
|
|
92
|
+
const binary = join(root, 'fake-test');
|
|
93
|
+
writeFileSync(
|
|
94
|
+
binary,
|
|
95
|
+
[
|
|
96
|
+
'#!/bin/sh',
|
|
97
|
+
'sh -c \'echo "start $$ 0 $(perl -MTime::HiRes=time -e "printf q(%d), time() * 1000000") namespace" >> "$COWSHED_LEASE_WAIT_RECORD"; ' +
|
|
98
|
+
`sleep ${wait}; ` +
|
|
99
|
+
'echo "end $$ 0 $(perl -MTime::HiRes=time -e "printf q(%d), time() * 1000000")" >> "$COWSHED_LEASE_WAIT_RECORD"\'',
|
|
100
|
+
`sleep ${work}`,
|
|
101
|
+
'echo "argument $1"',
|
|
102
|
+
`exit ${status}`,
|
|
103
|
+
].join('\n'),
|
|
104
|
+
);
|
|
105
|
+
chmodSync(binary, 0o755);
|
|
106
|
+
// The wrapper makes its record in its TMPDIR: this case's own root, so the count below is this run's alone.
|
|
107
|
+
const run = spawnSync(WRAPPER, [bound, binary, '--exact'], {
|
|
108
|
+
encoding: 'utf8',
|
|
109
|
+
env: { ...process.env, TMPDIR: root },
|
|
110
|
+
});
|
|
111
|
+
const recordsLeft = readdirSync(root).filter((name) => name.startsWith('cowshed-lease-waits-')).length;
|
|
112
|
+
return { status: run.status, stdout: run.stdout, stderr: run.stderr, recordsLeft };
|
|
113
|
+
} finally {
|
|
114
|
+
rmSync(root, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Real processes and real time, so the cases sleep as little as proves each verdict: 0.75s in all.
|
|
119
|
+
it('passes a test whose wall time is over its class only by its lease waits', () => {
|
|
120
|
+
const run = runWrapped('0.3', 0.4, 0, 0);
|
|
121
|
+
expect(run.stdout).toContain('argument --exact');
|
|
122
|
+
expect(run.stderr).toMatch(
|
|
123
|
+
/nextest-code-bound: code 0\.\d+s of 0\.3s, within its class \(wall \d+\.\d+s less \d+\.\ds waiting/,
|
|
124
|
+
);
|
|
125
|
+
expect(run.status).toBe(0);
|
|
126
|
+
expect(run.recordsLeft).toBe(0);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('reports code-time verdicts without changing the test exit status', () => {
|
|
130
|
+
for (const { label, bound, work, status, verdict } of [
|
|
131
|
+
{
|
|
132
|
+
label: 'warns of a passing test whose code time is over its class, and still passes it',
|
|
133
|
+
bound: '0.3',
|
|
134
|
+
work: 0.35,
|
|
135
|
+
status: 0,
|
|
136
|
+
verdict: 'OVER its class (a warning)',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
label: "keeps a failing test's own exit status and still reports its split",
|
|
140
|
+
bound: '30',
|
|
141
|
+
work: 0,
|
|
142
|
+
status: 3,
|
|
143
|
+
verdict: 'within its class',
|
|
144
|
+
},
|
|
145
|
+
]) {
|
|
146
|
+
const run = runWrapped(bound, 0, work, status);
|
|
147
|
+
expect(run.stderr, label).toContain(verdict);
|
|
148
|
+
expect(run.status, label).toBe(status);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('refuses to run without a class', () => {
|
|
153
|
+
expect(spawnSync(WRAPPER, ['soon', '/bin/true'], { encoding: 'utf8' }).status).toBe(2);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A nextest run-wrapper that measures a test's code time rather than its wall time against its class
|
|
11
|
+
* (specs/cowshed/08_testing.md, "Integration tests (real substrate)").
|
|
12
|
+
*
|
|
13
|
+
* A real-APFS test spends part of its wall time queued for the host disk-lifecycle lease, behind
|
|
14
|
+
* every other cowshed process on the host (05_gateway.md, "Disk-lifecycle lease"). That queue is
|
|
15
|
+
* the host's, not the test's code. The wrapper names a fresh lease-wait record in
|
|
16
|
+
* `COWSHED_LEASE_WAIT_RECORD`, runs the test binary, which every disk-lease client of the test's
|
|
17
|
+
* process tree appends its waits to, and then measures the test's code time, its wall time less the
|
|
18
|
+
* union of those waits, against the class it was configured with. It says the split on stderr after
|
|
19
|
+
* the test body, and warns when the code time is over the class; the test keeps its own exit status.
|
|
20
|
+
* A class is a slow warning, never a kill or a failure: the run's no-progress bound ends a hang.
|
|
21
|
+
*
|
|
22
|
+
* Usage, as nextest invokes it: `nextest-code-bound.ts <class-seconds> <test-binary> [args…]`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** The variable naming the record; the same name every disk-lease client reads. */
|
|
26
|
+
export const LEASE_WAIT_RECORD_ENV = 'COWSHED_LEASE_WAIT_RECORD';
|
|
27
|
+
|
|
28
|
+
/** One line of the record: a wait's start, before its client asks, or its end, however it ended. */
|
|
29
|
+
export type WaitEdge =
|
|
30
|
+
| {
|
|
31
|
+
readonly kind: 'start';
|
|
32
|
+
readonly pid: number;
|
|
33
|
+
readonly seq: number;
|
|
34
|
+
readonly atUs: number;
|
|
35
|
+
readonly diskClass: string;
|
|
36
|
+
}
|
|
37
|
+
| { readonly kind: 'end'; readonly pid: number; readonly seq: number; readonly atUs: number };
|
|
38
|
+
|
|
39
|
+
export type ParsedRecord = { ok: true; edges: WaitEdge[] } | { ok: false; error: string };
|
|
40
|
+
|
|
41
|
+
const INTEGER = /^\d+$/;
|
|
42
|
+
|
|
43
|
+
/** Reads a record as its clients write it. Any line that is not one of the two shapes is refused. */
|
|
44
|
+
export function parseWaitRecord(text: string): ParsedRecord {
|
|
45
|
+
const edges: WaitEdge[] = [];
|
|
46
|
+
for (const line of text.split('\n')) {
|
|
47
|
+
if (line === '') {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const fields = line.split(' ');
|
|
51
|
+
const [kind, pid, seq, atUs] = fields;
|
|
52
|
+
const numeric = [pid, seq, atUs].every((field) => field !== undefined && INTEGER.test(field));
|
|
53
|
+
if (kind === 'start' && fields.length === 5 && numeric) {
|
|
54
|
+
edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs), diskClass: fields[4] });
|
|
55
|
+
} else if (kind === 'end' && fields.length === 4 && numeric) {
|
|
56
|
+
edges.push({ kind, pid: Number(pid), seq: Number(seq), atUs: Number(atUs) });
|
|
57
|
+
} else {
|
|
58
|
+
return { ok: false, error: `line ${JSON.stringify(line)} is neither a wait's start nor its end` };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { ok: true, edges };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A wait whose end never reached the record: its process died while waiting, or still waits. */
|
|
65
|
+
export interface OpenWait {
|
|
66
|
+
readonly pid: number;
|
|
67
|
+
readonly seq: number;
|
|
68
|
+
readonly startedUs: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CodeTime {
|
|
72
|
+
readonly wallUs: number;
|
|
73
|
+
/** The union of every wait, clipped to the test's run: concurrent waits count once. */
|
|
74
|
+
readonly waitUs: number;
|
|
75
|
+
readonly codeUs: number;
|
|
76
|
+
readonly waits: number;
|
|
77
|
+
/** Counted to the test's end: the record cannot say when they stopped. */
|
|
78
|
+
readonly open: readonly OpenWait[];
|
|
79
|
+
/** Ends with no start, which can only follow an unwritable start: counted as code time. */
|
|
80
|
+
readonly strayEnds: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The test's code time: its wall time from `startedUs` to `endedUs` less the union of its waits. */
|
|
84
|
+
export function codeTime(edges: readonly WaitEdge[], startedUs: number, endedUs: number): CodeTime {
|
|
85
|
+
const starts = new Map<string, { atUs: number; pid: number; seq: number }>();
|
|
86
|
+
const intervals: Array<[number, number]> = [];
|
|
87
|
+
let strayEnds = 0;
|
|
88
|
+
for (const edge of edges) {
|
|
89
|
+
const key = `${edge.pid}:${edge.seq}`;
|
|
90
|
+
if (edge.kind === 'start') {
|
|
91
|
+
starts.set(key, { atUs: edge.atUs, pid: edge.pid, seq: edge.seq });
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const start = starts.get(key);
|
|
95
|
+
if (start === undefined) {
|
|
96
|
+
strayEnds += 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
starts.delete(key);
|
|
100
|
+
intervals.push([start.atUs, edge.atUs]);
|
|
101
|
+
}
|
|
102
|
+
const open = [...starts.values()].map(({ pid, seq, atUs }) => ({ pid, seq, startedUs: atUs }));
|
|
103
|
+
for (const wait of open) {
|
|
104
|
+
intervals.push([wait.startedUs, endedUs]);
|
|
105
|
+
}
|
|
106
|
+
const waits = intervals.length;
|
|
107
|
+
const clipped = intervals
|
|
108
|
+
.map(([from, to]): [number, number] => [Math.max(from, startedUs), Math.min(to, endedUs)])
|
|
109
|
+
.filter(([from, to]) => to > from)
|
|
110
|
+
.sort((left, right) => left[0] - right[0]);
|
|
111
|
+
let waitUs = 0;
|
|
112
|
+
let reach = startedUs;
|
|
113
|
+
for (const [from, to] of clipped) {
|
|
114
|
+
const begin = Math.max(from, reach);
|
|
115
|
+
if (to > begin) {
|
|
116
|
+
waitUs += to - begin;
|
|
117
|
+
reach = to;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const wallUs = Math.max(0, endedUs - startedUs);
|
|
121
|
+
return { wallUs, waitUs, codeUs: wallUs - waitUs, waits, open, strayEnds };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const seconds = (us: number): string => `${(us / 1_000_000).toFixed(1)}s`;
|
|
125
|
+
|
|
126
|
+
/** The one line the wrapper prints after the test body. */
|
|
127
|
+
export function describeCodeTime(time: CodeTime, classUs: number): string {
|
|
128
|
+
const verdict = time.codeUs > classUs ? 'OVER its class (a warning)' : 'within its class';
|
|
129
|
+
const parts = [
|
|
130
|
+
`nextest-code-bound: code ${seconds(time.codeUs)} of ${seconds(classUs)}, ${verdict}`,
|
|
131
|
+
`(wall ${seconds(time.wallUs)} less ${seconds(time.waitUs)} waiting for the host disk lease over ${time.waits} waits)`,
|
|
132
|
+
];
|
|
133
|
+
for (const wait of time.open) {
|
|
134
|
+
parts.push(`; pid ${wait.pid}'s wait ${wait.seq} never ended and counts to the test's end`);
|
|
135
|
+
}
|
|
136
|
+
if (time.strayEnds > 0) {
|
|
137
|
+
parts.push(`; ${time.strayEnds} wait ends had no recorded start and count as code time`);
|
|
138
|
+
}
|
|
139
|
+
return parts.join(' ');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const CLASS_PATTERN = /^\d+(\.\d+)?$/;
|
|
143
|
+
|
|
144
|
+
/** The signals the wrapper passes on to the test rather than dying of. */
|
|
145
|
+
const FORWARDED: readonly NodeJS.Signals[] = ['SIGTERM', 'SIGINT', 'SIGHUP'];
|
|
146
|
+
|
|
147
|
+
/** Runs the test under the record, reports its code time, and exits as the test did. */
|
|
148
|
+
async function main(argv: readonly string[]): Promise<never> {
|
|
149
|
+
const [codeClass, binary, ...args] = argv;
|
|
150
|
+
if (codeClass === undefined || !CLASS_PATTERN.test(codeClass) || Number(codeClass) <= 0 || binary === undefined) {
|
|
151
|
+
process.stderr.write('nextest-code-bound: usage: nextest-code-bound.ts <class-seconds> <test-binary> [args…]\n');
|
|
152
|
+
process.exit(2);
|
|
153
|
+
}
|
|
154
|
+
const classUs = Number(codeClass) * 1_000_000;
|
|
155
|
+
const record = join(tmpdir(), `cowshed-lease-waits-${process.pid}-${randomUUID()}`);
|
|
156
|
+
writeFileSync(record, '', { mode: 0o600, flag: 'wx' });
|
|
157
|
+
const startedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
|
|
158
|
+
const child = spawn(binary, args, { stdio: 'inherit', env: { ...process.env, [LEASE_WAIT_RECORD_ENV]: record } });
|
|
159
|
+
// nextest stops a test by signalling its process group, which the child is in; the wrapper stays
|
|
160
|
+
// to report what the stopped test spent, and passes on a signal sent to it alone.
|
|
161
|
+
const handlers = FORWARDED.map((signal) => {
|
|
162
|
+
const handler = () => {
|
|
163
|
+
child.kill(signal);
|
|
164
|
+
};
|
|
165
|
+
process.on(signal, handler);
|
|
166
|
+
return { signal, handler };
|
|
167
|
+
});
|
|
168
|
+
const exit = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((settle) => {
|
|
169
|
+
child.once('error', (error) => {
|
|
170
|
+
process.stderr.write(`nextest-code-bound: could not start ${binary}: ${error.message}\n`);
|
|
171
|
+
settle({ code: 1, signal: null });
|
|
172
|
+
});
|
|
173
|
+
child.once('exit', (code, signal) => settle({ code, signal }));
|
|
174
|
+
});
|
|
175
|
+
const endedUs = Math.round((performance.timeOrigin + performance.now()) * 1000);
|
|
176
|
+
for (const { signal, handler } of handlers) {
|
|
177
|
+
process.removeListener(signal, handler);
|
|
178
|
+
}
|
|
179
|
+
const parsed = parseWaitRecord(readFileSync(record, 'utf8'));
|
|
180
|
+
rmSync(record, { force: true });
|
|
181
|
+
if (!parsed.ok) {
|
|
182
|
+
process.stderr.write(`nextest-code-bound: the lease-wait record ${record} is unreadable: ${parsed.error}\n`);
|
|
183
|
+
process.exit(exit.code === 0 ? 1 : (exit.code ?? 1));
|
|
184
|
+
}
|
|
185
|
+
const time = codeTime(parsed.edges, startedUs, endedUs);
|
|
186
|
+
process.stderr.write(`${describeCodeTime(time, classUs)}\n`);
|
|
187
|
+
if (exit.signal !== null) {
|
|
188
|
+
process.kill(process.pid, exit.signal);
|
|
189
|
+
}
|
|
190
|
+
process.exit(exit.code ?? 1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
194
|
+
await main(process.argv.slice(2));
|
|
195
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readdir, realpath, rm, stat, utimes, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { tmpdir } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
import {
|
|
6
7
|
EXTRACTED_BINARIES_METADATA,
|
|
7
8
|
EXTRACTED_CARGO_METADATA,
|
|
8
9
|
ensureNextestArchiveExtracted,
|
|
10
|
+
NEXTEST_EXTRACTION_DIRECTORY,
|
|
9
11
|
type NextestArchiveExtractor,
|
|
10
12
|
type NextestExtractionEvent,
|
|
11
13
|
nextestArchiveKey,
|
|
12
14
|
nextestExtractionPaths,
|
|
15
|
+
nextestExtractionRoot,
|
|
13
16
|
} from './nextest-extraction.js';
|
|
14
17
|
|
|
15
18
|
/** What nextest leaves behind: the two metadata files a reuse run reads. */
|
|
@@ -27,7 +30,7 @@ describe('ensureNextestArchiveExtracted', () => {
|
|
|
27
30
|
try {
|
|
28
31
|
const archive = join(root, 'archive.tar.zst');
|
|
29
32
|
await writeFile(archive, 'archive bytes');
|
|
30
|
-
const paths = nextestExtractionPaths(
|
|
33
|
+
const paths = nextestExtractionPaths(join(root, 'extractions'), await nextestArchiveKey(archive));
|
|
31
34
|
// A holder killed mid-extraction (a bounded run's SIGKILL) leaves its
|
|
32
35
|
// lock behind, and a pid in it that may since belong to anyone.
|
|
33
36
|
await mkdir(paths.root, { recursive: true });
|
|
@@ -36,7 +39,13 @@ describe('ensureNextestArchiveExtracted', () => {
|
|
|
36
39
|
await utimes(paths.lock, minuteAgo, minuteAgo);
|
|
37
40
|
|
|
38
41
|
const events: NextestExtractionEvent[] = [];
|
|
39
|
-
const extraction = await ensureNextestArchiveExtracted(
|
|
42
|
+
const extraction = await ensureNextestArchiveExtracted(
|
|
43
|
+
archive,
|
|
44
|
+
paths.root,
|
|
45
|
+
unpack,
|
|
46
|
+
(event) => events.push(event),
|
|
47
|
+
FAST,
|
|
48
|
+
);
|
|
40
49
|
|
|
41
50
|
expect(extraction).toMatchObject({ kind: 'extracted', directory: paths.directory });
|
|
42
51
|
expect(events).toEqual([{ kind: 'stale-lock', holder: `pid ${process.pid}`, ageMs: expect.any(Number) }]);
|
|
@@ -51,7 +60,7 @@ describe('ensureNextestArchiveExtracted', () => {
|
|
|
51
60
|
try {
|
|
52
61
|
const archive = join(root, 'archive.tar.zst');
|
|
53
62
|
await writeFile(archive, 'archive bytes');
|
|
54
|
-
const paths = nextestExtractionPaths(
|
|
63
|
+
const paths = nextestExtractionPaths(join(root, 'extractions'), await nextestArchiveKey(archive));
|
|
55
64
|
// Unpacked from the old bytes, but the directory would be named for
|
|
56
65
|
// them while the path now holds others: a later run hashing the new
|
|
57
66
|
// bytes would never find it, and one hashing the old bytes again — the
|
|
@@ -61,7 +70,7 @@ describe('ensureNextestArchiveExtracted', () => {
|
|
|
61
70
|
await writeFile(archive, 'rebuilt archive bytes');
|
|
62
71
|
};
|
|
63
72
|
|
|
64
|
-
await expect(ensureNextestArchiveExtracted(archive, rebuiltMidway, () => {}, FAST)).rejects.toThrow(
|
|
73
|
+
await expect(ensureNextestArchiveExtracted(archive, paths.root, rebuiltMidway, () => {}, FAST)).rejects.toThrow(
|
|
65
74
|
/changed while it was being extracted/,
|
|
66
75
|
);
|
|
67
76
|
// No directory under the old key, no staging left over, no lock held.
|
|
@@ -72,3 +81,26 @@ describe('ensureNextestArchiveExtracted', () => {
|
|
|
72
81
|
}
|
|
73
82
|
});
|
|
74
83
|
});
|
|
84
|
+
|
|
85
|
+
describe('nextestExtractionRoot', () => {
|
|
86
|
+
it("extracts under the target directory Cargo reports, never beside the archive's Nx output", async () => {
|
|
87
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'nextest-extraction-root-')));
|
|
88
|
+
try {
|
|
89
|
+
await writeFile(
|
|
90
|
+
join(root, 'Cargo.toml'),
|
|
91
|
+
'[package]\nname = "extraction-root-probe"\nversion = "0.1.0"\nedition = "2021"\n',
|
|
92
|
+
);
|
|
93
|
+
await mkdir(join(root, 'src'));
|
|
94
|
+
await writeFile(join(root, 'src/lib.rs'), '');
|
|
95
|
+
expect(spawnSync('cargo', ['generate-lockfile', '--offline'], { cwd: root }).status).toBe(0);
|
|
96
|
+
expect(await nextestExtractionRoot(root)).toBe(join(root, 'target', NEXTEST_EXTRACTION_DIRECTORY));
|
|
97
|
+
|
|
98
|
+
// A repository that moves Cargo's build tree moves its extractions with it.
|
|
99
|
+
await mkdir(join(root, '.cargo'));
|
|
100
|
+
await writeFile(join(root, '.cargo/config.toml'), '[build]\ntarget-dir = "out/cargo"\n');
|
|
101
|
+
expect(await nextestExtractionRoot(root)).toBe(join(root, 'out/cargo', NEXTEST_EXTRACTION_DIRECTORY));
|
|
102
|
+
} finally {
|
|
103
|
+
await rm(root, { recursive: true, force: true });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -62,9 +62,19 @@ export async function nextestArchiveKey(archive: string): Promise<string> {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
65
|
+
* The directory, inside the Cargo target directory, that holds a workspace's
|
|
66
|
+
* archive extractions. An extraction is content-keyed per-checkout tool state
|
|
67
|
+
* of the same kind as the rest of the target directory: rebuilt from an Nx
|
|
68
|
+
* output, reused by the next run, never an Nx output itself. It therefore lives
|
|
69
|
+
* wherever Cargo's build tree lives, which a checkout that keeps its build state
|
|
70
|
+
* on its own volume already keeps off its source tree.
|
|
71
|
+
*/
|
|
72
|
+
export const NEXTEST_EXTRACTION_DIRECTORY = 'nextest-extracted';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A workspace's extractions live under one root, each under the hash of the
|
|
76
|
+
* bytes it came from; the lock and staging directories of a key carry that key
|
|
77
|
+
* as their prefix, so cleanup can tell them from another key's.
|
|
68
78
|
*/
|
|
69
79
|
export interface NextestExtractionPaths {
|
|
70
80
|
root: string;
|
|
@@ -73,8 +83,7 @@ export interface NextestExtractionPaths {
|
|
|
73
83
|
stagingPrefix: string;
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
export function nextestExtractionPaths(
|
|
77
|
-
const root = `${archive}.extracted`;
|
|
86
|
+
export function nextestExtractionPaths(root: string, key: string): NextestExtractionPaths {
|
|
78
87
|
return {
|
|
79
88
|
root,
|
|
80
89
|
directory: join(root, key),
|
|
@@ -84,8 +93,40 @@ export function nextestExtractionPaths(archive: string, key: string): NextestExt
|
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
/**
|
|
87
|
-
* The
|
|
88
|
-
*
|
|
96
|
+
* The extraction root of the Cargo workspace in `cwd`:
|
|
97
|
+
* `<target_directory>/nextest-extracted`, with the target directory Cargo itself
|
|
98
|
+
* reports, so a `build.target-dir` in the repository's Cargo config is honoured
|
|
99
|
+
* exactly as every build of the workspace honours it.
|
|
100
|
+
*/
|
|
101
|
+
export async function nextestExtractionRoot(cwd: string): Promise<string> {
|
|
102
|
+
const args = ['--frozen', 'metadata', '--no-deps', '--format-version', '1'];
|
|
103
|
+
const child = spawn('cargo', args, { cwd, stdio: ['ignore', 'pipe', 'inherit'] });
|
|
104
|
+
const chunks: Buffer[] = [];
|
|
105
|
+
child.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
106
|
+
// 'close', not 'exit': stdout may still hold unread metadata when the process exits.
|
|
107
|
+
const [code, signal]: unknown[] = await once(child, 'close');
|
|
108
|
+
if (code !== 0) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`cargo ${args.join(' ')} ${code === null ? `died of ${String(signal)}` : `exited with status ${String(code)}`}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return join(cargoTargetDirectory(Buffer.concat(chunks).toString('utf8')), NEXTEST_EXTRACTION_DIRECTORY);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `target_directory` from `cargo metadata --format-version 1` output. */
|
|
117
|
+
function cargoTargetDirectory(metadata: string): string {
|
|
118
|
+
const parsed: unknown = JSON.parse(metadata);
|
|
119
|
+
const directory =
|
|
120
|
+
typeof parsed === 'object' && parsed !== null && 'target_directory' in parsed ? parsed.target_directory : undefined;
|
|
121
|
+
if (typeof directory !== 'string' || directory.length === 0) {
|
|
122
|
+
throw new Error('cargo metadata named no target_directory');
|
|
123
|
+
}
|
|
124
|
+
return directory;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The directory under `root` holding `archive`'s extraction, extracting it
|
|
129
|
+
* first if no caller has yet.
|
|
89
130
|
*
|
|
90
131
|
* Correctness does not rest on the lock. An extraction lands under the hash of
|
|
91
132
|
* the bytes it came from by renaming a private staging directory into place,
|
|
@@ -96,20 +137,21 @@ export function nextestExtractionPaths(archive: string, key: string): NextestExt
|
|
|
96
137
|
* runner of one Nx run from unpacking the same bytes side by side, which is the
|
|
97
138
|
* cost it exists to remove.
|
|
98
139
|
*
|
|
99
|
-
* Publishing a key removes every other key's extraction
|
|
140
|
+
* Publishing a key removes every other key's extraction under `root`,
|
|
100
141
|
* including stale locks and staging left by a holder that died. Leftovers of
|
|
101
142
|
* the CURRENT key are not touched: a holder that took over a stale lock may
|
|
102
143
|
* still be extracting into one.
|
|
103
144
|
*/
|
|
104
145
|
export async function ensureNextestArchiveExtracted(
|
|
105
146
|
archive: string,
|
|
147
|
+
root: string,
|
|
106
148
|
extract: NextestArchiveExtractor,
|
|
107
149
|
onEvent: (event: NextestExtractionEvent) => void,
|
|
108
150
|
timing: NextestExtractionTiming = DEFAULT_TIMING,
|
|
109
151
|
): Promise<NextestExtraction> {
|
|
110
152
|
const started = performance.now();
|
|
111
153
|
const key = await nextestArchiveKey(archive);
|
|
112
|
-
const paths = nextestExtractionPaths(
|
|
154
|
+
const paths = nextestExtractionPaths(root, key);
|
|
113
155
|
if (await isDirectory(paths.directory)) {
|
|
114
156
|
return { kind: 'reused', key, directory: paths.directory };
|
|
115
157
|
}
|