@antelopejs/tooling-configs 0.3.6 → 0.3.8

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.
@@ -4,14 +4,14 @@ 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 { _ as withLocalBins, 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-CiFEGFRz.mjs";
7
+ import { _ as removeTree, a as readFeatures, b as writeWhole, c as allocateRun, d as isolatedEnv, f as loadRun, g as recordProcesses, h as operatorTmpdir, i as planFor, l as commandRecords, m as operatorEnv, n as SMOKE_FEATURE, o as CACHE_DIR, p as openWorkspace, r as checkMap, s as RUNS_DIR, u as git, v as saveRun, x as matchesPath, y as withLocalBins } from "../map-B23_WMGE.mjs";
8
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";
9
+ import { basename, dirname, extname, isAbsolute, join, 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
13
  import { createHash, randomBytes } from "node:crypto";
14
- import { constants as constants$1, tmpdir } from "node:os";
14
+ import { availableParallelism, constants as constants$1, tmpdir } from "node:os";
15
15
  import { parseArgs } from "node:util";
16
16
  import { createServer } from "node:net";
17
17
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
@@ -55,7 +55,7 @@ function flaggedDoors(workspace, files) {
55
55
  "publish"
56
56
  ].flatMap((kind) => {
57
57
  const globs = doorGlobs(workspace, kind);
58
- const hits = files.filter((file) => globs.some((glob) => matchesGlob(file, glob)));
58
+ const hits = files.filter((file) => globs.some((glob) => matchesPath(file, glob)));
59
59
  return hits.length > 0 ? [{
60
60
  kind,
61
61
  files: hits
@@ -511,7 +511,7 @@ function seconds(ms) {
511
511
  //#region src/verify/formal.ts
512
512
  const OUTPUT_LIMIT = 67108864;
513
513
  function changesCheckFiles(check, changed) {
514
- return changed.some((file) => (check.files ?? []).some((glob) => matchesGlob(file, glob)));
514
+ return changed.some((file) => (check.files ?? []).some((glob) => matchesPath(file, glob)));
515
515
  }
516
516
  /** The formal checks of verify.config.ts whose covered files or own `files` the change touches. */
517
517
  function touchedFormalChecks(workspace, changed) {
@@ -569,6 +569,44 @@ function baseRun(workspace, check, baseSha, folder) {
569
569
  writeRun(folder, "base-", command, run);
570
570
  return rulesOf(check, run);
571
571
  }
572
+ function gitOutput(root, args) {
573
+ const run = spawnSync("git", args, {
574
+ cwd: root,
575
+ encoding: "utf8",
576
+ maxBuffer: OUTPUT_LIMIT
577
+ });
578
+ return run.status === 0 ? run.stdout : null;
579
+ }
580
+ function namedOnBase(workspace, check, baseSha) {
581
+ const config = relative(workspace.root, join(workspace.skill, "verify.config.ts"));
582
+ const text = gitOutput(workspace.root, ["show", `${baseSha}:${config}`]);
583
+ if (text === null) return false;
584
+ return [
585
+ "\"",
586
+ "'",
587
+ "`"
588
+ ].some((quote) => text.includes(`${quote}${check.name}${quote}`));
589
+ }
590
+ function renamedFromBase(root, check, diff) {
591
+ const fields = (gitOutput(root, [
592
+ "diff",
593
+ "-M",
594
+ "--name-status",
595
+ "-z",
596
+ diff.baseSha,
597
+ diff.headSha
598
+ ]) ?? "").split("\0");
599
+ return fields.some((field, index) => field.startsWith("R") && (check.files ?? []).some((glob) => matchesPath(fields[index + 2] ?? "", glob)));
600
+ }
601
+ /**
602
+ * Whether the diff adds the check: the base could not run it, its name
603
+ * appears nowhere in the base's verify.config.ts, and no file of its own
604
+ * `files` is a rename of a base file. A moved or renamed check, or one whose
605
+ * base ran, is a changed check, gated against the base.
606
+ */
607
+ function addedByDiff(workspace, check, diff, base) {
608
+ return base.exitCode !== 0 && !namedOnBase(workspace, check, diff.baseSha) && !renamedFromBase(workspace.root, check, diff);
609
+ }
572
610
  function gateFields(workspace, check, diff, folder, head) {
573
611
  const behaviour = behaviourChange(workspace.root, check, diff);
574
612
  const checkChanged = changesCheckFiles(check, diff.changed);
@@ -584,6 +622,7 @@ function gateFields(workspace, check, diff, folder, head) {
584
622
  return {
585
623
  behaviour,
586
624
  checkChanged,
625
+ newCheck: checkChanged && addedByDiff(workspace, check, diff, base),
587
626
  base,
588
627
  fixed: base.violated.filter((rule) => head.passing.includes(rule) && !head.violated.includes(rule)),
589
628
  missing: base.violated.filter((rule) => !atHead.has(rule))
@@ -636,17 +675,58 @@ function knownFindingsOfBase(result) {
636
675
  });
637
676
  }
638
677
  /**
678
+ * The outcome a result's base run forces before the findings are weighed: a
679
+ * check the diff adds, on a diff that leaves the covered behaviour unchanged,
680
+ * passes its recorded findings, since its record is reviewed with it and the
681
+ * base has nothing to compare, and fails with the advice to land it alone when
682
+ * the covered code changed too; otherwise a failure
683
+ * for a changed check with no base run recorded, a base run that exited non-zero
684
+ * while HEAD breaks rules, or, when the covered behaviour is unchanged, a rule
685
+ * HEAD breaks that the base did not. `null` when the base decides nothing.
686
+ */
687
+ function baseGate(result) {
688
+ const { base, behaviour } = result;
689
+ if (result.newCheck === true && base && base.exitCode !== 0 && behaviour?.changed === false) return {
690
+ fails: false,
691
+ outcome: `new check, absent from the base: ${result.violated.length > 0 ? `recorded findings ${result.violated.join(", ")}` : "no violated rule"}`
692
+ };
693
+ if (result.newCheck === true && behaviour?.changed === true && result.violated.length > 0) return {
694
+ fails: true,
695
+ outcome: "new check with a covered-code change: land the check in its own PR first"
696
+ };
697
+ if (result.checkChanged === true && !base) return {
698
+ fails: true,
699
+ outcome: "the check's own files changed but no base run was recorded"
700
+ };
701
+ if (!base) return null;
702
+ if (base.exitCode !== 0 && result.violated.length > 0) return {
703
+ fails: true,
704
+ outcome: `the base run exited ${base.exitCode}, so ${result.violated.join(", ")} cannot be compared with the base`
705
+ };
706
+ const added = result.violated.filter((rule) => !base.violated.includes(rule));
707
+ if (behaviour?.changed === false && added.length > 0) return {
708
+ fails: true,
709
+ outcome: `covered behaviour unchanged (${behaviour.method}), but the check breaks rules the base did not: ${added.join(", ")}`
710
+ };
711
+ return null;
712
+ }
713
+ /**
639
714
  * How a formal check's result weighs on a verdict whose diff it covers. A
640
715
  * non-zero exit (a tool error, or a check that no longer matches its record)
641
716
  * fails, so every violated rule of a result that reaches the rest of the gate
642
717
  * is a recorded finding. A rule the base broke that HEAD does not report at
643
- * all fails. Recorded findings are known when the diff left the covered
644
- * code's behaviour unchanged. When it changed them, they are known only when
645
- * the base run exited 0 and broke every one of them, each with the same
646
- * counterexample length at HEAD as on the base, and every other rule the
647
- * base broke is fixed at HEAD; a new rule, a changed length, or a length
648
- * either run did not report fails. A rule the base broke and HEAD reports
649
- * passing is reported as fixed.
718
+ * all fails. A base run that exited non-zero cannot vouch for HEAD's findings,
719
+ * and a changed check with no base run recorded fails. A check the diff adds
720
+ * (the base could not run it, never names it and holds none of its files
721
+ * under another path) passes its recorded findings when the covered
722
+ * behaviour is unchanged. Otherwise, when the covered behaviour is unchanged,
723
+ * recorded findings are known, except a rule HEAD breaks that the base run
724
+ * did not, which fails whatever the diff touched. When the behaviour
725
+ * changed, they are known only when the base run exited 0 and broke every
726
+ * one of them, each with the same counterexample length at HEAD as on the
727
+ * base, and every other rule the base broke is fixed at HEAD; a new rule, a
728
+ * changed length, or a length either run did not report fails. A rule the
729
+ * base broke and HEAD reports passing is reported as fixed.
650
730
  */
651
731
  function formalGate(result) {
652
732
  if (result.exitCode !== 0) return {
@@ -662,6 +742,8 @@ function formalGate(result) {
662
742
  outcome: `violated ${result.violated.join(", ") || "nothing"}`
663
743
  };
664
744
  const how = result.behaviour.method;
745
+ const againstBase = baseGate(result);
746
+ if (againstBase) return againstBase;
665
747
  if (!result.behaviour.changed) return {
666
748
  fails: false,
667
749
  outcome: `covered behaviour unchanged (${how}): ${result.violated.length > 0 ? `known findings ${result.violated.join(", ")}` : "no violated rule"}`
@@ -675,16 +757,423 @@ function formalGate(result) {
675
757
  fails: false,
676
758
  outcome: `covered behaviour changed (${how}), same known findings as base: ${result.violated.join(", ")}${fixed}`
677
759
  };
678
- return {
679
- fails: true,
680
- outcome: `covered behaviour changed (${how}), violated ${result.violated.join(", ")}${fixed}`
760
+ return {
761
+ fails: true,
762
+ outcome: `covered behaviour changed (${how}), violated ${result.violated.join(", ")}${fixed}`
763
+ };
764
+ }
765
+ /** The recorded result of a formal check in a run, if it ran. */
766
+ function readFormalResult(state, name) {
767
+ const file = join(state.evidence, "formal", name, "result.json");
768
+ if (!existsSync(file)) return void 0;
769
+ return JSON.parse(readFileSync(file, "utf8"));
770
+ }
771
+ //#endregion
772
+ //#region src/verify/record.ts
773
+ const DEFAULT_TIMEOUT_MS = 6e5;
774
+ /** Quotes an argument the way a shell user would type it. */
775
+ function shellQuote(value) {
776
+ return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
777
+ }
778
+ function describe(spec) {
779
+ return [spec.program, ...spec.args].map(shellQuote).join(" ");
780
+ }
781
+ function writeCommand(folder, spec) {
782
+ mkdirSync(folder, { recursive: true });
783
+ writeFileSync(join(folder, "command.txt"), `cd ${shellQuote(spec.cwd)}\n${describe(spec)}\n`);
784
+ }
785
+ const foreground = /* @__PURE__ */ new Set();
786
+ const releases = /* @__PURE__ */ new Set();
787
+ const INTERRUPTS$1 = [
788
+ "SIGINT",
789
+ "SIGTERM",
790
+ "SIGHUP",
791
+ "SIGQUIT"
792
+ ];
793
+ let listening = false;
794
+ /** On the first interrupt, kills the process group of every foreground command, runs every registered release (one that throws is reported and the others still run), and exits with the shell's code for the signal. */
795
+ function listenForInterrupts() {
796
+ if (listening) return;
797
+ listening = true;
798
+ for (const signal of INTERRUPTS$1) process.once(signal, () => {
799
+ for (const child of foreground) if (child.pid !== void 0) killOwnGroup(child.pid);
800
+ for (const release of releases) try {
801
+ release();
802
+ } catch (error) {
803
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
804
+ }
805
+ process.exit(128 + constants$1.signals[signal]);
806
+ });
807
+ }
808
+ /**
809
+ * Until the returned function is called, an interrupt calls `release` after
810
+ * killing the process group of every command still running in the
811
+ * foreground, the processes it started included.
812
+ */
813
+ function onInterrupt(release) {
814
+ listenForInterrupts();
815
+ releases.add(release);
816
+ return () => releases.delete(release);
817
+ }
818
+ /** Runs a command to completion and writes command.txt, stdout.txt, stderr.txt and exit-code.txt into `folder`. */
819
+ function runRecorded(folder, spec) {
820
+ writeCommand(folder, spec);
821
+ listenForInterrupts();
822
+ return new Promise((resolve) => {
823
+ const child = spawn(spec.program, spec.args, {
824
+ cwd: spec.cwd,
825
+ env: spec.env,
826
+ detached: true,
827
+ stdio: [
828
+ "ignore",
829
+ "pipe",
830
+ "pipe"
831
+ ]
832
+ });
833
+ foreground.add(child);
834
+ const out = [];
835
+ const err = [];
836
+ child.stdout.on("data", (chunk) => out.push(chunk));
837
+ child.stderr.on("data", (chunk) => err.push(chunk));
838
+ const timer = setTimeout(() => {
839
+ if (child.pid !== void 0) killOwnGroup(child.pid);
840
+ }, spec.timeoutMs ?? DEFAULT_TIMEOUT_MS);
841
+ const finish = (code, signal, failure = "") => {
842
+ clearTimeout(timer);
843
+ foreground.delete(child);
844
+ const result = {
845
+ folder,
846
+ command: describe(spec),
847
+ exitCode: code,
848
+ signal,
849
+ stdout: Buffer.concat(out).toString("utf8"),
850
+ stderr: `${Buffer.concat(err).toString("utf8")}${failure}`
851
+ };
852
+ writeFileSync(join(folder, "stdout.txt"), result.stdout);
853
+ writeFileSync(join(folder, "stderr.txt"), result.stderr);
854
+ writeFileSync(join(folder, "exit-code.txt"), `${code ?? `signal ${signal}`}\n`);
855
+ resolve(result);
856
+ };
857
+ child.on("error", (error) => finish(null, null, `${error.message}\n`));
858
+ child.on("close", (code, signal) => finish(code, signal));
859
+ });
860
+ }
861
+ /** Starts a long-running command in its own process group, writing stdout and stderr straight to files. */
862
+ function startRecorded(folder, spec) {
863
+ writeCommand(folder, spec);
864
+ const stdout = openSync(join(folder, "stdout.txt"), "w");
865
+ const stderr = openSync(join(folder, "stderr.txt"), "w");
866
+ const child = spawn(spec.program, spec.args, {
867
+ cwd: spec.cwd,
868
+ env: spec.env,
869
+ detached: true,
870
+ stdio: [
871
+ "ignore",
872
+ stdout,
873
+ stderr
874
+ ]
875
+ });
876
+ closeSync(stdout);
877
+ closeSync(stderr);
878
+ const exited = new Promise((resolve) => {
879
+ child.on("exit", (exitCode, signal) => {
880
+ writeFileSync(join(folder, "exit-code.txt"), `${exitCode ?? `signal ${signal}`}\n`);
881
+ resolve({
882
+ exitCode,
883
+ signal
884
+ });
885
+ });
886
+ });
887
+ if (child.pid === void 0) throw new Error(`Could not start ${describe(spec)}`);
888
+ writeFileSync(join(folder, "pid.txt"), `${child.pid}\n`);
889
+ return {
890
+ folder,
891
+ child,
892
+ pid: child.pid,
893
+ exited
894
+ };
895
+ }
896
+ /** Kills the process group a detached command leads, never a lone PID the system may have reused since the command exited. */
897
+ function killOwnGroup(pid) {
898
+ try {
899
+ process.kill(-pid, "SIGKILL");
900
+ } catch {
901
+ return;
902
+ }
903
+ }
904
+ /** Kills the process group of `pid`, or `pid` alone, ignoring a process already gone. */
905
+ function killGroup(pid) {
906
+ try {
907
+ process.kill(-pid, "SIGKILL");
908
+ } catch {
909
+ try {
910
+ process.kill(pid, "SIGKILL");
911
+ } catch {
912
+ return;
913
+ }
914
+ }
915
+ }
916
+ /** Reads what a background command has written so far. */
917
+ function readOutput(folder) {
918
+ return {
919
+ stdout: readFileSync(join(folder, "stdout.txt"), "utf8"),
920
+ stderr: readFileSync(join(folder, "stderr.txt"), "utf8")
921
+ };
922
+ }
923
+ /** Where `freePort` looks first: below the kernel's ephemeral range, which outgoing connections keep drawing from, and below the 20000-29999 ports antelopejs-lease hands out. */
924
+ const PORT_RANGE = {
925
+ low: 1e4,
926
+ high: 2e4
927
+ };
928
+ const PORT_ATTEMPTS = 50;
929
+ function bindable(port) {
930
+ return new Promise((resolve) => {
931
+ const server = createServer();
932
+ server.once("error", () => resolve(null));
933
+ server.listen(port, "127.0.0.1", () => {
934
+ const address = server.address();
935
+ const bound = address !== null && address instanceof Object ? address.port : null;
936
+ server.close(() => resolve(bound));
937
+ });
938
+ });
939
+ }
940
+ /**
941
+ * A free TCP port on the loopback interface for a process the harness starts
942
+ * next. It tries random ports below the kernel's ephemeral range first, where
943
+ * no outgoing connection on a busy host takes it between this check and the
944
+ * app's own bind, and falls back to a port the kernel picks.
945
+ */
946
+ async function freePort() {
947
+ for (let attempt = 0; attempt < PORT_ATTEMPTS; attempt++) {
948
+ const bound = await bindable(PORT_RANGE.low + Math.floor(Math.random() * (PORT_RANGE.high - PORT_RANGE.low)));
949
+ if (bound !== null) return bound;
950
+ }
951
+ const picked = await bindable(0);
952
+ if (picked === null) throw new Error("no free loopback port");
953
+ return picked;
954
+ }
955
+ function reason(error) {
956
+ return error.cause instanceof Error ? error.cause.message : error.message;
957
+ }
958
+ /** Sends one request and writes http.json with the status and body. */
959
+ async function httpRecorded(folder, url, init = {}) {
960
+ mkdirSync(folder, { recursive: true });
961
+ let result;
962
+ try {
963
+ const response = await fetch(url, {
964
+ method: init.method ?? "GET",
965
+ body: init.body,
966
+ headers: init.body ? { "content-type": "application/json" } : void 0,
967
+ signal: AbortSignal.timeout(init.timeoutMs ?? 5e3)
968
+ });
969
+ const body = await response.text();
970
+ let json;
971
+ try {
972
+ json = parseJson(body);
973
+ } catch {
974
+ json = void 0;
975
+ }
976
+ result = {
977
+ folder,
978
+ url,
979
+ status: response.status,
980
+ body,
981
+ json,
982
+ error: null
983
+ };
984
+ } catch (error) {
985
+ result = {
986
+ folder,
987
+ url,
988
+ status: null,
989
+ body: "",
990
+ json: void 0,
991
+ error: error instanceof Error ? reason(error) : String(error)
992
+ };
993
+ }
994
+ writeFileSync(join(folder, "http.json"), `${JSON.stringify({
995
+ request: {
996
+ url,
997
+ ...init
998
+ },
999
+ response: result
1000
+ }, null, 2)}\n`);
1001
+ return result;
1002
+ }
1003
+ const TREE_SKIP = /* @__PURE__ */ new Set([
1004
+ "node_modules",
1005
+ ".git",
1006
+ ".pnpm-store"
1007
+ ]);
1008
+ function listTree(root, folder = root) {
1009
+ return readdirSync(folder, { withFileTypes: true }).filter((entry) => !TREE_SKIP.has(entry.name)).sort((left, right) => left.name.localeCompare(right.name)).flatMap((entry) => {
1010
+ const path = join(folder, entry.name);
1011
+ const name = relative(root, path);
1012
+ if (entry.isDirectory()) return [`${name}/`, ...listTree(root, path)];
1013
+ return [`${name} ${statSync(path).size}`];
1014
+ });
1015
+ }
1016
+ /** Writes `tree.txt`: every path under `root` with its size, node_modules and .git left out. */
1017
+ function recordTree(folder, root) {
1018
+ mkdirSync(folder, { recursive: true });
1019
+ let lines;
1020
+ try {
1021
+ lines = listTree(root);
1022
+ } catch {
1023
+ lines = [];
1024
+ }
1025
+ writeFileSync(join(folder, "tree.txt"), `${root}\n${lines.join("\n")}\n`);
1026
+ return lines;
1027
+ }
1028
+ //#endregion
1029
+ //#region src/verify/jobs.ts
1030
+ const INTERRUPTS = [
1031
+ "SIGINT",
1032
+ "SIGTERM",
1033
+ "SIGHUP",
1034
+ "SIGQUIT"
1035
+ ];
1036
+ /** How long a feature's process may take, after an interrupt, to stop what its journey started before it is killed. */
1037
+ const GRACE_MS = 5e3;
1038
+ /**
1039
+ * The most features a `journey` call runs at once: `requested`, capped at
1040
+ * the number of features and at half the logical cores, one feature per
1041
+ * physical core where each core runs two threads. A feature is mostly an
1042
+ * app booting under `ajs project dev`, which keeps a core busy, so features
1043
+ * past one per physical core slow each other's boot more than they overlap
1044
+ * it. The cap only stops a count that oversubscribes the machine; the
1045
+ * synced skill recommends 4 on an otherwise idle machine.
1046
+ */
1047
+ function jobLimit(requested, features) {
1048
+ return Math.max(1, Math.min(requested, features, Math.floor(availableParallelism() / 2)));
1049
+ }
1050
+ /**
1051
+ * For each feature, the earlier features of the list it waits for: the
1052
+ * same feature listed again, or one that registers a journey id it
1053
+ * registers too. A journey listed under two features runs once in a
1054
+ * sequential call and the later feature reuses its PASS (#194); running the
1055
+ * two at once would run it twice and print another line. Waiting keeps the
1056
+ * reuse, and with it the sequential output and evidence, at the cost of the
1057
+ * overlap of those two features only.
1058
+ */
1059
+ function dependencies(runs, journeysOf) {
1060
+ const ids = runs.map((run) => new Set(journeysOf(run.feature)));
1061
+ return runs.map((run, index) => runs.flatMap((earlier, before) => before < index && (earlier.feature === run.feature || [...ids[before]].some((id) => ids[index].has(id))) ? [before] : []));
1062
+ }
1063
+ /**
1064
+ * Starts `args` under this Node in a process group of its own, so a
1065
+ * terminal's interrupt reaches it once, through {@link runConcurrently}, and
1066
+ * collects what it prints into `slot`. Resolves once it exited. A process
1067
+ * that ended on a signal or could not start is named on its stderr.
1068
+ */
1069
+ function runProcess(slot, args) {
1070
+ return new Promise((resolve) => {
1071
+ const child = spawn(process.execPath, args, {
1072
+ stdio: [
1073
+ "ignore",
1074
+ "pipe",
1075
+ "pipe"
1076
+ ],
1077
+ detached: true
1078
+ });
1079
+ slot.child = child;
1080
+ child.stdout.on("data", (chunk) => slot.stdout.push(chunk));
1081
+ child.stderr.on("data", (chunk) => slot.stderr.push(chunk));
1082
+ const end = (passed, note) => {
1083
+ if (note !== void 0) slot.stderr.push(Buffer.from(`${slot.run.feature}: ${note}\n`));
1084
+ slot.passed = passed;
1085
+ resolve();
1086
+ };
1087
+ child.once("error", (error) => end(false, `its journey process could not start: ${error.message}`));
1088
+ child.once("close", (code, signal) => signal === null ? end(code === 0) : end(false, `its journey process ended on ${signal}`));
1089
+ });
1090
+ }
1091
+ /**
1092
+ * Runs each feature in its own `journey <run> <feature>` process, `jobs` at
1093
+ * a time, and prints each feature's output whole, in the order of `runs`,
1094
+ * as soon as it and every feature before it have ended. A process per
1095
+ * feature gives each one the `process.env`, verify.config.ts module state
1096
+ * and uncaught-error handler its own call would have, which features
1097
+ * sharing one process could not keep apart while running at once. A feature
1098
+ * whose process fails, ends on a signal or leaves an uncaught error does not
1099
+ * stop the others.
1100
+ *
1101
+ * An interrupt reaches every running feature's process, which stops what
1102
+ * its journey started. A process still running {@link GRACE_MS} later, or
1103
+ * at a second interrupt, is killed with its process group, and so is every
1104
+ * process its records file in `dir` names. The call then prints the output
1105
+ * of every feature that ended, in order, names on stderr the features that
1106
+ * never started, and exits with the shell's code for the first signal.
1107
+ * @param dir the run folder, whose records files name what each feature's process started.
1108
+ * @param argsOf the arguments, after the Node executable, of the process that runs one feature.
1109
+ * @returns 1 when any feature's process failed, else 0.
1110
+ */
1111
+ async function runConcurrently(dir, runs, jobs, journeysOf, argsOf) {
1112
+ const after = dependencies(runs, journeysOf);
1113
+ const slots = runs.map((run, index) => ({
1114
+ run,
1115
+ after: after[index],
1116
+ state: "waiting",
1117
+ stdout: [],
1118
+ stderr: [],
1119
+ passed: false
1120
+ }));
1121
+ const printed = /* @__PURE__ */ new Set();
1122
+ const print = (slot) => {
1123
+ printed.add(slot);
1124
+ process.stdout.write(Buffer.concat(slot.stdout));
1125
+ process.stderr.write(Buffer.concat(slot.stderr));
1126
+ };
1127
+ const flush = () => {
1128
+ for (const slot of slots) {
1129
+ if (slot.state !== "ended") return;
1130
+ if (!printed.has(slot)) print(slot);
1131
+ }
1132
+ };
1133
+ let interrupted;
1134
+ const ready = () => interrupted === void 0 ? slots.find((slot) => slot.state === "waiting" && slot.after.every((index) => slots[index].state === "ended")) : void 0;
1135
+ const busy = () => slots.filter((slot) => slot.state === "running").length;
1136
+ const kill = () => {
1137
+ for (const slot of slots) {
1138
+ const pid = slot.child?.pid;
1139
+ if (slot.state !== "running" || pid === void 0) continue;
1140
+ killGroup(pid);
1141
+ for (const record of commandRecords(dir, pid)) killGroup(record.pid);
1142
+ }
1143
+ };
1144
+ let deadline;
1145
+ const forward = (signal) => {
1146
+ if (interrupted !== void 0) {
1147
+ kill();
1148
+ return;
1149
+ }
1150
+ interrupted = signal;
1151
+ for (const slot of slots) if (slot.state === "running") slot.child?.kill(signal);
1152
+ deadline = setTimeout(kill, GRACE_MS);
681
1153
  };
682
- }
683
- /** The recorded result of a formal check in a run, if it ran. */
684
- function readFormalResult(state, name) {
685
- const file = join(state.evidence, "formal", name, "result.json");
686
- if (!existsSync(file)) return void 0;
687
- return JSON.parse(readFileSync(file, "utf8"));
1154
+ for (const signal of INTERRUPTS) process.on(signal, forward);
1155
+ await new Promise((done) => {
1156
+ const fill = () => {
1157
+ for (let slot = ready(); slot !== void 0 && busy() < jobs; slot = ready()) {
1158
+ const started = slot;
1159
+ started.state = "running";
1160
+ runProcess(started, argsOf(started.run)).then(() => {
1161
+ started.state = "ended";
1162
+ flush();
1163
+ fill();
1164
+ });
1165
+ }
1166
+ if (busy() === 0 && (interrupted !== void 0 || ready() === void 0)) done();
1167
+ };
1168
+ fill();
1169
+ });
1170
+ clearTimeout(deadline);
1171
+ for (const signal of INTERRUPTS) process.off(signal, forward);
1172
+ if (interrupted === void 0) return slots.every((slot) => slot.passed) ? 0 : 1;
1173
+ for (const slot of slots) if (slot.state === "ended" && !printed.has(slot)) print(slot);
1174
+ const unrun = slots.filter((slot) => slot.state === "waiting");
1175
+ if (unrun.length > 0) process.stderr.write(`not run: ${unrun.map((slot) => slot.run.feature).join(", ")}\n`);
1176
+ process.exit(128 + constants$1.signals[interrupted]);
688
1177
  }
689
1178
  //#endregion
690
1179
  //#region src/verify/judgement.ts
@@ -1476,389 +1965,132 @@ function diffSurface(published, head) {
1476
1965
  path,
1477
1966
  before,
1478
1967
  after
1479
- }] : [];
1480
- });
1481
- return {
1482
- added: added.sort(),
1483
- removed: removed.sort(),
1484
- changed: changed.sort((a, b) => a.path.localeCompare(b.path))
1485
- };
1486
- }
1487
- function parseVersion(text) {
1488
- const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(text.trim());
1489
- if (!match) throw new Error(`not a semver version: ${text}`);
1490
- return {
1491
- core: [
1492
- Number(match[1]),
1493
- Number(match[2]),
1494
- Number(match[3])
1495
- ],
1496
- pre: match[4] ? match[4].split(".") : []
1497
- };
1498
- }
1499
- function comparePre(a, b) {
1500
- if (a.length === 0 || b.length === 0) return b.length - a.length;
1501
- const numeric = /^\d+$/;
1502
- for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
1503
- const [left, right] = [a[index] ?? "", b[index] ?? ""];
1504
- const order = numeric.test(left) && numeric.test(right) ? Number(left) - Number(right) : numeric.test(left) === numeric.test(right) ? left.localeCompare(right) : numeric.test(left) ? -1 : 1;
1505
- if (order !== 0) return order;
1506
- }
1507
- return a.length - b.length;
1508
- }
1509
- function compareVersions(a, b) {
1510
- return a.core[0] - b.core[0] || a.core[1] - b.core[1] || a.core[2] - b.core[2] || comparePre(a.pre, b.pre);
1511
- }
1512
- function increment(version, bump) {
1513
- const [major, minor, patch] = version.core;
1514
- if (bump === "major") return {
1515
- core: [
1516
- major + 1,
1517
- 0,
1518
- 0
1519
- ],
1520
- pre: []
1521
- };
1522
- if (bump === "minor") return {
1523
- core: [
1524
- major,
1525
- minor + 1,
1526
- 0
1527
- ],
1528
- pre: []
1529
- };
1530
- return {
1531
- core: version.pre.length > 0 ? [
1532
- major,
1533
- minor,
1534
- patch
1535
- ] : [
1536
- major,
1537
- minor,
1538
- patch + 1
1539
- ],
1540
- pre: []
1541
- };
1542
- }
1543
- function format(version) {
1544
- const core = version.core.join(".");
1545
- return version.pre.length > 0 ? `${core}-${version.pre.join(".")}` : core;
1546
- }
1547
- function titleBump(title) {
1548
- const match = /^(\w+)(?:\([^)]*\))?(!)?:/.exec(title.trim());
1549
- if (match?.[2] === "!" || title.includes("BREAKING CHANGE")) return "major";
1550
- return match?.[1] === "feat" ? "minor" : "patch";
1551
- }
1552
- /**
1553
- * The bump changelogen 0.5.7 applies to `currentVersion` for these commit titles:
1554
- * `!` or a `BREAKING CHANGE` footer is major, `feat` minor, anything else patch,
1555
- * and on a `0.x` version major becomes minor and minor becomes patch.
1556
- */
1557
- function releaseType(currentVersion, titles) {
1558
- const order = [
1559
- "patch",
1560
- "minor",
1561
- "major"
1562
- ];
1563
- const highest = titles.map(titleBump).reduce((top, bump) => order.indexOf(bump) > order.indexOf(top) ? bump : top, "patch");
1564
- if (!currentVersion.startsWith("0.")) return highest;
1565
- return highest === "major" ? "minor" : "patch";
1566
- }
1567
- function listPaths(diff) {
1568
- return [
1569
- diff.added.length > 0 ? `added ${diff.added.join(", ")}` : "",
1570
- diff.changed.length > 0 ? `changed ${diff.changed.map((entry) => entry.path).join(", ")}` : "",
1571
- diff.removed.length > 0 ? `removed ${diff.removed.join(", ")}` : ""
1572
- ].filter((part) => part !== "").join("; ");
1573
- }
1574
- /**
1575
- * Judges the interface minor-bump rule: an added, changed or removed function needs a
1576
- * release of at least the next minor of the published version.
1577
- */
1578
- function minorRule(input) {
1579
- const { published, headVersion, titles, diff } = input;
1580
- if (published === null) return {
1581
- required: "none",
1582
- releases: headVersion,
1583
- ok: true,
1584
- reason: "never published: the first release has no surface to compare against"
1585
- };
1586
- const base = parseVersion(published);
1587
- const releases = compareVersions(parseVersion(headVersion), base) > 0 ? headVersion : format(increment(base, releaseType(published, titles)));
1588
- const required = diff.added.length + diff.changed.length + diff.removed.length > 0 ? "minor" : "none";
1589
- if (required === "none") return {
1590
- required,
1591
- releases,
1592
- ok: true,
1593
- reason: `no function added, changed or removed against ${published}: no minor required`
1594
- };
1595
- const floor = format(increment(base, "minor"));
1596
- const ok = compareVersions(parseVersion(releases), parseVersion(floor)) >= 0;
1597
- const facts = `${listPaths(diff)}: needs at least ${floor} against ${published}, this change releases as ${releases}`;
1598
- const title = base.core[0] === 0 ? "a `feat!:` commit title (changelogen turns a breaking change into a minor on 0.x)" : "a `feat:` commit title";
1599
- return {
1600
- required,
1601
- releases,
1602
- ok,
1603
- reason: ok ? facts : `${facts}. Fix: use ${title}, or run the release workflow with release-version ${floor}`
1604
- };
1605
- }
1606
- //#endregion
1607
- //#region src/verify/record.ts
1608
- const DEFAULT_TIMEOUT_MS = 6e5;
1609
- /** Quotes an argument the way a shell user would type it. */
1610
- function shellQuote(value) {
1611
- return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
1612
- }
1613
- function describe(spec) {
1614
- return [spec.program, ...spec.args].map(shellQuote).join(" ");
1615
- }
1616
- function writeCommand(folder, spec) {
1617
- mkdirSync(folder, { recursive: true });
1618
- writeFileSync(join(folder, "command.txt"), `cd ${shellQuote(spec.cwd)}\n${describe(spec)}\n`);
1619
- }
1620
- const foreground = /* @__PURE__ */ new Set();
1621
- const releases = /* @__PURE__ */ new Set();
1622
- const INTERRUPTS = [
1623
- "SIGINT",
1624
- "SIGTERM",
1625
- "SIGHUP",
1626
- "SIGQUIT"
1627
- ];
1628
- let listening = false;
1629
- /** On the first interrupt, kills the process group of every foreground command, runs every registered release (one that throws is reported and the others still run), and exits with the shell's code for the signal. */
1630
- function listenForInterrupts() {
1631
- if (listening) return;
1632
- listening = true;
1633
- for (const signal of INTERRUPTS) process.once(signal, () => {
1634
- for (const child of foreground) if (child.pid !== void 0) killOwnGroup(child.pid);
1635
- for (const release of releases) try {
1636
- release();
1637
- } catch (error) {
1638
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
1639
- }
1640
- process.exit(128 + constants$1.signals[signal]);
1641
- });
1642
- }
1643
- /**
1644
- * Until the returned function is called, an interrupt calls `release` after
1645
- * killing the process group of every command still running in the
1646
- * foreground, the processes it started included.
1647
- */
1648
- function onInterrupt(release) {
1649
- listenForInterrupts();
1650
- releases.add(release);
1651
- return () => releases.delete(release);
1652
- }
1653
- /** Runs a command to completion and writes command.txt, stdout.txt, stderr.txt and exit-code.txt into `folder`. */
1654
- function runRecorded(folder, spec) {
1655
- writeCommand(folder, spec);
1656
- listenForInterrupts();
1657
- return new Promise((resolve) => {
1658
- const child = spawn(spec.program, spec.args, {
1659
- cwd: spec.cwd,
1660
- env: spec.env,
1661
- detached: true,
1662
- stdio: [
1663
- "ignore",
1664
- "pipe",
1665
- "pipe"
1666
- ]
1667
- });
1668
- foreground.add(child);
1669
- const out = [];
1670
- const err = [];
1671
- child.stdout.on("data", (chunk) => out.push(chunk));
1672
- child.stderr.on("data", (chunk) => err.push(chunk));
1673
- const timer = setTimeout(() => {
1674
- if (child.pid !== void 0) killOwnGroup(child.pid);
1675
- }, spec.timeoutMs ?? DEFAULT_TIMEOUT_MS);
1676
- const finish = (code, signal, failure = "") => {
1677
- clearTimeout(timer);
1678
- foreground.delete(child);
1679
- const result = {
1680
- folder,
1681
- command: describe(spec),
1682
- exitCode: code,
1683
- signal,
1684
- stdout: Buffer.concat(out).toString("utf8"),
1685
- stderr: `${Buffer.concat(err).toString("utf8")}${failure}`
1686
- };
1687
- writeFileSync(join(folder, "stdout.txt"), result.stdout);
1688
- writeFileSync(join(folder, "stderr.txt"), result.stderr);
1689
- writeFileSync(join(folder, "exit-code.txt"), `${code ?? `signal ${signal}`}\n`);
1690
- resolve(result);
1691
- };
1692
- child.on("error", (error) => finish(null, null, `${error.message}\n`));
1693
- child.on("close", (code, signal) => finish(code, signal));
1694
- });
1695
- }
1696
- /** Starts a long-running command in its own process group, writing stdout and stderr straight to files. */
1697
- function startRecorded(folder, spec) {
1698
- writeCommand(folder, spec);
1699
- const stdout = openSync(join(folder, "stdout.txt"), "w");
1700
- const stderr = openSync(join(folder, "stderr.txt"), "w");
1701
- const child = spawn(spec.program, spec.args, {
1702
- cwd: spec.cwd,
1703
- env: spec.env,
1704
- detached: true,
1705
- stdio: [
1706
- "ignore",
1707
- stdout,
1708
- stderr
1709
- ]
1710
- });
1711
- closeSync(stdout);
1712
- closeSync(stderr);
1713
- const exited = new Promise((resolve) => {
1714
- child.on("exit", (exitCode, signal) => {
1715
- writeFileSync(join(folder, "exit-code.txt"), `${exitCode ?? `signal ${signal}`}\n`);
1716
- resolve({
1717
- exitCode,
1718
- signal
1719
- });
1720
- });
1968
+ }] : [];
1721
1969
  });
1722
- if (child.pid === void 0) throw new Error(`Could not start ${describe(spec)}`);
1723
- writeFileSync(join(folder, "pid.txt"), `${child.pid}\n`);
1724
1970
  return {
1725
- folder,
1726
- child,
1727
- pid: child.pid,
1728
- exited
1971
+ added: added.sort(),
1972
+ removed: removed.sort(),
1973
+ changed: changed.sort((a, b) => a.path.localeCompare(b.path))
1729
1974
  };
1730
1975
  }
1731
- /** Kills the process group a detached command leads, never a lone PID the system may have reused since the command exited. */
1732
- function killOwnGroup(pid) {
1733
- try {
1734
- process.kill(-pid, "SIGKILL");
1735
- } catch {
1736
- return;
1737
- }
1976
+ function parseVersion(text) {
1977
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(text.trim());
1978
+ if (!match) throw new Error(`not a semver version: ${text}`);
1979
+ return {
1980
+ core: [
1981
+ Number(match[1]),
1982
+ Number(match[2]),
1983
+ Number(match[3])
1984
+ ],
1985
+ pre: match[4] ? match[4].split(".") : []
1986
+ };
1738
1987
  }
1739
- /** Kills the process group of `pid`, or `pid` alone, ignoring a process already gone. */
1740
- function killGroup(pid) {
1741
- try {
1742
- process.kill(-pid, "SIGKILL");
1743
- } catch {
1744
- try {
1745
- process.kill(pid, "SIGKILL");
1746
- } catch {
1747
- return;
1748
- }
1988
+ function comparePre(a, b) {
1989
+ if (a.length === 0 || b.length === 0) return b.length - a.length;
1990
+ const numeric = /^\d+$/;
1991
+ for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
1992
+ const [left, right] = [a[index] ?? "", b[index] ?? ""];
1993
+ const order = numeric.test(left) && numeric.test(right) ? Number(left) - Number(right) : numeric.test(left) === numeric.test(right) ? left.localeCompare(right) : numeric.test(left) ? -1 : 1;
1994
+ if (order !== 0) return order;
1749
1995
  }
1996
+ return a.length - b.length;
1750
1997
  }
1751
- /** Reads what a background command has written so far. */
1752
- function readOutput(folder) {
1998
+ function compareVersions(a, b) {
1999
+ return a.core[0] - b.core[0] || a.core[1] - b.core[1] || a.core[2] - b.core[2] || comparePre(a.pre, b.pre);
2000
+ }
2001
+ function increment(version, bump) {
2002
+ const [major, minor, patch] = version.core;
2003
+ if (bump === "major") return {
2004
+ core: [
2005
+ major + 1,
2006
+ 0,
2007
+ 0
2008
+ ],
2009
+ pre: []
2010
+ };
2011
+ if (bump === "minor") return {
2012
+ core: [
2013
+ major,
2014
+ minor + 1,
2015
+ 0
2016
+ ],
2017
+ pre: []
2018
+ };
1753
2019
  return {
1754
- stdout: readFileSync(join(folder, "stdout.txt"), "utf8"),
1755
- stderr: readFileSync(join(folder, "stderr.txt"), "utf8")
2020
+ core: version.pre.length > 0 ? [
2021
+ major,
2022
+ minor,
2023
+ patch
2024
+ ] : [
2025
+ major,
2026
+ minor,
2027
+ patch + 1
2028
+ ],
2029
+ pre: []
1756
2030
  };
1757
2031
  }
1758
- /** Where `freePort` looks first: below the kernel's ephemeral range, which outgoing connections keep drawing from, and below the 20000-29999 ports antelopejs-lease hands out. */
1759
- const PORT_RANGE = {
1760
- low: 1e4,
1761
- high: 2e4
1762
- };
1763
- const PORT_ATTEMPTS = 50;
1764
- function bindable(port) {
1765
- return new Promise((resolve) => {
1766
- const server = createServer();
1767
- server.once("error", () => resolve(null));
1768
- server.listen(port, "127.0.0.1", () => {
1769
- const address = server.address();
1770
- const bound = address !== null && address instanceof Object ? address.port : null;
1771
- server.close(() => resolve(bound));
1772
- });
1773
- });
2032
+ function format(version) {
2033
+ const core = version.core.join(".");
2034
+ return version.pre.length > 0 ? `${core}-${version.pre.join(".")}` : core;
2035
+ }
2036
+ function titleBump(title) {
2037
+ const match = /^(\w+)(?:\([^)]*\))?(!)?:/.exec(title.trim());
2038
+ if (match?.[2] === "!" || title.includes("BREAKING CHANGE")) return "major";
2039
+ return match?.[1] === "feat" ? "minor" : "patch";
1774
2040
  }
1775
2041
  /**
1776
- * A free TCP port on the loopback interface for a process the harness starts
1777
- * next. It tries random ports below the kernel's ephemeral range first, where
1778
- * no outgoing connection on a busy host takes it between this check and the
1779
- * app's own bind, and falls back to a port the kernel picks.
2042
+ * The bump changelogen 0.5.7 applies to `currentVersion` for these commit titles:
2043
+ * `!` or a `BREAKING CHANGE` footer is major, `feat` minor, anything else patch,
2044
+ * and on a `0.x` version major becomes minor and minor becomes patch.
1780
2045
  */
1781
- async function freePort() {
1782
- for (let attempt = 0; attempt < PORT_ATTEMPTS; attempt++) {
1783
- const bound = await bindable(PORT_RANGE.low + Math.floor(Math.random() * (PORT_RANGE.high - PORT_RANGE.low)));
1784
- if (bound !== null) return bound;
1785
- }
1786
- const picked = await bindable(0);
1787
- if (picked === null) throw new Error("no free loopback port");
1788
- return picked;
1789
- }
1790
- function reason(error) {
1791
- return error.cause instanceof Error ? error.cause.message : error.message;
1792
- }
1793
- /** Sends one request and writes http.json with the status and body. */
1794
- async function httpRecorded(folder, url, init = {}) {
1795
- mkdirSync(folder, { recursive: true });
1796
- let result;
1797
- try {
1798
- const response = await fetch(url, {
1799
- method: init.method ?? "GET",
1800
- body: init.body,
1801
- headers: init.body ? { "content-type": "application/json" } : void 0,
1802
- signal: AbortSignal.timeout(init.timeoutMs ?? 5e3)
1803
- });
1804
- const body = await response.text();
1805
- let json;
1806
- try {
1807
- json = parseJson(body);
1808
- } catch {
1809
- json = void 0;
1810
- }
1811
- result = {
1812
- folder,
1813
- url,
1814
- status: response.status,
1815
- body,
1816
- json,
1817
- error: null
1818
- };
1819
- } catch (error) {
1820
- result = {
1821
- folder,
1822
- url,
1823
- status: null,
1824
- body: "",
1825
- json: void 0,
1826
- error: error instanceof Error ? reason(error) : String(error)
1827
- };
1828
- }
1829
- writeFileSync(join(folder, "http.json"), `${JSON.stringify({
1830
- request: {
1831
- url,
1832
- ...init
1833
- },
1834
- response: result
1835
- }, null, 2)}\n`);
1836
- return result;
2046
+ function releaseType(currentVersion, titles) {
2047
+ const order = [
2048
+ "patch",
2049
+ "minor",
2050
+ "major"
2051
+ ];
2052
+ const highest = titles.map(titleBump).reduce((top, bump) => order.indexOf(bump) > order.indexOf(top) ? bump : top, "patch");
2053
+ if (!currentVersion.startsWith("0.")) return highest;
2054
+ return highest === "major" ? "minor" : "patch";
1837
2055
  }
1838
- const TREE_SKIP = /* @__PURE__ */ new Set([
1839
- "node_modules",
1840
- ".git",
1841
- ".pnpm-store"
1842
- ]);
1843
- function listTree(root, folder = root) {
1844
- return readdirSync(folder, { withFileTypes: true }).filter((entry) => !TREE_SKIP.has(entry.name)).sort((left, right) => left.name.localeCompare(right.name)).flatMap((entry) => {
1845
- const path = join(folder, entry.name);
1846
- const name = relative(root, path);
1847
- if (entry.isDirectory()) return [`${name}/`, ...listTree(root, path)];
1848
- return [`${name} ${statSync(path).size}`];
1849
- });
2056
+ function listPaths(diff) {
2057
+ return [
2058
+ diff.added.length > 0 ? `added ${diff.added.join(", ")}` : "",
2059
+ diff.changed.length > 0 ? `changed ${diff.changed.map((entry) => entry.path).join(", ")}` : "",
2060
+ diff.removed.length > 0 ? `removed ${diff.removed.join(", ")}` : ""
2061
+ ].filter((part) => part !== "").join("; ");
1850
2062
  }
1851
- /** Writes `tree.txt`: every path under `root` with its size, node_modules and .git left out. */
1852
- function recordTree(folder, root) {
1853
- mkdirSync(folder, { recursive: true });
1854
- let lines;
1855
- try {
1856
- lines = listTree(root);
1857
- } catch {
1858
- lines = [];
1859
- }
1860
- writeFileSync(join(folder, "tree.txt"), `${root}\n${lines.join("\n")}\n`);
1861
- return lines;
2063
+ /**
2064
+ * Judges the interface minor-bump rule: an added, changed or removed function needs a
2065
+ * release of at least the next minor of the published version.
2066
+ */
2067
+ function minorRule(input) {
2068
+ const { published, headVersion, titles, diff } = input;
2069
+ if (published === null) return {
2070
+ required: "none",
2071
+ releases: headVersion,
2072
+ ok: true,
2073
+ reason: "never published: the first release has no surface to compare against"
2074
+ };
2075
+ const base = parseVersion(published);
2076
+ const releases = compareVersions(parseVersion(headVersion), base) > 0 ? headVersion : format(increment(base, releaseType(published, titles)));
2077
+ const required = diff.added.length + diff.changed.length + diff.removed.length > 0 ? "minor" : "none";
2078
+ if (required === "none") return {
2079
+ required,
2080
+ releases,
2081
+ ok: true,
2082
+ reason: `no function added, changed or removed against ${published}: no minor required`
2083
+ };
2084
+ const floor = format(increment(base, "minor"));
2085
+ const ok = compareVersions(parseVersion(releases), parseVersion(floor)) >= 0;
2086
+ const facts = `${listPaths(diff)}: needs at least ${floor} against ${published}, this change releases as ${releases}`;
2087
+ const title = base.core[0] === 0 ? "a `feat!:` commit title (changelogen turns a breaking change into a minor on 0.x)" : "a `feat:` commit title";
2088
+ return {
2089
+ required,
2090
+ releases,
2091
+ ok,
2092
+ reason: ok ? facts : `${facts}. Fix: use ${title}, or run the release workflow with release-version ${floor}`
2093
+ };
1862
2094
  }
1863
2095
  //#endregion
1864
2096
  //#region src/verify/interface.ts
@@ -2415,12 +2647,12 @@ function lastActivity(dir) {
2415
2647
  const file = join(dir, "run.json");
2416
2648
  return statSync(existsSync(file) ? file : dir).mtimeMs;
2417
2649
  }
2418
- /** The leftovers a run recorded; none when its run.json is missing or unreadable. */
2650
+ /** The leftovers a run recorded in run.json and its commands' records files; none when its run.json is missing or unreadable. */
2419
2651
  function recorded(dir) {
2420
2652
  try {
2421
2653
  const state = object(parseJson(readFileSync(join(dir, "run.json"), "utf8")), "run.json");
2422
2654
  return {
2423
- pids: children(state, "processes").map((entry) => num(entry, "pid")),
2655
+ pids: [...children(state, "processes").map((entry) => num(entry, "pid")), ...commandRecords(dir).map((record) => record.pid)],
2424
2656
  containers: children(state, "containers").map((entry) => str(entry, "name"))
2425
2657
  };
2426
2658
  } catch {
@@ -3466,11 +3698,10 @@ var VerifyContext = class {
3466
3698
  });
3467
3699
  this.running.push(entry);
3468
3700
  this.started.push(entry);
3469
- this.state.processes.push({
3701
+ recordProcesses(this.state, { add: [{
3470
3702
  name: `${name} (${project})`,
3471
3703
  pid: handle.pid
3472
- });
3473
- saveRun(this.state);
3704
+ }] });
3474
3705
  await this.waitReady(app, handle, fixture !== void 0);
3475
3706
  return this.caches.observed(app);
3476
3707
  }
@@ -3580,8 +3811,7 @@ var VerifyContext = class {
3580
3811
  untrack(pid) {
3581
3812
  const index = this.running.findIndex((entry) => entry.app.pid === pid);
3582
3813
  if (index !== -1) this.running.splice(index, 1);
3583
- this.state.processes = this.state.processes.filter((record) => record.pid !== pid);
3584
- saveRun(this.state);
3814
+ recordProcesses(this.state, { drop: [pid] });
3585
3815
  }
3586
3816
  async scaffold(name, project, flags = [
3587
3817
  "--pm",
@@ -3690,13 +3920,24 @@ function statusOf(context, failure) {
3690
3920
  if (failure.notVerified !== null) return "NOT VERIFIED";
3691
3921
  return failure.error !== null || context.steps.some((step) => step.checks.some((check) => !check.pass)) || context.steps.length === 0 ? "FAIL" : "PASS";
3692
3922
  }
3923
+ /** Removes the empty folders from `folder` up to, not including, `top`; it stops at the first that another journey of the run filled or removed meanwhile. */
3924
+ function removeEmptyParents(folder, top) {
3925
+ try {
3926
+ for (let parent = dirname(folder); parent !== top && readdirSync(parent).length === 0; parent = dirname(parent)) rmdirSync(parent);
3927
+ } catch {
3928
+ return;
3929
+ }
3930
+ }
3693
3931
  /** Deletes a journey's scratch folder and HOME, and their parents once empty; the evidence stays. A folder it cannot delete is reported on stderr and left for the next prune. */
3694
3932
  function discard(context) {
3695
- for (const folder of [context.work, context.home]) try {
3696
- removeTree(folder);
3697
- for (let parent = dirname(folder); parent !== context.state.dir && readdirSync(parent).length === 0; parent = dirname(parent)) rmdirSync(parent);
3698
- } catch (error) {
3699
- process.stderr.write(`could not delete ${folder}: ${error instanceof Error ? error.message : String(error)}\n`);
3933
+ for (const folder of [context.work, context.home]) {
3934
+ try {
3935
+ removeTree(folder);
3936
+ } catch (error) {
3937
+ process.stderr.write(`could not delete ${folder}: ${error instanceof Error ? error.message : String(error)}\n`);
3938
+ continue;
3939
+ }
3940
+ removeEmptyParents(folder, context.state.dir);
3700
3941
  }
3701
3942
  }
3702
3943
  async function runOne(workspace, state, feature, id, journey) {
@@ -3706,8 +3947,7 @@ async function runOne(workspace, state, feature, id, journey) {
3706
3947
  const own = state.processes.filter((record) => !others.has(record.pid));
3707
3948
  for (const record of own) killGroup(record.pid);
3708
3949
  discard(context);
3709
- state.processes = state.processes.filter((record) => others.has(record.pid));
3710
- saveRun(state);
3950
+ recordProcesses(state, { drop: own.map((record) => record.pid) });
3711
3951
  });
3712
3952
  try {
3713
3953
  return await driveJourney(context, feature, id, journey);
@@ -3882,7 +4122,7 @@ async function runFeature(workspace, state, feature, ids) {
3882
4122
  results.push(source === void 0 ? stamp(state, await runOne(workspace, state, feature, id, journey), tree) : reuse(state, feature, id, source));
3883
4123
  }
3884
4124
  const merged = registered.flatMap((id) => results.filter((result) => result.journey === id).concat(results.some((result) => result.journey === id) ? [] : earlier.filter((result) => result.journey === id)));
3885
- writeFileSync(join(state.evidence, feature, "feature.json"), `${JSON.stringify(merged, null, 2)}\n`);
4125
+ writeWhole(join(state.evidence, feature, "feature.json"), `${JSON.stringify(merged, null, 2)}\n`);
3886
4126
  return results;
3887
4127
  }
3888
4128
  //#endregion
@@ -4186,8 +4426,11 @@ const USAGE = `Usage: antelopejs-verify <command>
4186
4426
  build, prepare an isolated run, print its folder; --all runs every feature, before a release
4187
4427
  doctor <run> check the run is worth driving
4188
4428
  journey <run> <feature> [ids...] run a feature's journeys and record evidence
4189
- journey <run> --plan run every feature the run's plan lists, smoke first
4190
- journey <run> --features <a,b> run the named features, each whole, in that order
4429
+ journey <run> --plan [--jobs <n>] run every feature the run's plan lists, smoke first
4430
+ journey <run> --features <a,b> [--jobs <n>]
4431
+ run the named features, each whole, in that order;
4432
+ --jobs runs up to n features at once, each in its own process,
4433
+ at most half the cores, never with services
4191
4434
  formal <run> [--all] run the formal checks that cover the diff and gate them on changed behaviour
4192
4435
  doors [patch] [--base <ref>] print the One-way-door line for a patch, or for the diff
4193
4436
  clean <run> stop what the run started, keep only the evidence
@@ -4274,8 +4517,9 @@ async function journeyFeature(workspace, dir, { feature, ids }) {
4274
4517
  * feature. An uncaught error a journey leaves behind (a timer that throws, a
4275
4518
  * rejection nobody awaits) ends the call, as it would end a single call, and
4276
4519
  * names the features that did not run. Module-level state a repository's
4277
- * verify.config.ts keeps is shared by the features of one call. This loop is
4278
- * the one place a capped number of features would run at once.
4520
+ * verify.config.ts keeps is shared by the features of one call. `--jobs`
4521
+ * runs features at once in processes of their own instead, through
4522
+ * {@link runConcurrently}.
4279
4523
  * @returns 1 when any feature had a journey that did not pass or could not run, else 0.
4280
4524
  */
4281
4525
  async function runJourneys(workspace, dir, runs) {
@@ -4304,6 +4548,22 @@ function restoreEnv(saved) {
4304
4548
  for (const key of Object.keys(process.env)) if (!Object.hasOwn(saved, key)) delete process.env[key];
4305
4549
  Object.assign(process.env, saved);
4306
4550
  }
4551
+ /**
4552
+ * How many features a `journey` call runs at once: 1 without `--jobs`, else
4553
+ * `--jobs` capped by {@link jobLimit}. `--jobs` applies to `--plan` and
4554
+ * `--features` only, and more than 1 is refused when verify.config.ts
4555
+ * declares `services`: every journey resets them as it starts, which would
4556
+ * wipe the data of a journey running beside it.
4557
+ */
4558
+ function jobsFor(workspace, runs, flags) {
4559
+ if (flags.jobs === void 0) return 1;
4560
+ if (flags.plan !== true && flags.features === void 0) throw new Error("--jobs runs whole features at once: use it with --plan or --features");
4561
+ if (!/^[1-9]\d*$/.test(flags.jobs)) throw new Error(`--jobs takes a number of features, 1 or more, not ${flags.jobs}`);
4562
+ const requested = Number(flags.jobs);
4563
+ const services = Object.keys(workspace.config.services ?? {});
4564
+ if (requested > 1 && services.length > 0) throw new Error(`--jobs ${requested} refused: verify.config.ts declares services (${services.join(", ")}), and each journey resets them as it starts, which would wipe the data of a journey running beside it. Run the features without --jobs.`);
4565
+ return jobLimit(requested, runs.length);
4566
+ }
4307
4567
  function runFormal(workspace, dir, all) {
4308
4568
  const state = loadRun(dir);
4309
4569
  const plan = planFor(workspace, state.baseRef);
@@ -4364,7 +4624,8 @@ async function main(argv) {
4364
4624
  features: {
4365
4625
  type: "string",
4366
4626
  multiple: true
4367
- }
4627
+ },
4628
+ jobs: { type: "string" }
4368
4629
  }
4369
4630
  });
4370
4631
  const [command, ...rest] = positionals;
@@ -4386,8 +4647,22 @@ async function main(argv) {
4386
4647
  const lines = doctor(workspace, loadRun(rest[0]));
4387
4648
  for (const line of lines) print(`${line.ok ? "ok " : "FAIL"} ${line.check}: ${line.detail}`);
4388
4649
  return lines.every((line) => line.ok) ? 0 : 1;
4389
- } else if (command === "journey") return runJourneys(workspace, rest[0], featureRuns(workspace, rest, values));
4390
- else if (command === "formal") return runFormal(workspace, rest[0], values.all === true);
4650
+ } else if (command === "journey") {
4651
+ const runs = featureRuns(workspace, rest, values);
4652
+ const jobs = jobsFor(workspace, runs, values);
4653
+ if (jobs === 1) return runJourneys(workspace, rest[0], runs);
4654
+ const dir = resolve(rest[0]);
4655
+ return runConcurrently(dir, runs, jobs, (name) => featureJourneys(workspace, name) ?? [], ({ feature }) => [
4656
+ ...process.execArgv,
4657
+ process.argv[1],
4658
+ "journey",
4659
+ dir,
4660
+ "--kind",
4661
+ workspace.kind,
4662
+ "--",
4663
+ feature
4664
+ ]);
4665
+ } else if (command === "formal") return runFormal(workspace, rest[0], values.all === true);
4391
4666
  else if (command === "doors") return printDoors(workspace, rest[0] ? patchFiles(rest[0]) : planFor(workspace, values.base).changed);
4392
4667
  else if (command === "clean") for (const line of clean(loadRun(rest[0]))) print(line);
4393
4668
  else if (command === "verdict" || command === "publish") return judge(workspace, command, rest[0], Number(values.pr));