@smoothbricks/nx-plugin 0.4.26 → 0.4.28
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 +994 -117
- 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 +15 -73
- 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 +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- 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 +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- 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 +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- 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 +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- 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 +370 -138
- 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.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- 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 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- 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 +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- 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 +1146 -159
- 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 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- 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 +16 -74
- 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 -21
- 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 +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- 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 +1036 -578
- package/src/ensure-built.ts +820 -224
- 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 +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -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 +2 -6
- 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 +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- 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 +7 -16
- 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 +26 -25
- 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 +87 -89
- 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 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { mkdir, mkdtemp, readdir, readFile, rm, stat, symlink, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
10
|
+
import { RUNTIME_INPUT_SCRIPT, runtimeInput, shellWord } from './runtime-input.js';
|
|
11
|
+
|
|
12
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
|
+
const repoRoot = dirname(dirname(packageRoot));
|
|
14
|
+
const script = join(packageRoot, 'runtime-input.sh');
|
|
15
|
+
const nxEntry = join(repoRoot, 'node_modules', '.bin', 'nx');
|
|
16
|
+
|
|
17
|
+
interface Ran {
|
|
18
|
+
readonly status: number | null;
|
|
19
|
+
readonly stdout: Buffer;
|
|
20
|
+
readonly stderr: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function wrapped(workspace: string, ...command: string[]): Ran {
|
|
24
|
+
const ran = spawnSync('sh', [script, ...command], { cwd: workspace, encoding: 'buffer' });
|
|
25
|
+
return { status: ran.status, stdout: ran.stdout, stderr: ran.stderr.toString('utf8') };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function withWrapperWorkspace(run: (workspace: string) => Promise<void>): Promise<void> {
|
|
29
|
+
const workspace = await mkdtemp(join(tmpdir(), 'runtime-input-wrapper-'));
|
|
30
|
+
try {
|
|
31
|
+
await run(workspace);
|
|
32
|
+
} finally {
|
|
33
|
+
await rm(workspace, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function failureRecord(workspace: string): Promise<string> {
|
|
38
|
+
const root = join(workspace, '.runtime-input-failures');
|
|
39
|
+
const records = await readdir(root);
|
|
40
|
+
expect(records).toHaveLength(1);
|
|
41
|
+
return join(root, records[0]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('runtime-input.sh', () => {
|
|
45
|
+
it('preserves successful stdout bytes and their hash exactly, including whitespace and UTF-8', async () => {
|
|
46
|
+
await withWrapperWorkspace(async (workspace) => {
|
|
47
|
+
const command = ['sh', '-c', "printf ' \tvalue café\n\n'; printf 'diagnostic\n\n' >&2"];
|
|
48
|
+
// The pre-evidence wrapper's success path: stdout passes through, stderr is discarded.
|
|
49
|
+
const baseline = spawnSync(
|
|
50
|
+
'sh',
|
|
51
|
+
[
|
|
52
|
+
'-c',
|
|
53
|
+
'exec 3>&1; if diagnostic=$("$@" 2>&1 >&3 3>&-); then exit 0; else exit "$?"; fi',
|
|
54
|
+
'baseline',
|
|
55
|
+
...command,
|
|
56
|
+
],
|
|
57
|
+
{ cwd: workspace, encoding: 'buffer' },
|
|
58
|
+
);
|
|
59
|
+
const ran = wrapped(workspace, ...command);
|
|
60
|
+
expect(baseline.status).toBe(0);
|
|
61
|
+
expect(baseline.stderr).toEqual(Buffer.alloc(0));
|
|
62
|
+
expect(ran).toEqual({ status: 0, stdout: Buffer.from(' \tvalue café\n\n'), stderr: '' });
|
|
63
|
+
expect(ran.stdout).toEqual(baseline.stdout);
|
|
64
|
+
const hash = (bytes: Buffer) => createHash('sha256').update(bytes).digest('hex');
|
|
65
|
+
expect(hash(ran.stdout)).toBe(hash(baseline.stdout));
|
|
66
|
+
expect(existsSync(join(workspace, '.runtime-input-failures'))).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('poisons a failure and durably retains exact argv, stderr and exit status', async () => {
|
|
71
|
+
await withWrapperWorkspace(async (workspace) => {
|
|
72
|
+
const command = [
|
|
73
|
+
'sh',
|
|
74
|
+
'-c',
|
|
75
|
+
String.raw`printf 'partial\n'; printf 'the-cause\000raw\n\n' >&2; exit 3`,
|
|
76
|
+
'--',
|
|
77
|
+
'',
|
|
78
|
+
'two words',
|
|
79
|
+
"a'quote",
|
|
80
|
+
'line\nbreak',
|
|
81
|
+
];
|
|
82
|
+
const ran = wrapped(workspace, ...command);
|
|
83
|
+
expect(ran.status).toBe(3);
|
|
84
|
+
expect(ran.stdout).toEqual(Buffer.from([...Buffer.from('partial\n'), 0xff]));
|
|
85
|
+
const record = await failureRecord(workspace);
|
|
86
|
+
expect((await stat(record)).mode & 0o777).toBe(0o700);
|
|
87
|
+
expect(await readFile(join(record, 'argv'))).toEqual(Buffer.from(`${command.join('\0')}\0`));
|
|
88
|
+
expect(await readFile(join(record, 'stderr'))).toEqual(Buffer.from('the-cause\0raw\n\n'));
|
|
89
|
+
expect(await readFile(join(record, 'exit-status'), 'utf8')).toBe('3\n');
|
|
90
|
+
const report = await readFile(join(record, 'report'), 'utf8');
|
|
91
|
+
expect(report).toContain('runtime input exited 3: sh -c');
|
|
92
|
+
expect(report).toContain('argv[4]: <>');
|
|
93
|
+
expect(report).toContain('the-cause\0raw\n\n');
|
|
94
|
+
// Direct invocation sees the attempted stderr notice; Nx is allowed to drop it.
|
|
95
|
+
expect(ran.stderr).toContain('the-cause');
|
|
96
|
+
expect(ran.stderr).toContain('runtime input exited 3: sh -c');
|
|
97
|
+
expect(ran.stderr).toContain(join(record, 'report'));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('refuses to run nothing', async () => {
|
|
102
|
+
await withWrapperWorkspace(async (workspace) => {
|
|
103
|
+
const ran = wrapped(workspace);
|
|
104
|
+
expect(ran.status).toBe(64);
|
|
105
|
+
expect(ran.stdout).toEqual(Buffer.from([0xff]));
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* WHY this test is permanent. Nx 23.2.1 hashes a runtime input's stdout and
|
|
112
|
+
* stderr and ignores its exit status; the wrapper's 0xFF byte is what makes a
|
|
113
|
+
* failed input an error instead of a key (runtime-input.sh). Planted through
|
|
114
|
+
* real Nx, both through the daemon that hashes for a workspace's clients and
|
|
115
|
+
* without one, the failure must stop the run before the task executes. A
|
|
116
|
+
* future Nx that hashes those bytes turns this red; one that honours the exit
|
|
117
|
+
* status changes the message, which is the cue to drop the byte.
|
|
118
|
+
*/
|
|
119
|
+
describe('a planted runtime input failure through real Nx', () => {
|
|
120
|
+
for (const daemon of [false, true]) {
|
|
121
|
+
it(`is an error, not a hash${daemon ? ', through the daemon' : ''}`, async () => {
|
|
122
|
+
await withNxFixture('runtime-input-', async ({ workspace, socketDirectory }) => {
|
|
123
|
+
await writeProbeWorkspace(workspace);
|
|
124
|
+
const env = { ...fixtureNxEnv(workspace, socketDirectory), NX_DAEMON: String(daemon) };
|
|
125
|
+
|
|
126
|
+
const good = nx(workspace, env, 'probe:good');
|
|
127
|
+
expect(good.status, good.output).toBe(0);
|
|
128
|
+
expect(existsSync(join(workspace, 'good.ran'))).toBe(true);
|
|
129
|
+
|
|
130
|
+
const planted = nx(workspace, env, 'probe:planted');
|
|
131
|
+
expect(planted.status, planted.output).toBe(1);
|
|
132
|
+
expect(planted.output).toContain('invalid utf-8 sequence');
|
|
133
|
+
expect(existsSync(join(workspace, 'planted.ran'))).toBe(false);
|
|
134
|
+
const record = await failureRecord(workspace);
|
|
135
|
+
expect(await readFile(join(record, 'argv'))).toEqual(Buffer.from('sh\0-c\0echo planted-cause >&2; exit 3\0'));
|
|
136
|
+
expect(await readFile(join(record, 'stderr'), 'utf8')).toBe('planted-cause\n');
|
|
137
|
+
expect(await readFile(join(record, 'exit-status'), 'utf8')).toBe('3\n');
|
|
138
|
+
expect(await readFile(join(record, 'report'), 'utf8')).toContain('planted-cause');
|
|
139
|
+
const reset = spawnSync('bun', [nxEntry, 'reset'], { cwd: workspace, env, encoding: 'utf8' });
|
|
140
|
+
expect(reset.status, `${reset.stdout}${reset.stderr}`).toBe(0);
|
|
141
|
+
expect(await readFile(join(record, 'stderr'), 'utf8')).toBe('planted-cause\n');
|
|
142
|
+
expect(await readFile(join(record, 'report'), 'utf8')).toContain('runtime input exited 3: sh -c');
|
|
143
|
+
});
|
|
144
|
+
}, 60_000);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('runtime inputs of this repository', () => {
|
|
149
|
+
it('all run through the wrapper', async () => {
|
|
150
|
+
const offenders: string[] = [];
|
|
151
|
+
const declared = (file: string, value: unknown): void => {
|
|
152
|
+
if (Array.isArray(value)) {
|
|
153
|
+
for (const item of value) declared(file, item);
|
|
154
|
+
} else if (value !== null && typeof value === 'object') {
|
|
155
|
+
for (const [key, item] of Object.entries(value)) {
|
|
156
|
+
if (key === 'runtime' && !String(item).startsWith(`sh ${RUNTIME_INPUT_SCRIPT} `))
|
|
157
|
+
offenders.push(`${file}: ${item}`);
|
|
158
|
+
else declared(file, item);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const tracked = spawnSync(
|
|
163
|
+
'git',
|
|
164
|
+
['ls-files', '-z', 'nx.json', 'package.json', '**/package.json', '**/project.json'],
|
|
165
|
+
{
|
|
166
|
+
cwd: repoRoot,
|
|
167
|
+
encoding: 'utf8',
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
expect(tracked.status, tracked.stderr).toBe(0);
|
|
171
|
+
for (const file of tracked.stdout.split('\0').filter(Boolean)) {
|
|
172
|
+
declared(file, JSON.parse(await readFile(join(repoRoot, file), 'utf8')));
|
|
173
|
+
}
|
|
174
|
+
// Inferred inputs: every one goes through runtimeInput(), never a literal.
|
|
175
|
+
for (const file of await readdir(join(packageRoot, 'src'))) {
|
|
176
|
+
if (!file.endsWith('.ts') || file.endsWith('.test.ts') || file === 'runtime-input.ts') continue;
|
|
177
|
+
const source = await readFile(join(packageRoot, 'src', file), 'utf8');
|
|
178
|
+
for (const literal of source.match(/\{\s*runtime:\s*[`'"]/g) ?? []) offenders.push(`src/${file}: ${literal}`);
|
|
179
|
+
}
|
|
180
|
+
expect(offenders).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
async function writeProbeWorkspace(workspace: string): Promise<void> {
|
|
185
|
+
expect(spawnSync('git', ['init', '--quiet', workspace]).status).toBe(0);
|
|
186
|
+
await mkdir(join(workspace, 'probe'), { recursive: true });
|
|
187
|
+
// The repository's own node_modules: the Nx under test, and the wrapper at the path inputs name it by.
|
|
188
|
+
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
189
|
+
await writeFile(join(workspace, 'nx.json'), JSON.stringify({ useDaemonProcess: true, cacheDirectory: '.nx/cache' }));
|
|
190
|
+
const target = (name: string, command: string) => ({
|
|
191
|
+
executor: 'nx:run-commands',
|
|
192
|
+
cache: true,
|
|
193
|
+
inputs: [runtimeInput(command)],
|
|
194
|
+
options: { command: `touch ${name}.ran` },
|
|
195
|
+
});
|
|
196
|
+
await writeFile(
|
|
197
|
+
join(workspace, 'probe', 'project.json'),
|
|
198
|
+
JSON.stringify({
|
|
199
|
+
name: 'probe',
|
|
200
|
+
targets: {
|
|
201
|
+
good: target('good', `sh -c ${shellWord('echo value; echo noise >&2')}`),
|
|
202
|
+
planted: target('planted', `sh -c ${shellWord('echo planted-cause >&2; exit 3')}`),
|
|
203
|
+
},
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function nx(workspace: string, env: Record<string, string>, target: string): { status: number | null; output: string } {
|
|
209
|
+
const ran = spawnSync('bun', [nxEntry, 'run', target, '--outputStyle=static'], {
|
|
210
|
+
cwd: workspace,
|
|
211
|
+
env,
|
|
212
|
+
encoding: 'utf8',
|
|
213
|
+
});
|
|
214
|
+
return { status: ran.status, output: `${ran.stdout}${ran.stderr}` };
|
|
215
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one script every Nx runtime input runs through, named as the workspace
|
|
3
|
+
* root's `node_modules` links this package: Nx runs runtime inputs from the
|
|
4
|
+
* workspace root. `runtime-input.sh` explains why it exists: Nx hashes a failed
|
|
5
|
+
* input's error text as its value.
|
|
6
|
+
*/
|
|
7
|
+
export const RUNTIME_INPUT_SCRIPT = 'node_modules/@smoothbricks/nx-plugin/runtime-input.sh';
|
|
8
|
+
|
|
9
|
+
/** A runtime input whose failure stops Nx. `command` is shell words, already quoted. */
|
|
10
|
+
export function runtimeInput(command: string): { runtime: string } {
|
|
11
|
+
return { runtime: `sh ${RUNTIME_INPUT_SCRIPT} ${command}` };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** One shell word: bare when nothing in it is special to `sh`, single-quoted otherwise. */
|
|
15
|
+
export function shellWord(word: string): string {
|
|
16
|
+
return /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'"'"'`)}'`;
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Tokens shared by Rust input inference and statement comparison. */
|
|
2
|
+
export interface RustToken {
|
|
3
|
+
readonly text: string;
|
|
4
|
+
readonly literal: boolean;
|
|
5
|
+
readonly local: boolean;
|
|
6
|
+
readonly kind: 'ident' | 'literal' | 'punct' | 'lifetime';
|
|
7
|
+
readonly offset: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const RUST_IDENT = /[A-Za-z_][A-Za-z0-9_]*/uy;
|
|
11
|
+
const RUST_NUMBER =
|
|
12
|
+
/(?:0[xob][0-9A-Fa-f_]+|[0-9][0-9_]*(?:\.[0-9][0-9_]*)?(?:[eE][+-]?[0-9_]+)?)(?:[iuf](?:8|16|32|64|128|size))?/uy;
|
|
13
|
+
const RUST_RAW_STRING = /b?r(#*)"/uy;
|
|
14
|
+
const RUST_CHAR = /b?'(?:\\(?:u\{[0-9A-Fa-f]+\}|x[0-9A-Fa-f]{2}|.)|[^\\'\n])'/uy;
|
|
15
|
+
/** Longest first: `..` is one token, so a range end (`0..5`) is never read as a tuple index after `.`. */
|
|
16
|
+
const RUST_PUNCT = ['..=', '::', '->', '=>', '==', '!=', '<=', '>=', '&&', '||', '..'];
|
|
17
|
+
|
|
18
|
+
/** A Rust lexer that keeps exactly what statement comparison needs: idents, literals, lifetimes, punctuation. */
|
|
19
|
+
export function rustTokens(text: string): RustToken[] {
|
|
20
|
+
const tokens: RustToken[] = [];
|
|
21
|
+
let index = 0;
|
|
22
|
+
const at = (pattern: RegExp): string | undefined => {
|
|
23
|
+
pattern.lastIndex = index;
|
|
24
|
+
return pattern.exec(text)?.[0];
|
|
25
|
+
};
|
|
26
|
+
const push = (kind: RustToken['kind'], start: number): void => {
|
|
27
|
+
tokens.push({ text: text.slice(start, index), literal: kind === 'literal', local: false, kind, offset: start });
|
|
28
|
+
};
|
|
29
|
+
while (index < text.length) {
|
|
30
|
+
const char = text[index] ?? '';
|
|
31
|
+
const start = index;
|
|
32
|
+
if (/\s/u.test(char)) index += 1;
|
|
33
|
+
else if (text.startsWith('//', index)) {
|
|
34
|
+
const end = text.indexOf('\n', index);
|
|
35
|
+
index = end === -1 ? text.length : end;
|
|
36
|
+
} else if (text.startsWith('/*', index)) {
|
|
37
|
+
let depth = 0;
|
|
38
|
+
do {
|
|
39
|
+
if (text.startsWith('/*', index)) depth += 1;
|
|
40
|
+
else if (text.startsWith('*/', index)) depth -= 1;
|
|
41
|
+
index += text.startsWith('/*', index) || text.startsWith('*/', index) ? 2 : 1;
|
|
42
|
+
} while (depth > 0 && index < text.length);
|
|
43
|
+
} else if (at(RUST_RAW_STRING) !== undefined) {
|
|
44
|
+
const raw = at(RUST_RAW_STRING) ?? '';
|
|
45
|
+
const close = `"${raw.slice(raw.indexOf('r') + 1, -1)}`;
|
|
46
|
+
const end = text.indexOf(close, index + raw.length);
|
|
47
|
+
index = end === -1 ? text.length : end + close.length;
|
|
48
|
+
push('literal', start);
|
|
49
|
+
} else if (char === '"' || (char === 'b' && text[index + 1] === '"')) {
|
|
50
|
+
index += char === 'b' ? 2 : 1;
|
|
51
|
+
while (index < text.length && text[index] !== '"') index += text[index] === '\\' ? 2 : 1;
|
|
52
|
+
index += 1;
|
|
53
|
+
push('literal', start);
|
|
54
|
+
} else if (at(RUST_CHAR) !== undefined) {
|
|
55
|
+
index += at(RUST_CHAR)?.length ?? 0;
|
|
56
|
+
push('literal', start);
|
|
57
|
+
} else if (char === "'") {
|
|
58
|
+
index += 1;
|
|
59
|
+
index += at(RUST_IDENT)?.length ?? 0;
|
|
60
|
+
push('lifetime', start);
|
|
61
|
+
} else if (at(RUST_IDENT) !== undefined) {
|
|
62
|
+
const ident = at(RUST_IDENT) ?? '';
|
|
63
|
+
index += ident.length;
|
|
64
|
+
push(ident === 'true' || ident === 'false' ? 'literal' : 'ident', start);
|
|
65
|
+
} else if (tokens.at(-1)?.text === '.' && /[0-9]/u.test(char)) {
|
|
66
|
+
// A tuple index (`pair.0.1`) names a field; lexed as a number it would read `0.1` as one float literal.
|
|
67
|
+
while (/[0-9]/u.test(text[index] ?? '')) index += 1;
|
|
68
|
+
push('ident', start);
|
|
69
|
+
} else if ((at(RUST_NUMBER) ?? '') !== '') {
|
|
70
|
+
index += at(RUST_NUMBER)?.length ?? 0;
|
|
71
|
+
push('literal', start);
|
|
72
|
+
} else {
|
|
73
|
+
index += RUST_PUNCT.find((punct) => text.startsWith(punct, index))?.length ?? 1;
|
|
74
|
+
push('punct', start);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return tokens;
|
|
78
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdtemp, readdir, readFile, rm } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, sep } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
8
|
+
import { createTaskGraph } from 'nx/src/tasks-runner/create-task-graph.js';
|
|
9
|
+
import { parse as parseToml } from 'smol-toml';
|
|
10
|
+
import typia from 'typia';
|
|
11
|
+
import {
|
|
12
|
+
type CargoWorkspacePackage,
|
|
13
|
+
cargoPackageTestInputs,
|
|
14
|
+
listCargoWorkspacePackages,
|
|
15
|
+
NEXTEST_REPO_CONFIG_PATH,
|
|
16
|
+
SERIAL_TEST_GROUP_PLATFORM,
|
|
17
|
+
serialTestGroups,
|
|
18
|
+
} from './cargo-workspace.js';
|
|
19
|
+
import { COWSHED_EXECUTABLE_ENV } from './executors/bounded-exec/ram-temp.js';
|
|
20
|
+
import { isRecord } from './type-guards.js';
|
|
21
|
+
|
|
22
|
+
/** The repository this package is built in: its own nextest config, nx.json and manifests are what these pin. */
|
|
23
|
+
const REPOSITORY = fileURLToPath(new URL('../../..', import.meta.url));
|
|
24
|
+
const ROOT_PROJECT = '@smoothbricks/codebase';
|
|
25
|
+
const DEVICE_GROUP = 'cargo-test-group-real-apfs';
|
|
26
|
+
const HOST_GROUP = 'cargo-test-group-real-apfs-host';
|
|
27
|
+
/** cowshed's build, which leaves the host's own CLI where the package's launcher finds it. */
|
|
28
|
+
const CHECKOUT_COWSHED_BUILD = { projects: ['cowshed'], target: 'build' };
|
|
29
|
+
|
|
30
|
+
describe('the real-APFS serial groups of this repository', () => {
|
|
31
|
+
it('are exactly the device group and the host group, each scoped to the packages it holds', () => {
|
|
32
|
+
const groups = serialTestGroups(join(REPOSITORY, NEXTEST_REPO_CONFIG_PATH));
|
|
33
|
+
// A third group is a decision about ordering against these two, test-host and the explicit tests below.
|
|
34
|
+
expect(groups.map(({ group, scope }) => ({ group, scope }))).toEqual([
|
|
35
|
+
{ group: 'real-apfs', scope: { kind: 'packages', packages: ['cowshed-apfs-tests'] } },
|
|
36
|
+
{ group: 'real-apfs-host', scope: { kind: 'packages', packages: ['cowshed-cli', 'cowshed-core'] } },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('hash a scenario edit for the device group alone, and the production substrate they share for both', async () => {
|
|
41
|
+
const groups = serialTestGroups(join(REPOSITORY, NEXTEST_REPO_CONFIG_PATH));
|
|
42
|
+
const members = listCargoWorkspacePackages(REPOSITORY);
|
|
43
|
+
// The inputs Nx hashes for a group's runner: the closure of every package its filter names, as the plugin derives it.
|
|
44
|
+
const inputsOf = async (group: string): Promise<string[]> => {
|
|
45
|
+
const scope = groups.find((candidate) => candidate.group === group)?.scope;
|
|
46
|
+
if (scope?.kind !== 'packages') throw new Error(`${group} is not scoped to packages`);
|
|
47
|
+
const hashed = await Promise.all(
|
|
48
|
+
scope.packages.map((name) => {
|
|
49
|
+
const member = members.find((candidate) => candidate.name === name);
|
|
50
|
+
if (member === undefined) throw new Error(`${name} is not a member of the Cargo workspace`);
|
|
51
|
+
return cargoPackageTestInputs({
|
|
52
|
+
workspaceRoot: REPOSITORY,
|
|
53
|
+
absoluteProjectRoot: REPOSITORY,
|
|
54
|
+
memberDir: member.dir,
|
|
55
|
+
});
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
return hashed.flat();
|
|
59
|
+
};
|
|
60
|
+
const device = await inputsOf('real-apfs');
|
|
61
|
+
const host = await inputsOf('real-apfs-host');
|
|
62
|
+
const reruns = (path: string) => ({ device: hashes(device, path), host: hashes(host, path) });
|
|
63
|
+
const crates = 'packages/cowshed/crates';
|
|
64
|
+
|
|
65
|
+
// The three cases. An unrelated crate reruns neither group. A scenario edit reruns the device group alone,
|
|
66
|
+
// because no host crate depends on the crate the scenarios live in. A change to the production substrate, or to
|
|
67
|
+
// what it links, reruns both, because the host crates link it too.
|
|
68
|
+
expect(reruns('packages/columine/crates/columine-vm/src/lib.rs')).toEqual({ device: false, host: false });
|
|
69
|
+
expect(reruns(`${crates}/cowshed-apfs-tests/src/tests.rs`)).toEqual({ device: true, host: false });
|
|
70
|
+
expect(reruns(`${crates}/cowshed-apfs/src/lib.rs`)).toEqual({ device: true, host: true });
|
|
71
|
+
expect(reruns(`${crates}/cowshed-os/src/lib.rs`)).toEqual({ device: true, host: true });
|
|
72
|
+
expect(reruns(`${crates}/cowshed-core/src/lib.rs`)).toEqual({ device: false, host: true });
|
|
73
|
+
expect(reruns(`${crates}/cowshed-cli/src/main.rs`)).toEqual({ device: false, host: true });
|
|
74
|
+
// The test support every real-image binary compiles in stays hashed for both, and no tests tree is excluded.
|
|
75
|
+
for (const support of [
|
|
76
|
+
`${crates}/cowshed-apfs/tests/support/scratch_apfs.rs`,
|
|
77
|
+
`${crates}/cowshed-os/tests/support/scratch_processes.rs`,
|
|
78
|
+
]) {
|
|
79
|
+
expect(reruns(support), support).toEqual({ device: true, host: true });
|
|
80
|
+
}
|
|
81
|
+
for (const inputs of [device, host]) {
|
|
82
|
+
expect(inputs.filter((input) => input.startsWith('!') && /\btests?\b/.test(input))).toEqual([]);
|
|
83
|
+
}
|
|
84
|
+
}, 60_000);
|
|
85
|
+
|
|
86
|
+
it('run the host group after the device group, so two real-image runners never overlap', async () => {
|
|
87
|
+
const nx = await readRecord('nx.json', JSON.parse);
|
|
88
|
+
const host = child(child(nx, 'targetDefaults'), HOST_GROUP);
|
|
89
|
+
// `...` keeps the inferred archive and fetch edges ahead of the explicit ones.
|
|
90
|
+
expect(host.dependsOn).toEqual(['...', CHECKOUT_COWSHED_BUILD, DEVICE_GROUP]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("run this checkout's cowshed, built first, for every disk command the code under test makes", async () => {
|
|
94
|
+
const nx = await readRecord('nx.json', JSON.parse);
|
|
95
|
+
const plugin = await readRecord('packages/nx-plugin/package.json', JSON.parse);
|
|
96
|
+
// The groups and the RAM-volume host tests exercise the disk-command facade. An installed cowshed that predates a
|
|
97
|
+
// command this checkout added would fail them, so each names the checkout's launcher, after cowshed's build.
|
|
98
|
+
const targets = [
|
|
99
|
+
child(child(nx, 'targetDefaults'), DEVICE_GROUP),
|
|
100
|
+
child(child(nx, 'targetDefaults'), HOST_GROUP),
|
|
101
|
+
child(child(child(plugin, 'nx'), 'targets'), 'test-host'),
|
|
102
|
+
];
|
|
103
|
+
for (const target of targets) {
|
|
104
|
+
expect(target.dependsOn).toContainEqual(CHECKOUT_COWSHED_BUILD);
|
|
105
|
+
expect(child(child(target, 'options'), 'env')).toEqual({
|
|
106
|
+
[COWSHED_EXECUTABLE_ENV]: '{workspaceRoot}/packages/cowshed/bin/cowshed',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('reaches host groups only through the explicit host and land gates, preserving the old land task set', async () => {
|
|
112
|
+
const graph = await repositoryProjectGraph();
|
|
113
|
+
const projects = Object.keys(graph.nodes);
|
|
114
|
+
const targets = [...new Set(projects.flatMap((name) => Object.keys(graph.nodes[name]?.data.targets ?? {})))];
|
|
115
|
+
const tasks = createTaskGraph(graph, {}, projects, targets, undefined, {});
|
|
116
|
+
const device = `${ROOT_PROJECT}:${DEVICE_GROUP}`;
|
|
117
|
+
const host = `${ROOT_PROJECT}:${HOST_GROUP}`;
|
|
118
|
+
const hostGate = `${ROOT_PROJECT}:host-e2e`;
|
|
119
|
+
const gate = `${ROOT_PROJECT}:gate`;
|
|
120
|
+
// Package-declared nodes and explicit edges exist on every host; only macOS inference supplies a runner.
|
|
121
|
+
expect(Object.keys(tasks.tasks)).toEqual(expect.arrayContaining([device, host, hostGate, gate]));
|
|
122
|
+
for (const name of [DEVICE_GROUP, HOST_GROUP]) {
|
|
123
|
+
const target = graph.nodes[ROOT_PROJECT]?.data.targets?.[name];
|
|
124
|
+
expect(target, name).toBeDefined();
|
|
125
|
+
if (process.platform === 'darwin') {
|
|
126
|
+
expect(target?.executor, name).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
127
|
+
expect(target?.options?.command, name).toContain('nextest run');
|
|
128
|
+
} else {
|
|
129
|
+
// Nx normalizes the package-declared placeholder to a no-op, never an APFS runner.
|
|
130
|
+
expect(target?.executor, name).toBe('nx:noop');
|
|
131
|
+
expect(target?.options?.command, name).toBeUndefined();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const edges = (id: string): string[] => [
|
|
135
|
+
...(tasks.dependencies[id] ?? []),
|
|
136
|
+
...(tasks.continuousDependencies?.[id] ?? []),
|
|
137
|
+
];
|
|
138
|
+
const groupsReached: Record<string, string[]> = {};
|
|
139
|
+
for (const id of Object.keys(tasks.tasks)) {
|
|
140
|
+
const seen = new Set<string>();
|
|
141
|
+
const pending = edges(id);
|
|
142
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
143
|
+
if (seen.has(next)) continue;
|
|
144
|
+
seen.add(next);
|
|
145
|
+
pending.push(...edges(next));
|
|
146
|
+
}
|
|
147
|
+
const groups = [...seen].filter((reached) => reached === device || reached === host).sort();
|
|
148
|
+
if (groups.length > 0) groupsReached[id] = groups;
|
|
149
|
+
}
|
|
150
|
+
// Ordinary tests must not pull expensive images into the inner loop. Only these explicit aggregates may.
|
|
151
|
+
expect(groupsReached).toEqual({ [host]: [device], [hostGate]: [device, host], [gate]: [device, host] });
|
|
152
|
+
const planned = (selected: string[]): string[] => {
|
|
153
|
+
const runnable = projects.filter((name) =>
|
|
154
|
+
selected.some((target) => graph.nodes[name]?.data.targets?.[target] !== undefined),
|
|
155
|
+
);
|
|
156
|
+
return Object.keys(createTaskGraph(graph, {}, runnable, selected, undefined, {}).tasks).sort();
|
|
157
|
+
};
|
|
158
|
+
const oldGate = planned(['lint', 'test', 'build', DEVICE_GROUP, HOST_GROUP]);
|
|
159
|
+
expect(planned(['gate']).filter((id) => id !== gate && id !== hostGate)).toEqual(oldGate);
|
|
160
|
+
expect(planned(['host-e2e']).filter((id) => id !== hostGate)).toEqual(planned([DEVICE_GROUP, HOST_GROUP]));
|
|
161
|
+
expect(planned(['test'])).not.toContain(device);
|
|
162
|
+
expect(planned(['test'])).not.toContain(host);
|
|
163
|
+
}, 120_000);
|
|
164
|
+
|
|
165
|
+
it('wrap exactly their tests in the 30s code-bound class, behind the 60s class that wins first', async () => {
|
|
166
|
+
const config = await readRecord(NEXTEST_REPO_CONFIG_PATH, parseToml);
|
|
167
|
+
const profile = child(child(config, 'profile'), 'default');
|
|
168
|
+
const overrides = records(profile.overrides);
|
|
169
|
+
const scripts = records(profile.scripts);
|
|
170
|
+
const grouped = overrides.filter(
|
|
171
|
+
(override) => override['test-group'] === 'real-apfs' || override['test-group'] === 'real-apfs-host',
|
|
172
|
+
);
|
|
173
|
+
const thirtySecond = scripts.filter((script) => script['run-wrapper'] === 'real-apfs-code-30s');
|
|
174
|
+
|
|
175
|
+
// A config file has no `group()` predicate, so the 30s rules repeat the groups' filters verbatim, one for one:
|
|
176
|
+
// together they are exactly the tests the groups hold, and no ordinary test is bound to a real-image class.
|
|
177
|
+
expect(thirtySecond.map((script) => script.filter).sort()).toEqual(
|
|
178
|
+
grouped.map((override) => override.filter).sort(),
|
|
179
|
+
);
|
|
180
|
+
expect(scripts.map((script) => script['run-wrapper'])).toEqual([
|
|
181
|
+
'real-apfs-code-60s',
|
|
182
|
+
...grouped.map(() => 'real-apfs-code-30s'),
|
|
183
|
+
]);
|
|
184
|
+
// Everything here, groups and wrappers alike, applies on the one platform a serial group runs on.
|
|
185
|
+
for (const rule of [...grouped, ...scripts]) {
|
|
186
|
+
expect(rule.platform, JSON.stringify(rule.filter)).toBe(SERIAL_TEST_GROUP_PLATFORM);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('hold every real_apfs_ test: none sits in a package no group is scoped to', async () => {
|
|
191
|
+
const groups = serialTestGroups(join(REPOSITORY, NEXTEST_REPO_CONFIG_PATH));
|
|
192
|
+
const scoped = new Set(groups.flatMap(({ scope }) => (scope.kind === 'packages' ? scope.packages : [])));
|
|
193
|
+
const owners = new Set<string>();
|
|
194
|
+
for (const source of await rustSources(listCargoWorkspacePackages(REPOSITORY))) {
|
|
195
|
+
if (/\bfn real_apfs_\w+/.test(source.text)) owners.add(source.owner);
|
|
196
|
+
}
|
|
197
|
+
// Scoping a group to packages made this a rule to keep: a `real_apfs_` test in any other crate would run in an
|
|
198
|
+
// ordinary shard beside every other test, not in a serial group.
|
|
199
|
+
expect([...owners].filter((name) => !scoped.has(name))).toEqual([]);
|
|
200
|
+
expect([...owners].sort()).toEqual(['cowshed-apfs-tests', 'cowshed-cli', 'cowshed-core']);
|
|
201
|
+
}, 60_000);
|
|
202
|
+
|
|
203
|
+
it('pin each exact test by a function that exists at that module path', async () => {
|
|
204
|
+
const groups = serialTestGroups(join(REPOSITORY, NEXTEST_REPO_CONFIG_PATH));
|
|
205
|
+
const scoped = new Set(groups.flatMap(({ scope }) => (scope.kind === 'packages' ? scope.packages : [])));
|
|
206
|
+
const sources = await rustSources(listCargoWorkspacePackages(REPOSITORY), scoped);
|
|
207
|
+
// A group with no exact-name clause pins nothing, so there is nothing that can go stale.
|
|
208
|
+
const pinned = groups.flatMap(({ filter }) => [...filter.matchAll(/test\(=([^),]+)\)/g)].map((match) => match[1]));
|
|
209
|
+
for (const exactName of pinned) {
|
|
210
|
+
// `a::b::tests::name`: a module path, the `tests` module, then the function. A name that moved with its
|
|
211
|
+
// module matches no test and silently leaves the group, so each must still resolve to one function.
|
|
212
|
+
const segments = (exactName ?? '').split('::');
|
|
213
|
+
const name = segments[segments.length - 1];
|
|
214
|
+
const modulePath = segments.slice(0, -2).join('/');
|
|
215
|
+
const holders = sources.filter(({ text }) => text.includes(`fn ${name}(`));
|
|
216
|
+
expect(holders, exactName).toHaveLength(1);
|
|
217
|
+
expect(holders[0]?.path, exactName).toMatch(new RegExp(`/src/${modulePath}(?:/mod)?\\.rs$`));
|
|
218
|
+
expect(holders[0]?.text, exactName).toContain('mod tests');
|
|
219
|
+
}
|
|
220
|
+
}, 60_000);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/** `path` of the repository, parsed by `parse`, which must be an object. */
|
|
224
|
+
async function readRecord(path: string, parse: (text: string) => unknown): Promise<Record<string, unknown>> {
|
|
225
|
+
const parsed = parse(await readFile(join(REPOSITORY, path), 'utf8'));
|
|
226
|
+
if (!isRecord(parsed)) throw new Error(`${path} is not an object`);
|
|
227
|
+
return parsed;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function child(parent: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
231
|
+
const value = parent[key];
|
|
232
|
+
if (!isRecord(value)) throw new Error(`${key} is not an object`);
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function records(value: unknown): Record<string, unknown>[] {
|
|
237
|
+
if (!Array.isArray(value)) throw new Error('expected an array of tables');
|
|
238
|
+
return value.map((entry) => {
|
|
239
|
+
if (!isRecord(entry)) throw new Error('expected a table');
|
|
240
|
+
return entry;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const parseProjectGraph = typia.json.createAssertParse<ProjectGraph>();
|
|
245
|
+
// The child computes the graph outside this package's bunfig; it takes the same transform preload as the test runner.
|
|
246
|
+
const VALIDATION_PRELOAD = fileURLToPath(import.meta.resolve('@smoothbricks/validation/bun/preload'));
|
|
247
|
+
const GRAPH_SCRIPT = `const { createProjectGraphAsync } = await import('nx/src/project-graph/project-graph.js');
|
|
248
|
+
const graph = await createProjectGraphAsync({ exitOnError: false });
|
|
249
|
+
process.stdout.write(JSON.stringify({ nodes: graph.nodes, dependencies: graph.dependencies }));`;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The repository's own project graph, as Nx builds it with this plugin: computed daemonless, in a child that exits when
|
|
253
|
+
* it is done, with plugins in its own process and workspace data of its own, so it neither starts a daemon nor writes
|
|
254
|
+
* the checkout's graph cache.
|
|
255
|
+
*/
|
|
256
|
+
async function repositoryProjectGraph(): Promise<ProjectGraph> {
|
|
257
|
+
const data = await mkdtemp(join(tmpdir(), 'serial-group-graph-'));
|
|
258
|
+
try {
|
|
259
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('NX_')));
|
|
260
|
+
const run = spawnSync(process.execPath, ['--preload', VALIDATION_PRELOAD, '-e', GRAPH_SCRIPT], {
|
|
261
|
+
cwd: REPOSITORY,
|
|
262
|
+
encoding: 'utf8',
|
|
263
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
264
|
+
env: {
|
|
265
|
+
...env,
|
|
266
|
+
NX_DAEMON: 'false',
|
|
267
|
+
NX_ISOLATE_PLUGINS: 'false',
|
|
268
|
+
NX_CACHE_PROJECT_GRAPH: 'false',
|
|
269
|
+
NX_WORKSPACE_DATA_DIRECTORY: data,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
if (run.status !== 0) throw new Error(`the project graph child exited ${run.status}: ${run.stderr}`);
|
|
273
|
+
return parseProjectGraph(run.stdout);
|
|
274
|
+
} finally {
|
|
275
|
+
await rm(data, { recursive: true, force: true });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface RustSource {
|
|
280
|
+
/** The Cargo package whose tree holds the file. */
|
|
281
|
+
readonly owner: string;
|
|
282
|
+
/** The file, relative to the repository. */
|
|
283
|
+
readonly path: string;
|
|
284
|
+
readonly text: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Every Rust source of `members` (of only the packages `only` names, when given), each credited to the deepest
|
|
289
|
+
* member whose directory holds it: a crate nested inside another is its own owner's.
|
|
290
|
+
*/
|
|
291
|
+
async function rustSources(
|
|
292
|
+
members: readonly CargoWorkspacePackage[],
|
|
293
|
+
only?: ReadonlySet<string>,
|
|
294
|
+
): Promise<RustSource[]> {
|
|
295
|
+
const sources: RustSource[] = [];
|
|
296
|
+
for (const member of members.filter(({ name }) => only?.has(name) ?? true)) {
|
|
297
|
+
const nested = members
|
|
298
|
+
.filter(({ dir }) => dir.startsWith(`${member.dir}/`))
|
|
299
|
+
.map(({ dir }) => dir.slice(member.dir.length + 1));
|
|
300
|
+
const files = (await readdir(join(REPOSITORY, member.dir), { recursive: true })).filter(
|
|
301
|
+
(file) =>
|
|
302
|
+
file.endsWith('.rs') &&
|
|
303
|
+
!file.split(sep).some((part) => part === 'target' || part === 'node_modules') &&
|
|
304
|
+
!nested.some((dir) => file.startsWith(`${dir}${sep}`)),
|
|
305
|
+
);
|
|
306
|
+
const read = await Promise.all(
|
|
307
|
+
files.map(async (file) => ({
|
|
308
|
+
owner: member.name,
|
|
309
|
+
path: join(member.dir, file),
|
|
310
|
+
text: await readFile(join(REPOSITORY, member.dir, file), 'utf8'),
|
|
311
|
+
})),
|
|
312
|
+
);
|
|
313
|
+
sources.push(...read);
|
|
314
|
+
}
|
|
315
|
+
return sources;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Whether Nx would hash `path` (workspace-relative) under the `{workspaceRoot}` filesets of `inputs`. */
|
|
319
|
+
function hashes(inputs: readonly string[], path: string): boolean {
|
|
320
|
+
const filesets = inputs.filter((input) => input.includes('{workspaceRoot}'));
|
|
321
|
+
const matches = (fileset: string): boolean => new Bun.Glob(fileset.replace('{workspaceRoot}/', '')).match(path);
|
|
322
|
+
return (
|
|
323
|
+
filesets.some((input) => !input.startsWith('!') && matches(input)) &&
|
|
324
|
+
!filesets.some((input) => input.startsWith('!') && matches(input.slice(1)))
|
|
325
|
+
);
|
|
326
|
+
}
|