@smoothbricks/nx-plugin 0.4.24 → 0.4.26
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 +147 -37
- package/dist/bin/smoo-nx-exec.js +3 -14
- package/dist/cargo-closure-input.d.ts +13 -15
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -37
- package/dist/cargo-source-hash.d.ts +12 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +416 -32
- package/dist/cargo-workspace.d.ts +7 -7
- package/dist/cargo-workspace.js +8 -8
- package/dist/ensure-built.d.ts +6 -0
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -96
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +6 -0
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +6 -2
- package/dist/workspace-manifest.d.ts +0 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/envrc +15 -0
- package/managed/raw/git-format-staged.yml +1 -0
- package/managed/raw/tooling/direnv/developer-links.ts +43 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +5 -0
- package/managed/raw/tooling/direnv/inherited-devenv.ts +665 -0
- package/managed/raw/tooling/direnv/setup-environment.ts +123 -7
- package/nextest.toml +3 -37
- package/package.json +40 -3
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +711 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +93 -3
- package/src/bin/smoo-nx-exec.ts +3 -14
- package/src/bounded-test-policy.test.ts +0 -1
- package/src/cargo-closure-input.test.ts +313 -15
- package/src/cargo-closure-input.ts +42 -50
- package/src/cargo-resolve-cache.test.ts +975 -0
- package/src/cargo-source-hash.test.ts +17 -3
- package/src/cargo-source-hash.ts +447 -37
- package/src/cargo-workspace.ts +8 -8
- package/src/ensure-built.test.ts +122 -20
- package/src/ensure-built.ts +82 -5
- package/src/index.test.ts +203 -107
- package/src/index.ts +86 -115
- package/src/managed-assets.ts +12 -0
- package/src/managed-files/files.ts +6 -0
- package/src/manifest-hash.ts +7 -2
- package/src/nextest-partitions.test.ts +150 -0
- package/src/nx-cache-bound.test.ts +114 -0
- package/src/nx-resident-graph-workers.test.ts +121 -0
- package/src/nx-store-resolution.test.ts +98 -0
- package/src/task-history-namespace.test.ts +183 -0
- package/src/workspace-manifest.ts +0 -1
- package/test-timings.json +35 -0
- package/src/__tests__/in-process-nx-index.ts +0 -9
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
7
|
+
import { fixtureNxEnv } from './__tests__/fixture-nx-env.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Guards the cache-bound hunk of `patches/nx@23.2.1.patch`, the local build of
|
|
11
|
+
* nrwl/nx#37269. When nx.json sets no `maxCacheSize`, Nx 23.2.1 bounds its
|
|
12
|
+
* cache at a tenth of the disk holding it, and asks its native
|
|
13
|
+
* `getDefaultMaxCacheSize`, which lists every mounted disk (`sysinfo`
|
|
14
|
+
* `Disks::new_with_refreshed_list`). On macOS that is a `getfsstat` plus IOKit
|
|
15
|
+
* and CacheDelete round trips per mount, on the client's main thread, between
|
|
16
|
+
* hashing and the first task: about 80 ms on a quiet host, and up to 2.3 s
|
|
17
|
+
* measured while disk images attach, detach or resize. Fixture `release pack`
|
|
18
|
+
* runs stalled 16 s and 24 s in that same window with their daemon idle; that
|
|
19
|
+
* this call was the stall is inferred, not captured. The patched bound asks
|
|
20
|
+
* only the cache directory's filesystem (`statfs`).
|
|
21
|
+
*
|
|
22
|
+
* The fixture's Nx runs with that native call replaced by one that throws, so
|
|
23
|
+
* a run that still consults the host's disk inventory fails instead of passing
|
|
24
|
+
* whenever the host happens to be quiet. Drop the hunk, and keep this test,
|
|
25
|
+
* once the Nx version in use contains that fix.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
29
|
+
|
|
30
|
+
/** Loaded into every fixture Nx process before Nx itself. */
|
|
31
|
+
const FORBID_DISK_INVENTORY = `require('nx/src/native').getDefaultMaxCacheSize = () => {
|
|
32
|
+
throw new Error('Nx enumerated the host disks to bound its cache');
|
|
33
|
+
};
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
async function runNx(root: string, env: Record<string, string>): Promise<{ code: number | null; output: string }> {
|
|
37
|
+
const child = spawn(
|
|
38
|
+
'node',
|
|
39
|
+
[join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:build', '--outputStyle=static'],
|
|
40
|
+
{ cwd: root, env, detached: process.platform !== 'win32', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
41
|
+
);
|
|
42
|
+
let output = '';
|
|
43
|
+
child.stdout?.setEncoding('utf8').on('data', (text: string) => {
|
|
44
|
+
output += text;
|
|
45
|
+
});
|
|
46
|
+
child.stderr?.setEncoding('utf8').on('data', (text: string) => {
|
|
47
|
+
output += text;
|
|
48
|
+
});
|
|
49
|
+
const { promise: ended, resolve, reject } = Promise.withResolvers<number | null>();
|
|
50
|
+
child.once('error', reject);
|
|
51
|
+
child.once('close', resolve);
|
|
52
|
+
try {
|
|
53
|
+
const code = await guardEvent(
|
|
54
|
+
ended,
|
|
55
|
+
'Nx app:build to close',
|
|
56
|
+
() => `pid ${child.pid}, exit ${child.exitCode}, signal ${child.signalCode}\n${output}`,
|
|
57
|
+
);
|
|
58
|
+
return { code, output };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (child.pid !== undefined && child.exitCode === null && child.signalCode === null) {
|
|
61
|
+
try {
|
|
62
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, 'SIGKILL');
|
|
63
|
+
} catch (killError) {
|
|
64
|
+
if (!(killError instanceof Error && 'code' in killError && killError.code === 'ESRCH')) {
|
|
65
|
+
throw new AggregateError([error, killError], 'could not retire the failed fixture Nx command');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await ended.catch(() => undefined);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it('bounds the default cache from its own filesystem without listing the host disks', async () => {
|
|
75
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'nx-cache-bound-')));
|
|
76
|
+
try {
|
|
77
|
+
await mkdir(join(root, 'app'));
|
|
78
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
79
|
+
await writeFile(join(root, '.gitignore'), 'node_modules\n.nx\napp/result.txt\n');
|
|
80
|
+
await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'cache-bound-fixture', private: true }));
|
|
81
|
+
// No maxCacheSize: the bound is Nx's default, the code under test.
|
|
82
|
+
await writeFile(join(root, 'nx.json'), '{}\n');
|
|
83
|
+
await writeFile(
|
|
84
|
+
join(root, 'app/project.json'),
|
|
85
|
+
JSON.stringify({
|
|
86
|
+
name: 'app',
|
|
87
|
+
targets: {
|
|
88
|
+
build: {
|
|
89
|
+
executor: 'nx:run-commands',
|
|
90
|
+
cache: true,
|
|
91
|
+
inputs: [],
|
|
92
|
+
outputs: ['{projectRoot}/result.txt'],
|
|
93
|
+
options: { cwd: 'app', command: 'printf built > result.txt' },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
await writeFile(join(root, 'forbid-disk-inventory.cjs'), FORBID_DISK_INVENTORY);
|
|
99
|
+
execFileSync('git', ['init', '--quiet', root], { stdio: 'pipe' });
|
|
100
|
+
|
|
101
|
+
// The bound is taken by the client that runs the tasks, daemon or not.
|
|
102
|
+
// The cache directory does not exist yet, as on a checkout's first run.
|
|
103
|
+
const { code, output } = await runNx(root, {
|
|
104
|
+
...fixtureNxEnv(root),
|
|
105
|
+
NX_DAEMON: 'false',
|
|
106
|
+
NODE_OPTIONS: `--require ${join(root, 'forbid-disk-inventory.cjs')}`,
|
|
107
|
+
});
|
|
108
|
+
expect(output).not.toContain('Nx enumerated the host disks');
|
|
109
|
+
expect(code, output).toBe(0);
|
|
110
|
+
expect(await readFile(join(root, 'app/result.txt'), 'utf8')).toBe('built');
|
|
111
|
+
} finally {
|
|
112
|
+
await rm(root, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
7
|
+
import { fixtureNxEnv, stopFixtureNxDaemon } from './__tests__/fixture-nx-env.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Guards the resident-worker hunk of `patches/nx@23.2.1.patch`, the local build
|
|
11
|
+
* of nrwl/nx#37271. Nx 23.2.1's `PluginLifecycleManager` stops each isolated
|
|
12
|
+
* plugin worker after the last phase it has hooks for, which for the built-in
|
|
13
|
+
* graph plugins is the graph itself. In a one-shot client that frees the
|
|
14
|
+
* worker for the tasks; in the daemon, which recomputes the graph for every
|
|
15
|
+
* tracked file change, it means every change spawns and loads each graph
|
|
16
|
+
* plugin's worker again: 0.4-0.5 s per change on an idle host and 0.9-1.5 s
|
|
17
|
+
* under a gate's load, measured in a dev watcher's fixture daemon. The patched
|
|
18
|
+
* daemon keeps a worker with graph hooks for its own lifetime.
|
|
19
|
+
*
|
|
20
|
+
* The fixture's daemon computes the graph, sees one tracked edit, and computes
|
|
21
|
+
* it again. Unpatched, no graph plugin worker outlives the first graph and the
|
|
22
|
+
* second spawns new ones; patched, the same worker processes answer both.
|
|
23
|
+
* Drop the hunk, and keep this test, once the Nx version in use contains that
|
|
24
|
+
* fix.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
28
|
+
|
|
29
|
+
async function showApp(root: string, env: Record<string, string>): Promise<unknown> {
|
|
30
|
+
const child = spawn('node', [join(repositoryRoot, 'node_modules/.bin/nx'), 'show', 'project', 'app', '--json'], {
|
|
31
|
+
cwd: root,
|
|
32
|
+
env,
|
|
33
|
+
detached: process.platform !== 'win32',
|
|
34
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
35
|
+
});
|
|
36
|
+
let stdout = '';
|
|
37
|
+
let stderr = '';
|
|
38
|
+
child.stdout?.setEncoding('utf8').on('data', (text: string) => {
|
|
39
|
+
stdout += text;
|
|
40
|
+
});
|
|
41
|
+
child.stderr?.setEncoding('utf8').on('data', (text: string) => {
|
|
42
|
+
stderr += text;
|
|
43
|
+
});
|
|
44
|
+
const { promise: ended, resolve, reject } = Promise.withResolvers<number | null>();
|
|
45
|
+
child.once('error', reject);
|
|
46
|
+
child.once('close', resolve);
|
|
47
|
+
try {
|
|
48
|
+
const code = await guardEvent(
|
|
49
|
+
ended,
|
|
50
|
+
'nx show project app to close',
|
|
51
|
+
() => `pid ${child.pid}, exit ${child.exitCode}, signal ${child.signalCode}\n${stdout}${stderr}`,
|
|
52
|
+
);
|
|
53
|
+
expect(code, `${stdout}${stderr}`).toBe(0);
|
|
54
|
+
return JSON.parse(stdout) as unknown;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (child.pid !== undefined && child.exitCode === null && child.signalCode === null) {
|
|
57
|
+
try {
|
|
58
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, 'SIGKILL');
|
|
59
|
+
} catch (killError) {
|
|
60
|
+
if (!(killError instanceof Error && 'code' in killError && killError.code === 'ESRCH')) {
|
|
61
|
+
throw new AggregateError([error, killError], 'could not retire the failed fixture Nx command');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
await ended.catch(() => undefined);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The pids of the isolated plugin workers `daemon` has running now. */
|
|
71
|
+
function pluginWorkers(daemon: number): number[] {
|
|
72
|
+
const found = spawnSync('pgrep', ['-P', String(daemon), '-f', 'plugin-worker.js'], { encoding: 'utf8' });
|
|
73
|
+
// pgrep exits 1 when nothing matches, and 2 or more on a real failure.
|
|
74
|
+
if (found.status === 1) return [];
|
|
75
|
+
if (found.status !== 0) throw new Error(`pgrep failed (${found.status}): ${found.stderr}`, { cause: found.error });
|
|
76
|
+
return found.stdout
|
|
77
|
+
.split('\n')
|
|
78
|
+
.filter((line) => line !== '')
|
|
79
|
+
.map(Number)
|
|
80
|
+
.sort((a, b) => a - b);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
it('keeps the daemon graph plugin workers running from one tracked change to the next', async () => {
|
|
84
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'nx-resident-workers-')));
|
|
85
|
+
// fixtureNxEnv runs plugins in process; this regression is about isolated
|
|
86
|
+
// workers. NX_DAEMON: the daemon is the host under test even when the
|
|
87
|
+
// enclosing gate runs with CI=true, where Nx would otherwise disable it.
|
|
88
|
+
const env = { ...fixtureNxEnv(root), NX_ISOLATE_PLUGINS: 'true', NX_DAEMON: 'true' };
|
|
89
|
+
try {
|
|
90
|
+
await mkdir(join(root, 'app'));
|
|
91
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
92
|
+
await writeFile(join(root, '.gitignore'), 'node_modules\n.nx\n');
|
|
93
|
+
await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'resident-workers-fixture', private: true }));
|
|
94
|
+
await writeFile(join(root, 'nx.json'), '{}\n');
|
|
95
|
+
await writeFile(join(root, 'app/project.json'), JSON.stringify({ name: 'app', tags: ['first'] }));
|
|
96
|
+
execFileSync('git', ['init', '--quiet', root], { stdio: 'pipe' });
|
|
97
|
+
|
|
98
|
+
expect(await showApp(root, env)).toMatchObject({ tags: ['first'] });
|
|
99
|
+
const record = await readFile(join(root, '.nx/workspace-data/d/server-process.json'), 'utf8');
|
|
100
|
+
const server: unknown = JSON.parse(record);
|
|
101
|
+
if (!(typeof server === 'object' && server !== null && 'processId' in server)) {
|
|
102
|
+
throw new Error(`the fixture daemon record names no process: ${record}`);
|
|
103
|
+
}
|
|
104
|
+
const daemon = Number(server.processId);
|
|
105
|
+
const afterFirstGraph = pluginWorkers(daemon);
|
|
106
|
+
expect(afterFirstGraph).not.toEqual([]);
|
|
107
|
+
|
|
108
|
+
// A tracked edit the daemon recomputes the graph for, through the same
|
|
109
|
+
// project.json plugin worker that built the first graph.
|
|
110
|
+
await writeFile(join(root, 'app/project.json'), JSON.stringify({ name: 'app', tags: ['second'] }));
|
|
111
|
+
expect(await showApp(root, env)).toMatchObject({ tags: ['second'] });
|
|
112
|
+
expect(await readFile(join(root, '.nx/workspace-data/d/server-process.json'), 'utf8')).toBe(record);
|
|
113
|
+
expect(pluginWorkers(daemon)).toEqual(afterFirstGraph);
|
|
114
|
+
} finally {
|
|
115
|
+
try {
|
|
116
|
+
await stopFixtureNxDaemon(root);
|
|
117
|
+
} finally {
|
|
118
|
+
await rm(root, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
7
|
+
import { fixtureNxEnv } from './__tests__/fixture-nx-env.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Guards the workspace-resolution hunk of `patches/nx@23.2.1.patch`, the local build of nrwl/nx#37272. The
|
|
11
|
+
* repository installs Nx from an immutable tarball, so Bun links it from its global store
|
|
12
|
+
* (`~/.bun/install/cache/links`), next to nothing but Nx's own dependencies. Nx 23.2.1 loads `typescript` with a
|
|
13
|
+
* plain `require`, which from there finds nothing: its dependency analysis then skips every TypeScript import and
|
|
14
|
+
* the graph loses each edge one project's source import makes to another, without a warning (12 of this
|
|
15
|
+
* repository's 44 edges). The patched Nx resolves `typescript` from the workspace first. Release version actions
|
|
16
|
+
* take the same resolution; `packages/cli`'s release-version tests run them through it.
|
|
17
|
+
*
|
|
18
|
+
* Drop the hunk, and keep this test, once the Nx version in use contains that fix.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
22
|
+
|
|
23
|
+
it('keeps the source-import edges when Nx is linked from the global store', async () => {
|
|
24
|
+
const nx = await realpath(join(repositoryRoot, 'node_modules/nx'));
|
|
25
|
+
// The regression only exists for an Nx linked from Bun's store, outside this checkout (wherever the install
|
|
26
|
+
// cache lives on this host); a project-local Nx resolves typescript by walking up to the repository's
|
|
27
|
+
// node_modules, and this test would prove nothing.
|
|
28
|
+
const checkout = await realpath(repositoryRoot);
|
|
29
|
+
expect(nx.startsWith(`${checkout}/`), `${nx} is inside the checkout`).toBe(false);
|
|
30
|
+
|
|
31
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'nx-store-resolution-')));
|
|
32
|
+
try {
|
|
33
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
34
|
+
await writeFile(join(root, '.gitignore'), 'node_modules\n.nx\n');
|
|
35
|
+
await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'store-resolution-fixture', private: true }));
|
|
36
|
+
// The fixture's root package.json names no @nx/* package, so Nx analyzes source files only when told to.
|
|
37
|
+
await writeFile(
|
|
38
|
+
join(root, 'nx.json'),
|
|
39
|
+
JSON.stringify({ pluginsConfig: { '@nx/js': { analyzeSourceFiles: true } } }),
|
|
40
|
+
);
|
|
41
|
+
await writeFile(
|
|
42
|
+
join(root, 'tsconfig.base.json'),
|
|
43
|
+
JSON.stringify({ compilerOptions: { baseUrl: '.', paths: { '@fixture/a': ['a/src/index.ts'] } } }),
|
|
44
|
+
);
|
|
45
|
+
for (const name of ['a', 'b']) {
|
|
46
|
+
await mkdir(join(root, name, 'src'), { recursive: true });
|
|
47
|
+
await writeFile(join(root, name, 'project.json'), JSON.stringify({ name, sourceRoot: `${name}/src` }));
|
|
48
|
+
}
|
|
49
|
+
await writeFile(join(root, 'a/src/index.ts'), 'export const a = 1;\n');
|
|
50
|
+
// b depends on a only through this import: no package.json, no implicitDependencies.
|
|
51
|
+
await writeFile(join(root, 'b/src/index.ts'), "import { a } from '@fixture/a';\nexport const b = a + 1;\n");
|
|
52
|
+
execFileSync('git', ['init', '--quiet', root], { stdio: 'pipe' });
|
|
53
|
+
|
|
54
|
+
const graphFile = join(root, 'graph.json');
|
|
55
|
+
const child = spawn('node', [join(repositoryRoot, 'node_modules/.bin/nx'), 'graph', `--file=${graphFile}`], {
|
|
56
|
+
cwd: root,
|
|
57
|
+
env: { ...fixtureNxEnv(root), NX_DAEMON: 'false' },
|
|
58
|
+
detached: process.platform !== 'win32',
|
|
59
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
60
|
+
});
|
|
61
|
+
let output = '';
|
|
62
|
+
child.stdout?.setEncoding('utf8').on('data', (text: string) => {
|
|
63
|
+
output += text;
|
|
64
|
+
});
|
|
65
|
+
child.stderr?.setEncoding('utf8').on('data', (text: string) => {
|
|
66
|
+
output += text;
|
|
67
|
+
});
|
|
68
|
+
const { promise: ended, resolve, reject } = Promise.withResolvers<number | null>();
|
|
69
|
+
child.once('error', reject);
|
|
70
|
+
child.once('close', resolve);
|
|
71
|
+
let code: number | null;
|
|
72
|
+
try {
|
|
73
|
+
code = await guardEvent(
|
|
74
|
+
ended,
|
|
75
|
+
'nx graph to close',
|
|
76
|
+
() => `pid ${child.pid}, exit ${child.exitCode}, signal ${child.signalCode}\n${output}`,
|
|
77
|
+
);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (child.pid !== undefined && child.exitCode === null && child.signalCode === null) {
|
|
80
|
+
try {
|
|
81
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, 'SIGKILL');
|
|
82
|
+
} catch (killError) {
|
|
83
|
+
if (!(killError instanceof Error && 'code' in killError && killError.code === 'ESRCH')) {
|
|
84
|
+
throw new AggregateError([error, killError], 'could not retire the failed fixture Nx command');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
await ended.catch(() => undefined);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
expect(code, output).toBe(0);
|
|
92
|
+
expect(JSON.parse(await readFile(graphFile, 'utf8'))).toMatchObject({
|
|
93
|
+
graph: { dependencies: { b: [{ source: 'b', target: 'a', type: 'static' }] } },
|
|
94
|
+
});
|
|
95
|
+
} finally {
|
|
96
|
+
await rm(root, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { expect, it } from 'bun:test';
|
|
3
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
4
|
+
import { mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
8
|
+
import { fixtureNxEnv, stopFixtureNxDaemon } from './__tests__/fixture-nx-env.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Guards `patches/nx@23.2.1.patch`, the local build of nrwl/nx#37268 (issue
|
|
12
|
+
* nrwl/nx#37118): Nx 23.2.1 forwards task history to its daemon, whose database
|
|
13
|
+
* scope can differ from the client's, and a run then exits 1 with SQLite
|
|
14
|
+
* FOREIGN KEY 787 after its tasks succeed. Drop the patch, and keep this test,
|
|
15
|
+
* once the Nx version in use contains that fix.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
19
|
+
|
|
20
|
+
async function runNx(root: string, env: Record<string, string>, configuration: string): Promise<string> {
|
|
21
|
+
const child = spawn(
|
|
22
|
+
'node',
|
|
23
|
+
[join(repositoryRoot, 'node_modules/.bin/nx'), 'run', `app:build:${configuration}`, '--outputStyle=static'],
|
|
24
|
+
{
|
|
25
|
+
cwd: root,
|
|
26
|
+
env,
|
|
27
|
+
detached: process.platform !== 'win32',
|
|
28
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
let output = '';
|
|
32
|
+
child.stdout?.setEncoding('utf8').on('data', (text: string) => {
|
|
33
|
+
output += text;
|
|
34
|
+
});
|
|
35
|
+
child.stderr?.setEncoding('utf8').on('data', (text: string) => {
|
|
36
|
+
output += text;
|
|
37
|
+
});
|
|
38
|
+
const { promise: ended, resolve, reject } = Promise.withResolvers<number | null>();
|
|
39
|
+
child.once('error', reject);
|
|
40
|
+
child.once('close', resolve);
|
|
41
|
+
try {
|
|
42
|
+
const code = await guardEvent(
|
|
43
|
+
ended,
|
|
44
|
+
`Nx app:build:${configuration} to close`,
|
|
45
|
+
() => `pid ${child.pid}, exit ${child.exitCode}, signal ${child.signalCode}\n${output}`,
|
|
46
|
+
);
|
|
47
|
+
expect(code, output).toBe(0);
|
|
48
|
+
return output;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (child.pid !== undefined && child.exitCode === null && child.signalCode === null) {
|
|
51
|
+
try {
|
|
52
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, 'SIGKILL');
|
|
53
|
+
} catch (killError) {
|
|
54
|
+
if (!(killError instanceof Error && 'code' in killError && killError.code === 'ESRCH')) {
|
|
55
|
+
throw new AggregateError([error, killError], 'could not retire the failed fixture Nx command');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await ended.catch(() => undefined);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function recordedRuns(directory: string) {
|
|
65
|
+
const files = (await readdir(directory)).filter((file) => file.endsWith('.db'));
|
|
66
|
+
expect(files).toHaveLength(1);
|
|
67
|
+
const file = files[0];
|
|
68
|
+
if (file === undefined) throw new Error(`no Nx database in ${directory}`);
|
|
69
|
+
// Nx keeps this database in WAL mode, and its last connection deletes the
|
|
70
|
+
// -wal/-shm pair on close. A SQLITE_OPEN_READONLY connection cannot recreate
|
|
71
|
+
// the -shm index and fails with SQLITE_CANTOPEN, so read through an ordinary
|
|
72
|
+
// read-write (never create) connection, which also sees any un-checkpointed
|
|
73
|
+
// WAL frames. The query below only reads.
|
|
74
|
+
const database = new Database(join(directory, file), { readwrite: true });
|
|
75
|
+
try {
|
|
76
|
+
return database
|
|
77
|
+
.query<{ configuration: string; status: string; code: number; cacheCode: number }, []>(`
|
|
78
|
+
SELECT details.configuration, history.status, history.code, cache.code AS cacheCode
|
|
79
|
+
FROM task_history history
|
|
80
|
+
JOIN task_details details ON details.hash = history.hash
|
|
81
|
+
JOIN cache_outputs cache ON cache.hash = history.hash
|
|
82
|
+
WHERE history.status = 'success'
|
|
83
|
+
ORDER BY history.id
|
|
84
|
+
`)
|
|
85
|
+
.all();
|
|
86
|
+
} finally {
|
|
87
|
+
database.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
it('records task history in the client database when the running daemon resolved the shared one', async () => {
|
|
92
|
+
const base = await realpath(await mkdtemp(join(tmpdir(), 'nx-history-owner-')));
|
|
93
|
+
const root = join(base, 'workspace');
|
|
94
|
+
// Nx shares its DB and cache across a repository's checkouts under ~/.nx/<id>;
|
|
95
|
+
// a private HOME keeps that shared scope inside the fixture.
|
|
96
|
+
const home = join(base, 'home');
|
|
97
|
+
const { NX_WORKSPACE_DATA_DIRECTORY: _data, NX_CACHE_DIRECTORY: _cache, ...defaultScope } = fixtureNxEnv(root);
|
|
98
|
+
// NX_DAEMON: this regression needs the daemon even when the enclosing gate
|
|
99
|
+
// runs with CI=true, where Nx would otherwise disable it.
|
|
100
|
+
const sharedEnv = { ...defaultScope, HOME: home, NX_DAEMON: 'true' };
|
|
101
|
+
// Naming the checkout's default workspace-data directory explicitly keeps the
|
|
102
|
+
// same daemon record, but any explicit data/cache directory turns Nx's sharing
|
|
103
|
+
// off: this client's task details and cache rows land in the checkout DB.
|
|
104
|
+
const localEnv = { ...fixtureNxEnv(root), HOME: home, NX_DAEMON: 'true' };
|
|
105
|
+
const localData = join(root, '.nx/workspace-data');
|
|
106
|
+
try {
|
|
107
|
+
await mkdir(join(root, 'app'), { recursive: true });
|
|
108
|
+
await mkdir(home);
|
|
109
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
110
|
+
await writeFile(join(root, '.gitignore'), 'node_modules\n.nx\nexecutions.log\napp/result.txt\n');
|
|
111
|
+
await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'history-owner-fixture', private: true }));
|
|
112
|
+
await writeFile(join(root, 'nx.json'), '{}\n');
|
|
113
|
+
await writeFile(
|
|
114
|
+
join(root, 'app/project.json'),
|
|
115
|
+
JSON.stringify({
|
|
116
|
+
name: 'app',
|
|
117
|
+
targets: {
|
|
118
|
+
build: {
|
|
119
|
+
executor: 'nx:run-commands',
|
|
120
|
+
cache: true,
|
|
121
|
+
inputs: ['{projectRoot}/build.cjs'],
|
|
122
|
+
outputs: ['{projectRoot}/result.txt'],
|
|
123
|
+
options: { cwd: 'app' },
|
|
124
|
+
configurations: {
|
|
125
|
+
first: { command: 'node build.cjs first' },
|
|
126
|
+
second: { command: 'node build.cjs second' },
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
await writeFile(
|
|
133
|
+
join(root, 'app/build.cjs'),
|
|
134
|
+
`const fs = require('node:fs');\nconst value = process.argv[2];\nfs.writeFileSync('result.txt', value);\nfs.appendFileSync('../executions.log', value + '\\n');\n`,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
execFileSync('git', ['init', '--quiet', root], { stdio: 'pipe' });
|
|
138
|
+
// A remote is what gives the checkout the repository identity Nx shares by.
|
|
139
|
+
execFileSync('git', ['-C', root, 'remote', 'add', 'origin', 'https://github.com/example/history-owner.git'], {
|
|
140
|
+
stdio: 'pipe',
|
|
141
|
+
});
|
|
142
|
+
const firstOutput = await runNx(root, sharedEnv, 'first');
|
|
143
|
+
const daemonRecord = join(localData, 'd/server-process.json');
|
|
144
|
+
const initialDaemon = await readFile(daemonRecord, 'utf8').catch(async (error: unknown) => {
|
|
145
|
+
const log = await readFile(join(localData, 'd/daemon.log'), 'utf8').catch(
|
|
146
|
+
(readError: unknown) => `daemon log unreadable: ${String(readError)}`,
|
|
147
|
+
);
|
|
148
|
+
throw new Error(`fixture Nx did not retain its normal daemon record\n${firstOutput}\n${log}`, { cause: error });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Same daemon, but this client's TaskDetails select the checkout DB. Unpatched
|
|
152
|
+
// Nx 23.2.1 forwards RECORD_TASK_RUNS to the daemon, whose DB scope was frozen
|
|
153
|
+
// shared at startup and lacks the new hash: after the successful task footer
|
|
154
|
+
// it prints "DB transaction error ... extended_code: 787" and exits 1.
|
|
155
|
+
await runNx(root, localEnv, 'second');
|
|
156
|
+
expect(await readFile(daemonRecord, 'utf8')).toBe(initialDaemon);
|
|
157
|
+
expect(await readFile(join(root, 'executions.log'), 'utf8')).toBe('first\nsecond\n');
|
|
158
|
+
|
|
159
|
+
// The checkout cache answers the repeat: the recorded hash is usable.
|
|
160
|
+
await runNx(root, localEnv, 'second');
|
|
161
|
+
expect(await readFile(join(root, 'executions.log'), 'utf8')).toBe('first\nsecond\n');
|
|
162
|
+
expect(await readFile(join(root, 'app/result.txt'), 'utf8')).toBe('second');
|
|
163
|
+
expect(await readFile(daemonRecord, 'utf8')).toBe(initialDaemon);
|
|
164
|
+
// Stop the fixture's daemon so no Nx process still holds either database
|
|
165
|
+
// when the independent SQLite reader inspects them.
|
|
166
|
+
await stopFixtureNxDaemon(root);
|
|
167
|
+
const [sharedId, ...otherShared] = await readdir(join(home, '.nx'));
|
|
168
|
+
expect(otherShared).toEqual([]);
|
|
169
|
+
if (sharedId === undefined) throw new Error(`no shared Nx scope under ${home}/.nx`);
|
|
170
|
+
expect(await recordedRuns(join(home, '.nx', sharedId, 'databases'))).toEqual([
|
|
171
|
+
{ configuration: 'first', status: 'success', code: 0, cacheCode: 0 },
|
|
172
|
+
]);
|
|
173
|
+
expect(await recordedRuns(localData)).toEqual([
|
|
174
|
+
{ configuration: 'second', status: 'success', code: 0, cacheCode: 0 },
|
|
175
|
+
]);
|
|
176
|
+
} finally {
|
|
177
|
+
try {
|
|
178
|
+
await stopFixtureNxDaemon(root);
|
|
179
|
+
} finally {
|
|
180
|
+
await rm(base, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"files": {
|
|
4
|
+
"src/index.test.ts": 70559,
|
|
5
|
+
"src/cargo-source-hash.test.ts": 27186,
|
|
6
|
+
"src/ensure-built.test.ts": 25998,
|
|
7
|
+
"src/cargo-resolve-cache.test.ts": 25726,
|
|
8
|
+
"src/cargo-closure-input.test.ts": 19270,
|
|
9
|
+
"src/typecheck-test-policy.test.ts": 7183,
|
|
10
|
+
"src/executors/bounded-exec/executor.test.ts": 5980,
|
|
11
|
+
"src/nextest-partitions.test.ts": 3481,
|
|
12
|
+
"src/executors/napi-cross-toolchain/executor.test.ts": 3336,
|
|
13
|
+
"src/executors/typescript-emit/executor.test.ts": 2499,
|
|
14
|
+
"src/cross-check-policy.test.ts": 2424,
|
|
15
|
+
"src/nextest-extraction.test.ts": 1206,
|
|
16
|
+
"src/managed-files/generator.test.ts": 356,
|
|
17
|
+
"src/managed-files/github-host-cache-isolation.test.ts": 269,
|
|
18
|
+
"src/version-actions.test.ts": 177,
|
|
19
|
+
"src/cargo-workspace.test.ts": 100,
|
|
20
|
+
"src/package-target-policy.test.ts": 63,
|
|
21
|
+
"src/manifest-hash.test.ts": 61,
|
|
22
|
+
"src/bounded-test-policy.test.ts": 40,
|
|
23
|
+
"src/generators/make-public/generator.test.ts": 39,
|
|
24
|
+
"src/release-config-policy.test.ts": 30,
|
|
25
|
+
"src/managed-files/managed-content.test.ts": 28,
|
|
26
|
+
"src/generators/bun-test-tracing/generator.test.ts": 21,
|
|
27
|
+
"src/workspace-config-policy.test.ts": 20,
|
|
28
|
+
"src/generators/create-package/generator.test.ts": 19,
|
|
29
|
+
"src/generators/bounded-test-targets/generator.test.ts": 18,
|
|
30
|
+
"src/bun-bootstrap.test.ts": 14,
|
|
31
|
+
"src/executors/clean-outputs/executor.test.ts": 14,
|
|
32
|
+
"src/managed-files/tree-permissions.test.ts": 14,
|
|
33
|
+
"src/managed-files/tree.test.ts": 12
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-process plugin tests infer targets for temporary fixture workspaces. Nx's
|
|
3
|
-
* daemon client answers file-index queries for the workspace this process
|
|
4
|
-
* started in, never for the fixture root a query names, so a daemon-backed
|
|
5
|
-
* glob would silently describe the wrong tree. With the daemon off, Nx builds
|
|
6
|
-
* the index in process for the root each query names, as a CI run does.
|
|
7
|
-
* Child Nx processes the tests spawn set NX_DAEMON themselves.
|
|
8
|
-
*/
|
|
9
|
-
process.env.NX_DAEMON = 'false';
|