@smoothbricks/nx-plugin 0.4.28 → 0.4.30
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 +277 -89
- package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-clocks.js +28 -0
- package/dist/bounded-test-policy.d.ts +8 -8
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +18 -30
- package/dist/cargo-closure-input.d.ts +23 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +41 -9
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +40 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +297 -159
- package/dist/ensure-built-witness.d.ts +65 -4
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2237 -23
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +45 -56
- package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +51 -22
- package/dist/executors/bounded-exec/executor.d.ts +12 -3
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +174 -51
- package/dist/executors/bounded-exec/no-space.d.ts +8 -0
- package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
- package/dist/executors/bounded-exec/no-space.js +31 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +20 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +42 -17
- package/dist/executors/bounded-exec/verdict.d.ts +34 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +54 -3
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +102 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +637 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/owned-installation.d.ts +14 -0
- package/dist/owned-installation.d.ts.map +1 -0
- package/dist/owned-installation.js +324 -0
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +926 -0
- package/dist/test-backstop.d.ts +9 -0
- package/dist/test-backstop.d.ts.map +1 -0
- package/dist/test-backstop.js +10 -0
- package/dist/test-clock-policy.d.ts +30 -0
- package/dist/test-clock-policy.d.ts.map +1 -0
- package/dist/test-clock-policy.js +686 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +66 -1
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +148 -29
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -115
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +25 -9
- package/src/__tests__/cargo-closure-fixture.ts +113 -0
- package/src/__tests__/counted-cargo.ts +8 -25
- package/src/__tests__/directory-change.ts +27 -0
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +14 -0
- package/src/__tests__/past-tick.ts +12 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bin/smoo-nx-test-clocks.ts +29 -0
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +18 -32
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.property.test.ts +50 -0
- package/src/cargo-closure-input.test.ts +73 -121
- package/src/cargo-closure-input.ts +47 -8
- package/src/cargo-closure-key.test.ts +239 -0
- package/src/cargo-resolve-cache.test.ts +168 -31
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +294 -149
- package/src/ensure-built-witness.test.ts +306 -13
- package/src/ensure-built-witness.ts +255 -24
- package/src/ensure-built.test.ts +228 -102
- package/src/ensure-built.ts +127 -66
- package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
- package/src/executors/bounded-exec/cpu-pool.ts +64 -20
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
- package/src/executors/bounded-exec/executor-host.test.ts +74 -52
- package/src/executors/bounded-exec/executor.test.ts +343 -97
- package/src/executors/bounded-exec/executor.ts +192 -56
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
- package/src/executors/bounded-exec/no-space.ts +40 -0
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
- package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
- package/src/executors/bounded-exec/ram-temp.ts +49 -20
- package/src/executors/bounded-exec/verdict.test.ts +127 -22
- package/src/executors/bounded-exec/verdict.ts +78 -3
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +379 -0
- package/src/graph-input-contract.ts +627 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-extraction.test.ts +114 -4
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +10 -8
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +61 -1
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +36 -22
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/owned-installation.ts +174 -0
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +636 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-backstop.ts +11 -0
- package/src/test-clock-policy.test.ts +338 -0
- package/src/test-clock-policy.ts +708 -0
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +67 -1
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +8 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expect, it } from 'bun:test';
|
|
1
|
+
import { afterAll, expect, it } from 'bun:test';
|
|
2
2
|
import { execFile, execFileSync } from 'node:child_process';
|
|
3
|
-
import { appendFile, mkdir, mkdtemp, readFile, realpath, rm,
|
|
3
|
+
import { appendFile, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { promisify } from 'node:util';
|
|
@@ -8,6 +8,7 @@ import { promisify } from 'node:util';
|
|
|
8
8
|
import type { CreateNodesResultV2 } from 'nx/src/devkit-exports.js';
|
|
9
9
|
import { Watcher, WorkspaceContext } from 'nx/src/native/index.js';
|
|
10
10
|
import { globWithWorkspaceContextSync, resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
11
|
+
import { byFile, closureFixture, closureOf, graphComputation } from './__tests__/cargo-closure-fixture.js';
|
|
11
12
|
import {
|
|
12
13
|
aggregateOf,
|
|
13
14
|
type CountedCargo,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
withEnvironment,
|
|
20
21
|
} from './__tests__/counted-cargo.js';
|
|
21
22
|
import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
|
|
23
|
+
import { testFileInstallation } from './__tests__/owned-installation.js';
|
|
22
24
|
import { runtimeInputValue } from './__tests__/runtime-input.js';
|
|
23
25
|
import { CARGO_CLOSURE_INPUT, indexedCargoManifests } from './cargo-closure-input.js';
|
|
24
26
|
import { hashCargoPathInputs } from './cargo-source-hash.js';
|
|
@@ -28,89 +30,14 @@ const repositoryRoot = join(import.meta.dir, '../../..');
|
|
|
28
30
|
|
|
29
31
|
useFixtureCargoHome();
|
|
30
32
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* `bridge` too. `unrelated` is a member nothing depends on. `app` declares a
|
|
35
|
-
* custom cached target keyed on its closure.
|
|
36
|
-
* `extraFiles` (paths relative to `root`) are written with the rest, last.
|
|
37
|
-
*/
|
|
38
|
-
async function closureFixture(
|
|
39
|
-
root: string,
|
|
40
|
-
gitignore = 'node_modules/\ntarget/\ndist/\n.nx/\n',
|
|
41
|
-
extraFiles: Record<string, string> = {},
|
|
42
|
-
) {
|
|
43
|
-
const workspace = join(root, 'workspace');
|
|
44
|
-
const files: Record<string, string> = {
|
|
45
|
-
'workspace/.gitignore': gitignore,
|
|
46
|
-
'workspace/package.json':
|
|
47
|
-
'{"name":"cargo-closure-fixture","private":true,"workspaces":["packages/*","crates/*"]}\n',
|
|
48
|
-
'workspace/nx.json': JSON.stringify({
|
|
49
|
-
plugins: ['@smoothbricks/nx-plugin'],
|
|
50
|
-
namedInputs: { externalRustCrates: [] },
|
|
51
|
-
}),
|
|
52
|
-
'workspace/Cargo.toml':
|
|
53
|
-
'[workspace]\nmembers=["packages/app","crates/bridge","crates/leaf","crates/unrelated"]\nresolver="2"\n',
|
|
54
|
-
'workspace/packages/app/package.json': JSON.stringify({
|
|
55
|
-
name: 'app',
|
|
56
|
-
private: true,
|
|
57
|
-
nx: {
|
|
58
|
-
targets: {
|
|
59
|
-
compile: {
|
|
60
|
-
executor: 'nx:run-commands',
|
|
61
|
-
cache: true,
|
|
62
|
-
inputs: [CARGO_CLOSURE_INPUT],
|
|
63
|
-
options: { command: 'cargo build --quiet --locked --offline --manifest-path packages/app/Cargo.toml' },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
'workspace/packages/app/Cargo.toml':
|
|
69
|
-
'[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nbridge={path="../../crates/bridge"}\n',
|
|
70
|
-
'workspace/packages/app/src/main.rs': 'fn main() { println!("{}", bridge::answer()); }\n',
|
|
71
|
-
'workspace/crates/bridge/Cargo.toml':
|
|
72
|
-
'[package]\nname="bridge"\nversion="0.1.0"\nedition="2021"\n[dependencies]\nleaf={path="../leaf"}\nexternal={path="../../../external"}\n',
|
|
73
|
-
'workspace/crates/bridge/src/lib.rs': 'pub fn answer() -> u8 { leaf::answer() + external::answer() }\n',
|
|
74
|
-
'workspace/crates/leaf/package.json': '{"name":"leaf","private":true}\n',
|
|
75
|
-
'workspace/crates/leaf/Cargo.toml': '[package]\nname="leaf"\nversion="0.1.0"\nedition="2021"\n',
|
|
76
|
-
'workspace/crates/leaf/src/lib.rs': 'pub fn answer() -> u8 { 1 }\n',
|
|
77
|
-
'workspace/crates/unrelated/Cargo.toml': '[package]\nname="unrelated"\nversion="0.1.0"\nedition="2021"\n',
|
|
78
|
-
'workspace/crates/unrelated/src/lib.rs': 'pub fn unrelated() -> u8 { 3 }\n',
|
|
79
|
-
'external/Cargo.toml': '[package]\nname="external"\nversion="0.1.0"\nedition="2021"\n[workspace]\n',
|
|
80
|
-
'external/src/lib.rs': 'pub fn answer() -> u8 { 10 }\n',
|
|
81
|
-
...extraFiles,
|
|
82
|
-
};
|
|
83
|
-
for (const [path, text] of Object.entries(files)) {
|
|
84
|
-
await mkdir(dirname(join(root, path)), { recursive: true });
|
|
85
|
-
await writeFile(join(root, path), text);
|
|
86
|
-
}
|
|
87
|
-
execFileSync('git', ['init', '--quiet', workspace], { stdio: 'pipe' });
|
|
88
|
-
await symlink(join(repositoryRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
89
|
-
execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', join(workspace, 'Cargo.toml')], {
|
|
90
|
-
stdio: 'pipe',
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Rewrite a fixture file as an edit Nx can see. Nx keeps each file's hash
|
|
95
|
-
* beside its mtime in whole seconds and reuses the hash until that second
|
|
96
|
-
* changes, so a rewrite inside the second the file was last hashed in is
|
|
97
|
-
* invisible to every fileset input. A fast host runs this whole fixture in
|
|
98
|
-
* about a second; the edit is dated at least a second past the old mtime.
|
|
99
|
-
*/
|
|
100
|
-
async function edit(path: string, text: string): Promise<void> {
|
|
101
|
-
const file = join(root, path);
|
|
102
|
-
const { mtimeMs } = await stat(file);
|
|
103
|
-
await writeFile(file, text);
|
|
104
|
-
const edited = new Date(Math.max(Date.now(), mtimeMs + 1000));
|
|
105
|
-
await utimes(file, edited, edited);
|
|
106
|
-
}
|
|
107
|
-
return { workspace, edit };
|
|
108
|
-
}
|
|
33
|
+
/** The Nx installation this file's fixtures share; none may write into it. */
|
|
34
|
+
const installation = testFileInstallation('cargo-closure-installation-');
|
|
35
|
+
afterAll(() => installation.retire());
|
|
109
36
|
|
|
110
37
|
it('keys a custom target on exactly its Cargo closure, inside the workspace and out', async () => {
|
|
111
38
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-')));
|
|
112
39
|
try {
|
|
113
|
-
const { workspace, edit } = await closureFixture(root);
|
|
40
|
+
const { workspace, edit } = await closureFixture(installation, root);
|
|
114
41
|
resetWorkspaceContext();
|
|
115
42
|
const closure = closureOf(byFile(await graphComputation(workspace)()), 'packages/app');
|
|
116
43
|
const filesets = closure.flatMap((input) => (typeof input === 'string' ? [input] : []));
|
|
@@ -150,12 +77,12 @@ it('keys a custom target on exactly its Cargo closure, inside the workspace and
|
|
|
150
77
|
} finally {
|
|
151
78
|
await rm(root, { recursive: true, force: true });
|
|
152
79
|
}
|
|
153
|
-
}
|
|
80
|
+
});
|
|
154
81
|
|
|
155
82
|
it('keys literal compiled-in data inside and outside crate directories without keying comments or unrelated crates', async () => {
|
|
156
83
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-compiled-data-')));
|
|
157
84
|
try {
|
|
158
|
-
const { workspace, edit } = await closureFixture(root, undefined, {
|
|
85
|
+
const { workspace, edit } = await closureFixture(installation, root, undefined, {
|
|
159
86
|
'workspace/packages/app/src/main.rs':
|
|
160
87
|
'const LOCAL: &str = include_str!("data/local.txt");\nfn main() { println!("{}", bridge::answer()); }\n',
|
|
161
88
|
'workspace/packages/app/src/data/local.txt': 'local-one',
|
|
@@ -208,12 +135,61 @@ it('keys literal compiled-in data inside and outside crate directories without k
|
|
|
208
135
|
} finally {
|
|
209
136
|
await rm(root, { recursive: true, force: true });
|
|
210
137
|
}
|
|
211
|
-
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('names no compiled-in build output, so a producer run leaves the closure it was hashed under unchanged', async () => {
|
|
141
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-compiled-output-')));
|
|
142
|
+
try {
|
|
143
|
+
const { workspace } = await closureFixture(
|
|
144
|
+
installation,
|
|
145
|
+
root,
|
|
146
|
+
'node_modules/\ntarget/\ndist/\n.nx/\ncrates/leaf/src/generated/\n',
|
|
147
|
+
{
|
|
148
|
+
'workspace/crates/leaf/src/lib.rs': [
|
|
149
|
+
'pub fn answer() -> u8 { 1 }',
|
|
150
|
+
'pub const TABLE: &[u8] = include_bytes!("generated/table.bin");',
|
|
151
|
+
'pub const SKILL: &str = include_str!("../../../skills/SKILL.md");',
|
|
152
|
+
].join('\n'),
|
|
153
|
+
'workspace/skills/SKILL.md': 'skill-one',
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
// A producer's run: ignored outputs, content-named ones among them, and a generated source including those.
|
|
157
|
+
const generated = join(workspace, 'crates/leaf/src/generated');
|
|
158
|
+
const produce = async (content: string) => {
|
|
159
|
+
await rm(generated, { recursive: true, force: true });
|
|
160
|
+
await mkdir(generated, { recursive: true });
|
|
161
|
+
await writeFile(join(generated, 'table.bin'), content);
|
|
162
|
+
await writeFile(join(generated, `chunk-${content}.js`), content);
|
|
163
|
+
await writeFile(
|
|
164
|
+
join(generated, 'vocabulary.rs'),
|
|
165
|
+
`pub const CHUNK: &str = include_str!("chunk-${content}.js");\n`,
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
const closure = async () => {
|
|
169
|
+
resetWorkspaceContext();
|
|
170
|
+
return closureOf(byFile(await graphComputation(workspace)()), 'packages/app');
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const unproduced = await closure();
|
|
174
|
+
expect(unproduced).toContain('{workspaceRoot}/skills/SKILL.md');
|
|
175
|
+
expect(JSON.stringify(unproduced)).not.toContain('generated/');
|
|
176
|
+
await produce('one');
|
|
177
|
+
expect(await closure()).toEqual(unproduced);
|
|
178
|
+
await produce('two');
|
|
179
|
+
expect(await closure()).toEqual(unproduced);
|
|
180
|
+
} finally {
|
|
181
|
+
await rm(root, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
212
184
|
|
|
213
185
|
it('refuses a closure member in an ignored directory, which no fileset can see, instead of hashing the whole workspace', async () => {
|
|
214
186
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-ignored-')));
|
|
215
187
|
try {
|
|
216
|
-
const { workspace } = await closureFixture(
|
|
188
|
+
const { workspace } = await closureFixture(
|
|
189
|
+
installation,
|
|
190
|
+
root,
|
|
191
|
+
'node_modules/\ntarget/\ndist/\n.nx/\ncrates/leaf/\n',
|
|
192
|
+
);
|
|
217
193
|
resetWorkspaceContext();
|
|
218
194
|
const failure = aggregateOf(await rejectionOf(graphComputation(workspace)()));
|
|
219
195
|
const refusals = failure.errors.flatMap(([, error]) => (error.name === 'CargoClosureInputError' ? [error] : []));
|
|
@@ -226,12 +202,12 @@ it('refuses a closure member in an ignored directory, which no fileset can see,
|
|
|
226
202
|
} finally {
|
|
227
203
|
await rm(root, { recursive: true, force: true });
|
|
228
204
|
}
|
|
229
|
-
}
|
|
205
|
+
});
|
|
230
206
|
|
|
231
207
|
it('leaves a closure inside the workspace to Nx: no process runs when its tasks are hashed', async () => {
|
|
232
208
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-inferred-')));
|
|
233
209
|
try {
|
|
234
|
-
const { workspace } = await closureFixture(root);
|
|
210
|
+
const { workspace } = await closureFixture(installation, root);
|
|
235
211
|
resetWorkspaceContext();
|
|
236
212
|
const [, infer] = createNodesV2;
|
|
237
213
|
const inferred = await infer(['package.json', 'packages/app/package.json', 'crates/leaf/package.json'], undefined, {
|
|
@@ -257,7 +233,7 @@ it('leaves a closure inside the workspace to Nx: no process runs when its tasks
|
|
|
257
233
|
} finally {
|
|
258
234
|
await rm(root, { recursive: true, force: true });
|
|
259
235
|
}
|
|
260
|
-
}
|
|
236
|
+
});
|
|
261
237
|
|
|
262
238
|
/** `leaf` as the fixture writes it, and the dependency that draws `unrelated` into every closure reaching `leaf`. */
|
|
263
239
|
const LEAF_MANIFEST = '[package]\nname="leaf"\nversion="0.1.0"\nedition="2021"\n';
|
|
@@ -267,30 +243,6 @@ const LEAF_LINK = '[dependencies]\nunrelated={path="../unrelated"}\n';
|
|
|
267
243
|
const crateFiles = (crates: string) =>
|
|
268
244
|
`{workspaceRoot}/crates/${crates}/**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}`;
|
|
269
245
|
|
|
270
|
-
/** One project-graph computation over the fixture: the plugin's `createNodes`, as Nx runs it for each recomputation. */
|
|
271
|
-
function graphComputation(workspace: string) {
|
|
272
|
-
const [, infer] = createNodesV2;
|
|
273
|
-
return async () =>
|
|
274
|
-
infer(['package.json', 'packages/app/package.json', 'crates/leaf/package.json'], undefined, {
|
|
275
|
-
workspaceRoot: workspace,
|
|
276
|
-
nxJsonConfiguration: { namedInputs: { externalRustCrates: [] } },
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** The computation's nodes in file order: the plugin pushes them as their projects finish. */
|
|
281
|
-
function byFile(graph: CreateNodesResultV2): CreateNodesResultV2 {
|
|
282
|
-
return [...graph].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/** The `cargoClosure` definition the computation gave the project at `projectRoot`. */
|
|
286
|
-
function closureOf(graph: CreateNodesResultV2, projectRoot: string) {
|
|
287
|
-
return (
|
|
288
|
-
graph.find(([file]) => dirname(file) === projectRoot)?.[1].projects?.[projectRoot]?.namedInputs?.[
|
|
289
|
-
CARGO_CLOSURE_INPUT
|
|
290
|
-
] ?? []
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
246
|
/** Turn `leaf`'s dependency on `unrelated` on or off, and bring Cargo.lock in line with the manifests. */
|
|
295
247
|
function leafControls(workspace: string, edit: (path: string, text: string) => Promise<void>) {
|
|
296
248
|
return {
|
|
@@ -306,7 +258,7 @@ it('delegates counted Cargo through the caller launcher without re-entering its
|
|
|
306
258
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-counted-delegate-')));
|
|
307
259
|
let fixtureCargo: CountedCargo | undefined;
|
|
308
260
|
try {
|
|
309
|
-
const { workspace } = await closureFixture(root);
|
|
261
|
+
const { workspace } = await closureFixture(installation, root);
|
|
310
262
|
const manifest = join(workspace, 'Cargo.toml');
|
|
311
263
|
const args = ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', manifest];
|
|
312
264
|
const expected = execFileSync('cargo', args, { encoding: 'utf8' });
|
|
@@ -333,13 +285,13 @@ it('delegates counted Cargo through the caller launcher without re-entering its
|
|
|
333
285
|
await fixtureCargo?.release();
|
|
334
286
|
await rm(root, { recursive: true, force: true });
|
|
335
287
|
}
|
|
336
|
-
}
|
|
288
|
+
});
|
|
337
289
|
|
|
338
290
|
it('shares one Cargo child among overlapping graph computations, and an unchanged workspace never asks Cargo again', async () => {
|
|
339
291
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-overlap-')));
|
|
340
292
|
let fixtureCargo: CountedCargo | undefined;
|
|
341
293
|
try {
|
|
342
|
-
const { workspace, edit } = await closureFixture(root);
|
|
294
|
+
const { workspace, edit } = await closureFixture(installation, root);
|
|
343
295
|
const { linkLeaf, relock } = leafControls(workspace, edit);
|
|
344
296
|
const cargo = await countedCargo(root);
|
|
345
297
|
fixtureCargo = cargo;
|
|
@@ -388,13 +340,13 @@ it('shares one Cargo child among overlapping graph computations, and an unchange
|
|
|
388
340
|
await fixtureCargo?.release();
|
|
389
341
|
await rm(root, { recursive: true, force: true });
|
|
390
342
|
}
|
|
391
|
-
}
|
|
343
|
+
});
|
|
392
344
|
|
|
393
345
|
it('refuses with a typed error what Cargo refuses, and follows an edit made while a child holds its answer with a resolution after it', async () => {
|
|
394
346
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-pending-')));
|
|
395
347
|
let fixtureCargo: CountedCargo | undefined;
|
|
396
348
|
try {
|
|
397
|
-
const { workspace, edit } = await closureFixture(root);
|
|
349
|
+
const { workspace, edit } = await closureFixture(installation, root);
|
|
398
350
|
const { linkLeaf, relock } = leafControls(workspace, edit);
|
|
399
351
|
const cargo = await countedCargo(root);
|
|
400
352
|
fixtureCargo = cargo;
|
|
@@ -454,12 +406,12 @@ it('refuses with a typed error what Cargo refuses, and follows an edit made whil
|
|
|
454
406
|
await fixtureCargo?.release();
|
|
455
407
|
await rm(root, { recursive: true, force: true });
|
|
456
408
|
}
|
|
457
|
-
}
|
|
409
|
+
});
|
|
458
410
|
|
|
459
411
|
it("indexes a source tree's Cargo manifests and none of the runtime state a cowshed keeps in it", async () => {
|
|
460
412
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-runtime-state-')));
|
|
461
413
|
try {
|
|
462
|
-
const { workspace } = await closureFixture(root, undefined, {
|
|
414
|
+
const { workspace } = await closureFixture(installation, root, undefined, {
|
|
463
415
|
'workspace/.nxignore': await readFile(join(repositoryRoot, '.nxignore'), 'utf8'),
|
|
464
416
|
'workspace/.cowshed/cache/nx/workspace-data/d/daemon.log': 'daemon log\n',
|
|
465
417
|
'workspace/.cowshed/job/1/stdout.log': 'job output\n',
|
|
@@ -477,7 +429,7 @@ it("indexes a source tree's Cargo manifests and none of the runtime state a cows
|
|
|
477
429
|
} finally {
|
|
478
430
|
await rm(root, { recursive: true, force: true });
|
|
479
431
|
}
|
|
480
|
-
}
|
|
432
|
+
});
|
|
481
433
|
|
|
482
434
|
const SOURCE_FILE = 'src/lib.rs';
|
|
483
435
|
|
|
@@ -551,4 +503,4 @@ it("keeps a cowshed's runtime state from waking the watcher that recomputes the
|
|
|
551
503
|
const paths = await watchedPaths(await readFile(join(repositoryRoot, '.nxignore'), 'utf8'));
|
|
552
504
|
expect(paths).toContain(SOURCE_FILE);
|
|
553
505
|
expect(paths.filter((path) => path.startsWith('.cowshed'))).toEqual([]);
|
|
554
|
-
}
|
|
506
|
+
});
|
|
@@ -60,6 +60,8 @@ const GLOB_SYNTAX = /[*?[\]{}()!,]/;
|
|
|
60
60
|
*/
|
|
61
61
|
export interface CargoClosureSource {
|
|
62
62
|
readonly manifest: string;
|
|
63
|
+
/** The Nx workspace root as the computation names it, which Nx's file index is keyed by. */
|
|
64
|
+
readonly workspaceRoot: string;
|
|
63
65
|
/** The canonical Nx workspace root. */
|
|
64
66
|
readonly root: string;
|
|
65
67
|
readonly cargo: CargoResolve;
|
|
@@ -90,7 +92,7 @@ export async function resolveCargoClosureSource(
|
|
|
90
92
|
): Promise<CargoClosureSource> {
|
|
91
93
|
const [root, index] = await Promise.all([realpath(workspaceRoot), indexed]);
|
|
92
94
|
const cargo = await readCargoResolve(join(root, manifest), root, index);
|
|
93
|
-
return { manifest, root, cargo, indexed: index, compiledFilesCache };
|
|
95
|
+
return { manifest, workspaceRoot, root, cargo, indexed: index, compiledFilesCache };
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
@@ -112,6 +114,16 @@ export async function resolveCargoClosureSource(
|
|
|
112
114
|
* An in-workspace member missing from Nx's file index is a typed refusal,
|
|
113
115
|
* never a whole-workspace runtime hash. Only outside-workspace members need
|
|
114
116
|
* the external-only runtime input.
|
|
117
|
+
*
|
|
118
|
+
* A compiled-in file is named only when Nx's file index holds both it and the
|
|
119
|
+
* source that includes it. An ignored one is a build output: no fileset can
|
|
120
|
+
* hash its bytes, which reach a consumer through its producer's dependency
|
|
121
|
+
* outputs instead, so naming it would add nothing to any task's key except
|
|
122
|
+
* the names of whatever output last ran. That state is exactly what a project
|
|
123
|
+
* graph must not read (`globIndexedFiles`): a producer that regenerates
|
|
124
|
+
* content-named files would otherwise move every key of the graph it was
|
|
125
|
+
* hashed under, and the run that compiled a tree would leave its verdict
|
|
126
|
+
* under a key no later run of the same tree computes.
|
|
115
127
|
*/
|
|
116
128
|
export async function cargoClosureInputs(
|
|
117
129
|
projectRoot: string,
|
|
@@ -140,7 +152,8 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
140
152
|
const { root, cargo, indexed } = source;
|
|
141
153
|
const packageDirectories: string[] = [];
|
|
142
154
|
const files: string[] = [];
|
|
143
|
-
const
|
|
155
|
+
const compiledIn: CompiledInclusion[] = [];
|
|
156
|
+
let compiledFiles: readonly string[] = [];
|
|
144
157
|
let external = false;
|
|
145
158
|
try {
|
|
146
159
|
const members = await dependencyClosure(cargo, join(root, projectRoot));
|
|
@@ -154,10 +167,13 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
154
167
|
if (!indexed.has(posix.join(directory, 'Cargo.toml'))) {
|
|
155
168
|
throw new Error(`the Cargo package ${directory} is not in Nx's file index (an ignored directory)`);
|
|
156
169
|
}
|
|
157
|
-
for (const
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
|
|
170
|
+
for (const compiled of compiledInFiles(pkg.directory, source.compiledFilesCache)) {
|
|
171
|
+
const file = indexablePath(root, compiled.file);
|
|
172
|
+
if (file === null) throw new Error(`${directory} compiles ${compiled.file}, which Nx's file index cannot hold`);
|
|
173
|
+
// The scan starts inside this package's indexable directory, so its sources can always be named.
|
|
174
|
+
const declaring = indexablePath(root, compiled.source);
|
|
175
|
+
if (declaring === null) throw new Error(`${compiled.source} was scanned outside ${directory}`);
|
|
176
|
+
compiledIn.push({ declaring, file });
|
|
161
177
|
}
|
|
162
178
|
packageDirectories.push(directory);
|
|
163
179
|
for (const file of [...pkg.sources, pkg.governingManifest]) {
|
|
@@ -166,8 +182,12 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
166
182
|
files.push(path);
|
|
167
183
|
}
|
|
168
184
|
}
|
|
169
|
-
const
|
|
185
|
+
const compiledPaths = [...new Set(compiledIn.flatMap(({ declaring, file }) => [declaring, file]))];
|
|
186
|
+
const unglobbable = [...packageDirectories, ...files, ...compiledPaths].find((path) => GLOB_SYNTAX.test(path));
|
|
170
187
|
if (unglobbable !== undefined) throw new Error(`${unglobbable} contains glob syntax, so no fileset can name it`);
|
|
188
|
+
// Literal paths, so each matches exactly itself in the index.
|
|
189
|
+
const held = new Set(compiledPaths.length === 0 ? [] : await globIndexedFiles(source.workspaceRoot, compiledPaths));
|
|
190
|
+
compiledFiles = indexedCompiledFiles(compiledIn, held);
|
|
171
191
|
} catch (error) {
|
|
172
192
|
throw new CargoClosureInputError(projectRoot, error);
|
|
173
193
|
}
|
|
@@ -211,12 +231,31 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
211
231
|
...packageGlobs.map((glob) => anchored(glob, PACKAGE_FILES)),
|
|
212
232
|
...packageGlobs.map((glob) => `!${anchored(glob, SKIPPED_TREES)}`),
|
|
213
233
|
...[...ancestors].sort().map((ancestor) => anchored(ancestor, ANCESTOR_FILES)),
|
|
214
|
-
...
|
|
234
|
+
...compiledFiles.map((file) => anchored(file)),
|
|
215
235
|
...[...loose].sort().map((file) => anchored(file)),
|
|
216
236
|
...(external ? [runtimeInput(`${CARGO_HASH_COMMAND} ${closureArguments}`)] : []),
|
|
217
237
|
];
|
|
218
238
|
}
|
|
219
239
|
|
|
240
|
+
/** A compiled-in file and the source whose `include_str!`/`include_bytes!` names it, relative to the workspace root. */
|
|
241
|
+
export interface CompiledInclusion {
|
|
242
|
+
readonly declaring: string;
|
|
243
|
+
readonly file: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The compiled-in files a `cargoClosure` names, sorted: each one Nx's file index holds together with the source that
|
|
248
|
+
* includes it. `held` is the index's answer for exactly those paths. A file it does not hold is a build output or
|
|
249
|
+
* ignored, and naming it would key the graph on whatever last wrote it rather than on the tree.
|
|
250
|
+
*/
|
|
251
|
+
export function indexedCompiledFiles(compiledIn: readonly CompiledInclusion[], held: ReadonlySet<string>): string[] {
|
|
252
|
+
const named = new Set<string>();
|
|
253
|
+
for (const { declaring, file } of compiledIn) {
|
|
254
|
+
if (held.has(declaring) && held.has(file)) named.add(file);
|
|
255
|
+
}
|
|
256
|
+
return [...named].sort();
|
|
257
|
+
}
|
|
258
|
+
|
|
220
259
|
/**
|
|
221
260
|
* `path` relative to the workspace root, `/`-separated, when it is somewhere
|
|
222
261
|
* Nx's file index can hold: inside the workspace and not under `node_modules`.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { afterAll, expect, it } from 'bun:test';
|
|
2
|
+
import { mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import fc from 'fast-check';
|
|
7
|
+
import { WorkspaceContext } from 'nx/src/native/index.js';
|
|
8
|
+
import { resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
9
|
+
import { byFile, closureFixture, closureOf, graphComputation } from './__tests__/cargo-closure-fixture.js';
|
|
10
|
+
import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
|
|
11
|
+
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
12
|
+
import { testFileInstallation } from './__tests__/owned-installation.js';
|
|
13
|
+
import { runtimeInputValue } from './__tests__/runtime-input.js';
|
|
14
|
+
import { CARGO_CLOSURE_INPUT } from './cargo-closure-input.js';
|
|
15
|
+
import { isRecord } from './type-guards.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The pre-push hook's key is the gate's key at the same tree (test-hardening #5).
|
|
19
|
+
*
|
|
20
|
+
* `check:linux` (the gate) writes its verdict under the key Nx computed from a project graph it
|
|
21
|
+
* built before its own tasks ran; the pre-push probe (the hook) recomputes the graph afterwards
|
|
22
|
+
* and reads under that key. A consumer's code generator, run by the gate, rewrites ignored,
|
|
23
|
+
* content-named chunk files and the generated `.rs` sources that `include_str!` them. When the
|
|
24
|
+
* Cargo closure named those files, the generator's own output moved the input list, so every
|
|
25
|
+
* first push of a gated tree was refused (1f5c3a58e). The properties below hold the key to a
|
|
26
|
+
* function of Nx's file index: no history of producer runs moves it, and the real Nx hook run
|
|
27
|
+
* reads exactly the hash the real gate run wrote.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
useFixtureCargoHome();
|
|
31
|
+
|
|
32
|
+
/** The Nx installation this file's fixtures share; none may write into it. */
|
|
33
|
+
const installation = testFileInstallation('cargo-closure-key-installation-');
|
|
34
|
+
afterAll(() => installation.retire());
|
|
35
|
+
|
|
36
|
+
/** The ignored directory the producer owns, inside `leaf`, which every closure of `app` reaches. */
|
|
37
|
+
const GENERATED = 'crates/leaf/src/generated';
|
|
38
|
+
const GITIGNORE = `node_modules/\ntarget/\ndist/\n.nx/\n.runs\n${GENERATED}/\n`;
|
|
39
|
+
|
|
40
|
+
/** `leaf` compiles an indexed file in, and the generated sources by `include!`, as a consumer's tracked sources do. */
|
|
41
|
+
const LEAF_FILES = {
|
|
42
|
+
'workspace/crates/leaf/src/lib.rs': [
|
|
43
|
+
'pub fn answer() -> u8 { 1 }',
|
|
44
|
+
'pub const SKILL: &str = include_str!("../../../skills/SKILL.md");',
|
|
45
|
+
'include!("generated/vocabulary.rs");',
|
|
46
|
+
].join('\n'),
|
|
47
|
+
'workspace/skills/SKILL.md': 'skill-one',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** One producer run: the chunk contents it emits, whether it clears the previous run's files, and where. */
|
|
51
|
+
interface ProducerRun {
|
|
52
|
+
readonly chunks: readonly string[];
|
|
53
|
+
readonly clean: boolean;
|
|
54
|
+
readonly nested: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const producerRun: fc.Arbitrary<ProducerRun> = fc.record({
|
|
58
|
+
chunks: fc.uniqueArray(fc.string({ minLength: 1, maxLength: 12 }), { minLength: 1, maxLength: 3 }),
|
|
59
|
+
clean: fc.boolean(),
|
|
60
|
+
nested: fc.boolean(),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** A content-named chunk, as a bundler names it: the name moves whenever the content does. */
|
|
64
|
+
const chunkName = (content: string) => `chunk-${Bun.hash(content).toString(36)}.js`;
|
|
65
|
+
|
|
66
|
+
/** Write one run's ignored outputs: a table, its chunks, and the generated source including each. */
|
|
67
|
+
async function produce(workspace: string, { chunks, clean, nested }: ProducerRun): Promise<void> {
|
|
68
|
+
const generated = join(workspace, GENERATED);
|
|
69
|
+
if (clean) await rm(generated, { recursive: true, force: true });
|
|
70
|
+
const directory = nested ? join(generated, 'shared') : generated;
|
|
71
|
+
await mkdir(directory, { recursive: true });
|
|
72
|
+
await writeFile(join(generated, 'table.bin'), chunks.join('\0'));
|
|
73
|
+
const includes = chunks.map((content, index) => {
|
|
74
|
+
const name = chunkName(content);
|
|
75
|
+
return { name: `${nested ? 'shared/' : ''}${name}`, content, index };
|
|
76
|
+
});
|
|
77
|
+
for (const { name, content } of includes) await writeFile(join(generated, name), content);
|
|
78
|
+
await writeFile(
|
|
79
|
+
join(generated, 'vocabulary.rs'),
|
|
80
|
+
[
|
|
81
|
+
'pub const TABLE: &[u8] = include_bytes!("table.bin");',
|
|
82
|
+
...includes.map(({ name, index }) => `pub const CHUNK_${index}: &str = include_str!("${name}");`),
|
|
83
|
+
].join('\n'),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let contexts = 0;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* `app`'s Cargo-closure key as a task hashes it: the input list the project graph names, the
|
|
91
|
+
* bytes Nx's file index hashes for its filesets, and the stdout of its runtime entry. A fresh
|
|
92
|
+
* graph computation and a fresh file context each time, as each `nx` process starts with.
|
|
93
|
+
*/
|
|
94
|
+
async function closureKey(workspace: string): Promise<string> {
|
|
95
|
+
resetWorkspaceContext();
|
|
96
|
+
const inputs = closureOf(byFile(await graphComputation(workspace)()), 'packages/app');
|
|
97
|
+
// Every fileset the closure names is workspace-anchored; `!` entries exclude.
|
|
98
|
+
const filesets = inputs.flatMap((input) => (typeof input === 'string' ? [input] : []));
|
|
99
|
+
for (const input of filesets) expect(input).toMatch(/^!?\{workspaceRoot\}\//);
|
|
100
|
+
const anchored = (input: string) => input.replace(/^!?\{workspaceRoot\}\//, '');
|
|
101
|
+
const positive = filesets.filter((input) => !input.startsWith('!')).map(anchored);
|
|
102
|
+
const negative = filesets.filter((input) => input.startsWith('!')).map(anchored);
|
|
103
|
+
contexts += 1;
|
|
104
|
+
const context = new WorkspaceContext(workspace, join(workspace, `.nx/closure-key-${contexts}`));
|
|
105
|
+
const runtime = await Promise.all(
|
|
106
|
+
inputs.flatMap((input) =>
|
|
107
|
+
typeof input === 'object' && 'runtime' in input ? [runtimeInputValue(input.runtime, workspace)] : [],
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
return JSON.stringify({ inputs, files: context.hashFilesMatchingGlob(positive, negative), runtime });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
it('no history of producer runs over ignored compiled-in files moves the Cargo closure key', async () => {
|
|
114
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-closure-key-')));
|
|
115
|
+
try {
|
|
116
|
+
const { workspace, edit } = await closureFixture(installation, root, GITIGNORE, LEAF_FILES);
|
|
117
|
+
const gate = await closureKey(workspace);
|
|
118
|
+
// The key really reaches leaf's compiled-in data, so an unmoved key is not an empty one.
|
|
119
|
+
expect(gate).toContain('{workspaceRoot}/skills/SKILL.md');
|
|
120
|
+
expect(gate).not.toContain('generated/');
|
|
121
|
+
|
|
122
|
+
await fc.assert(
|
|
123
|
+
fc.asyncProperty(fc.array(producerRun, { minLength: 1, maxLength: 4 }), async (history) => {
|
|
124
|
+
await rm(join(workspace, GENERATED), { recursive: true, force: true });
|
|
125
|
+
for (const run of history) await produce(workspace, run);
|
|
126
|
+
expect(await closureKey(workspace)).toBe(gate);
|
|
127
|
+
}),
|
|
128
|
+
{ numRuns: 15 },
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// And an edit Nx's index sees still moves it: the property is not a key that never moves.
|
|
132
|
+
await edit('workspace/skills/SKILL.md', 'skill-two');
|
|
133
|
+
expect(await closureKey(workspace)).not.toBe(gate);
|
|
134
|
+
} finally {
|
|
135
|
+
await rm(root, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const RECEIPT_ENV = 'COWSHED_NX_TASK_RECEIPT_ID';
|
|
140
|
+
const GATE_RECEIPT = '0123456789abcdef0123456789abcdef';
|
|
141
|
+
const HOOK_RECEIPT = 'fedcba9876543210fedcba9876543210';
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The gate's task: a producer like a consumer's runtime-vocabulary generator. Each execution writes a chunk
|
|
145
|
+
* named for a new run number and the generated source including it, replacing the last run's,
|
|
146
|
+
* and counts itself in `.runs`, which no input names.
|
|
147
|
+
*/
|
|
148
|
+
const PRODUCER = [
|
|
149
|
+
'set -e',
|
|
150
|
+
`d=${GENERATED}`,
|
|
151
|
+
'n=$(( $(cat .runs 2>/dev/null || echo 0) + 1 ))',
|
|
152
|
+
'echo "$n" > .runs',
|
|
153
|
+
'rm -rf "$d"',
|
|
154
|
+
'mkdir -p "$d"',
|
|
155
|
+
`printf 'chunk %s' "$n" > "$d/chunk-$n.js"`,
|
|
156
|
+
`printf 'pub const CHUNK: &str = include_str!("chunk-%s.js");\\n' "$n" > "$d/vocabulary.rs"`,
|
|
157
|
+
].join('\n');
|
|
158
|
+
|
|
159
|
+
/** The task hash and cache status the plugin's hint recorded for the one task a receipt's run ran. */
|
|
160
|
+
async function recorded(workspace: string, receipt: string): Promise<{ hash: string; status: string }> {
|
|
161
|
+
const namespace = join(workspace, '.nx/cache/.cowshed-task-results', receipt);
|
|
162
|
+
const files = await readdir(namespace);
|
|
163
|
+
expect(files).toHaveLength(1);
|
|
164
|
+
const [file] = files;
|
|
165
|
+
if (file === undefined) throw new Error(`no hint in ${namespace}`);
|
|
166
|
+
const hint: unknown = JSON.parse(await readFile(join(namespace, file), 'utf8'));
|
|
167
|
+
const tasks = isRecord(hint) && Array.isArray(hint.tasks) ? hint.tasks : [];
|
|
168
|
+
expect(tasks).toHaveLength(1);
|
|
169
|
+
const [entry] = tasks;
|
|
170
|
+
const task = isRecord(entry) && isRecord(entry.task) ? entry.task : undefined;
|
|
171
|
+
expect(task?.id).toBe('app:gate');
|
|
172
|
+
const hash = task?.hash;
|
|
173
|
+
const status = isRecord(entry) ? entry.status : undefined;
|
|
174
|
+
if (typeof hash !== 'string' || typeof status !== 'string') throw new Error(`malformed hint ${namespace}/${file}`);
|
|
175
|
+
return { hash, status };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
it('the hook run reads the key the gate run wrote, after the gate rewrote compiled-in outputs', async () => {
|
|
179
|
+
await withNxFixture(
|
|
180
|
+
'cargo-closure-key',
|
|
181
|
+
async ({ root, workspace, socketDirectory }) => {
|
|
182
|
+
await closureFixture(installation, root, GITIGNORE, {
|
|
183
|
+
...LEAF_FILES,
|
|
184
|
+
'workspace/produce.sh': `${PRODUCER}\n`,
|
|
185
|
+
'workspace/packages/app/package.json': JSON.stringify({
|
|
186
|
+
name: 'app',
|
|
187
|
+
private: true,
|
|
188
|
+
nx: {
|
|
189
|
+
targets: {
|
|
190
|
+
gate: {
|
|
191
|
+
executor: 'nx:run-commands',
|
|
192
|
+
cache: true,
|
|
193
|
+
inputs: [CARGO_CLOSURE_INPUT],
|
|
194
|
+
options: { command: 'sh produce.sh', cwd: '{workspaceRoot}' },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
const { [RECEIPT_ENV]: _inherited, ...env } = fixtureNxEnv(workspace, socketDirectory);
|
|
201
|
+
const nx = async (receipt: string) => {
|
|
202
|
+
const argv = [
|
|
203
|
+
process.execPath,
|
|
204
|
+
join(workspace, 'node_modules/.bin/nx'),
|
|
205
|
+
'run',
|
|
206
|
+
'app:gate',
|
|
207
|
+
'--outputStyle=static',
|
|
208
|
+
];
|
|
209
|
+
const child = Bun.spawn(argv, {
|
|
210
|
+
cwd: workspace,
|
|
211
|
+
env: { ...env, [RECEIPT_ENV]: receipt },
|
|
212
|
+
stdout: 'pipe',
|
|
213
|
+
stderr: 'pipe',
|
|
214
|
+
});
|
|
215
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
216
|
+
child.exited,
|
|
217
|
+
new Response(child.stdout).text(),
|
|
218
|
+
new Response(child.stderr).text(),
|
|
219
|
+
]);
|
|
220
|
+
return { exitCode, log: `${stdout}${stderr}` };
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const gate = await nx(GATE_RECEIPT);
|
|
224
|
+
expect(gate.exitCode, gate.log).toBe(0);
|
|
225
|
+
expect(await readFile(join(workspace, '.runs'), 'utf8')).toBe('1\n');
|
|
226
|
+
// The gate's own execution left a compiled-in file its graph never saw.
|
|
227
|
+
expect(await readdir(join(workspace, GENERATED))).toEqual(['chunk-1.js', 'vocabulary.rs']);
|
|
228
|
+
|
|
229
|
+
const hook = await nx(HOOK_RECEIPT);
|
|
230
|
+
expect(hook.exitCode, hook.log).toBe(0);
|
|
231
|
+
const [gateTask, hookTask] = [await recorded(workspace, GATE_RECEIPT), await recorded(workspace, HOOK_RECEIPT)];
|
|
232
|
+
expect(gateTask.status).toBe('success');
|
|
233
|
+
// The hook computed the gate's hash and read its entry (`-kept-existing`: the task declares no outputs).
|
|
234
|
+
expect(hookTask).toEqual({ hash: gateTask.hash, status: 'local-cache-kept-existing' });
|
|
235
|
+
expect(await readFile(join(workspace, '.runs'), 'utf8')).toBe('1\n');
|
|
236
|
+
},
|
|
237
|
+
'workspace',
|
|
238
|
+
);
|
|
239
|
+
});
|