@antelopejs/tooling-configs 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bin/sync.mjs +6 -7
- package/dist/bin/verify.mjs +424 -565
- package/dist/{map-COx26Bu6.mjs → map-B23_WMGE.mjs} +52 -51
- package/package.json +1 -1
package/dist/bin/verify.mjs
CHANGED
|
@@ -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
|
|
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
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 { availableParallelism, constants as constants$1
|
|
14
|
+
import { availableParallelism, constants as constants$1 } 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";
|
|
@@ -769,13 +769,272 @@ function readFormalResult(state, name) {
|
|
|
769
769
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
770
770
|
}
|
|
771
771
|
//#endregion
|
|
772
|
-
//#region src/verify/
|
|
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();
|
|
773
787
|
const INTERRUPTS$1 = [
|
|
774
788
|
"SIGINT",
|
|
775
789
|
"SIGTERM",
|
|
776
790
|
"SIGHUP",
|
|
777
791
|
"SIGQUIT"
|
|
778
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;
|
|
779
1038
|
/**
|
|
780
1039
|
* The most features a `journey` call runs at once: `requested`, capped at
|
|
781
1040
|
* the number of features and at half the logical cores, one feature per
|
|
@@ -783,7 +1042,7 @@ const INTERRUPTS$1 = [
|
|
|
783
1042
|
* app booting under `ajs project dev`, which keeps a core busy, so features
|
|
784
1043
|
* past one per physical core slow each other's boot more than they overlap
|
|
785
1044
|
* it. The cap only stops a count that oversubscribes the machine; the
|
|
786
|
-
* synced skill recommends 4.
|
|
1045
|
+
* synced skill recommends 4 on an otherwise idle machine.
|
|
787
1046
|
*/
|
|
788
1047
|
function jobLimit(requested, features) {
|
|
789
1048
|
return Math.max(1, Math.min(requested, features, Math.floor(availableParallelism() / 2)));
|
|
@@ -837,13 +1096,19 @@ function runProcess(slot, args) {
|
|
|
837
1096
|
* and uncaught-error handler its own call would have, which features
|
|
838
1097
|
* sharing one process could not keep apart while running at once. A feature
|
|
839
1098
|
* whose process fails, ends on a signal or leaves an uncaught error does not
|
|
840
|
-
* stop the others.
|
|
841
|
-
*
|
|
842
|
-
*
|
|
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.
|
|
843
1108
|
* @param argsOf the arguments, after the Node executable, of the process that runs one feature.
|
|
844
1109
|
* @returns 1 when any feature's process failed, else 0.
|
|
845
1110
|
*/
|
|
846
|
-
async function runConcurrently(runs, jobs, journeysOf, argsOf) {
|
|
1111
|
+
async function runConcurrently(dir, runs, jobs, journeysOf, argsOf) {
|
|
847
1112
|
const after = dependencies(runs, journeysOf);
|
|
848
1113
|
const slots = runs.map((run, index) => ({
|
|
849
1114
|
run,
|
|
@@ -853,21 +1118,40 @@ async function runConcurrently(runs, jobs, journeysOf, argsOf) {
|
|
|
853
1118
|
stderr: [],
|
|
854
1119
|
passed: false
|
|
855
1120
|
}));
|
|
856
|
-
|
|
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
|
+
};
|
|
857
1127
|
const flush = () => {
|
|
858
|
-
for (
|
|
859
|
-
|
|
860
|
-
|
|
1128
|
+
for (const slot of slots) {
|
|
1129
|
+
if (slot.state !== "ended") return;
|
|
1130
|
+
if (!printed.has(slot)) print(slot);
|
|
861
1131
|
}
|
|
862
1132
|
};
|
|
863
1133
|
let interrupted;
|
|
864
1134
|
const ready = () => interrupted === void 0 ? slots.find((slot) => slot.state === "waiting" && slot.after.every((index) => slots[index].state === "ended")) : void 0;
|
|
865
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;
|
|
866
1145
|
const forward = (signal) => {
|
|
867
|
-
interrupted
|
|
1146
|
+
if (interrupted !== void 0) {
|
|
1147
|
+
kill();
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
interrupted = signal;
|
|
868
1151
|
for (const slot of slots) if (slot.state === "running") slot.child?.kill(signal);
|
|
1152
|
+
deadline = setTimeout(kill, GRACE_MS);
|
|
869
1153
|
};
|
|
870
|
-
for (const signal of INTERRUPTS
|
|
1154
|
+
for (const signal of INTERRUPTS) process.on(signal, forward);
|
|
871
1155
|
await new Promise((done) => {
|
|
872
1156
|
const fill = () => {
|
|
873
1157
|
for (let slot = ready(); slot !== void 0 && busy() < jobs; slot = ready()) {
|
|
@@ -883,9 +1167,13 @@ async function runConcurrently(runs, jobs, journeysOf, argsOf) {
|
|
|
883
1167
|
};
|
|
884
1168
|
fill();
|
|
885
1169
|
});
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
return slots.every((slot) => slot.passed) ? 0 : 1;
|
|
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]);
|
|
889
1177
|
}
|
|
890
1178
|
//#endregion
|
|
891
1179
|
//#region src/verify/judgement.ts
|
|
@@ -1694,372 +1982,115 @@ function parseVersion(text) {
|
|
|
1694
1982
|
Number(match[2]),
|
|
1695
1983
|
Number(match[3])
|
|
1696
1984
|
],
|
|
1697
|
-
pre: match[4] ? match[4].split(".") : []
|
|
1698
|
-
};
|
|
1699
|
-
}
|
|
1700
|
-
function comparePre(a, b) {
|
|
1701
|
-
if (a.length === 0 || b.length === 0) return b.length - a.length;
|
|
1702
|
-
const numeric = /^\d+$/;
|
|
1703
|
-
for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
|
|
1704
|
-
const [left, right] = [a[index] ?? "", b[index] ?? ""];
|
|
1705
|
-
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;
|
|
1706
|
-
if (order !== 0) return order;
|
|
1707
|
-
}
|
|
1708
|
-
return a.length - b.length;
|
|
1709
|
-
}
|
|
1710
|
-
function compareVersions(a, b) {
|
|
1711
|
-
return a.core[0] - b.core[0] || a.core[1] - b.core[1] || a.core[2] - b.core[2] || comparePre(a.pre, b.pre);
|
|
1712
|
-
}
|
|
1713
|
-
function increment(version, bump) {
|
|
1714
|
-
const [major, minor, patch] = version.core;
|
|
1715
|
-
if (bump === "major") return {
|
|
1716
|
-
core: [
|
|
1717
|
-
major + 1,
|
|
1718
|
-
0,
|
|
1719
|
-
0
|
|
1720
|
-
],
|
|
1721
|
-
pre: []
|
|
1722
|
-
};
|
|
1723
|
-
if (bump === "minor") return {
|
|
1724
|
-
core: [
|
|
1725
|
-
major,
|
|
1726
|
-
minor + 1,
|
|
1727
|
-
0
|
|
1728
|
-
],
|
|
1729
|
-
pre: []
|
|
1730
|
-
};
|
|
1731
|
-
return {
|
|
1732
|
-
core: version.pre.length > 0 ? [
|
|
1733
|
-
major,
|
|
1734
|
-
minor,
|
|
1735
|
-
patch
|
|
1736
|
-
] : [
|
|
1737
|
-
major,
|
|
1738
|
-
minor,
|
|
1739
|
-
patch + 1
|
|
1740
|
-
],
|
|
1741
|
-
pre: []
|
|
1742
|
-
};
|
|
1743
|
-
}
|
|
1744
|
-
function format(version) {
|
|
1745
|
-
const core = version.core.join(".");
|
|
1746
|
-
return version.pre.length > 0 ? `${core}-${version.pre.join(".")}` : core;
|
|
1747
|
-
}
|
|
1748
|
-
function titleBump(title) {
|
|
1749
|
-
const match = /^(\w+)(?:\([^)]*\))?(!)?:/.exec(title.trim());
|
|
1750
|
-
if (match?.[2] === "!" || title.includes("BREAKING CHANGE")) return "major";
|
|
1751
|
-
return match?.[1] === "feat" ? "minor" : "patch";
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* The bump changelogen 0.5.7 applies to `currentVersion` for these commit titles:
|
|
1755
|
-
* `!` or a `BREAKING CHANGE` footer is major, `feat` minor, anything else patch,
|
|
1756
|
-
* and on a `0.x` version major becomes minor and minor becomes patch.
|
|
1757
|
-
*/
|
|
1758
|
-
function releaseType(currentVersion, titles) {
|
|
1759
|
-
const order = [
|
|
1760
|
-
"patch",
|
|
1761
|
-
"minor",
|
|
1762
|
-
"major"
|
|
1763
|
-
];
|
|
1764
|
-
const highest = titles.map(titleBump).reduce((top, bump) => order.indexOf(bump) > order.indexOf(top) ? bump : top, "patch");
|
|
1765
|
-
if (!currentVersion.startsWith("0.")) return highest;
|
|
1766
|
-
return highest === "major" ? "minor" : "patch";
|
|
1767
|
-
}
|
|
1768
|
-
function listPaths(diff) {
|
|
1769
|
-
return [
|
|
1770
|
-
diff.added.length > 0 ? `added ${diff.added.join(", ")}` : "",
|
|
1771
|
-
diff.changed.length > 0 ? `changed ${diff.changed.map((entry) => entry.path).join(", ")}` : "",
|
|
1772
|
-
diff.removed.length > 0 ? `removed ${diff.removed.join(", ")}` : ""
|
|
1773
|
-
].filter((part) => part !== "").join("; ");
|
|
1774
|
-
}
|
|
1775
|
-
/**
|
|
1776
|
-
* Judges the interface minor-bump rule: an added, changed or removed function needs a
|
|
1777
|
-
* release of at least the next minor of the published version.
|
|
1778
|
-
*/
|
|
1779
|
-
function minorRule(input) {
|
|
1780
|
-
const { published, headVersion, titles, diff } = input;
|
|
1781
|
-
if (published === null) return {
|
|
1782
|
-
required: "none",
|
|
1783
|
-
releases: headVersion,
|
|
1784
|
-
ok: true,
|
|
1785
|
-
reason: "never published: the first release has no surface to compare against"
|
|
1786
|
-
};
|
|
1787
|
-
const base = parseVersion(published);
|
|
1788
|
-
const releases = compareVersions(parseVersion(headVersion), base) > 0 ? headVersion : format(increment(base, releaseType(published, titles)));
|
|
1789
|
-
const required = diff.added.length + diff.changed.length + diff.removed.length > 0 ? "minor" : "none";
|
|
1790
|
-
if (required === "none") return {
|
|
1791
|
-
required,
|
|
1792
|
-
releases,
|
|
1793
|
-
ok: true,
|
|
1794
|
-
reason: `no function added, changed or removed against ${published}: no minor required`
|
|
1795
|
-
};
|
|
1796
|
-
const floor = format(increment(base, "minor"));
|
|
1797
|
-
const ok = compareVersions(parseVersion(releases), parseVersion(floor)) >= 0;
|
|
1798
|
-
const facts = `${listPaths(diff)}: needs at least ${floor} against ${published}, this change releases as ${releases}`;
|
|
1799
|
-
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";
|
|
1800
|
-
return {
|
|
1801
|
-
required,
|
|
1802
|
-
releases,
|
|
1803
|
-
ok,
|
|
1804
|
-
reason: ok ? facts : `${facts}. Fix: use ${title}, or run the release workflow with release-version ${floor}`
|
|
1805
|
-
};
|
|
1806
|
-
}
|
|
1807
|
-
//#endregion
|
|
1808
|
-
//#region src/verify/record.ts
|
|
1809
|
-
const DEFAULT_TIMEOUT_MS = 6e5;
|
|
1810
|
-
/** Quotes an argument the way a shell user would type it. */
|
|
1811
|
-
function shellQuote(value) {
|
|
1812
|
-
return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
1813
|
-
}
|
|
1814
|
-
function describe(spec) {
|
|
1815
|
-
return [spec.program, ...spec.args].map(shellQuote).join(" ");
|
|
1816
|
-
}
|
|
1817
|
-
function writeCommand(folder, spec) {
|
|
1818
|
-
mkdirSync(folder, { recursive: true });
|
|
1819
|
-
writeFileSync(join(folder, "command.txt"), `cd ${shellQuote(spec.cwd)}\n${describe(spec)}\n`);
|
|
1820
|
-
}
|
|
1821
|
-
const foreground = /* @__PURE__ */ new Set();
|
|
1822
|
-
const releases = /* @__PURE__ */ new Set();
|
|
1823
|
-
const INTERRUPTS = [
|
|
1824
|
-
"SIGINT",
|
|
1825
|
-
"SIGTERM",
|
|
1826
|
-
"SIGHUP",
|
|
1827
|
-
"SIGQUIT"
|
|
1828
|
-
];
|
|
1829
|
-
let listening = false;
|
|
1830
|
-
/** 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. */
|
|
1831
|
-
function listenForInterrupts() {
|
|
1832
|
-
if (listening) return;
|
|
1833
|
-
listening = true;
|
|
1834
|
-
for (const signal of INTERRUPTS) process.once(signal, () => {
|
|
1835
|
-
for (const child of foreground) if (child.pid !== void 0) killOwnGroup(child.pid);
|
|
1836
|
-
for (const release of releases) try {
|
|
1837
|
-
release();
|
|
1838
|
-
} catch (error) {
|
|
1839
|
-
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
1840
|
-
}
|
|
1841
|
-
process.exit(128 + constants$1.signals[signal]);
|
|
1842
|
-
});
|
|
1843
|
-
}
|
|
1844
|
-
/**
|
|
1845
|
-
* Until the returned function is called, an interrupt calls `release` after
|
|
1846
|
-
* killing the process group of every command still running in the
|
|
1847
|
-
* foreground, the processes it started included.
|
|
1848
|
-
*/
|
|
1849
|
-
function onInterrupt(release) {
|
|
1850
|
-
listenForInterrupts();
|
|
1851
|
-
releases.add(release);
|
|
1852
|
-
return () => releases.delete(release);
|
|
1853
|
-
}
|
|
1854
|
-
/** Runs a command to completion and writes command.txt, stdout.txt, stderr.txt and exit-code.txt into `folder`. */
|
|
1855
|
-
function runRecorded(folder, spec) {
|
|
1856
|
-
writeCommand(folder, spec);
|
|
1857
|
-
listenForInterrupts();
|
|
1858
|
-
return new Promise((resolve) => {
|
|
1859
|
-
const child = spawn(spec.program, spec.args, {
|
|
1860
|
-
cwd: spec.cwd,
|
|
1861
|
-
env: spec.env,
|
|
1862
|
-
detached: true,
|
|
1863
|
-
stdio: [
|
|
1864
|
-
"ignore",
|
|
1865
|
-
"pipe",
|
|
1866
|
-
"pipe"
|
|
1867
|
-
]
|
|
1868
|
-
});
|
|
1869
|
-
foreground.add(child);
|
|
1870
|
-
const out = [];
|
|
1871
|
-
const err = [];
|
|
1872
|
-
child.stdout.on("data", (chunk) => out.push(chunk));
|
|
1873
|
-
child.stderr.on("data", (chunk) => err.push(chunk));
|
|
1874
|
-
const timer = setTimeout(() => {
|
|
1875
|
-
if (child.pid !== void 0) killOwnGroup(child.pid);
|
|
1876
|
-
}, spec.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
1877
|
-
const finish = (code, signal, failure = "") => {
|
|
1878
|
-
clearTimeout(timer);
|
|
1879
|
-
foreground.delete(child);
|
|
1880
|
-
const result = {
|
|
1881
|
-
folder,
|
|
1882
|
-
command: describe(spec),
|
|
1883
|
-
exitCode: code,
|
|
1884
|
-
signal,
|
|
1885
|
-
stdout: Buffer.concat(out).toString("utf8"),
|
|
1886
|
-
stderr: `${Buffer.concat(err).toString("utf8")}${failure}`
|
|
1887
|
-
};
|
|
1888
|
-
writeFileSync(join(folder, "stdout.txt"), result.stdout);
|
|
1889
|
-
writeFileSync(join(folder, "stderr.txt"), result.stderr);
|
|
1890
|
-
writeFileSync(join(folder, "exit-code.txt"), `${code ?? `signal ${signal}`}\n`);
|
|
1891
|
-
resolve(result);
|
|
1892
|
-
};
|
|
1893
|
-
child.on("error", (error) => finish(null, null, `${error.message}\n`));
|
|
1894
|
-
child.on("close", (code, signal) => finish(code, signal));
|
|
1895
|
-
});
|
|
1896
|
-
}
|
|
1897
|
-
/** Starts a long-running command in its own process group, writing stdout and stderr straight to files. */
|
|
1898
|
-
function startRecorded(folder, spec) {
|
|
1899
|
-
writeCommand(folder, spec);
|
|
1900
|
-
const stdout = openSync(join(folder, "stdout.txt"), "w");
|
|
1901
|
-
const stderr = openSync(join(folder, "stderr.txt"), "w");
|
|
1902
|
-
const child = spawn(spec.program, spec.args, {
|
|
1903
|
-
cwd: spec.cwd,
|
|
1904
|
-
env: spec.env,
|
|
1905
|
-
detached: true,
|
|
1906
|
-
stdio: [
|
|
1907
|
-
"ignore",
|
|
1908
|
-
stdout,
|
|
1909
|
-
stderr
|
|
1910
|
-
]
|
|
1911
|
-
});
|
|
1912
|
-
closeSync(stdout);
|
|
1913
|
-
closeSync(stderr);
|
|
1914
|
-
const exited = new Promise((resolve) => {
|
|
1915
|
-
child.on("exit", (exitCode, signal) => {
|
|
1916
|
-
writeFileSync(join(folder, "exit-code.txt"), `${exitCode ?? `signal ${signal}`}\n`);
|
|
1917
|
-
resolve({
|
|
1918
|
-
exitCode,
|
|
1919
|
-
signal
|
|
1920
|
-
});
|
|
1921
|
-
});
|
|
1922
|
-
});
|
|
1923
|
-
if (child.pid === void 0) throw new Error(`Could not start ${describe(spec)}`);
|
|
1924
|
-
writeFileSync(join(folder, "pid.txt"), `${child.pid}\n`);
|
|
1925
|
-
return {
|
|
1926
|
-
folder,
|
|
1927
|
-
child,
|
|
1928
|
-
pid: child.pid,
|
|
1929
|
-
exited
|
|
1930
|
-
};
|
|
1931
|
-
}
|
|
1932
|
-
/** Kills the process group a detached command leads, never a lone PID the system may have reused since the command exited. */
|
|
1933
|
-
function killOwnGroup(pid) {
|
|
1934
|
-
try {
|
|
1935
|
-
process.kill(-pid, "SIGKILL");
|
|
1936
|
-
} catch {
|
|
1937
|
-
return;
|
|
1938
|
-
}
|
|
1985
|
+
pre: match[4] ? match[4].split(".") : []
|
|
1986
|
+
};
|
|
1939
1987
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
} catch {
|
|
1948
|
-
return;
|
|
1949
|
-
}
|
|
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;
|
|
1950
1995
|
}
|
|
1996
|
+
return a.length - b.length;
|
|
1951
1997
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
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
|
+
};
|
|
1954
2019
|
return {
|
|
1955
|
-
|
|
1956
|
-
|
|
2020
|
+
core: version.pre.length > 0 ? [
|
|
2021
|
+
major,
|
|
2022
|
+
minor,
|
|
2023
|
+
patch
|
|
2024
|
+
] : [
|
|
2025
|
+
major,
|
|
2026
|
+
minor,
|
|
2027
|
+
patch + 1
|
|
2028
|
+
],
|
|
2029
|
+
pre: []
|
|
1957
2030
|
};
|
|
1958
2031
|
}
|
|
1959
|
-
|
|
1960
|
-
const
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
const
|
|
1965
|
-
|
|
1966
|
-
return
|
|
1967
|
-
const server = createServer();
|
|
1968
|
-
server.once("error", () => resolve(null));
|
|
1969
|
-
server.listen(port, "127.0.0.1", () => {
|
|
1970
|
-
const address = server.address();
|
|
1971
|
-
const bound = address !== null && address instanceof Object ? address.port : null;
|
|
1972
|
-
server.close(() => resolve(bound));
|
|
1973
|
-
});
|
|
1974
|
-
});
|
|
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";
|
|
1975
2040
|
}
|
|
1976
2041
|
/**
|
|
1977
|
-
*
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
1980
|
-
* 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.
|
|
1981
2045
|
*/
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
return
|
|
1990
|
-
|
|
1991
|
-
function reason(error) {
|
|
1992
|
-
return error.cause instanceof Error ? error.cause.message : error.message;
|
|
1993
|
-
}
|
|
1994
|
-
/** Sends one request and writes http.json with the status and body. */
|
|
1995
|
-
async function httpRecorded(folder, url, init = {}) {
|
|
1996
|
-
mkdirSync(folder, { recursive: true });
|
|
1997
|
-
let result;
|
|
1998
|
-
try {
|
|
1999
|
-
const response = await fetch(url, {
|
|
2000
|
-
method: init.method ?? "GET",
|
|
2001
|
-
body: init.body,
|
|
2002
|
-
headers: init.body ? { "content-type": "application/json" } : void 0,
|
|
2003
|
-
signal: AbortSignal.timeout(init.timeoutMs ?? 5e3)
|
|
2004
|
-
});
|
|
2005
|
-
const body = await response.text();
|
|
2006
|
-
let json;
|
|
2007
|
-
try {
|
|
2008
|
-
json = parseJson(body);
|
|
2009
|
-
} catch {
|
|
2010
|
-
json = void 0;
|
|
2011
|
-
}
|
|
2012
|
-
result = {
|
|
2013
|
-
folder,
|
|
2014
|
-
url,
|
|
2015
|
-
status: response.status,
|
|
2016
|
-
body,
|
|
2017
|
-
json,
|
|
2018
|
-
error: null
|
|
2019
|
-
};
|
|
2020
|
-
} catch (error) {
|
|
2021
|
-
result = {
|
|
2022
|
-
folder,
|
|
2023
|
-
url,
|
|
2024
|
-
status: null,
|
|
2025
|
-
body: "",
|
|
2026
|
-
json: void 0,
|
|
2027
|
-
error: error instanceof Error ? reason(error) : String(error)
|
|
2028
|
-
};
|
|
2029
|
-
}
|
|
2030
|
-
writeFileSync(join(folder, "http.json"), `${JSON.stringify({
|
|
2031
|
-
request: {
|
|
2032
|
-
url,
|
|
2033
|
-
...init
|
|
2034
|
-
},
|
|
2035
|
-
response: result
|
|
2036
|
-
}, null, 2)}\n`);
|
|
2037
|
-
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";
|
|
2038
2055
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
return readdirSync(folder, { withFileTypes: true }).filter((entry) => !TREE_SKIP.has(entry.name)).sort((left, right) => left.name.localeCompare(right.name)).flatMap((entry) => {
|
|
2046
|
-
const path = join(folder, entry.name);
|
|
2047
|
-
const name = relative(root, path);
|
|
2048
|
-
if (entry.isDirectory()) return [`${name}/`, ...listTree(root, path)];
|
|
2049
|
-
return [`${name} ${statSync(path).size}`];
|
|
2050
|
-
});
|
|
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("; ");
|
|
2051
2062
|
}
|
|
2052
|
-
/**
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
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
|
+
};
|
|
2063
2094
|
}
|
|
2064
2095
|
//#endregion
|
|
2065
2096
|
//#region src/verify/interface.ts
|
|
@@ -2616,12 +2647,12 @@ function lastActivity(dir) {
|
|
|
2616
2647
|
const file = join(dir, "run.json");
|
|
2617
2648
|
return statSync(existsSync(file) ? file : dir).mtimeMs;
|
|
2618
2649
|
}
|
|
2619
|
-
/** 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. */
|
|
2620
2651
|
function recorded(dir) {
|
|
2621
2652
|
try {
|
|
2622
2653
|
const state = object(parseJson(readFileSync(join(dir, "run.json"), "utf8")), "run.json");
|
|
2623
2654
|
return {
|
|
2624
|
-
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)],
|
|
2625
2656
|
containers: children(state, "containers").map((entry) => str(entry, "name"))
|
|
2626
2657
|
};
|
|
2627
2658
|
} catch {
|
|
@@ -2786,155 +2817,6 @@ function clean(state) {
|
|
|
2786
2817
|
return lines;
|
|
2787
2818
|
}
|
|
2788
2819
|
//#endregion
|
|
2789
|
-
//#region src/verify/publish.ts
|
|
2790
|
-
const EVIDENCE_BRANCH = "verify-evidence";
|
|
2791
|
-
const SCRATCH_BRANCH = "verify-evidence-scratch";
|
|
2792
|
-
const STATUS = {
|
|
2793
|
-
PASS: "success",
|
|
2794
|
-
"PASS+NOTES": "success",
|
|
2795
|
-
"NOT VERIFIED": "error",
|
|
2796
|
-
FAIL: "failure"
|
|
2797
|
-
};
|
|
2798
|
-
/**
|
|
2799
|
-
* Commits the run's evidence under pr-<n>/<sha>/ of the orphan evidence
|
|
2800
|
-
* branch and pushes it. Works in a temporary worktree so the checkout under
|
|
2801
|
-
* review is never touched. Returns the pushed evidence commit.
|
|
2802
|
-
*/
|
|
2803
|
-
function pushEvidence(root, state, verdict) {
|
|
2804
|
-
const worktree = mkdtempSync(join(tmpdir(), "verify-evidence-"));
|
|
2805
|
-
try {
|
|
2806
|
-
if (git(root, [
|
|
2807
|
-
"ls-remote",
|
|
2808
|
-
"--heads",
|
|
2809
|
-
"origin",
|
|
2810
|
-
EVIDENCE_BRANCH
|
|
2811
|
-
]) !== "") {
|
|
2812
|
-
git(root, [
|
|
2813
|
-
"fetch",
|
|
2814
|
-
"--quiet",
|
|
2815
|
-
"origin",
|
|
2816
|
-
`${EVIDENCE_BRANCH}:refs/remotes/origin/${EVIDENCE_BRANCH}`
|
|
2817
|
-
]);
|
|
2818
|
-
git(root, [
|
|
2819
|
-
"worktree",
|
|
2820
|
-
"add",
|
|
2821
|
-
"--quiet",
|
|
2822
|
-
"--detach",
|
|
2823
|
-
worktree,
|
|
2824
|
-
`origin/${EVIDENCE_BRANCH}`
|
|
2825
|
-
]);
|
|
2826
|
-
} else git(root, [
|
|
2827
|
-
"worktree",
|
|
2828
|
-
"add",
|
|
2829
|
-
"--quiet",
|
|
2830
|
-
"--orphan",
|
|
2831
|
-
"-B",
|
|
2832
|
-
SCRATCH_BRANCH,
|
|
2833
|
-
worktree
|
|
2834
|
-
]);
|
|
2835
|
-
const target = join(worktree, `pr-${verdict.pr}`, verdict.headSha);
|
|
2836
|
-
rmSync(target, {
|
|
2837
|
-
recursive: true,
|
|
2838
|
-
force: true
|
|
2839
|
-
});
|
|
2840
|
-
mkdirSync(target, { recursive: true });
|
|
2841
|
-
cpSync(state.evidence, target, { recursive: true });
|
|
2842
|
-
git(worktree, [
|
|
2843
|
-
"add",
|
|
2844
|
-
"--all",
|
|
2845
|
-
"."
|
|
2846
|
-
]);
|
|
2847
|
-
git(worktree, [
|
|
2848
|
-
"-c",
|
|
2849
|
-
"commit.gpgsign=false",
|
|
2850
|
-
"commit",
|
|
2851
|
-
"--quiet",
|
|
2852
|
-
"--allow-empty",
|
|
2853
|
-
"-m",
|
|
2854
|
-
`verify: evidence for #${verdict.pr} at ${verdict.headSha.slice(0, 7)} (${verdict.result})`
|
|
2855
|
-
]);
|
|
2856
|
-
git(worktree, [
|
|
2857
|
-
"push",
|
|
2858
|
-
"--quiet",
|
|
2859
|
-
"origin",
|
|
2860
|
-
`HEAD:refs/heads/${EVIDENCE_BRANCH}`
|
|
2861
|
-
]);
|
|
2862
|
-
return git(worktree, ["rev-parse", "HEAD"]);
|
|
2863
|
-
} finally {
|
|
2864
|
-
git(root, [
|
|
2865
|
-
"worktree",
|
|
2866
|
-
"remove",
|
|
2867
|
-
"--force",
|
|
2868
|
-
worktree
|
|
2869
|
-
]);
|
|
2870
|
-
if (git(root, [
|
|
2871
|
-
"branch",
|
|
2872
|
-
"--list",
|
|
2873
|
-
SCRATCH_BRANCH
|
|
2874
|
-
]) !== "") git(root, [
|
|
2875
|
-
"branch",
|
|
2876
|
-
"--quiet",
|
|
2877
|
-
"-D",
|
|
2878
|
-
SCRATCH_BRANCH
|
|
2879
|
-
]);
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
/** Posts the verdict as a PR comment and returns the comment URL printed by gh. */
|
|
2883
|
-
function postComment(root, verdict) {
|
|
2884
|
-
return execFileSync("gh", [
|
|
2885
|
-
"pr",
|
|
2886
|
-
"comment",
|
|
2887
|
-
String(verdict.pr),
|
|
2888
|
-
"--repo",
|
|
2889
|
-
verdict.repository,
|
|
2890
|
-
"--body",
|
|
2891
|
-
verdict.markdown
|
|
2892
|
-
], {
|
|
2893
|
-
cwd: root,
|
|
2894
|
-
encoding: "utf8"
|
|
2895
|
-
}).trim();
|
|
2896
|
-
}
|
|
2897
|
-
/**
|
|
2898
|
-
* Sets the `verify` commit status on the head SHA the verdict judged and
|
|
2899
|
-
* reads it back from GitHub. Returns what GitHub holds, or the error GitHub
|
|
2900
|
-
* answered, so a token without `statuses: write` is reported, never hidden.
|
|
2901
|
-
*/
|
|
2902
|
-
function setStatus(root, verdict, targetUrl) {
|
|
2903
|
-
const write = spawnSync("gh", [
|
|
2904
|
-
"api",
|
|
2905
|
-
"--silent",
|
|
2906
|
-
`repos/${verdict.repository}/statuses/${verdict.headSha}`,
|
|
2907
|
-
"-f",
|
|
2908
|
-
`state=${STATUS[verdict.result]}`,
|
|
2909
|
-
"-f",
|
|
2910
|
-
"context=verify",
|
|
2911
|
-
"-f",
|
|
2912
|
-
`description=verify: ${verdict.result}`,
|
|
2913
|
-
"-f",
|
|
2914
|
-
`target_url=${targetUrl}`
|
|
2915
|
-
], {
|
|
2916
|
-
cwd: root,
|
|
2917
|
-
encoding: "utf8"
|
|
2918
|
-
});
|
|
2919
|
-
if (write.status !== 0) return {
|
|
2920
|
-
ok: false,
|
|
2921
|
-
detail: `setting status verify failed: ${(write.stderr || write.stdout).trim()}`
|
|
2922
|
-
};
|
|
2923
|
-
const state = spawnSync("gh", [
|
|
2924
|
-
"api",
|
|
2925
|
-
`repos/${verdict.repository}/commits/${verdict.headSha}/statuses`,
|
|
2926
|
-
"--jq",
|
|
2927
|
-
"[.[] | select(.context == \"verify\")][0].state"
|
|
2928
|
-
], {
|
|
2929
|
-
cwd: root,
|
|
2930
|
-
encoding: "utf8"
|
|
2931
|
-
}).stdout.trim();
|
|
2932
|
-
return {
|
|
2933
|
-
ok: state === STATUS[verdict.result],
|
|
2934
|
-
detail: `status verify on ${verdict.headSha}: ${state || "absent"}`
|
|
2935
|
-
};
|
|
2936
|
-
}
|
|
2937
|
-
//#endregion
|
|
2938
2820
|
//#region src/verify/builtins.ts
|
|
2939
2821
|
/** Loads the module from its local source next to its backing services, then stops it. */
|
|
2940
2822
|
const moduleDev = {
|
|
@@ -4147,27 +4029,16 @@ function timingTable(report) {
|
|
|
4147
4029
|
}
|
|
4148
4030
|
//#endregion
|
|
4149
4031
|
//#region src/verify/verdict.ts
|
|
4150
|
-
/** The GitHub `owner/repo` of the origin remote. */
|
|
4151
|
-
function originRepository(root) {
|
|
4152
|
-
const url = git(root, [
|
|
4153
|
-
"remote",
|
|
4154
|
-
"get-url",
|
|
4155
|
-
"origin"
|
|
4156
|
-
]);
|
|
4157
|
-
const match = /github\.com[:/](.+?)(?:\.git)?$/.exec(url);
|
|
4158
|
-
if (!match) throw new Error(`origin ${url} is not a GitHub repository`);
|
|
4159
|
-
return match[1];
|
|
4160
|
-
}
|
|
4161
4032
|
function short(sha) {
|
|
4162
4033
|
return sha.slice(0, 7);
|
|
4163
4034
|
}
|
|
4164
4035
|
function bullets(entries, empty) {
|
|
4165
4036
|
return (entries.length > 0 ? entries : [empty]).map((entry) => `- ${entry}`);
|
|
4166
4037
|
}
|
|
4167
|
-
function journeyRow(label, result
|
|
4038
|
+
function journeyRow(label, result) {
|
|
4168
4039
|
const outcome = result.status === "PASS" ? "pass" : result.status === "FAIL" ? "**fail**" : "**not verified**";
|
|
4169
|
-
const reused = result.reusedFrom === void 0 ? "" : ` (not run again: reuses [${result.reusedFrom}](${
|
|
4170
|
-
return `| ${label} | \`${result.journey}\`: ${result.entryPoint} | ${outcome}: ${result.title}${reused} | [${result.folder}](${
|
|
4040
|
+
const reused = result.reusedFrom === void 0 ? "" : ` (not run again: reuses [${result.reusedFrom}](${result.reusedFrom}))`;
|
|
4041
|
+
return `| ${label} | \`${result.journey}\`: ${result.entryPoint} | ${outcome}: ${result.title}${reused} | [${result.folder}](${result.folder}) |`;
|
|
4171
4042
|
}
|
|
4172
4043
|
/** For a reused result, the status of its source when that is no longer PASS (`missing` when gone); otherwise null. */
|
|
4173
4044
|
function staleReuse(state, result) {
|
|
@@ -4181,7 +4052,7 @@ function staleReuse(state, result) {
|
|
|
4181
4052
|
function featuresOutsidePlan(state, plan) {
|
|
4182
4053
|
return readdirSync(state.evidence, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !plan.run.includes(entry.name) && existsSync(join(state.evidence, entry.name, "feature.json"))).map((entry) => entry.name).sort();
|
|
4183
4054
|
}
|
|
4184
|
-
function journeyRows(workspace, state, plan
|
|
4055
|
+
function journeyRows(workspace, state, plan) {
|
|
4185
4056
|
const rows = [];
|
|
4186
4057
|
const reasons = [];
|
|
4187
4058
|
const notVerified = [];
|
|
@@ -4201,7 +4072,7 @@ function journeyRows(workspace, state, plan, link) {
|
|
|
4201
4072
|
if (result.status === "NOT VERIFIED") notVerified.push(`${feature}/${result.journey}: ${result.notVerified}`);
|
|
4202
4073
|
const stale = staleReuse(state, result);
|
|
4203
4074
|
if (stale !== null) reasons.push(`${feature}/${result.journey} reuses ${result.reusedFrom}, which is now ${stale}`);
|
|
4204
|
-
rows.push(journeyRow(feature, result
|
|
4075
|
+
rows.push(journeyRow(feature, result));
|
|
4205
4076
|
}
|
|
4206
4077
|
}
|
|
4207
4078
|
for (const feature of featuresOutsidePlan(state, plan)) {
|
|
@@ -4215,7 +4086,7 @@ function journeyRows(workspace, state, plan, link) {
|
|
|
4215
4086
|
const stale = staleReuse(state, result);
|
|
4216
4087
|
if (stale !== null) reasons.push(`${feature}/${result.journey} reuses ${result.reusedFrom}, which is now ${stale}`);
|
|
4217
4088
|
if (result.status === "NOT VERIFIED") outsideNotVerified.push(`${feature}/${result.journey}: ${result.notVerified}`);
|
|
4218
|
-
rows.push(journeyRow(`${feature} (outside the diff's features)`, result
|
|
4089
|
+
rows.push(journeyRow(`${feature} (outside the diff's features)`, result));
|
|
4219
4090
|
}
|
|
4220
4091
|
}
|
|
4221
4092
|
return {
|
|
@@ -4245,7 +4116,7 @@ function doorsSection(judgement) {
|
|
|
4245
4116
|
...judgement.doors.map((door) => `| ${door.kind} | \`${door.location}\` | ${door.irreversible} | ${door.containment} |`)
|
|
4246
4117
|
];
|
|
4247
4118
|
}
|
|
4248
|
-
function formalSection(workspace, state, plan
|
|
4119
|
+
function formalSection(workspace, state, plan) {
|
|
4249
4120
|
const reasons = [];
|
|
4250
4121
|
const lines = [];
|
|
4251
4122
|
const ran = [];
|
|
@@ -4262,7 +4133,7 @@ function formalSection(workspace, state, plan, link) {
|
|
|
4262
4133
|
const weight = formalGate(result);
|
|
4263
4134
|
if (gate && weight.fails) reasons.push(`formal check ${check.name}: ${weight.outcome}`);
|
|
4264
4135
|
const summary = gate ? weight.outcome : result.violated.length > 0 ? `violated: ${result.violated.join(", ")}` : `exit ${result.exitCode}, no violated rule`;
|
|
4265
|
-
lines.push(`\`${check.name}\` (${gate ? "covers the diff, gates the verdict" : "does not cover the diff, informational"}): ${summary}. [evidence](${
|
|
4136
|
+
lines.push(`\`${check.name}\` (${gate ? "covers the diff, gates the verdict" : "does not cover the diff, informational"}): ${summary}. [evidence](${result.folder})`);
|
|
4266
4137
|
}
|
|
4267
4138
|
return {
|
|
4268
4139
|
reasons,
|
|
@@ -4301,7 +4172,6 @@ function unmappedSection(unmapped) {
|
|
|
4301
4172
|
*/
|
|
4302
4173
|
function renderVerdict(workspace, state, pr, judgement) {
|
|
4303
4174
|
const plan = planFor(workspace, state.baseRef, state.all);
|
|
4304
|
-
const repository = originRepository(workspace.root);
|
|
4305
4175
|
const skillSha = git(workspace.root, [
|
|
4306
4176
|
"log",
|
|
4307
4177
|
"-1",
|
|
@@ -4309,11 +4179,10 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
4309
4179
|
"--",
|
|
4310
4180
|
relative(workspace.root, workspace.skill)
|
|
4311
4181
|
]) || plan.headSha;
|
|
4312
|
-
const link = (path) => `https://github.com/${repository}/tree/verify-evidence/pr-${pr}/${plan.headSha}/${path}`;
|
|
4313
4182
|
const reasons = [];
|
|
4314
4183
|
if (plan.headSha !== state.headSha) reasons.push(`the run was created at ${short(state.headSha)} but HEAD is ${short(plan.headSha)}`);
|
|
4315
|
-
const journeys = journeyRows(workspace, state, plan
|
|
4316
|
-
const formal = formalSection(workspace, state, plan
|
|
4184
|
+
const journeys = journeyRows(workspace, state, plan);
|
|
4185
|
+
const formal = formalSection(workspace, state, plan);
|
|
4317
4186
|
reasons.push(...journeys.reasons, ...plan.unmapped.map((file) => `unmapped surface ${file}`), ...docsReasons(judgement, plan), ...doorReasons(workspace, judgement, plan), ...formal.reasons);
|
|
4318
4187
|
const notVerified = [
|
|
4319
4188
|
...journeys.notVerified,
|
|
@@ -4361,8 +4230,6 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
4361
4230
|
"",
|
|
4362
4231
|
"### Timing",
|
|
4363
4232
|
...timingTable(timings),
|
|
4364
|
-
"",
|
|
4365
|
-
`Evidence: \`verify-evidence\` branch, [\`pr-${pr}/${plan.headSha}/\`](${link("")})`,
|
|
4366
4233
|
""
|
|
4367
4234
|
].join("\n");
|
|
4368
4235
|
writeFileSync(join(state.evidence, "verdict.md"), markdown);
|
|
@@ -4380,7 +4247,6 @@ function renderVerdict(workspace, state, pr, judgement) {
|
|
|
4380
4247
|
headSha: plan.headSha,
|
|
4381
4248
|
skillSha,
|
|
4382
4249
|
pr,
|
|
4383
|
-
repository,
|
|
4384
4250
|
markdown,
|
|
4385
4251
|
reasons
|
|
4386
4252
|
};
|
|
@@ -4404,7 +4270,6 @@ const USAGE = `Usage: antelopejs-verify <command>
|
|
|
4404
4270
|
doors [patch] [--base <ref>] print the One-way-door line for a patch, or for the diff
|
|
4405
4271
|
clean <run> stop what the run started, keep only the evidence
|
|
4406
4272
|
verdict <run> --pr <n> render evidence/verdict.md from the results and evidence/judgement.json
|
|
4407
|
-
publish <run> --pr <n> push the evidence to verify-evidence, comment the verdict, set status verify
|
|
4408
4273
|
`;
|
|
4409
4274
|
function print(text) {
|
|
4410
4275
|
process.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
|
|
@@ -4558,19 +4423,11 @@ function printDoors(workspace, files) {
|
|
|
4558
4423
|
for (const door of doors) print(` ${door.kind}: ${door.files.join(", ")}`);
|
|
4559
4424
|
return 0;
|
|
4560
4425
|
}
|
|
4561
|
-
function judge(workspace,
|
|
4562
|
-
if (!Number.isInteger(pr) || pr <= 0) throw new Error(
|
|
4426
|
+
function judge(workspace, dir, pr) {
|
|
4427
|
+
if (!Number.isInteger(pr) || pr <= 0) throw new Error("verdict needs --pr <number>");
|
|
4563
4428
|
const state = loadRun(dir);
|
|
4564
4429
|
const verdict = renderVerdict(workspace, state, pr, readJudgement(join(state.evidence, "judgement.json")));
|
|
4565
4430
|
print(verdict.markdown);
|
|
4566
|
-
if (command === "publish") {
|
|
4567
|
-
print(`evidence commit ${pushEvidence(workspace.root, state, verdict)}`);
|
|
4568
|
-
const comment = postComment(workspace.root, verdict);
|
|
4569
|
-
print(`comment ${comment}`);
|
|
4570
|
-
const status = setStatus(workspace.root, verdict, comment);
|
|
4571
|
-
print(status.detail);
|
|
4572
|
-
if (!status.ok) return 1;
|
|
4573
|
-
}
|
|
4574
4431
|
return verdict.result === "PASS" || verdict.result === "PASS+NOTES" ? 0 : 1;
|
|
4575
4432
|
}
|
|
4576
4433
|
async function main(argv) {
|
|
@@ -4620,19 +4477,21 @@ async function main(argv) {
|
|
|
4620
4477
|
const runs = featureRuns(workspace, rest, values);
|
|
4621
4478
|
const jobs = jobsFor(workspace, runs, values);
|
|
4622
4479
|
if (jobs === 1) return runJourneys(workspace, rest[0], runs);
|
|
4623
|
-
|
|
4480
|
+
const dir = resolve(rest[0]);
|
|
4481
|
+
return runConcurrently(dir, runs, jobs, (name) => featureJourneys(workspace, name) ?? [], ({ feature }) => [
|
|
4624
4482
|
...process.execArgv,
|
|
4625
4483
|
process.argv[1],
|
|
4626
4484
|
"journey",
|
|
4627
|
-
|
|
4628
|
-
feature,
|
|
4485
|
+
dir,
|
|
4629
4486
|
"--kind",
|
|
4630
|
-
workspace.kind
|
|
4487
|
+
workspace.kind,
|
|
4488
|
+
"--",
|
|
4489
|
+
feature
|
|
4631
4490
|
]);
|
|
4632
4491
|
} else if (command === "formal") return runFormal(workspace, rest[0], values.all === true);
|
|
4633
4492
|
else if (command === "doors") return printDoors(workspace, rest[0] ? patchFiles(rest[0]) : planFor(workspace, values.base).changed);
|
|
4634
4493
|
else if (command === "clean") for (const line of clean(loadRun(rest[0]))) print(line);
|
|
4635
|
-
else if (command === "verdict"
|
|
4494
|
+
else if (command === "verdict") return judge(workspace, rest[0], Number(values.pr));
|
|
4636
4495
|
else {
|
|
4637
4496
|
print(USAGE);
|
|
4638
4497
|
return 2;
|