@antelopejs/tooling-configs 0.3.4 → 0.3.5
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/dist/bin/lease.mjs +1 -50
- package/dist/bin/sync.mjs +3 -2
- package/dist/bin/verify.mjs +712 -77
- package/dist/env-DT0UJNeL.mjs +79 -0
- package/dist/{map-mT2iQzit.mjs → map-s_jKqBQv.mjs} +63 -7
- package/dist/verify/index.d.mts +35 -2
- package/package.json +1 -1
package/dist/bin/verify.mjs
CHANGED
|
@@ -4,16 +4,17 @@ import { a as isString, c as object, f as parseJson, i as isObject, n as childre
|
|
|
4
4
|
import { a as exitIs, c as interrupted, i as exists, r as equal, u as refused } from "../checks-CxkSu2E6.mjs";
|
|
5
5
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
6
6
|
import { c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
7
|
-
import { a as readFeatures, c as allocateRun, d as loadRun, f as openWorkspace, i as planFor, l as git, m as
|
|
8
|
-
import { appendFileSync, closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync, rmdirSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { dirname, extname, isAbsolute, join, matchesGlob, posix, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { a as readFeatures, c as allocateRun, d as loadRun, f as openWorkspace, g as saveRun, h as removeTree, i as planFor, l as git, m as operatorTmpdir, n as SMOKE_FEATURE, o as CACHE_DIR, p as operatorEnv, r as checkMap, s as RUNS_DIR, u as isolatedEnv } from "../map-s_jKqBQv.mjs";
|
|
8
|
+
import { appendFileSync, closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { basename, dirname, extname, isAbsolute, join, matchesGlob, posix, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import ts from "typescript";
|
|
13
|
-
import { createHash } from "node:crypto";
|
|
13
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
14
14
|
import { constants as constants$1, tmpdir } from "node:os";
|
|
15
15
|
import { parseArgs } from "node:util";
|
|
16
16
|
import { createServer } from "node:net";
|
|
17
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
17
18
|
//#region src/verify/doors.ts
|
|
18
19
|
const RELEASE_FILES = [
|
|
19
20
|
"package.json",
|
|
@@ -339,7 +340,7 @@ const DETAIL_LENGTH = 160;
|
|
|
339
340
|
const OUTPUT_LIMIT$1 = 67108864;
|
|
340
341
|
/** Runs `action` in a throwaway worktree of `sha` whose `node_modules` links the checkout's, then removes it. */
|
|
341
342
|
function inWorktree(repo, sha, action) {
|
|
342
|
-
const dir = mkdtempSync(join(
|
|
343
|
+
const dir = mkdtempSync(join(operatorTmpdir(), "antelopejs-verify-behaviour-"));
|
|
343
344
|
git(repo, [
|
|
344
345
|
"worktree",
|
|
345
346
|
"add",
|
|
@@ -370,6 +371,7 @@ function probeFingerprint(repo, command, sha) {
|
|
|
370
371
|
return inWorktree(repo, sha, (dir) => {
|
|
371
372
|
const run = spawnSync(program, [...args, dir], {
|
|
372
373
|
cwd: repo,
|
|
374
|
+
env: operatorEnv(),
|
|
373
375
|
encoding: "utf8",
|
|
374
376
|
maxBuffer: OUTPUT_LIMIT$1
|
|
375
377
|
});
|
|
@@ -451,6 +453,61 @@ function behaviourChange(repo, check, commits) {
|
|
|
451
453
|
};
|
|
452
454
|
}
|
|
453
455
|
//#endregion
|
|
456
|
+
//#region src/verify/timing.ts
|
|
457
|
+
/** Starts a clock; the returned function gives the whole milliseconds elapsed since. */
|
|
458
|
+
function stopwatch() {
|
|
459
|
+
const start = performance.now();
|
|
460
|
+
return () => Math.round(performance.now() - start);
|
|
461
|
+
}
|
|
462
|
+
/** Runs `phase` and records how long it took on the run, also when it throws, so a run whose `new` failed still shows the time it spent; a failed phase is labelled as such. */
|
|
463
|
+
async function timed(state, phase, run) {
|
|
464
|
+
const elapsed = stopwatch();
|
|
465
|
+
let failed = true;
|
|
466
|
+
try {
|
|
467
|
+
const value = await run();
|
|
468
|
+
failed = false;
|
|
469
|
+
return value;
|
|
470
|
+
} finally {
|
|
471
|
+
state.timings.push({
|
|
472
|
+
phase: failed ? `${phase} (failed)` : phase,
|
|
473
|
+
ms: elapsed()
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Times the step folders of one journey: a step lasts from the `start` call
|
|
479
|
+
* that names it to the next `start` call, or to `finish` for the last one.
|
|
480
|
+
*/
|
|
481
|
+
var StepClock = class {
|
|
482
|
+
times = [];
|
|
483
|
+
open = null;
|
|
484
|
+
/** Ends the running step, if any, and starts timing `step`. */
|
|
485
|
+
start(step) {
|
|
486
|
+
this.close();
|
|
487
|
+
this.open = {
|
|
488
|
+
step,
|
|
489
|
+
elapsed: stopwatch()
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
/** Ends the running step and returns how long every step lasted, in the order they started. */
|
|
493
|
+
finish() {
|
|
494
|
+
this.close();
|
|
495
|
+
return this.times;
|
|
496
|
+
}
|
|
497
|
+
close() {
|
|
498
|
+
if (this.open === null) return;
|
|
499
|
+
this.times.push({
|
|
500
|
+
step: this.open.step,
|
|
501
|
+
ms: this.open.elapsed()
|
|
502
|
+
});
|
|
503
|
+
this.open = null;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
/** Milliseconds as seconds with one decimal, e.g. `12.3 s`; `not measured` when there is no measurement. */
|
|
507
|
+
function seconds(ms) {
|
|
508
|
+
return ms === null || ms === void 0 ? "not measured" : `${(ms / 1e3).toFixed(1)} s`;
|
|
509
|
+
}
|
|
510
|
+
//#endregion
|
|
454
511
|
//#region src/verify/formal.ts
|
|
455
512
|
const OUTPUT_LIMIT = 67108864;
|
|
456
513
|
function changesCheckFiles(check, changed) {
|
|
@@ -479,6 +536,7 @@ function runCommand(command, cwd) {
|
|
|
479
536
|
const [program, ...args] = command;
|
|
480
537
|
return spawnSync(program, args, {
|
|
481
538
|
cwd,
|
|
539
|
+
env: operatorEnv(),
|
|
482
540
|
encoding: "utf8",
|
|
483
541
|
maxBuffer: OUTPUT_LIMIT
|
|
484
542
|
});
|
|
@@ -525,6 +583,7 @@ function gateFields(workspace, check, diff, folder, head) {
|
|
|
525
583
|
* the rules the base broke that HEAD reports neither failing nor passing.
|
|
526
584
|
*/
|
|
527
585
|
function runFormalCheck(workspace, state, check, diff) {
|
|
586
|
+
const elapsed = stopwatch();
|
|
528
587
|
const folder = join(state.evidence, "formal", check.name);
|
|
529
588
|
mkdirSync(folder, { recursive: true });
|
|
530
589
|
const run = runCommand(check.command, workspace.root);
|
|
@@ -541,6 +600,7 @@ function runFormalCheck(workspace, state, check, diff) {
|
|
|
541
600
|
baseSha: diff.baseSha,
|
|
542
601
|
headSha: diff.headSha
|
|
543
602
|
} }, gateFields(workspace, check, diff, folder, head));
|
|
603
|
+
result.ms = elapsed();
|
|
544
604
|
writeFileSync(join(folder, "result.json"), `${JSON.stringify(result, null, 2)}\n`);
|
|
545
605
|
return result;
|
|
546
606
|
}
|
|
@@ -742,20 +802,30 @@ function startServices(workspace, state, prefix) {
|
|
|
742
802
|
definition.image
|
|
743
803
|
];
|
|
744
804
|
const folder = join(state.evidence, "services", service);
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
805
|
+
const elapsed = stopwatch();
|
|
806
|
+
let failed = true;
|
|
807
|
+
try {
|
|
808
|
+
const started = docker(args);
|
|
809
|
+
record(join(folder, "01-run"), args, started);
|
|
810
|
+
if (started.status !== 0) throw new Error(`docker ${args.join(" ")} failed: ${started.stderr}`);
|
|
811
|
+
const container = {
|
|
812
|
+
service,
|
|
813
|
+
name,
|
|
814
|
+
host: "127.0.0.1",
|
|
815
|
+
port: 0
|
|
816
|
+
};
|
|
817
|
+
state.containers.push(container);
|
|
818
|
+
saveRun(state);
|
|
819
|
+
container.port = publishedPort(name, definition.port);
|
|
820
|
+
saveRun(state);
|
|
821
|
+
waitReady(name, definition.ready, join(folder, "02-ready"));
|
|
822
|
+
failed = false;
|
|
823
|
+
} finally {
|
|
824
|
+
state.timings.push({
|
|
825
|
+
phase: `service ${service} (start and ready)${failed ? " (failed)" : ""}`,
|
|
826
|
+
ms: elapsed()
|
|
827
|
+
});
|
|
828
|
+
}
|
|
759
829
|
}
|
|
760
830
|
}
|
|
761
831
|
/** Runs a service's readiness command once in its container, recorded in `folder`: the stderr when it fails, `null` when it passes. */
|
|
@@ -2105,16 +2175,22 @@ function setupCommands(workspace) {
|
|
|
2105
2175
|
async function runSetup(workspace, state) {
|
|
2106
2176
|
const commands = setupCommands(workspace);
|
|
2107
2177
|
for (const [index, [program, ...args]] of commands.entries()) {
|
|
2108
|
-
const
|
|
2178
|
+
const name = `${String(index + 1).padStart(2, "0")}-${program}`;
|
|
2179
|
+
const folder = join(state.evidence, "setup", name);
|
|
2180
|
+
const elapsed = stopwatch();
|
|
2109
2181
|
const result = await runRecorded(folder, {
|
|
2110
2182
|
program,
|
|
2111
2183
|
args,
|
|
2112
2184
|
cwd: workspace.root,
|
|
2113
2185
|
env: {
|
|
2114
|
-
...
|
|
2186
|
+
...operatorEnv(),
|
|
2115
2187
|
...workspace.config.env
|
|
2116
2188
|
}
|
|
2117
2189
|
});
|
|
2190
|
+
state.timings.push({
|
|
2191
|
+
phase: `setup/${name}${result.exitCode === 0 ? "" : " (failed)"}`,
|
|
2192
|
+
ms: elapsed()
|
|
2193
|
+
});
|
|
2118
2194
|
if (result.exitCode !== 0) throw new Error(`setup \`${result.command}\` exited ${result.exitCode}; see ${folder}`);
|
|
2119
2195
|
}
|
|
2120
2196
|
}
|
|
@@ -2175,7 +2251,7 @@ function recorded(dir) {
|
|
|
2175
2251
|
};
|
|
2176
2252
|
}
|
|
2177
2253
|
}
|
|
2178
|
-
function entries(folder) {
|
|
2254
|
+
function entries$1(folder) {
|
|
2179
2255
|
try {
|
|
2180
2256
|
return readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(folder, entry.name));
|
|
2181
2257
|
} catch {
|
|
@@ -2202,7 +2278,7 @@ function pruneRun(dir, now) {
|
|
|
2202
2278
|
*/
|
|
2203
2279
|
function pruneRuns() {
|
|
2204
2280
|
const now = Date.now();
|
|
2205
|
-
for (const repo of entries(RUNS_DIR)) for (const dir of entries(repo)) pruneRun(dir, now);
|
|
2281
|
+
for (const repo of entries$1(RUNS_DIR)) for (const dir of entries$1(repo)) pruneRun(dir, now);
|
|
2206
2282
|
}
|
|
2207
2283
|
/**
|
|
2208
2284
|
* Creates an isolated run: runs the setup (the build by default), then
|
|
@@ -2211,17 +2287,26 @@ function pruneRuns() {
|
|
|
2211
2287
|
* kind's backing `services` start in Docker on free ports.
|
|
2212
2288
|
*/
|
|
2213
2289
|
async function createRun(workspace, baseRef, title, all) {
|
|
2290
|
+
const pruned = stopwatch();
|
|
2214
2291
|
pruneRuns();
|
|
2292
|
+
const pruneMs = pruned();
|
|
2215
2293
|
const state = allocateRun(workspace, baseRef, title, all);
|
|
2294
|
+
state.timings.push({
|
|
2295
|
+
phase: "prune old runs",
|
|
2296
|
+
ms: pruneMs
|
|
2297
|
+
});
|
|
2216
2298
|
saveRun(state);
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2299
|
+
try {
|
|
2300
|
+
await runSetup(workspace, state);
|
|
2301
|
+
if (workspace.kind === "interface") state.pack = await timed(state, "pack interface", () => packInterface(workspace, state));
|
|
2302
|
+
startServices(workspace, state, containerPrefix());
|
|
2303
|
+
if (workspace.kind === "template") await timed(state, "seed template sources", () => {
|
|
2304
|
+
state.manifestUrl = seedSources(workspace, state);
|
|
2305
|
+
state.templateName = templateName(workspace);
|
|
2306
|
+
});
|
|
2307
|
+
} finally {
|
|
2308
|
+
saveRun(state);
|
|
2223
2309
|
}
|
|
2224
|
-
saveRun(state);
|
|
2225
2310
|
return state;
|
|
2226
2311
|
}
|
|
2227
2312
|
function alive(pid) {
|
|
@@ -2530,6 +2615,478 @@ const BUILTIN_JOURNEYS = {
|
|
|
2530
2615
|
}
|
|
2531
2616
|
};
|
|
2532
2617
|
//#endregion
|
|
2618
|
+
//#region src/verify/app-fault.ts
|
|
2619
|
+
/** The signals a process outside the run sends to end an app. Any other signal, such as SIGABRT or SIGSEGV, is the product crashing. */
|
|
2620
|
+
const OUTSIDE_KILLS = /* @__PURE__ */ new Set([
|
|
2621
|
+
"SIGKILL",
|
|
2622
|
+
"SIGTERM",
|
|
2623
|
+
"SIGHUP",
|
|
2624
|
+
"SIGINT"
|
|
2625
|
+
]);
|
|
2626
|
+
/**
|
|
2627
|
+
* Why one of the apps a journey started points away from the product, or
|
|
2628
|
+
* `null`: an app killed by SIGKILL, SIGTERM, SIGHUP or SIGINT that the harness
|
|
2629
|
+
* did not send, or an app that could not bind the port the harness gave it.
|
|
2630
|
+
*/
|
|
2631
|
+
function appFault(started) {
|
|
2632
|
+
for (const { app, sent, exit } of started) {
|
|
2633
|
+
const label = `${app.name} (pid ${app.pid})`;
|
|
2634
|
+
if (exit?.signal && OUTSIDE_KILLS.has(exit.signal) && !sent.includes(exit.signal)) return `${label} was killed by ${exit.signal}, a signal the harness did not send`;
|
|
2635
|
+
const output = readOutput(app.folder);
|
|
2636
|
+
const port = new RegExp(`(?<![0-9])${app.port}(?![0-9])`);
|
|
2637
|
+
const taken = `${output.stdout}\n${output.stderr}`.split("\n").find((line) => line.includes("EADDRINUSE") && port.test(line));
|
|
2638
|
+
if (taken !== void 0) return `${label} could not bind port ${app.port}, which another process holds: ${taken.trim().slice(0, 300)}`;
|
|
2639
|
+
}
|
|
2640
|
+
return null;
|
|
2641
|
+
}
|
|
2642
|
+
//#endregion
|
|
2643
|
+
//#region src/verify/caches.ts
|
|
2644
|
+
/** Where `ajs` installs the modules of a project that names no other `cacheFolder`. */
|
|
2645
|
+
const PROJECT_CACHE = join(".antelope", "cache");
|
|
2646
|
+
const MANIFEST = "manifest.json";
|
|
2647
|
+
/** Where `ajs` keeps a project's lock records, one folder per `<package>@<version>`. */
|
|
2648
|
+
const LOCK_FOLDER = "antelope-lock";
|
|
2649
|
+
/** How many milliseconds the harness waits at most for the file system clock to pass an install. */
|
|
2650
|
+
const CLOCK_ATTEMPTS = 100;
|
|
2651
|
+
/** A start time later than every command's, for a module the harness first sees outside a command: any lock record it has counts as one `ajs` installed it from. */
|
|
2652
|
+
const UNKNOWN_START = 2n ** 63n;
|
|
2653
|
+
/** A version `ajs` records for a registry package; a git module records `git:<branch>:<commit>`. */
|
|
2654
|
+
const REGISTRY_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]*)?$/;
|
|
2655
|
+
/** When the folder at `path` was created, which tells apart the folders created one after another there even when the file system reuses the inode; `0n` when the file system does not record it. */
|
|
2656
|
+
function bornAt(path) {
|
|
2657
|
+
try {
|
|
2658
|
+
return lstatSync(path, { bigint: true }).birthtimeNs;
|
|
2659
|
+
} catch {
|
|
2660
|
+
return 0n;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
/** Whether `project` held the lock record of `name@version` when a command that started at `start` began; `ajs` writes a record only after an install that used none. */
|
|
2664
|
+
function pinned(project, name, version, start) {
|
|
2665
|
+
try {
|
|
2666
|
+
const record = join(project, LOCK_FOLDER, `${name}@${version}`);
|
|
2667
|
+
return lstatSync(record, { bigint: true }).mtimeNs <= start;
|
|
2668
|
+
} catch {
|
|
2669
|
+
return false;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
function names(folder) {
|
|
2673
|
+
try {
|
|
2674
|
+
return readdirSync(folder).filter((name) => !name.startsWith("."));
|
|
2675
|
+
} catch {
|
|
2676
|
+
return [];
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
/** Every entry under `root`, by its path relative to `root`, with its modification time; symbolic links are listed, not followed. */
|
|
2680
|
+
function* entries(root, prefix = "") {
|
|
2681
|
+
for (const entry of readdirSync(join(root, prefix), { withFileTypes: true })) {
|
|
2682
|
+
const path = join(prefix, entry.name);
|
|
2683
|
+
const directory = entry.isDirectory();
|
|
2684
|
+
yield {
|
|
2685
|
+
path,
|
|
2686
|
+
mtime: lstatSync(join(root, path), { bigint: true }).mtimeNs,
|
|
2687
|
+
directory
|
|
2688
|
+
};
|
|
2689
|
+
if (directory) yield* entries(root, path);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
/** Whether a project's antelope config (antelope.json or antelope.config.*) mentions `cacheFolder`, so `ajs` may install somewhere other than `.antelope/cache`. */
|
|
2693
|
+
function namesCacheFolder(project) {
|
|
2694
|
+
try {
|
|
2695
|
+
return readdirSync(project).filter((name) => /^antelope(\.config)?\.[cm]?[jt]s(on)?$/.test(name)).some((name) => /\bcacheFolder\b/.test(readFileSync(join(project, name), "utf8")));
|
|
2696
|
+
} catch {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* Copies `source` into a staging entry next to `target` and renames it onto
|
|
2702
|
+
* `target`, so a reader sees all of the copy or none of it. A failed copy, a
|
|
2703
|
+
* deleted source or a `target` another writer filled first leaves `target`
|
|
2704
|
+
* as it was.
|
|
2705
|
+
*/
|
|
2706
|
+
function publish(source, target) {
|
|
2707
|
+
const staging = join(dirname(target), `.staging-${randomBytes(6).toString("hex")}`);
|
|
2708
|
+
try {
|
|
2709
|
+
cpSync(source, staging, {
|
|
2710
|
+
recursive: true,
|
|
2711
|
+
verbatimSymlinks: true,
|
|
2712
|
+
preserveTimestamps: true
|
|
2713
|
+
});
|
|
2714
|
+
renameSync(staging, target);
|
|
2715
|
+
} catch {
|
|
2716
|
+
return;
|
|
2717
|
+
} finally {
|
|
2718
|
+
removeTree(staging);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
/** The manifest `ajs` writes each time it finishes installing a module: its modification time and each module's version, sorted by module. */
|
|
2722
|
+
function manifestOf(cache) {
|
|
2723
|
+
try {
|
|
2724
|
+
const file = join(cache, MANIFEST);
|
|
2725
|
+
const manifest = parseJson(readFileSync(file, "utf8"));
|
|
2726
|
+
if (!isObject(manifest)) return void 0;
|
|
2727
|
+
const modules = Object.entries(manifest).map(([name, version]) => [name, String(version)]).sort(([left], [right]) => left < right ? -1 : 1);
|
|
2728
|
+
return {
|
|
2729
|
+
mtime: lstatSync(file, { bigint: true }).mtimeNs,
|
|
2730
|
+
modules
|
|
2731
|
+
};
|
|
2732
|
+
} catch {
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Why `cache` is not exactly what `ajs` installed, or `undefined` when it is.
|
|
2738
|
+
* Each file of a module must be no newer than the module's bound. Outside the
|
|
2739
|
+
* modules, `ajs` writes only the manifest and the folders that hold the
|
|
2740
|
+
* modules, which must be no newer than the manifest.
|
|
2741
|
+
*/
|
|
2742
|
+
function changeIn(cache, installed, manifest) {
|
|
2743
|
+
const modules = [...installed].map(([name, module]) => ({
|
|
2744
|
+
folder: join(name),
|
|
2745
|
+
label: `${name}@${module.version}`,
|
|
2746
|
+
bound: module.bound
|
|
2747
|
+
}));
|
|
2748
|
+
try {
|
|
2749
|
+
for (const { path, mtime, directory } of entries(cache)) {
|
|
2750
|
+
if (path === MANIFEST) continue;
|
|
2751
|
+
const owner = modules.find(({ folder }) => path === folder || path.startsWith(`${folder}${sep}`));
|
|
2752
|
+
if (owner === void 0) {
|
|
2753
|
+
if (!directory) return `${path} belongs to no installed module`;
|
|
2754
|
+
if (mtime > manifest) return `${path} changed after ajs wrote ${MANIFEST}`;
|
|
2755
|
+
} else if (mtime > owner.bound) return `${path} changed after ajs installed ${owner.label}`;
|
|
2756
|
+
}
|
|
2757
|
+
} catch (error) {
|
|
2758
|
+
return `it could not be read: ${error instanceof Error ? error.message : String(error)}`;
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
/**
|
|
2762
|
+
* The module caches of the projects one journey creates, and the run's kept
|
|
2763
|
+
* copies of them in `store`. Kept copies are never written, so journeys of
|
|
2764
|
+
* one run can copy them at once.
|
|
2765
|
+
*
|
|
2766
|
+
* Only a cache exactly as a fresh `ajs` install leaves it is kept. `ajs`
|
|
2767
|
+
* writes a registry module's files, then records its version in
|
|
2768
|
+
* `manifest.json`, so the manifest's modification time when the harness first
|
|
2769
|
+
* sees the module bounds every file of it. A file modified later, a module
|
|
2770
|
+
* whose version or folder changes after that, a module `ajs` installed from a
|
|
2771
|
+
* lock record the project held before the command, and a git module, which
|
|
2772
|
+
* `ajs` updates in place and builds with the project's own install command,
|
|
2773
|
+
* each keep the cache out of the store.
|
|
2774
|
+
*/
|
|
2775
|
+
var ProjectCaches = class {
|
|
2776
|
+
store;
|
|
2777
|
+
projects = /* @__PURE__ */ new Map();
|
|
2778
|
+
constructor(store) {
|
|
2779
|
+
this.store = store;
|
|
2780
|
+
}
|
|
2781
|
+
/** Gives a project that has installed no module yet a copy of the largest kept cache, so `ajs` reuses the packages an earlier journey installed instead of packing and installing them again. A project whose antelope config names its own `cacheFolder` gets no copy, since `ajs` would not read `.antelope/cache`. */
|
|
2782
|
+
seed(project) {
|
|
2783
|
+
const state = { installed: /* @__PURE__ */ new Map() };
|
|
2784
|
+
this.projects.set(project, state);
|
|
2785
|
+
if (namesCacheFolder(project)) return;
|
|
2786
|
+
const cache = join(project, PROJECT_CACHE);
|
|
2787
|
+
if ((manifestOf(cache)?.modules.length ?? 0) > 0) {
|
|
2788
|
+
this.observe();
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
let largest;
|
|
2792
|
+
for (const name of names(this.store)) {
|
|
2793
|
+
const folder = join(this.store, name);
|
|
2794
|
+
const size = manifestOf(folder)?.modules.length ?? 0;
|
|
2795
|
+
if (size > (largest?.size ?? 0)) largest = {
|
|
2796
|
+
folder,
|
|
2797
|
+
size
|
|
2798
|
+
};
|
|
2799
|
+
}
|
|
2800
|
+
if (largest === void 0) return;
|
|
2801
|
+
mkdirSync(dirname(cache), { recursive: true });
|
|
2802
|
+
publish(largest.folder, cache);
|
|
2803
|
+
const copied = manifestOf(cache);
|
|
2804
|
+
if (copied === void 0) return;
|
|
2805
|
+
let bound = copied.mtime;
|
|
2806
|
+
try {
|
|
2807
|
+
for (const { mtime } of entries(cache)) if (mtime > bound) bound = mtime;
|
|
2808
|
+
} catch {
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2811
|
+
for (const [name, version] of copied.modules) state.installed.set(name, {
|
|
2812
|
+
version,
|
|
2813
|
+
born: bornAt(join(cache, name)),
|
|
2814
|
+
bound
|
|
2815
|
+
});
|
|
2816
|
+
this.passClock(bound);
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Records the bound of each module that appeared in a project's manifest
|
|
2820
|
+
* since the last call, and refuses the cache of a project whose recorded
|
|
2821
|
+
* module left the manifest, changed version or sits in a new folder. A
|
|
2822
|
+
* module that appeared with a lock record no newer than `start`, the start
|
|
2823
|
+
* of the command that just ended, was installed from that record.
|
|
2824
|
+
*/
|
|
2825
|
+
observe(start = UNKNOWN_START) {
|
|
2826
|
+
let latest = -1n;
|
|
2827
|
+
for (const [project, state] of this.projects) {
|
|
2828
|
+
const cache = join(project, PROJECT_CACHE);
|
|
2829
|
+
const manifest = manifestOf(cache);
|
|
2830
|
+
if (manifest === void 0) continue;
|
|
2831
|
+
const listed = new Map(manifest.modules);
|
|
2832
|
+
for (const [name, known] of state.installed) if (!listed.has(name)) state.refused ??= `${name} left ${MANIFEST} after ajs installed ${name}@${known.version}`;
|
|
2833
|
+
for (const [name, version] of manifest.modules) {
|
|
2834
|
+
const born = bornAt(join(cache, name));
|
|
2835
|
+
const known = state.installed.get(name);
|
|
2836
|
+
if (known === void 0) {
|
|
2837
|
+
state.installed.set(name, {
|
|
2838
|
+
version,
|
|
2839
|
+
born,
|
|
2840
|
+
bound: manifest.mtime
|
|
2841
|
+
});
|
|
2842
|
+
if (manifest.mtime > latest) latest = manifest.mtime;
|
|
2843
|
+
if (pinned(project, name, version, start)) state.refused ??= `ajs installed ${name}@${version} from the project's lock record`;
|
|
2844
|
+
} else if (known.version !== version) state.refused ??= `${name} changed from ${known.version} to ${version} after ajs installed it`;
|
|
2845
|
+
else if (born !== known.born) state.refused ??= `${name} was created again after ajs installed ${name}@${version}`;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
if (latest >= 0n) this.passClock(latest);
|
|
2849
|
+
}
|
|
2850
|
+
/** Observes the project caches once a command or an app start has ended, and returns its result. Its `folder` is the step folder the harness created as it began, so a lock record no newer than that folder was there before the command. */
|
|
2851
|
+
observed(result) {
|
|
2852
|
+
this.observe(bornAt(result.folder) || UNKNOWN_START);
|
|
2853
|
+
return result;
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* Returns once the file system clock has moved past `time`, so a file the
|
|
2857
|
+
* journey writes from now on is newer than a bound of `time`. The clock
|
|
2858
|
+
* advances in ticks of a few milliseconds, and a write within the tick of
|
|
2859
|
+
* the bound would carry the bound's time.
|
|
2860
|
+
*/
|
|
2861
|
+
passClock(time) {
|
|
2862
|
+
const probe = join(this.store, `.clock-${randomBytes(6).toString("hex")}`);
|
|
2863
|
+
const pause = new Int32Array(new SharedArrayBuffer(4));
|
|
2864
|
+
try {
|
|
2865
|
+
mkdirSync(this.store, { recursive: true });
|
|
2866
|
+
for (let attempt = 0; attempt < CLOCK_ATTEMPTS; attempt += 1) {
|
|
2867
|
+
writeFileSync(probe, "");
|
|
2868
|
+
if (lstatSync(probe, { bigint: true }).mtimeNs > time) return;
|
|
2869
|
+
Atomics.wait(pause, 0, 0, 1);
|
|
2870
|
+
}
|
|
2871
|
+
} catch {
|
|
2872
|
+
return;
|
|
2873
|
+
} finally {
|
|
2874
|
+
rmSync(probe, { force: true });
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Keeps a copy of each project's module cache for the rest of the run, one per set of installed versions; a set already kept stays as it is. Call it once the journey passed and every app stopped.
|
|
2879
|
+
* Returns why each cache that changed after `ajs` installed it was not kept.
|
|
2880
|
+
*/
|
|
2881
|
+
keep() {
|
|
2882
|
+
this.observe();
|
|
2883
|
+
const skipped = [];
|
|
2884
|
+
for (const [project, state] of this.projects) {
|
|
2885
|
+
const cache = join(project, PROJECT_CACHE);
|
|
2886
|
+
const manifest = manifestOf(cache);
|
|
2887
|
+
if (manifest === void 0 || manifest.modules.length === 0) continue;
|
|
2888
|
+
const target = join(this.store, createHash("sha256").update(manifest.modules.map((entry) => entry.join("@")).join("\n")).digest("hex").slice(0, 16));
|
|
2889
|
+
if (existsSync(target)) continue;
|
|
2890
|
+
const unregistered = manifest.modules.find(([, version]) => !REGISTRY_VERSION.test(version));
|
|
2891
|
+
const change = state.refused ?? (unregistered === void 0 ? changeIn(cache, state.installed, manifest.mtime) : `${unregistered.join("@")} is not a registry version, and ajs updates a git module in place`);
|
|
2892
|
+
if (change !== void 0) {
|
|
2893
|
+
skipped.push(`${cache}: ${change}`);
|
|
2894
|
+
continue;
|
|
2895
|
+
}
|
|
2896
|
+
mkdirSync(this.store, { recursive: true });
|
|
2897
|
+
publish(cache, target);
|
|
2898
|
+
}
|
|
2899
|
+
return skipped;
|
|
2900
|
+
}
|
|
2901
|
+
};
|
|
2902
|
+
//#endregion
|
|
2903
|
+
//#region src/verify/prepared.ts
|
|
2904
|
+
const KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2905
|
+
/** The path of `path` inside `root`, or `null` when it lies outside. */
|
|
2906
|
+
function inside(root, path) {
|
|
2907
|
+
const rest = relative(root, path);
|
|
2908
|
+
if (rest === ".." || rest.startsWith(`..${sep}`) || isAbsolute(rest)) return null;
|
|
2909
|
+
return rest;
|
|
2910
|
+
}
|
|
2911
|
+
/** Surveys `folder` in one walk that descends only into real directories, so it never follows a symlink; a target may name the folder by its real path. */
|
|
2912
|
+
function survey(folder) {
|
|
2913
|
+
const real = realpathSync(folder);
|
|
2914
|
+
const found = {
|
|
2915
|
+
links: [],
|
|
2916
|
+
special: null
|
|
2917
|
+
};
|
|
2918
|
+
const walk = (at) => {
|
|
2919
|
+
for (const entry of readdirSync(join(folder, at), { withFileTypes: true })) {
|
|
2920
|
+
const path = join(at, entry.name);
|
|
2921
|
+
if (entry.isDirectory()) walk(path);
|
|
2922
|
+
else if (entry.isSymbolicLink()) {
|
|
2923
|
+
const pointed = readlinkSync(join(folder, path));
|
|
2924
|
+
const target = isAbsolute(pointed) ? inside(folder, pointed) ?? inside(real, pointed) : null;
|
|
2925
|
+
if (target !== null) found.links.push({
|
|
2926
|
+
path,
|
|
2927
|
+
target
|
|
2928
|
+
});
|
|
2929
|
+
} else if (!entry.isFile()) found.special ??= path;
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
walk("");
|
|
2933
|
+
return found;
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Copies `source` to `target`, which ends up at `root`. Each of `links`
|
|
2937
|
+
* points to its target inside `root`, so no copy reaches another journey's
|
|
2938
|
+
* folder. Every other symlink keeps its target, so pnpm's relative links in a
|
|
2939
|
+
* copy never point back into the source.
|
|
2940
|
+
*/
|
|
2941
|
+
function copyTree(source, target, links = [], root = target) {
|
|
2942
|
+
cpSync(source, target, {
|
|
2943
|
+
recursive: true,
|
|
2944
|
+
verbatimSymlinks: true,
|
|
2945
|
+
preserveTimestamps: true
|
|
2946
|
+
});
|
|
2947
|
+
for (const link of links) {
|
|
2948
|
+
unlinkSync(join(target, link.path));
|
|
2949
|
+
symlinkSync(join(root, link.target), join(target, link.path));
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
/** Judges the build of `folder` by the steps it recorded. */
|
|
2953
|
+
function judge$1(steps, folder) {
|
|
2954
|
+
const checks = steps.flatMap((step) => step.checks);
|
|
2955
|
+
if (checks.length === 0) return {
|
|
2956
|
+
kept: false,
|
|
2957
|
+
reason: "the build recorded no check"
|
|
2958
|
+
};
|
|
2959
|
+
if (!checks.every((check) => check.pass)) return {
|
|
2960
|
+
kept: false,
|
|
2961
|
+
reason: "a check of the build failed"
|
|
2962
|
+
};
|
|
2963
|
+
const found = survey(folder);
|
|
2964
|
+
return found.special === null ? {
|
|
2965
|
+
kept: true,
|
|
2966
|
+
links: found.links
|
|
2967
|
+
} : {
|
|
2968
|
+
kept: false,
|
|
2969
|
+
reason: `${found.special} is not a file, directory or symlink, which a copy would drop`
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
/** The links `keep` recorded, each a path then its target, joined by NUL, the one character no path holds. */
|
|
2973
|
+
function readLinks(kept) {
|
|
2974
|
+
const fields = readFileSync(join(kept, "links"), "utf8").split("\0");
|
|
2975
|
+
const links = [];
|
|
2976
|
+
for (let at = 0; at + 1 < fields.length; at += 2) links.push({
|
|
2977
|
+
path: fields[at],
|
|
2978
|
+
target: fields[at + 1]
|
|
2979
|
+
});
|
|
2980
|
+
return links;
|
|
2981
|
+
}
|
|
2982
|
+
/** The journey that built what the run kept, as its path under the evidence. */
|
|
2983
|
+
function builder(kept) {
|
|
2984
|
+
return readFileSync(join(kept, "from.txt"), "utf8").trim();
|
|
2985
|
+
}
|
|
2986
|
+
/**
|
|
2987
|
+
* Copies what the run kept into the journey, with the evidence of that build
|
|
2988
|
+
* under the step `marker`, and returns `null`. When the copy fails, or what
|
|
2989
|
+
* the run kept is gone or replaced once it ends, as when the journey that
|
|
2990
|
+
* built reruns meanwhile, the partial copy is removed and this returns why.
|
|
2991
|
+
*/
|
|
2992
|
+
function reuse$1({ marker, key, kept, folder }) {
|
|
2993
|
+
const evidence = join(marker, "build");
|
|
2994
|
+
try {
|
|
2995
|
+
const memo = statSync(kept).ino;
|
|
2996
|
+
copyTree(join(kept, "evidence"), evidence);
|
|
2997
|
+
copyTree(join(kept, "folder"), folder, readLinks(kept));
|
|
2998
|
+
const from = builder(kept);
|
|
2999
|
+
if (statSync(kept).ino !== memo) throw new Error(`${kept} was replaced while it was copied`);
|
|
3000
|
+
writeFileSync(join(marker, "prepared.txt"), `${key}: ${folder} is a copy of what ${from} prepared; build/ holds the evidence of that build\n`);
|
|
3001
|
+
return null;
|
|
3002
|
+
} catch (error) {
|
|
3003
|
+
removeTree(evidence);
|
|
3004
|
+
removeTree(folder);
|
|
3005
|
+
return error instanceof Error ? error.message : String(error);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
/** Removes what the run kept by first renaming it away, so a journey copying it meanwhile fails instead of copying a half-deleted tree. */
|
|
3009
|
+
function drop(kept) {
|
|
3010
|
+
const trash = mkdtempSync(`${kept}.`);
|
|
3011
|
+
renameSync(kept, join(trash, "dropped"));
|
|
3012
|
+
removeTree(trash);
|
|
3013
|
+
}
|
|
3014
|
+
/** Keeps the built folder and the build's step evidence for the rest of the run, published by one rename; when another journey kept the key first, its copy stays and this returns `false`. */
|
|
3015
|
+
function keep(context, kept, folder, built) {
|
|
3016
|
+
mkdirSync(dirname(kept), { recursive: true });
|
|
3017
|
+
const staging = mkdtempSync(`${kept}.`);
|
|
3018
|
+
try {
|
|
3019
|
+
mkdirSync(join(staging, "evidence"));
|
|
3020
|
+
for (const step of built.steps) copyTree(join(context.folder, step), join(staging, "evidence", step));
|
|
3021
|
+
copyTree(folder, join(staging, "folder"), built.links, join(kept, "folder"));
|
|
3022
|
+
writeFileSync(join(staging, "links"), built.links.flatMap((link) => [link.path, link.target]).join("\0"));
|
|
3023
|
+
writeFileSync(join(staging, "from.txt"), `${relative(context.state.evidence, context.folder)}\n`);
|
|
3024
|
+
renameSync(staging, kept);
|
|
3025
|
+
return true;
|
|
3026
|
+
} catch (error) {
|
|
3027
|
+
if (!existsSync(kept)) throw error;
|
|
3028
|
+
return false;
|
|
3029
|
+
} finally {
|
|
3030
|
+
removeTree(staging);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
/** Runs `build` with a HOME of its own for its commands, deleted when it ends. */
|
|
3034
|
+
async function buildAlone(context, key, folder, build) {
|
|
3035
|
+
const outer = context.buildHome;
|
|
3036
|
+
const home = join(context.home, `.prepared-${key}`);
|
|
3037
|
+
mkdirSync(home, { recursive: true });
|
|
3038
|
+
context.buildHome = home;
|
|
3039
|
+
try {
|
|
3040
|
+
await build(folder);
|
|
3041
|
+
} finally {
|
|
3042
|
+
context.buildHome = outer;
|
|
3043
|
+
removeTree(home);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
/** Builds `key` in this journey after the step `marker`, which marks the steps after it as the build and says, after `before`, whether the run kept it. */
|
|
3047
|
+
async function buildHere(context, where, build, before = "") {
|
|
3048
|
+
const { marker, key, kept, folder } = where;
|
|
3049
|
+
const note = (outcome) => writeFileSync(join(marker, "prepared.txt"), `${key}: ${before}${folder} was built here by the steps after this one; ${outcome}\n`);
|
|
3050
|
+
const earlier = new Set(readdirSync(context.folder));
|
|
3051
|
+
const checked = context.steps.length;
|
|
3052
|
+
mkdirSync(folder, { recursive: true });
|
|
3053
|
+
try {
|
|
3054
|
+
await buildAlone(context, key, folder, build);
|
|
3055
|
+
} catch (error) {
|
|
3056
|
+
note("not kept: the build threw, so the next journey builds again");
|
|
3057
|
+
throw error;
|
|
3058
|
+
}
|
|
3059
|
+
const verdict = judge$1(context.steps.slice(checked), folder);
|
|
3060
|
+
if (!verdict.kept) {
|
|
3061
|
+
note(`not kept: ${verdict.reason}, so the next journey builds again`);
|
|
3062
|
+
return;
|
|
3063
|
+
}
|
|
3064
|
+
note(keep(context, kept, folder, {
|
|
3065
|
+
steps: readdirSync(context.folder).filter((entry) => !earlier.has(entry)),
|
|
3066
|
+
links: verdict.links
|
|
3067
|
+
}) ? "kept, so later journeys of the run copy it" : `not kept: ${builder(kept)} kept ${key} first, so later journeys copy that build`);
|
|
3068
|
+
}
|
|
3069
|
+
/** `JourneyContext.prepared` for one journey of the run. */
|
|
3070
|
+
async function prepare(context, key, build) {
|
|
3071
|
+
if (!KEY.test(key)) throw new Error(`prepared key ${JSON.stringify(key)} must be lowercase letters and digits joined by dashes`);
|
|
3072
|
+
const folder = join(context.work, key);
|
|
3073
|
+
if (existsSync(folder)) throw new Error(`${folder} already exists: a journey prepares ${key} once`);
|
|
3074
|
+
const kept = join(context.state.dir, "prepared", key);
|
|
3075
|
+
if (existsSync(kept) && builder(kept) === relative(context.state.evidence, context.folder)) drop(kept);
|
|
3076
|
+
const where = {
|
|
3077
|
+
marker: context.step(`prepared ${key}`),
|
|
3078
|
+
key,
|
|
3079
|
+
kept,
|
|
3080
|
+
folder
|
|
3081
|
+
};
|
|
3082
|
+
if (!existsSync(kept)) await buildHere(context, where, build);
|
|
3083
|
+
else {
|
|
3084
|
+
const failed = reuse$1(where);
|
|
3085
|
+
if (failed !== null) await buildHere(context, where, build, `copying what the run kept failed (${failed}), so `);
|
|
3086
|
+
}
|
|
3087
|
+
return folder;
|
|
3088
|
+
}
|
|
3089
|
+
//#endregion
|
|
2533
3090
|
//#region src/verify/context.ts
|
|
2534
3091
|
var JourneyAbort = class extends Error {};
|
|
2535
3092
|
var NotVerified = class extends Error {};
|
|
@@ -2543,19 +3100,9 @@ const READINESS_RETRY_MS = [
|
|
|
2543
3100
|
1e3,
|
|
2544
3101
|
2e3
|
|
2545
3102
|
];
|
|
2546
|
-
/** The signals a process outside the run sends to end an app. Any other signal, such as SIGABRT or SIGSEGV, is the product crashing. */
|
|
2547
|
-
const OUTSIDE_KILLS = /* @__PURE__ */ new Set([
|
|
2548
|
-
"SIGKILL",
|
|
2549
|
-
"SIGTERM",
|
|
2550
|
-
"SIGHUP",
|
|
2551
|
-
"SIGINT"
|
|
2552
|
-
]);
|
|
2553
3103
|
function slug(text) {
|
|
2554
3104
|
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
2555
3105
|
}
|
|
2556
|
-
function sleep(ms) {
|
|
2557
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2558
|
-
}
|
|
2559
3106
|
/** The harness side of a journey: every driving call writes its evidence into a new numbered step folder. */
|
|
2560
3107
|
var VerifyContext = class {
|
|
2561
3108
|
repo;
|
|
@@ -2563,12 +3110,17 @@ var VerifyContext = class {
|
|
|
2563
3110
|
work;
|
|
2564
3111
|
home;
|
|
2565
3112
|
steps = [];
|
|
3113
|
+
/** The HOME every command gets while `prepared` runs a build; the journey's HOME when `null`. */
|
|
3114
|
+
buildHome = null;
|
|
2566
3115
|
running = [];
|
|
2567
3116
|
started = [];
|
|
2568
3117
|
fixtures = /* @__PURE__ */ new Map();
|
|
2569
3118
|
index = 0;
|
|
3119
|
+
/** Times every step folder of the journey. */
|
|
3120
|
+
clock = new StepClock();
|
|
2570
3121
|
workspace;
|
|
2571
3122
|
state;
|
|
3123
|
+
caches;
|
|
2572
3124
|
constructor(workspace, state, feature, journey) {
|
|
2573
3125
|
this.workspace = workspace;
|
|
2574
3126
|
this.state = state;
|
|
@@ -2576,6 +3128,7 @@ var VerifyContext = class {
|
|
|
2576
3128
|
this.folder = join(state.evidence, feature, journey);
|
|
2577
3129
|
this.work = join(state.dir, "work", feature, journey);
|
|
2578
3130
|
this.home = join(state.dir, "homes", feature, journey);
|
|
3131
|
+
this.caches = new ProjectCaches(join(state.dir, "ajs-cache"));
|
|
2579
3132
|
for (const folder of [
|
|
2580
3133
|
this.folder,
|
|
2581
3134
|
this.work,
|
|
@@ -2588,16 +3141,18 @@ var VerifyContext = class {
|
|
|
2588
3141
|
mkdirSync(folder, { recursive: true });
|
|
2589
3142
|
}
|
|
2590
3143
|
}
|
|
2591
|
-
/** A fresh numbered step folder. */
|
|
3144
|
+
/** A fresh numbered step folder; it also ends the clock of the previous step and starts its own. */
|
|
2592
3145
|
step(name) {
|
|
2593
3146
|
this.index += 1;
|
|
2594
3147
|
const folder = join(this.folder, `${String(this.index).padStart(2, "0")}-${slug(name)}`);
|
|
2595
3148
|
mkdirSync(folder, { recursive: true });
|
|
3149
|
+
this.clock.start(basename(folder));
|
|
2596
3150
|
return folder;
|
|
2597
3151
|
}
|
|
2598
3152
|
env(extra = {}) {
|
|
2599
|
-
return isolatedEnv(this.workspace, this.home, extra);
|
|
3153
|
+
return isolatedEnv(this.workspace, this.buildHome ?? this.home, extra);
|
|
2600
3154
|
}
|
|
3155
|
+
prepared = (key, build) => prepare(this, key, build);
|
|
2601
3156
|
command(name, program, args, options = {}) {
|
|
2602
3157
|
return runRecorded(this.step(name), {
|
|
2603
3158
|
program,
|
|
@@ -2605,7 +3160,7 @@ var VerifyContext = class {
|
|
|
2605
3160
|
cwd: options.cwd ?? this.work,
|
|
2606
3161
|
env: this.env(options.env),
|
|
2607
3162
|
timeoutMs: options.timeoutMs
|
|
2608
|
-
});
|
|
3163
|
+
}).then((result) => this.caches.observed(result));
|
|
2609
3164
|
}
|
|
2610
3165
|
/** Runs `ajs <args>` of the repository's `@antelopejs/core`. */
|
|
2611
3166
|
ajs(name, args, options = {}) {
|
|
@@ -2669,6 +3224,7 @@ var VerifyContext = class {
|
|
|
2669
3224
|
const fixture = writeFixture(this.workspace, this.state, folder, config);
|
|
2670
3225
|
this.fixtures.set(fixture.project, fixture);
|
|
2671
3226
|
this.tree("fixture project", fixture.project);
|
|
3227
|
+
this.caches.seed(fixture.project);
|
|
2672
3228
|
return fixture.project;
|
|
2673
3229
|
}
|
|
2674
3230
|
/** The log the stub provider wrote, one call per line: the provider's view of what core delivered. */
|
|
@@ -2732,7 +3288,7 @@ var VerifyContext = class {
|
|
|
2732
3288
|
});
|
|
2733
3289
|
saveRun(this.state);
|
|
2734
3290
|
await this.waitReady(app, handle, fixture !== void 0);
|
|
2735
|
-
return app;
|
|
3291
|
+
return this.caches.observed(app);
|
|
2736
3292
|
}
|
|
2737
3293
|
async probe(app, fixture, folder) {
|
|
2738
3294
|
const probe = this.workspace.config.template?.probe;
|
|
@@ -2763,11 +3319,11 @@ var VerifyContext = class {
|
|
|
2763
3319
|
});
|
|
2764
3320
|
let check = await this.probe(app, fixture, folder);
|
|
2765
3321
|
while (!check.pass && !exited && Date.now() < deadline) {
|
|
2766
|
-
await
|
|
3322
|
+
await setTimeout$1(POLL_MS);
|
|
2767
3323
|
check = await this.probe(app, fixture, folder);
|
|
2768
3324
|
}
|
|
2769
3325
|
const settle = this.workspace.config.template?.probe.log ? this.workspace.config.template.probe.settleMs ?? SETTLE_MS : 0;
|
|
2770
|
-
if (check.pass && settle > 0) await
|
|
3326
|
+
if (check.pass && settle > 0) await setTimeout$1(settle);
|
|
2771
3327
|
const alive = {
|
|
2772
3328
|
name: "still running after readiness",
|
|
2773
3329
|
pass: !exited,
|
|
@@ -2858,7 +3414,7 @@ var VerifyContext = class {
|
|
|
2858
3414
|
pass: set.exitCode === 0,
|
|
2859
3415
|
detail: set.stderr.slice(-300)
|
|
2860
3416
|
}], { critical: true });
|
|
2861
|
-
|
|
3417
|
+
const init = await this.ajs(name, [
|
|
2862
3418
|
"project",
|
|
2863
3419
|
"init",
|
|
2864
3420
|
relative(this.work, project),
|
|
@@ -2866,6 +3422,8 @@ var VerifyContext = class {
|
|
|
2866
3422
|
this.state.templateName,
|
|
2867
3423
|
...flags
|
|
2868
3424
|
]);
|
|
3425
|
+
if (init.exitCode === 0) this.caches.seed(project);
|
|
3426
|
+
return init;
|
|
2869
3427
|
}
|
|
2870
3428
|
/** Stops every app the journey left running. */
|
|
2871
3429
|
async cleanup() {
|
|
@@ -2885,21 +3443,13 @@ var VerifyContext = class {
|
|
|
2885
3443
|
const failure = await this.unready(name, service.ready);
|
|
2886
3444
|
if (failure !== null) return `the service ${name} no longer passes its readiness command: ${failure}`;
|
|
2887
3445
|
}
|
|
2888
|
-
|
|
2889
|
-
const label = `${app.name} (pid ${app.pid})`;
|
|
2890
|
-
if (exit?.signal && OUTSIDE_KILLS.has(exit.signal) && !sent.includes(exit.signal)) return `${label} was killed by ${exit.signal}, a signal the harness did not send`;
|
|
2891
|
-
const output = readOutput(app.folder);
|
|
2892
|
-
const port = new RegExp(`(?<![0-9])${app.port}(?![0-9])`);
|
|
2893
|
-
const taken = `${output.stdout}\n${output.stderr}`.split("\n").find((line) => line.includes("EADDRINUSE") && port.test(line));
|
|
2894
|
-
if (taken !== void 0) return `${label} could not bind port ${app.port}, which another process holds: ${taken.trim().slice(0, 300)}`;
|
|
2895
|
-
}
|
|
2896
|
-
return null;
|
|
3446
|
+
return appFault(this.started);
|
|
2897
3447
|
}
|
|
2898
3448
|
/** The last readiness failure of a service after the reruns, or `null` once one rerun passes. */
|
|
2899
3449
|
async unready(name, ready) {
|
|
2900
3450
|
let failure = null;
|
|
2901
3451
|
for (const wait of [0, ...READINESS_RETRY_MS]) {
|
|
2902
|
-
await
|
|
3452
|
+
await setTimeout$1(wait);
|
|
2903
3453
|
failure = readinessFailure(this.service(name).container, ready, this.step(`${name} readiness after the failure`));
|
|
2904
3454
|
if (failure === null) return null;
|
|
2905
3455
|
}
|
|
@@ -2935,12 +3485,12 @@ function resetServices(context) {
|
|
|
2935
3485
|
for (const [name, service] of Object.entries(context.workspace.config.services ?? {})) {
|
|
2936
3486
|
if (!service.reset) continue;
|
|
2937
3487
|
const container = context.service(name).container;
|
|
3488
|
+
const folder = context.step(`reset ${name}`);
|
|
2938
3489
|
const run = spawnSync("docker", [
|
|
2939
3490
|
"exec",
|
|
2940
3491
|
container,
|
|
2941
3492
|
...service.reset
|
|
2942
3493
|
], { encoding: "utf8" });
|
|
2943
|
-
const folder = context.step(`reset ${name}`);
|
|
2944
3494
|
writeFileSync(join(folder, "command.txt"), `docker exec ${container} ${service.reset.join(" ")}\n`);
|
|
2945
3495
|
writeFileSync(join(folder, "stdout.txt"), run.stdout ?? "");
|
|
2946
3496
|
writeFileSync(join(folder, "stderr.txt"), run.stderr ?? "");
|
|
@@ -2983,6 +3533,7 @@ async function runOne(workspace, state, feature, id, journey) {
|
|
|
2983
3533
|
}
|
|
2984
3534
|
async function driveJourney(context, feature, id, journey) {
|
|
2985
3535
|
const { state } = context;
|
|
3536
|
+
const elapsed = stopwatch();
|
|
2986
3537
|
let failure = {
|
|
2987
3538
|
error: null,
|
|
2988
3539
|
notVerified: null
|
|
@@ -3002,15 +3553,20 @@ async function driveJourney(context, feature, id, journey) {
|
|
|
3002
3553
|
notVerified: fault
|
|
3003
3554
|
};
|
|
3004
3555
|
}
|
|
3556
|
+
const status = statusOf(context, failure);
|
|
3557
|
+
const skipped = status === "PASS" ? context.caches.keep() : [];
|
|
3558
|
+
if (skipped.length > 0) writeFileSync(join(context.step("module cache not kept"), "note.txt"), `${skipped.map((reason) => `${reason}; a later journey installs its modules again`).join("\n")}\n`);
|
|
3005
3559
|
const result = {
|
|
3006
3560
|
feature,
|
|
3007
3561
|
journey: id,
|
|
3008
3562
|
title: journey.title,
|
|
3009
3563
|
entryPoint: journey.entryPoint,
|
|
3010
|
-
status
|
|
3564
|
+
status,
|
|
3011
3565
|
steps: context.steps,
|
|
3012
3566
|
...failure,
|
|
3013
|
-
folder: relative(state.evidence, context.folder)
|
|
3567
|
+
folder: relative(state.evidence, context.folder),
|
|
3568
|
+
stepMs: context.clock.finish(),
|
|
3569
|
+
ms: elapsed()
|
|
3014
3570
|
};
|
|
3015
3571
|
writeFileSync(join(context.folder, "result.json"), `${JSON.stringify(result, null, 2)}\n`);
|
|
3016
3572
|
return result;
|
|
@@ -3092,7 +3648,7 @@ function stamp(state, result, tree) {
|
|
|
3092
3648
|
writeFileSync(join(state.evidence, result.folder, "result.json"), `${JSON.stringify(stamped, null, 2)}\n`);
|
|
3093
3649
|
return stamped;
|
|
3094
3650
|
}
|
|
3095
|
-
/** Records `source` as the result of `id` under `feature` without running the journey: its own result.json names the folder it reuses. */
|
|
3651
|
+
/** Records `source` as the result of `id` under `feature` without running the journey: its own result.json names the folder it reuses, and its time is zero so a run's total counts the journey once. */
|
|
3096
3652
|
function reuse(state, feature, id, source) {
|
|
3097
3653
|
const folder = join(state.evidence, feature, id);
|
|
3098
3654
|
rmSync(folder, {
|
|
@@ -3104,7 +3660,9 @@ function reuse(state, feature, id, source) {
|
|
|
3104
3660
|
...source,
|
|
3105
3661
|
feature,
|
|
3106
3662
|
folder: relative(state.evidence, folder),
|
|
3107
|
-
reusedFrom: source.folder
|
|
3663
|
+
reusedFrom: source.folder,
|
|
3664
|
+
ms: 0,
|
|
3665
|
+
stepMs: []
|
|
3108
3666
|
};
|
|
3109
3667
|
writeFileSync(join(folder, "result.json"), `${JSON.stringify(result, null, 2)}\n`);
|
|
3110
3668
|
return result;
|
|
@@ -3143,6 +3701,57 @@ async function runFeature(workspace, state, feature, ids) {
|
|
|
3143
3701
|
return results;
|
|
3144
3702
|
}
|
|
3145
3703
|
//#endregion
|
|
3704
|
+
//#region src/verify/timing-report.ts
|
|
3705
|
+
/** How many of a journey's steps the verdict names. */
|
|
3706
|
+
const SLOWEST_STEPS = 3;
|
|
3707
|
+
/** The label of the verdict's last timing row; it states what the sum leaves out. */
|
|
3708
|
+
const TOTAL_LABEL = "**Total measured** (commands only; agent time between commands is not included)";
|
|
3709
|
+
function sum(values) {
|
|
3710
|
+
return values.every((ms) => ms !== null) ? values.reduce((total, ms) => total + (ms ?? 0), 0) : null;
|
|
3711
|
+
}
|
|
3712
|
+
function slowest(steps) {
|
|
3713
|
+
return steps.toSorted((a, b) => b.ms - a.ms).slice(0, SLOWEST_STEPS);
|
|
3714
|
+
}
|
|
3715
|
+
/** Collects what a run measured: its `new` phases, each journey's total and slowest steps, each formal check. */
|
|
3716
|
+
function timingReport(setup, features, formal) {
|
|
3717
|
+
const journeys = features.flatMap(({ feature, results }) => results.map((result) => ({
|
|
3718
|
+
feature,
|
|
3719
|
+
journey: result.journey,
|
|
3720
|
+
ms: result.ms ?? null,
|
|
3721
|
+
slowestSteps: slowest(result.stepMs ?? [])
|
|
3722
|
+
})));
|
|
3723
|
+
const checks = formal.map((result) => ({
|
|
3724
|
+
name: result.name,
|
|
3725
|
+
ms: result.ms ?? null
|
|
3726
|
+
}));
|
|
3727
|
+
return {
|
|
3728
|
+
setup,
|
|
3729
|
+
journeys,
|
|
3730
|
+
formal: checks,
|
|
3731
|
+
totalMs: setup.length === 0 ? null : sum([
|
|
3732
|
+
...setup.map((entry) => entry.ms),
|
|
3733
|
+
...journeys.map((entry) => entry.ms),
|
|
3734
|
+
...checks.map((entry) => entry.ms)
|
|
3735
|
+
])
|
|
3736
|
+
};
|
|
3737
|
+
}
|
|
3738
|
+
function journeyCell(entry) {
|
|
3739
|
+
if (entry.ms === null || entry.slowestSteps.length === 0) return seconds(entry.ms);
|
|
3740
|
+
const steps = entry.slowestSteps.map((step) => `\`${step.step}\` ${seconds(step.ms)}`).join(", ");
|
|
3741
|
+
return `${seconds(entry.ms)} (slowest steps: ${steps})`;
|
|
3742
|
+
}
|
|
3743
|
+
/** The `### Timing` table of a verdict: one row per measured phase, journey and formal check, then the sum. */
|
|
3744
|
+
function timingTable(report) {
|
|
3745
|
+
return [
|
|
3746
|
+
"| Phase | Time |",
|
|
3747
|
+
"|---|---|",
|
|
3748
|
+
...report.setup.length > 0 ? report.setup.map((entry) => `| ${entry.phase} | ${seconds(entry.ms)} |`) : [`| new (setup, pack, services, sources) | ${seconds(null)} |`],
|
|
3749
|
+
...report.journeys.map((entry) => `| journey ${entry.feature}/${entry.journey} | ${journeyCell(entry)} |`),
|
|
3750
|
+
...report.formal.map((entry) => `| formal ${entry.name} | ${seconds(entry.ms)} |`),
|
|
3751
|
+
`| ${TOTAL_LABEL} | ${seconds(report.totalMs)} |`
|
|
3752
|
+
];
|
|
3753
|
+
}
|
|
3754
|
+
//#endregion
|
|
3146
3755
|
//#region src/verify/verdict.ts
|
|
3147
3756
|
/** The GitHub `owner/repo` of the origin remote. */
|
|
3148
3757
|
function originRepository(root) {
|
|
@@ -3183,8 +3792,13 @@ function journeyRows(workspace, state, plan, link) {
|
|
|
3183
3792
|
const reasons = [];
|
|
3184
3793
|
const notVerified = [];
|
|
3185
3794
|
const outsideNotVerified = [];
|
|
3795
|
+
const listed = [];
|
|
3186
3796
|
for (const feature of plan.run) {
|
|
3187
3797
|
const results = readResults(state, feature) ?? [];
|
|
3798
|
+
listed.push({
|
|
3799
|
+
feature,
|
|
3800
|
+
results
|
|
3801
|
+
});
|
|
3188
3802
|
const registered = featureJourneys(workspace, feature) ?? [];
|
|
3189
3803
|
for (const id of registered.filter((journey) => !results.some((result) => result.journey === journey))) reasons.push(`${feature}/${id} was not run`);
|
|
3190
3804
|
for (const result of results) {
|
|
@@ -3196,18 +3810,26 @@ function journeyRows(workspace, state, plan, link) {
|
|
|
3196
3810
|
rows.push(journeyRow(feature, result, link));
|
|
3197
3811
|
}
|
|
3198
3812
|
}
|
|
3199
|
-
for (const feature of featuresOutsidePlan(state, plan))
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3813
|
+
for (const feature of featuresOutsidePlan(state, plan)) {
|
|
3814
|
+
const results = readResults(state, feature) ?? [];
|
|
3815
|
+
listed.push({
|
|
3816
|
+
feature,
|
|
3817
|
+
results
|
|
3818
|
+
});
|
|
3819
|
+
for (const result of results) {
|
|
3820
|
+
if (result.status === "FAIL") reasons.push(`${feature}/${result.journey} failed; ${feature} is outside the diff's features, so check its covers globs`);
|
|
3821
|
+
const stale = staleReuse(state, result);
|
|
3822
|
+
if (stale !== null) reasons.push(`${feature}/${result.journey} reuses ${result.reusedFrom}, which is now ${stale}`);
|
|
3823
|
+
if (result.status === "NOT VERIFIED") outsideNotVerified.push(`${feature}/${result.journey}: ${result.notVerified}`);
|
|
3824
|
+
rows.push(journeyRow(`${feature} (outside the diff's features)`, result, link));
|
|
3825
|
+
}
|
|
3205
3826
|
}
|
|
3206
3827
|
return {
|
|
3207
3828
|
rows,
|
|
3208
3829
|
reasons,
|
|
3209
3830
|
notVerified,
|
|
3210
|
-
outsideNotVerified
|
|
3831
|
+
outsideNotVerified,
|
|
3832
|
+
listed
|
|
3211
3833
|
};
|
|
3212
3834
|
}
|
|
3213
3835
|
function doorReasons(workspace, judgement, plan) {
|
|
@@ -3232,6 +3854,7 @@ function doorsSection(judgement) {
|
|
|
3232
3854
|
function formalSection(workspace, state, plan, link) {
|
|
3233
3855
|
const reasons = [];
|
|
3234
3856
|
const lines = [];
|
|
3857
|
+
const ran = [];
|
|
3235
3858
|
const touched = touchedFormalChecks(workspace, plan.changed).map((check) => check.name);
|
|
3236
3859
|
for (const check of workspace.config.formal ?? []) {
|
|
3237
3860
|
const result = readFormalResult(state, check.name);
|
|
@@ -3240,6 +3863,7 @@ function formalSection(workspace, state, plan, link) {
|
|
|
3240
3863
|
if (gate) reasons.push(`formal check ${check.name} covers the diff but was not run`);
|
|
3241
3864
|
continue;
|
|
3242
3865
|
}
|
|
3866
|
+
ran.push(result);
|
|
3243
3867
|
if (gate && result.behaviour === void 0 && result.exitCode === 0) reasons.push(`formal check ${check.name} covers the diff but its run did not compare the covered behaviour with the base`);
|
|
3244
3868
|
const weight = formalGate(result);
|
|
3245
3869
|
if (gate && weight.fails) reasons.push(`formal check ${check.name}: ${weight.outcome}`);
|
|
@@ -3248,7 +3872,8 @@ function formalSection(workspace, state, plan, link) {
|
|
|
3248
3872
|
}
|
|
3249
3873
|
return {
|
|
3250
3874
|
reasons,
|
|
3251
|
-
lines
|
|
3875
|
+
lines,
|
|
3876
|
+
ran
|
|
3252
3877
|
};
|
|
3253
3878
|
}
|
|
3254
3879
|
function docsReasons(judgement, plan) {
|
|
@@ -3266,6 +3891,15 @@ function resultOf(reasons, notVerified, notes) {
|
|
|
3266
3891
|
if (notVerified.length > 0) return "NOT VERIFIED";
|
|
3267
3892
|
return notes > 0 ? "PASS+NOTES" : "PASS";
|
|
3268
3893
|
}
|
|
3894
|
+
/** The verdict's Unmapped surfaces section, empty when every changed surface has a feature. */
|
|
3895
|
+
function unmappedSection(unmapped) {
|
|
3896
|
+
if (unmapped.length === 0) return [];
|
|
3897
|
+
return [
|
|
3898
|
+
"### Unmapped surfaces",
|
|
3899
|
+
...unmapped.map((file) => `- \`${file}\` matches no feature glob; add it to a feature file.`),
|
|
3900
|
+
""
|
|
3901
|
+
];
|
|
3902
|
+
}
|
|
3269
3903
|
/**
|
|
3270
3904
|
* Computes the verdict of a run from its journey results, the diff plan and
|
|
3271
3905
|
* the verifier's judgement, and writes verdict.md, verdict.json and plan.json
|
|
@@ -3293,6 +3927,7 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
3293
3927
|
...judgement.notVerified
|
|
3294
3928
|
];
|
|
3295
3929
|
const result = resultOf(reasons, journeys.notVerified, notVerified.length + judgement.attention.length);
|
|
3930
|
+
const timings = timingReport(state.timings, journeys.listed, formal.ran);
|
|
3296
3931
|
const touched = plan.touched.map((entry) => `\`${entry.feature}\` (diff: ${entry.files.map((file) => `\`${file}\``).join(", ")})`);
|
|
3297
3932
|
const markdown = [
|
|
3298
3933
|
`## Verify: ${result}`,
|
|
@@ -3307,11 +3942,7 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
3307
3942
|
`- ${SMOKE_FEATURE}: runs on every verdict`,
|
|
3308
3943
|
...plan.full ? [`- ${fullLine(plan.full)}`] : [],
|
|
3309
3944
|
"",
|
|
3310
|
-
...plan.unmapped
|
|
3311
|
-
"### Unmapped surfaces",
|
|
3312
|
-
...plan.unmapped.map((file) => `- \`${file}\` matches no feature glob; add it to a feature file.`),
|
|
3313
|
-
""
|
|
3314
|
-
] : [],
|
|
3945
|
+
...unmappedSection(plan.unmapped),
|
|
3315
3946
|
...reasons.length > 0 ? [
|
|
3316
3947
|
"### Why it fails",
|
|
3317
3948
|
...reasons.map((reason) => `- ${reason}`),
|
|
@@ -3334,6 +3965,9 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
3334
3965
|
"### Attention",
|
|
3335
3966
|
...bullets(judgement.attention, "Nothing."),
|
|
3336
3967
|
"",
|
|
3968
|
+
"### Timing",
|
|
3969
|
+
...timingTable(timings),
|
|
3970
|
+
"",
|
|
3337
3971
|
`Evidence: \`verify-evidence\` branch, [\`pr-${pr}/${plan.headSha}/\`](${link("")})`,
|
|
3338
3972
|
""
|
|
3339
3973
|
].join("\n");
|
|
@@ -3344,7 +3978,8 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
3344
3978
|
headSha: plan.headSha,
|
|
3345
3979
|
skillSha,
|
|
3346
3980
|
pr,
|
|
3347
|
-
reasons
|
|
3981
|
+
reasons,
|
|
3982
|
+
timings
|
|
3348
3983
|
}, null, 2)}\n`);
|
|
3349
3984
|
return {
|
|
3350
3985
|
result,
|
|
@@ -3392,7 +4027,7 @@ function printMap(workspace) {
|
|
|
3392
4027
|
async function runJourneys(workspace, dir, feature, ids) {
|
|
3393
4028
|
const results = await runFeature(workspace, loadRun(dir), feature, ids);
|
|
3394
4029
|
for (const result of results) {
|
|
3395
|
-
print(`${result.status} ${feature}/${result.journey}${result.reusedFrom === void 0 ?
|
|
4030
|
+
print(`${result.status} ${feature}/${result.journey}${result.reusedFrom === void 0 ? ` (${seconds(result.ms)})` : ` (reuses ${result.reusedFrom}, not run again)`}`);
|
|
3396
4031
|
for (const step of result.steps) for (const check of step.checks.filter((entry) => !entry.pass)) print(` ${step.name}: ${check.name} (${check.detail})`);
|
|
3397
4032
|
if (result.error) print(` ${result.error.split("\n")[0]}`);
|
|
3398
4033
|
if (result.notVerified) print(` ${result.notVerified}`);
|