@antelopejs/tooling-configs 0.3.7 → 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.
- package/dist/bin/sync.mjs +3 -3
- package/dist/bin/verify.mjs +554 -521
- package/dist/{map-COx26Bu6.mjs → map-B23_WMGE.mjs} +52 -51
- package/package.json +1 -1
package/dist/bin/verify.mjs
CHANGED
|
@@ -4,7 +4,7 @@ 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";
|
|
@@ -769,159 +769,447 @@ 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
|
];
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
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
|
+
});
|
|
790
807
|
}
|
|
791
808
|
/**
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
* sequential call and the later feature reuses its PASS (#194); running the
|
|
796
|
-
* two at once would run it twice and print another line. Waiting keeps the
|
|
797
|
-
* reuse, and with it the sequential output and evidence, at the cost of the
|
|
798
|
-
* overlap of those two features only.
|
|
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.
|
|
799
812
|
*/
|
|
800
|
-
function
|
|
801
|
-
|
|
802
|
-
|
|
813
|
+
function onInterrupt(release) {
|
|
814
|
+
listenForInterrupts();
|
|
815
|
+
releases.add(release);
|
|
816
|
+
return () => releases.delete(release);
|
|
803
817
|
}
|
|
804
|
-
/**
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
* that ended on a signal or could not start is named on its stderr.
|
|
809
|
-
*/
|
|
810
|
-
function runProcess(slot, args) {
|
|
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();
|
|
811
822
|
return new Promise((resolve) => {
|
|
812
|
-
const child = spawn(
|
|
823
|
+
const child = spawn(spec.program, spec.args, {
|
|
824
|
+
cwd: spec.cwd,
|
|
825
|
+
env: spec.env,
|
|
826
|
+
detached: true,
|
|
813
827
|
stdio: [
|
|
814
828
|
"ignore",
|
|
815
829
|
"pipe",
|
|
816
830
|
"pipe"
|
|
817
|
-
]
|
|
818
|
-
detached: true
|
|
831
|
+
]
|
|
819
832
|
});
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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);
|
|
827
856
|
};
|
|
828
|
-
child.
|
|
829
|
-
child.
|
|
857
|
+
child.on("error", (error) => finish(null, null, `${error.message}\n`));
|
|
858
|
+
child.on("close", (code, signal) => finish(code, signal));
|
|
830
859
|
});
|
|
831
860
|
}
|
|
832
|
-
/**
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
async function runConcurrently(runs, jobs, journeysOf, argsOf) {
|
|
847
|
-
const after = dependencies(runs, journeysOf);
|
|
848
|
-
const slots = runs.map((run, index) => ({
|
|
849
|
-
run,
|
|
850
|
-
after: after[index],
|
|
851
|
-
state: "waiting",
|
|
852
|
-
stdout: [],
|
|
853
|
-
stderr: [],
|
|
854
|
-
passed: false
|
|
855
|
-
}));
|
|
856
|
-
let printed = 0;
|
|
857
|
-
const flush = () => {
|
|
858
|
-
for (; slots[printed]?.state === "ended"; printed++) {
|
|
859
|
-
process.stdout.write(Buffer.concat(slots[printed].stdout));
|
|
860
|
-
process.stderr.write(Buffer.concat(slots[printed].stderr));
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
let interrupted;
|
|
864
|
-
const ready = () => interrupted === void 0 ? slots.find((slot) => slot.state === "waiting" && slot.after.every((index) => slots[index].state === "ended")) : void 0;
|
|
865
|
-
const busy = () => slots.filter((slot) => slot.state === "running").length;
|
|
866
|
-
const forward = (signal) => {
|
|
867
|
-
interrupted ??= signal;
|
|
868
|
-
for (const slot of slots) if (slot.state === "running") slot.child?.kill(signal);
|
|
869
|
-
};
|
|
870
|
-
for (const signal of INTERRUPTS$1) process.on(signal, forward);
|
|
871
|
-
await new Promise((done) => {
|
|
872
|
-
const fill = () => {
|
|
873
|
-
for (let slot = ready(); slot !== void 0 && busy() < jobs; slot = ready()) {
|
|
874
|
-
const started = slot;
|
|
875
|
-
started.state = "running";
|
|
876
|
-
runProcess(started, argsOf(started.run)).then(() => {
|
|
877
|
-
started.state = "ended";
|
|
878
|
-
flush();
|
|
879
|
-
fill();
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
if (busy() === 0 && (interrupted !== void 0 || ready() === void 0)) done();
|
|
883
|
-
};
|
|
884
|
-
fill();
|
|
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
|
+
]
|
|
885
875
|
});
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
"
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
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
|
+
};
|
|
902
895
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
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
|
+
}
|
|
906
903
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
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
|
+
}
|
|
910
915
|
}
|
|
911
|
-
|
|
912
|
-
|
|
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
|
+
};
|
|
913
922
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
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
|
+
});
|
|
917
939
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
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);
|
|
1153
|
+
};
|
|
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]);
|
|
1177
|
+
}
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region src/verify/judgement.ts
|
|
1180
|
+
const DOOR_KINDS = [
|
|
1181
|
+
"data",
|
|
1182
|
+
"format",
|
|
1183
|
+
"contract",
|
|
1184
|
+
"outbound",
|
|
1185
|
+
"exposure",
|
|
1186
|
+
"publish"
|
|
1187
|
+
];
|
|
1188
|
+
function isDoorKind(value) {
|
|
1189
|
+
return DOOR_KINDS.some((kind) => kind === value);
|
|
1190
|
+
}
|
|
1191
|
+
function text(source, key) {
|
|
1192
|
+
const value = source[key];
|
|
1193
|
+
return value !== void 0 && isString(value) ? value.trim() : "";
|
|
1194
|
+
}
|
|
1195
|
+
function texts(source, key) {
|
|
1196
|
+
const value = source[key];
|
|
1197
|
+
return Array.isArray(value) ? value.filter(isString) : [];
|
|
1198
|
+
}
|
|
1199
|
+
function objects(value) {
|
|
1200
|
+
return Array.isArray(value) ? value.filter(isObject) : [];
|
|
1201
|
+
}
|
|
1202
|
+
function doorKind(value, label) {
|
|
1203
|
+
if (!isDoorKind(value)) throw new Error(`judgement.json: ${label} is "${value}", not one of ${DOOR_KINDS.join(", ")}`);
|
|
1204
|
+
return value;
|
|
1205
|
+
}
|
|
1206
|
+
function parseRows(doors) {
|
|
1207
|
+
return objects(doors.rows).map((row, index) => {
|
|
1208
|
+
const parsed = {
|
|
1209
|
+
location: text(row, "location"),
|
|
1210
|
+
irreversible: text(row, "irreversible"),
|
|
1211
|
+
containment: text(row, "containment")
|
|
1212
|
+
};
|
|
925
1213
|
if (!parsed.location || !parsed.irreversible || !parsed.containment) throw new Error(`judgement.json: doors.rows[${index}] needs kind, location, irreversible and containment`);
|
|
926
1214
|
return {
|
|
927
1215
|
...parsed,
|
|
@@ -1659,407 +1947,150 @@ function declaredSurface(packageFolder) {
|
|
|
1659
1947
|
};
|
|
1660
1948
|
const missing = unresolvedImports(walk, program);
|
|
1661
1949
|
if (missing.length > 0) throw new Error(`unresolved imports in declarations: ${missing.join(", ")}${nodeTypes === void 0 && missing.some((entry) => entry.includes("-> node:")) ? "; install @types/node so node: built-ins resolve" : ""}`);
|
|
1662
|
-
for (const [subpath, file] of files) {
|
|
1663
|
-
const source = program.getSourceFile(file);
|
|
1664
|
-
const module = source && walk.checker.getSymbolAtLocation(source);
|
|
1665
|
-
if (!module) continue;
|
|
1666
|
-
for (const member of walk.checker.getExportsOfModule(module)) visit(walk, member, `${subpath}:${member.name}`, []);
|
|
1667
|
-
}
|
|
1668
|
-
return walk.surface;
|
|
1669
|
-
}
|
|
1670
|
-
/** The paths added, removed and changed from `published` to `head`, each sorted. */
|
|
1671
|
-
function diffSurface(published, head) {
|
|
1672
|
-
const added = [...head.keys()].filter((path) => !published.has(path));
|
|
1673
|
-
const removed = [...published.keys()].filter((path) => !head.has(path));
|
|
1674
|
-
const changed = [...head].flatMap(([path, after]) => {
|
|
1675
|
-
const before = published.get(path);
|
|
1676
|
-
return before !== void 0 && before !== after ? [{
|
|
1677
|
-
path,
|
|
1678
|
-
before,
|
|
1679
|
-
after
|
|
1680
|
-
}] : [];
|
|
1681
|
-
});
|
|
1682
|
-
return {
|
|
1683
|
-
added: added.sort(),
|
|
1684
|
-
removed: removed.sort(),
|
|
1685
|
-
changed: changed.sort((a, b) => a.path.localeCompare(b.path))
|
|
1686
|
-
};
|
|
1687
|
-
}
|
|
1688
|
-
function parseVersion(text) {
|
|
1689
|
-
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(text.trim());
|
|
1690
|
-
if (!match) throw new Error(`not a semver version: ${text}`);
|
|
1691
|
-
return {
|
|
1692
|
-
core: [
|
|
1693
|
-
Number(match[1]),
|
|
1694
|
-
Number(match[2]),
|
|
1695
|
-
Number(match[3])
|
|
1696
|
-
],
|
|
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
|
-
});
|
|
1950
|
+
for (const [subpath, file] of files) {
|
|
1951
|
+
const source = program.getSourceFile(file);
|
|
1952
|
+
const module = source && walk.checker.getSymbolAtLocation(source);
|
|
1953
|
+
if (!module) continue;
|
|
1954
|
+
for (const member of walk.checker.getExportsOfModule(module)) visit(walk, member, `${subpath}:${member.name}`, []);
|
|
1955
|
+
}
|
|
1956
|
+
return walk.surface;
|
|
1957
|
+
}
|
|
1958
|
+
/** The paths added, removed and changed from `published` to `head`, each sorted. */
|
|
1959
|
+
function diffSurface(published, head) {
|
|
1960
|
+
const added = [...head.keys()].filter((path) => !published.has(path));
|
|
1961
|
+
const removed = [...published.keys()].filter((path) => !head.has(path));
|
|
1962
|
+
const changed = [...head].flatMap(([path, after]) => {
|
|
1963
|
+
const before = published.get(path);
|
|
1964
|
+
return before !== void 0 && before !== after ? [{
|
|
1965
|
+
path,
|
|
1966
|
+
before,
|
|
1967
|
+
after
|
|
1968
|
+
}] : [];
|
|
1922
1969
|
});
|
|
1923
|
-
if (child.pid === void 0) throw new Error(`Could not start ${describe(spec)}`);
|
|
1924
|
-
writeFileSync(join(folder, "pid.txt"), `${child.pid}\n`);
|
|
1925
1970
|
return {
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
exited
|
|
1971
|
+
added: added.sort(),
|
|
1972
|
+
removed: removed.sort(),
|
|
1973
|
+
changed: changed.sort((a, b) => a.path.localeCompare(b.path))
|
|
1930
1974
|
};
|
|
1931
1975
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
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
|
+
};
|
|
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 {
|
|
@@ -4620,14 +4651,16 @@ async function main(argv) {
|
|
|
4620
4651
|
const runs = featureRuns(workspace, rest, values);
|
|
4621
4652
|
const jobs = jobsFor(workspace, runs, values);
|
|
4622
4653
|
if (jobs === 1) return runJourneys(workspace, rest[0], runs);
|
|
4623
|
-
|
|
4654
|
+
const dir = resolve(rest[0]);
|
|
4655
|
+
return runConcurrently(dir, runs, jobs, (name) => featureJourneys(workspace, name) ?? [], ({ feature }) => [
|
|
4624
4656
|
...process.execArgv,
|
|
4625
4657
|
process.argv[1],
|
|
4626
4658
|
"journey",
|
|
4627
|
-
|
|
4628
|
-
feature,
|
|
4659
|
+
dir,
|
|
4629
4660
|
"--kind",
|
|
4630
|
-
workspace.kind
|
|
4661
|
+
workspace.kind,
|
|
4662
|
+
"--",
|
|
4663
|
+
feature
|
|
4631
4664
|
]);
|
|
4632
4665
|
} else if (command === "formal") return runFormal(workspace, rest[0], values.all === true);
|
|
4633
4666
|
else if (command === "doors") return printDoors(workspace, rest[0] ? patchFiles(rest[0]) : planFor(workspace, values.base).changed);
|