@smoothbricks/nx-plugin 0.7.17 → 0.7.18
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 +204 -64
- package/dist/.build-inputs.json +24 -21
- package/dist/bun-lock-scope.d.ts +128 -20
- package/dist/bun-lock-scope.d.ts.map +1 -1
- package/dist/bun-lock-scope.js +267 -44
- package/dist/cargo-closure-input.d.ts +8 -6
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +14 -11
- package/dist/cargo-source-hash.d.ts +23 -4
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +80 -14
- package/dist/cargo-workspace.d.ts +20 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +42 -22
- package/dist/ensure-built-receipt.d.ts +3 -2
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +3 -2
- package/dist/eslint-config-closure.d.ts +8 -3
- package/dist/eslint-config-closure.d.ts.map +1 -1
- package/dist/eslint-config-closure.js +24 -5
- package/dist/executors/bounded-exec/bounds.d.ts +12 -1
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +8 -4
- package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
- package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-rise.js +111 -0
- package/dist/executors/bounded-exec/executor.d.ts +1 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +54 -22
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +8 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +66 -6
- package/dist/executors/bounded-exec/mbx-pool.d.ts +16 -2
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +18 -2
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +5 -2
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +5 -3
- package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
- package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress-channel.js +113 -0
- package/dist/executors/bounded-exec/progress.d.ts +2 -1
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +123 -16
- package/dist/executors/bounded-exec/schema.d.ts +5 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/schema.js +17 -1
- package/dist/executors/bounded-exec/verdict.d.ts +13 -6
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +34 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +199 -89
- package/dist/managed-files/generator.d.ts +5 -1
- package/dist/managed-files/generator.d.ts.map +1 -1
- package/dist/managed-files/generator.js +22 -7
- package/dist/managed-files/render-memo.d.ts +13 -0
- package/dist/managed-files/render-memo.d.ts.map +1 -0
- package/dist/managed-files/render-memo.js +94 -0
- package/dist/test-program.d.ts +11 -6
- package/dist/test-program.d.ts.map +1 -1
- package/dist/test-program.js +39 -35
- package/dist/tool-bins.d.ts +12 -0
- package/dist/tool-bins.d.ts.map +1 -1
- package/dist/tool-bins.js +31 -6
- package/dist/typecheck-test-policy.d.ts +10 -1
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +40 -24
- package/dist/workspace-index.d.ts +14 -1
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +36 -4
- package/managed/raw/patches/nx@24.0.3.patch +703 -119
- package/managed/raw/tooling/direnv/developer-links.ts +17 -3
- package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
- package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
- package/package.json +3 -2
- package/src/bun-lock-scope.ts +293 -40
- package/src/cargo-closure-input.ts +19 -11
- package/src/cargo-source-hash.ts +103 -13
- package/src/cargo-workspace.ts +59 -20
- package/src/ensure-built-receipt.ts +3 -2
- package/src/eslint-config-closure.ts +27 -6
- package/src/executors/bounded-exec/bounds.ts +13 -4
- package/src/executors/bounded-exec/cpu-rise.ts +156 -0
- package/src/executors/bounded-exec/executor.ts +65 -21
- package/src/executors/bounded-exec/hang-diagnostics.ts +88 -6
- package/src/executors/bounded-exec/mbx-pool.ts +24 -3
- package/src/executors/bounded-exec/mbx-reservations.ts +7 -5
- package/src/executors/bounded-exec/progress-channel.ts +129 -0
- package/src/executors/bounded-exec/progress.ts +2 -1
- package/src/executors/bounded-exec/ram-temp.ts +137 -17
- package/src/executors/bounded-exec/schema.ts +19 -0
- package/src/executors/bounded-exec/verdict.ts +44 -16
- package/src/index.ts +255 -98
- package/src/managed-files/generator.ts +21 -6
- package/src/managed-files/render-memo.ts +135 -0
- package/src/test-program.ts +36 -41
- package/src/tool-bins.ts +35 -6
- package/src/typecheck-test-policy.ts +49 -24
- package/src/workspace-index.ts +40 -5
- package/test-timings.json +6 -0
package/src/cargo-source-hash.ts
CHANGED
|
@@ -14,16 +14,16 @@ import {
|
|
|
14
14
|
import { lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
|
-
import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
17
|
+
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
18
18
|
import type { Readable } from 'node:stream';
|
|
19
19
|
import { CARGO_ANCESTOR_INPUTS } from '@smoothbricks/cargo-retain/cargo-ancestor-inputs';
|
|
20
|
-
import native from 'nx/src/native/index.js';
|
|
20
|
+
import native, { type FileData } from 'nx/src/native/index.js';
|
|
21
21
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
|
|
22
22
|
import { CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
23
23
|
import { describeTeardown, killProcessGroupNow, TEARDOWN_PATIENCE } from './process-group.js';
|
|
24
24
|
import { rustTokens } from './rust-tokens.js';
|
|
25
25
|
|
|
26
|
-
const { IS_WASM, WorkspaceContext } = native;
|
|
26
|
+
const { IS_WASM, WorkspaceContext, hashArray } = native;
|
|
27
27
|
|
|
28
28
|
const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
|
|
29
29
|
|
|
@@ -1025,7 +1025,7 @@ export async function hashCargoPathInputs(
|
|
|
1025
1025
|
const scan = scans.get(input.file);
|
|
1026
1026
|
if (scan !== undefined) {
|
|
1027
1027
|
scans.delete(input.file);
|
|
1028
|
-
collectCompiledInputs(input.file, bytes.toString('utf8'), scan.found);
|
|
1028
|
+
collectCompiledInputs(input.file, includeSpellings(bytes.toString('utf8')), scan.found);
|
|
1029
1029
|
}
|
|
1030
1030
|
hash.update(input.key);
|
|
1031
1031
|
hash.update('\0');
|
|
@@ -1046,7 +1046,7 @@ export async function hashCargoPathInputs(
|
|
|
1046
1046
|
if (!scans.delete(source)) continue;
|
|
1047
1047
|
// Discovery also visits ignored sources. They have no scheduled identity;
|
|
1048
1048
|
// if an include alias later names one, preserve the old read-then-hash path.
|
|
1049
|
-
collectCompiledInputs(source, readFileSync(source, 'utf8'), scan.found);
|
|
1049
|
+
collectCompiledInputs(source, includeSpellings(readFileSync(source, 'utf8')), scan.found);
|
|
1050
1050
|
}
|
|
1051
1051
|
for (const input of [...scan.found.values()].sort((left, right) =>
|
|
1052
1052
|
left.file < right.file ? -1 : left.file > right.file ? 1 : 0,
|
|
@@ -1231,8 +1231,13 @@ function* compiledSourceFiles(root: string): Generator<string> {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
}
|
|
1233
1233
|
|
|
1234
|
-
|
|
1235
|
-
|
|
1234
|
+
/** What a source with no include spells. */
|
|
1235
|
+
const NO_SPELLINGS: readonly string[] = [];
|
|
1236
|
+
|
|
1237
|
+
/** The paths a Rust source's text spells as literal include_str!/include_bytes! arguments. */
|
|
1238
|
+
function includeSpellings(text: string): readonly string[] {
|
|
1239
|
+
if (!text.includes('include_')) return NO_SPELLINGS;
|
|
1240
|
+
const spellings: string[] = [];
|
|
1236
1241
|
const tokens = rustTokens(text);
|
|
1237
1242
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
1238
1243
|
if (tokens[index]?.text !== 'include_str' && tokens[index]?.text !== 'include_bytes') continue;
|
|
@@ -1244,7 +1249,18 @@ function collectCompiledInputs(source: string, text: string, found: Map<string,
|
|
|
1244
1249
|
// must reference path-sized storage, not a view into the decoded source.
|
|
1245
1250
|
const literal = Buffer.from(tokens[index + 3]?.text ?? '', 'utf8').toString('utf8');
|
|
1246
1251
|
const path = INCLUDE_STRING.exec(literal)?.[1] ?? INCLUDE_RAW_STRING.exec(literal)?.[2];
|
|
1247
|
-
if (path
|
|
1252
|
+
if (path !== undefined && path !== '') spellings.push(path);
|
|
1253
|
+
}
|
|
1254
|
+
return spellings;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/** Records each existing file `source` spells, keeping the smallest declaring source and spelling per file. */
|
|
1258
|
+
function collectCompiledInputs(
|
|
1259
|
+
source: string,
|
|
1260
|
+
spellings: readonly string[],
|
|
1261
|
+
found: Map<string, CompiledCargoInput>,
|
|
1262
|
+
): void {
|
|
1263
|
+
for (const path of spellings) {
|
|
1248
1264
|
const file = resolve(dirname(source), path);
|
|
1249
1265
|
if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
1250
1266
|
const prior = found.get(file);
|
|
@@ -1256,15 +1272,89 @@ function collectCompiledInputs(source: string, text: string, found: Map<string,
|
|
|
1256
1272
|
}
|
|
1257
1273
|
|
|
1258
1274
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1275
|
+
* The Rust sources and Cargo packages of Nx's workspace file index (.gitignore and .nxignore applied, as for every
|
|
1276
|
+
* fileset input), canonical and absolute. A graph computation takes a package's sources and nested packages from
|
|
1277
|
+
* here, so it lists no directory and probes no path for a manifest.
|
|
1278
|
+
*/
|
|
1279
|
+
export interface CargoSourceIndex {
|
|
1280
|
+
/** Every `Cargo.toml` in the index, relative to the workspace root. */
|
|
1281
|
+
readonly manifests: ReadonlySet<string>;
|
|
1282
|
+
/** Every directory holding an indexed `Cargo.toml`. */
|
|
1283
|
+
readonly packageDirectories: ReadonlySet<string>;
|
|
1284
|
+
/** Nx's content hash of every indexed `.rs` file. */
|
|
1285
|
+
readonly rustSources: ReadonlyMap<string, string>;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/** {@link CargoSourceIndex} of Nx's file data (workspace-relative paths and content hashes) under the canonical `root`. */
|
|
1289
|
+
export function cargoSourceIndex(root: string, files: Iterable<FileData>): CargoSourceIndex {
|
|
1290
|
+
const manifests = new Set<string>();
|
|
1291
|
+
const packageDirectories = new Set<string>();
|
|
1292
|
+
const rustSources = new Map<string, string>();
|
|
1293
|
+
for (const { file, hash } of files) {
|
|
1294
|
+
if (file === 'Cargo.toml' || file.endsWith('/Cargo.toml')) {
|
|
1295
|
+
manifests.add(file);
|
|
1296
|
+
packageDirectories.add(dirname(join(root, file)));
|
|
1297
|
+
} else if (file.endsWith('.rs')) {
|
|
1298
|
+
rustSources.set(join(root, file), hash);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return { manifests, packageDirectories, rustSources };
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* The include spellings of every Rust source text scanned, by Nx's content hash of that text: a source whose hash is
|
|
1306
|
+
* unchanged is not read again. An entry is kept only when the text read hashes to that hash, so a write Nx's index has
|
|
1307
|
+
* not seen yet is scanned but never remembered under the hash of the bytes it replaced. Entries leave when no index
|
|
1308
|
+
* holds their hash any longer ({@link retainIncludeScans}); nothing expires by time.
|
|
1309
|
+
*/
|
|
1310
|
+
const includeScans = new Map<string, readonly string[]>();
|
|
1311
|
+
|
|
1312
|
+
/** Forgets the scan of every source text `index` no longer holds. */
|
|
1313
|
+
export function retainIncludeScans(index: CargoSourceIndex): void {
|
|
1314
|
+
const held = new Set(index.rustSources.values());
|
|
1315
|
+
for (const hash of includeScans.keys()) if (!held.has(hash)) includeScans.delete(hash);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function includeSpellingsOf(source: string, hash: string): readonly string[] {
|
|
1319
|
+
const known = includeScans.get(hash);
|
|
1320
|
+
if (known !== undefined) return known;
|
|
1321
|
+
const text = readFileSync(source, 'utf8');
|
|
1322
|
+
const spellings = includeSpellings(text);
|
|
1323
|
+
if (hashArray([text]) === hash) includeScans.set(hash, spellings);
|
|
1324
|
+
return spellings;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
const SCAN_SKIPPED: ReadonlySet<string> = new Set(HASH_SKIPPED_DIRECTORIES);
|
|
1328
|
+
|
|
1329
|
+
/** The indexed Rust sources of the package at `root`, with their hashes: none beneath a nested package or a skipped directory. */
|
|
1330
|
+
function* packageRustSources(root: string, index: CargoSourceIndex): Generator<readonly [string, string]> {
|
|
1331
|
+
const prefix = `${root}${sep}`;
|
|
1332
|
+
sources: for (const [source, hash] of index.rustSources) {
|
|
1333
|
+
if (!source.startsWith(prefix)) continue;
|
|
1334
|
+
for (let directory = dirname(source); directory !== root; directory = dirname(directory)) {
|
|
1335
|
+
if (index.packageDirectories.has(directory) || SCAN_SKIPPED.has(basename(directory))) continue sources;
|
|
1336
|
+
}
|
|
1337
|
+
yield [source, hash];
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Existing literal include_str!/include_bytes! files read by this package's Rust sources, as Nx's file index holds
|
|
1343
|
+
* them: a generated (ignored) source is its producer's output and keys a consumer through its dependency outputs.
|
|
1344
|
+
* One graph owns the memo; runtime hashing consumes the same discovery alongside source bytes. Nested packages own
|
|
1345
|
+
* their sources separately. Computed paths remain explicit inputs.
|
|
1262
1346
|
*/
|
|
1263
|
-
export function compiledInFiles(
|
|
1347
|
+
export function compiledInFiles(
|
|
1348
|
+
root: string,
|
|
1349
|
+
index: CargoSourceIndex,
|
|
1350
|
+
cache: Map<string, CompiledCargoInput[]>,
|
|
1351
|
+
): CompiledCargoInput[] {
|
|
1264
1352
|
const cached = cache.get(root);
|
|
1265
1353
|
if (cached !== undefined) return cached;
|
|
1266
1354
|
const found = new Map<string, CompiledCargoInput>();
|
|
1267
|
-
for (const source of
|
|
1355
|
+
for (const [source, hash] of packageRustSources(root, index)) {
|
|
1356
|
+
collectCompiledInputs(source, includeSpellingsOf(source, hash), found);
|
|
1357
|
+
}
|
|
1268
1358
|
const files = [...found.values()].sort((left, right) =>
|
|
1269
1359
|
left.file < right.file ? -1 : left.file > right.file ? 1 : 0,
|
|
1270
1360
|
);
|
package/src/cargo-workspace.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
-
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { readNxJson } from 'nx/src/config/nx-json.js';
|
|
5
5
|
import { parse as parseToml, type TomlTable } from 'smol-toml';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
buildClosure,
|
|
9
|
+
type CargoResolve,
|
|
10
|
+
type CargoSourceIndex,
|
|
11
|
+
type CompiledCargoInput,
|
|
12
|
+
compiledInFiles,
|
|
13
|
+
} from './cargo-source-hash.js';
|
|
8
14
|
|
|
9
15
|
export interface CargoWorkspacePackage {
|
|
10
16
|
name: string;
|
|
@@ -225,6 +231,8 @@ export interface CargoPackageTestInputsOptions {
|
|
|
225
231
|
memberDir: string;
|
|
226
232
|
/** Cargo's locked resolve of that workspace, which decides the crates the member's tests build. */
|
|
227
233
|
cargo: CargoResolve;
|
|
234
|
+
/** Nx's indexed Cargo sources, where the crates' Rust sources and nested packages are found. */
|
|
235
|
+
sources: CargoSourceIndex;
|
|
228
236
|
/** Shared across every call of one graph computation; see {@link createCargoInputsCache}. */
|
|
229
237
|
cache?: CargoInputsCache;
|
|
230
238
|
}
|
|
@@ -236,7 +244,9 @@ export interface CargoPackageTestInputsOptions {
|
|
|
236
244
|
* three targets over ~45 crates that was ~135 derivations and the dominant
|
|
237
245
|
* cost of loading the graph. The cache lives exactly as long as one
|
|
238
246
|
* `createNodes` call — Nx recomputes the graph when a manifest changes, so
|
|
239
|
-
* nothing here can go stale across runs.
|
|
247
|
+
* nothing here can go stale across runs. What outlives the call is keyed by
|
|
248
|
+
* content, not by time: a Rust source's include scan by Nx's hash of it
|
|
249
|
+
* (`compiledInFiles`), so a recomputation reads only the sources that changed.
|
|
240
250
|
*/
|
|
241
251
|
export interface CargoInputsCache {
|
|
242
252
|
readonly manifests: Map<string, Promise<TomlTable>>;
|
|
@@ -249,6 +259,33 @@ export function createCargoInputsCache(): CargoInputsCache {
|
|
|
249
259
|
return { manifests: new Map(), nestedCrateDirs: new Map(), compiledInFiles: new Map(), results: new Map() };
|
|
250
260
|
}
|
|
251
261
|
|
|
262
|
+
/** A producer output a Cargo target hashes: the files one producer edge writes under one closure file set. */
|
|
263
|
+
export interface CargoProducerOutputInput {
|
|
264
|
+
readonly dependentTasksOutputFiles: string;
|
|
265
|
+
readonly transitive: false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The outputs of a Cargo target's producers its compile can read: one `dependentTasksOutputFiles` per file set of its
|
|
270
|
+
* closure (`cargoPackageTestInputs`, or the generic fallback rooted at `projectRoot`). A producer that writes a
|
|
271
|
+
* generated crate source, a compiled-in file or a manifest keys the target; one that writes anywhere else, such as a
|
|
272
|
+
* TypeScript package's `dist`, does not. Nx matches the glob against each output file's workspace-relative path (the
|
|
273
|
+
* same `matchGlobPaths` its `--check` uses), so the `{workspaceRoot}/` anchor is dropped. An exclusion or a named input
|
|
274
|
+
* has no output form, and a producer writes into no build directory the exclusions name.
|
|
275
|
+
*/
|
|
276
|
+
export function cargoProducerOutputInputs(
|
|
277
|
+
inputs: readonly (string | object)[],
|
|
278
|
+
projectRoot: string,
|
|
279
|
+
): CargoProducerOutputInput[] {
|
|
280
|
+
const globs = inputs.flatMap((input) => {
|
|
281
|
+
if (typeof input !== 'string') return [];
|
|
282
|
+
if (input.startsWith('{workspaceRoot}/')) return [input.slice('{workspaceRoot}/'.length)];
|
|
283
|
+
if (input.startsWith('{projectRoot}/')) return [posix.join(projectRoot, input.slice('{projectRoot}/'.length))];
|
|
284
|
+
return [];
|
|
285
|
+
});
|
|
286
|
+
return [...new Set(globs)].map((glob) => ({ dependentTasksOutputFiles: glob, transitive: false }));
|
|
287
|
+
}
|
|
288
|
+
|
|
252
289
|
export function cargoPackageTestInputs(options: CargoPackageTestInputsOptions): Promise<string[]> {
|
|
253
290
|
const cache = options.cache ?? createCargoInputsCache();
|
|
254
291
|
const key = `${options.absoluteProjectRoot}\0${options.memberDir}`;
|
|
@@ -260,7 +297,7 @@ export function cargoPackageTestInputs(options: CargoPackageTestInputsOptions):
|
|
|
260
297
|
}
|
|
261
298
|
|
|
262
299
|
async function deriveCargoPackageTestInputs(
|
|
263
|
-
{ workspaceRoot, absoluteProjectRoot, memberDir, cargo }: CargoPackageTestInputsOptions,
|
|
300
|
+
{ workspaceRoot, absoluteProjectRoot, memberDir, cargo, sources }: CargoPackageTestInputsOptions,
|
|
264
301
|
cache: CargoInputsCache,
|
|
265
302
|
): Promise<string[]> {
|
|
266
303
|
// Every fileset is anchored at `{workspaceRoot}`, never `{projectRoot}`: Nx
|
|
@@ -328,14 +365,14 @@ async function deriveCargoPackageTestInputs(
|
|
|
328
365
|
// Cargo packages can compile include_bytes!, headers, schemas and build.rs,
|
|
329
366
|
// not only Rust sources. Nested packages are separate source owners.
|
|
330
367
|
inputs.add(`${inputPath(absoluteDir)}/**/*`);
|
|
331
|
-
for (const child of nestedCrateDirs(absoluteDir, cache)) {
|
|
368
|
+
for (const child of nestedCrateDirs(absoluteDir, sources, cache)) {
|
|
332
369
|
const childDir = relative(cargoRoot, child).split(sep).join('/');
|
|
333
370
|
if (!dirs.has(childDir)) exclusions.add(`!${inputPath(child)}/**`);
|
|
334
371
|
}
|
|
335
372
|
// `include_str!("../../../skills/SKILL.md")` compiles a file the package's own
|
|
336
373
|
// fileset does not reach; a target that does not hash it serves a binary
|
|
337
374
|
// built from the file's old bytes.
|
|
338
|
-
for (const { file } of compiledInFiles(absoluteDir, cache.compiledInFiles)) {
|
|
375
|
+
for (const { file } of compiledInFiles(absoluteDir, sources, cache.compiledInFiles)) {
|
|
339
376
|
if (isOutsideRoot(relative(absoluteDir, file))) declaredSources.add(file);
|
|
340
377
|
}
|
|
341
378
|
}
|
|
@@ -415,25 +452,27 @@ export function requireExternalRustCratesInput(
|
|
|
415
452
|
}
|
|
416
453
|
|
|
417
454
|
/** Every directory beneath `root` that holds its own `Cargo.toml`, the walk stopping at each. */
|
|
418
|
-
|
|
455
|
+
/** Directories whose packages are never nested crates of a package: build output, VCS and Nx state, installed packages. */
|
|
456
|
+
const NESTED_CRATE_SKIPPED: ReadonlySet<string> = new Set(['target', '.git', 'node_modules', '.nx']);
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* The packages nested in the package at `root`: the indexed package directories beneath it with no other package,
|
|
460
|
+
* and no skipped directory, in between. Read from Nx's file index, so no directory is listed and no path probed.
|
|
461
|
+
*/
|
|
462
|
+
function nestedCrateDirs(root: string, sources: CargoSourceIndex, cache: CargoInputsCache): string[] {
|
|
419
463
|
const cached = cache.nestedCrateDirs.get(root);
|
|
420
464
|
if (cached !== undefined) return cached;
|
|
465
|
+
const prefix = `${root}${sep}`;
|
|
421
466
|
const found: string[] = [];
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (!entry.isDirectory()) continue;
|
|
428
|
-
const child = join(current, entry.name);
|
|
429
|
-
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
430
|
-
} else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
431
|
-
found.push(child);
|
|
432
|
-
} else {
|
|
433
|
-
scan.push(child);
|
|
434
|
-
}
|
|
467
|
+
nested: for (const directory of sources.packageDirectories) {
|
|
468
|
+
if (!directory.startsWith(prefix)) continue;
|
|
469
|
+
if (NESTED_CRATE_SKIPPED.has(basename(directory))) continue;
|
|
470
|
+
for (let parent = dirname(directory); parent !== root; parent = dirname(parent)) {
|
|
471
|
+
if (sources.packageDirectories.has(parent) || NESTED_CRATE_SKIPPED.has(basename(parent))) continue nested;
|
|
435
472
|
}
|
|
473
|
+
found.push(directory);
|
|
436
474
|
}
|
|
475
|
+
found.sort();
|
|
437
476
|
cache.nestedCrateDirs.set(root, found);
|
|
438
477
|
return found;
|
|
439
478
|
}
|
|
@@ -50,8 +50,9 @@ export interface ProducerSourceWitness {
|
|
|
50
50
|
readonly outputs: readonly string[];
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in
|
|
54
|
-
*
|
|
53
|
+
* Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in the process that
|
|
54
|
+
* runs the tasks (patches/README.md, "A run's task hooks run in its own process"), a host shell's or a sandboxed job's,
|
|
55
|
+
* under whatever HOME that process has; git with the operator's HOME
|
|
55
56
|
* reads the operator's global configuration, the sandbox denies it, and git dies (specs/cowshed/04_sandbox.md, the
|
|
56
57
|
* runtime-input contract). A receipt's tree, HEAD and tracked-file status are read under the repository's own
|
|
57
58
|
* configuration alone, so a host run and a sandboxed run agree on them.
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
* `createRequire(module).resolve` and each `import` with
|
|
17
17
|
* `import.meta.resolve(specifier, module)`.
|
|
18
18
|
*
|
|
19
|
-
* A builtin
|
|
20
|
-
*
|
|
19
|
+
* A builtin adds nothing. A package installed outside the workspace's own
|
|
20
|
+
* files is reported by name with the directory whose module loads it: the
|
|
21
|
+
* lint target keys it by the lock scope that declares it there
|
|
22
|
+
* (bun-lock-scope.ts, `bunLoadScope`). A package
|
|
21
23
|
* that resolves into the workspace's own files (a workspace member linked into
|
|
22
24
|
* `node_modules`) is keyed and walked like a relative module. Every loaded
|
|
23
25
|
* file keys the package.json files that decide how it loads: the nearest one
|
|
@@ -36,6 +38,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
36
38
|
import type * as Jiti from 'jiti';
|
|
37
39
|
import ts from 'typescript';
|
|
38
40
|
import typia from 'typia';
|
|
41
|
+
import { type PackageLoad, specifierPackage } from './bun-lock-scope.js';
|
|
39
42
|
|
|
40
43
|
type LoadKind = 'require' | 'import';
|
|
41
44
|
/** One load a module performs: CommonJS `require` and ESM `import` resolve under different conditions. */
|
|
@@ -72,16 +75,18 @@ console.log(JSON.stringify(loads.map(({ kind, specifier, from }) => {
|
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
77
|
* The workspace-relative files `configs` load, transitively, the configs
|
|
75
|
-
* excluded, sorted
|
|
76
|
-
*
|
|
78
|
+
* excluded, sorted, and the installed packages those modules load by name.
|
|
79
|
+
* `indexed` is Nx's workspace file index (at least its JavaScript,
|
|
80
|
+
* TypeScript, JSON and package.json files); a file outside it refuses.
|
|
77
81
|
*/
|
|
78
82
|
export function eslintConfigClosure(
|
|
79
83
|
workspaceRoot: string,
|
|
80
84
|
configs: readonly string[],
|
|
81
85
|
indexed: ReadonlySet<string>,
|
|
82
|
-
): string[] {
|
|
86
|
+
): { readonly files: string[]; readonly packageLoads: PackageLoad[] } {
|
|
83
87
|
const root = realpathSync(workspaceRoot);
|
|
84
88
|
const keyed = new Set<string>();
|
|
89
|
+
const packageLoads = new Map<string, PackageLoad>();
|
|
85
90
|
const jiti = configs.some((config) => TYPESCRIPT_CONFIG.test(config)) ? workspaceJiti(workspaceRoot) : null;
|
|
86
91
|
for (const config of configs) {
|
|
87
92
|
const loader = TYPESCRIPT_CONFIG.test(config) ? jiti : null;
|
|
@@ -103,6 +108,11 @@ export function eslintConfigClosure(
|
|
|
103
108
|
const workspacePath = relative(root, real).split(sep).join('/');
|
|
104
109
|
const installed = workspacePath.split('/').includes('node_modules');
|
|
105
110
|
if (workspacePath.startsWith('../') || isAbsolute(workspacePath) || installed) {
|
|
111
|
+
if (load.bare) {
|
|
112
|
+
const directory = relative(root, dirname(load.from)).split(sep).join('/') || '.';
|
|
113
|
+
const name = specifierPackage(load.specifier);
|
|
114
|
+
packageLoads.set(`${directory}\0${name}`, { directory, name });
|
|
115
|
+
}
|
|
106
116
|
if (load.bare || installed) return;
|
|
107
117
|
throw new Error(
|
|
108
118
|
`${load.importer} imports '${load.specifier}', which resolves outside the workspace to ${real}`,
|
|
@@ -121,7 +131,18 @@ export function eslintConfigClosure(
|
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
}
|
|
124
|
-
return
|
|
134
|
+
return {
|
|
135
|
+
files: [...keyed].sort(),
|
|
136
|
+
packageLoads: [...packageLoads.values()].sort((left, right) =>
|
|
137
|
+
left.directory === right.directory
|
|
138
|
+
? left.name < right.name
|
|
139
|
+
? -1
|
|
140
|
+
: 1
|
|
141
|
+
: left.directory < right.directory
|
|
142
|
+
? -1
|
|
143
|
+
: 1,
|
|
144
|
+
),
|
|
145
|
+
};
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
/** The loads `module` performs that resolve to a file; refuses a computed load or an unresolvable specifier kind. */
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* ceiling starts at spawn. Later zero-hold intervals pause only the idle budget.
|
|
8
8
|
* - Any explicitly queued task process pauses idle, including alongside held grants; ceilings keep running.
|
|
9
9
|
* - The fixture ceiling ends with its segment. The idle clock also stops outside the testing lifecycle.
|
|
10
|
-
* - Finished tests reset the idle budget whether their release byte arrived before or after their output
|
|
10
|
+
* - Finished tests reset the idle budget whether their release byte arrived before or after their output, and so does
|
|
11
|
+
* progress a running test reports on the run's progress channel (progress-channel.ts). The run's CPU is no event:
|
|
12
|
+
* it never resets the budget.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/** The limits a run was given, in milliseconds; an absent one never expires. */
|
|
@@ -63,6 +65,11 @@ export type BoundEvent =
|
|
|
63
65
|
readonly wasTesting: boolean;
|
|
64
66
|
readonly finished: boolean;
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* A running test reported progress on the run's progress channel: it restarts the idle bound as a finished test
|
|
70
|
+
* does, and moves no phase, so `testing` is the answer before and after it.
|
|
71
|
+
*/
|
|
72
|
+
| { readonly kind: 'reported'; readonly at: number; readonly testing: boolean }
|
|
66
73
|
/** The fixture's segment ended: its ceiling no longer applies. */
|
|
67
74
|
| { readonly kind: 'fixture-done' };
|
|
68
75
|
|
|
@@ -151,10 +158,12 @@ export function stepBounds(bounds: Bounds, limits: BoundLimits, event: BoundEven
|
|
|
151
158
|
idleRemaining: bounds.idle === null ? bounds.idleRemaining : Math.max(0, bounds.idle - event.at),
|
|
152
159
|
};
|
|
153
160
|
}
|
|
154
|
-
case 'progress':
|
|
155
|
-
|
|
161
|
+
case 'progress':
|
|
162
|
+
case 'reported': {
|
|
163
|
+
const moved = event.kind === 'reported' || event.finished;
|
|
164
|
+
if (bounds.queued) return moved ? { ...bounds, idleRemaining: limits.idleMs ?? null } : bounds;
|
|
156
165
|
if (!event.testing) return { ...bounds, idle: null, idleRemaining: limits.idleMs ?? null };
|
|
157
|
-
const restart = event.
|
|
166
|
+
const restart = moved || (event.kind === 'progress' && !event.wasTesting);
|
|
158
167
|
if (!restart || limits.idleMs === undefined) return bounds;
|
|
159
168
|
return {
|
|
160
169
|
...bounds,
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { tags } from 'typia';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The CPU a run's tree used while its idle bound counted down. A test that runs a compiler is a build inside the test,
|
|
5
|
+
* which is a defect and not a test (specs/cowshed/08_testing.md, "Integration tests (real substrate)"): the pre-signal
|
|
6
|
+
* snapshot names the processes whose CPU time rose between its two process censuses, so the expiry fails as that and
|
|
7
|
+
* not as an anonymous hang. CPU never restarts the idle bound, which counts only finished tests and the progress a
|
|
8
|
+
* running test reports (progress-channel.ts); this says what ran.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** What a rising process makes of the expiry, said in the same words by the snapshot and by the verdict. */
|
|
12
|
+
export const CPU_RISING_CLASS = "a process in the test's tree was using CPU: likely a build inside the test";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The least gain that names a rise, whatever resolution ps prints CPU time at: 10% of a core over the snapshot's five
|
|
16
|
+
* seconds between censuses.
|
|
17
|
+
*/
|
|
18
|
+
export const CPU_RISE_FLOOR_MS = 500;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What a printed CPU time resolves to, in milliseconds: the value of its last digit. Whole seconds are 1,000, a
|
|
22
|
+
* fraction of n digits is 10^(3-n); a finer fraction is kept to the millisecond, so none is below 1.
|
|
23
|
+
*/
|
|
24
|
+
export type CpuResolutionMs = 1_000 | 100 | 10 | 1;
|
|
25
|
+
|
|
26
|
+
/** A CPU time ps printed, with the resolution it was printed at. */
|
|
27
|
+
export interface CpuTime {
|
|
28
|
+
readonly ms: number;
|
|
29
|
+
readonly resolutionMs: CpuResolutionMs;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The longest command a rise keeps: a compiler's argument list runs to kilobytes, and its name leads it. */
|
|
33
|
+
const COMMAND_CHARS = 160;
|
|
34
|
+
|
|
35
|
+
/** A process whose CPU time rose between the snapshot's two censuses. */
|
|
36
|
+
export interface CpuRise {
|
|
37
|
+
readonly pid: number & tags.Type<'uint32'> & tags.Minimum<1>;
|
|
38
|
+
readonly command: string;
|
|
39
|
+
readonly gainedMs: number & tags.Minimum<0>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One process of a census, as far as CPU is concerned. */
|
|
43
|
+
export interface CpuSample {
|
|
44
|
+
readonly pid: number;
|
|
45
|
+
readonly started: string;
|
|
46
|
+
readonly command: string;
|
|
47
|
+
/** Null when ps printed a CPU time that does not parse. */
|
|
48
|
+
readonly cpu: CpuTime | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CpuChange {
|
|
52
|
+
/** Largest gain first. */
|
|
53
|
+
readonly rising: readonly CpuRise[];
|
|
54
|
+
/** Processes in both censuses that one of them gave no readable CPU time for: not counted idle. */
|
|
55
|
+
readonly unread: readonly number[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolutionOfFraction(digits: number): CpuResolutionMs {
|
|
59
|
+
switch (digits) {
|
|
60
|
+
case 0:
|
|
61
|
+
return 1_000;
|
|
62
|
+
case 1:
|
|
63
|
+
return 100;
|
|
64
|
+
case 2:
|
|
65
|
+
return 10;
|
|
66
|
+
default:
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A ps CPU time (`cputime=`): `[[D-]HH:]MM:SS` with an optional fraction, as Linux prints it (whole seconds) and macOS
|
|
73
|
+
* does (centiseconds). Null for anything else, such as the `-` ps prints for a process it may not read.
|
|
74
|
+
*/
|
|
75
|
+
export function parseCpuTime(text: string): CpuTime | null {
|
|
76
|
+
const match = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+(?:\.(\d+))?)$/.exec(text);
|
|
77
|
+
if (match === null) return null;
|
|
78
|
+
const [, days, hours, minutes, seconds, fraction] = match;
|
|
79
|
+
if (minutes === undefined || seconds === undefined) return null;
|
|
80
|
+
const wholeMinutes = ((Number(days ?? 0) * 24 + Number(hours ?? 0)) * 60 + Number(minutes)) * 60;
|
|
81
|
+
return {
|
|
82
|
+
ms: Math.round((wholeMinutes + Number(seconds)) * 1_000),
|
|
83
|
+
resolutionMs: resolutionOfFraction(fraction?.length ?? 0),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The least gain between two readings of one process that names a rise: twice the coarser of their resolutions, and
|
|
89
|
+
* never under {@link CPU_RISE_FLOOR_MS}. A process that crossed a boundary of the last printed digit on a few
|
|
90
|
+
* milliseconds of work gains one resolution, so two are more than one. That is 2,000 ms between whole-second readings
|
|
91
|
+
* and 500 ms between centisecond ones.
|
|
92
|
+
*/
|
|
93
|
+
export function cpuRiseThresholdMs(before: CpuTime, after: CpuTime): number {
|
|
94
|
+
return Math.max(CPU_RISE_FLOOR_MS, 2 * Math.max(before.resolutionMs, after.resolutionMs));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Each process present in both censuses (same pid and start), as its earlier and its later sample. */
|
|
98
|
+
function paired(before: readonly CpuSample[], after: readonly CpuSample[]): (readonly [CpuSample, CpuSample])[] {
|
|
99
|
+
const earlier = new Map(before.map((sample) => [`${sample.pid} ${sample.started}`, sample]));
|
|
100
|
+
const pairs: (readonly [CpuSample, CpuSample])[] = [];
|
|
101
|
+
for (const sample of after) {
|
|
102
|
+
const first = earlier.get(`${sample.pid} ${sample.started}`);
|
|
103
|
+
if (first !== undefined) pairs.push([first, sample]);
|
|
104
|
+
}
|
|
105
|
+
return pairs;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The processes present in both censuses (same pid and start) whose CPU time rose by at least
|
|
110
|
+
* {@link cpuRiseThresholdMs}.
|
|
111
|
+
*/
|
|
112
|
+
export function cpuChange(before: readonly CpuSample[], after: readonly CpuSample[]): CpuChange {
|
|
113
|
+
const rising: CpuRise[] = [];
|
|
114
|
+
const unread: number[] = [];
|
|
115
|
+
for (const [first, sample] of paired(before, after)) {
|
|
116
|
+
if (first.cpu === null || sample.cpu === null) {
|
|
117
|
+
unread.push(sample.pid);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const gainedMs = sample.cpu.ms - first.cpu.ms;
|
|
121
|
+
if (gainedMs < cpuRiseThresholdMs(first.cpu, sample.cpu)) continue;
|
|
122
|
+
const command =
|
|
123
|
+
sample.command.length > COMMAND_CHARS ? `${sample.command.slice(0, COMMAND_CHARS)}…` : sample.command;
|
|
124
|
+
rising.push({ pid: sample.pid, command, gainedMs });
|
|
125
|
+
}
|
|
126
|
+
rising.sort((a, b) => b.gainedMs - a.gainedMs || a.pid - b.pid);
|
|
127
|
+
return { rising, unread };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The gains {@link cpuChange} held these censuses to, each distinct one once, smallest first: one per resolution of the
|
|
132
|
+
* readings compared, and none when no process had a readable CPU time in both.
|
|
133
|
+
*/
|
|
134
|
+
export function cpuRiseThresholdsMs(before: readonly CpuSample[], after: readonly CpuSample[]): readonly number[] {
|
|
135
|
+
const thresholds = new Set<number>();
|
|
136
|
+
for (const [first, sample] of paired(before, after)) {
|
|
137
|
+
if (first.cpu !== null && sample.cpu !== null) thresholds.add(cpuRiseThresholdMs(first.cpu, sample.cpu));
|
|
138
|
+
}
|
|
139
|
+
return [...thresholds].sort((a, b) => a - b);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The gains of {@link cpuRiseThresholdsMs} in seconds, as the snapshot says them: `2 s`, or `0.5 s or 2 s`. */
|
|
143
|
+
export function describeCpuThresholds(thresholdsMs: readonly number[]): string {
|
|
144
|
+
return thresholdsMs.map((ms) => `${ms / 1_000} s`).join(' or ');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function describeCpuRise(rise: CpuRise): string {
|
|
148
|
+
return `pid ${rise.pid} (${rise.command}) gained ${(rise.gainedMs / 1_000).toFixed(1)} s of CPU`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The largest gains, named, and how many more there were: a parallel build runs many processes. */
|
|
152
|
+
export function describeCpuRises(rises: readonly CpuRise[], named = 3): string {
|
|
153
|
+
const shown = rises.slice(0, named).map(describeCpuRise);
|
|
154
|
+
const more = rises.length - shown.length;
|
|
155
|
+
return `${shown.join('; ')}${more > 0 ? `; and ${more} more` : ''}`;
|
|
156
|
+
}
|