@antelopejs/tooling-configs 0.3.6 → 0.3.7
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 +9 -5
- package/dist/bin/verify.mjs +274 -32
- package/dist/{map-CiFEGFRz.mjs → map-COx26Bu6.mjs} +87 -6
- package/package.json +2 -1
package/dist/bin/sync.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { a as gitFiles, c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
|
8
8
|
import { i as recordedRelease, t as measureBaseline } from "../ratchet-Q-JXuZIX.mjs";
|
|
9
9
|
import { a as ciWorkflow, c as ciNodeCallers, l as ciRenovateSyncCallers, o as placeholderTestScript, p as renovateArtifacts, r as CI_PATH, s as MISSING_CHECKS_WORKFLOW, u as hasChecksWorkflow } from "../ci-workflow-37qJa9LX.mjs";
|
|
10
10
|
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-C0SkPO5R.mjs";
|
|
11
|
-
import { t as DEFAULT_SHARED } from "../map-
|
|
11
|
+
import { t as DEFAULT_SHARED } from "../map-COx26Bu6.mjs";
|
|
12
12
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { dirname, join, posix, resolve } from "node:path";
|
|
14
14
|
import { execFileSync } from "node:child_process";
|
|
@@ -1266,14 +1266,18 @@ Doctor checks that HEAD has not moved since \`new\`, \`ajs\` comes from the repo
|
|
|
1266
1266
|
|
|
1267
1267
|
\`\`\`bash
|
|
1268
1268
|
${BIN} plan --base origin/main
|
|
1269
|
-
${BIN} journey <run> --plan
|
|
1269
|
+
${BIN} journey <run> --plan --jobs 4
|
|
1270
1270
|
\`\`\`
|
|
1271
1271
|
|
|
1272
|
-
\`plan\` maps the diff to features and lists unmapped surfaces. \`journey <run> --plan\` runs every feature \`plan\` lists as \`run\` for the run's base, \`smoke\` first, in one call: it prints each feature's lines in turn, keeps going after a feature fails, and exits 1 when any journey did not pass.
|
|
1272
|
+
\`plan\` maps the diff to features and lists unmapped surfaces. \`journey <run> --plan\` runs every feature \`plan\` lists as \`run\` for the run's base, \`smoke\` first, in one call: it prints each feature's lines in turn, keeps going after a feature fails, and exits 1 when any journey did not pass. Run it once instead of one call per feature.
|
|
1273
|
+
|
|
1274
|
+
When verify.config.ts declares no \`services\`, pass \`--jobs 4\`: up to four features run at once, each in a process of its own, capped at half the machine's cores. The output, the evidence and the exit code are those of the call without \`--jobs\`, and a feature that lists a journey an earlier feature lists waits for it, so it still reuses that PASS. A feature whose process dies or leaves an uncaught error is named on stderr, and the others still run. \`--jobs\` above 1 is refused when verify.config.ts declares \`services\`, because each journey resets them as it starts, which would wipe the data of a journey running beside it. Without \`--jobs\`, a journey that leaves an uncaught error behind ends the call and the line \`not run: <features>\` names what to rerun.
|
|
1275
|
+
|
|
1276
|
+
To rerun after a fix, run one feature, or only the journeys you name, or several features by name, with \`--jobs\` too:
|
|
1273
1277
|
|
|
1274
1278
|
\`\`\`bash
|
|
1275
1279
|
${BIN} journey <run> <feature> [journey...]
|
|
1276
|
-
${BIN} journey <run> --features <feature>,<feature>
|
|
1280
|
+
${BIN} journey <run> --features <feature>,<feature> [--jobs 4]
|
|
1277
1281
|
\`\`\`
|
|
1278
1282
|
|
|
1279
1283
|
The pack ships these journeys for this kind; a feature file names them next to the repository's own:
|
|
@@ -1317,7 +1321,7 @@ ${BIN} map
|
|
|
1317
1321
|
4. **Docs.** Judge every page \`plan\` lists as \`docs\` against what the journeys showed: the \`docs:\` pages of the touched features, or of every feature when the full set runs. A stale page fails the verdict.
|
|
1318
1322
|
5. **Formal checks.** \`${BIN} formal <run>\` runs every formal check of \`verify.config.ts\` that covers the diff, or whose own \`files\` the diff changes, and records it under \`evidence/formal/<name>/\`. For each one it decides, without judgement, whether the diff changed what the covered code does. \`emit\` (the default) compares the structure of the covered files' JavaScript on the base and on HEAD: node kinds, names and literal values, leaving out types, comments, formatting, parentheses and \`export\` keywords. Each use of an imported binding stands for its origin (the resolved module and the imported name), so an import retargeted to another module or alias counts as changed; a function declaration refers to the top-level variables and classes of its own file by file and name, so moving it next to a different variable of the same name counts as changed. Exports are keyed by the origin they export, so a re-export or an \`export { f as run }\` retargeted to another binding counts as changed. Each file must keep its top-level statements and its side-effect imports in order; function declarations, which are hoisted, may move between covered files with their imports. So a type-only edit, a reformat or a moved function declaration counts as unchanged, while reordering statements or moving any other statement counts as changed. \`emit\` judges behaviour, not the public surface: exports are the api-diff's job. \`probe\` runs the check's \`behaviour.command\` with a worktree of each commit and compares what it prints. Then:
|
|
1319
1323
|
- a covered check that did not run, or exits non-zero (a tool error, or a check that no longer matches its record), fails the verdict;
|
|
1320
|
-
- when the covered behaviour did not change, the verdict reports recorded findings as known findings;
|
|
1324
|
+
- when the covered behaviour did not change, the verdict reports recorded findings as known findings, except a rule HEAD breaks that the base run did not, which fails the verdict whatever the diff touched, the check's own \`files\` included; when the base run itself exited non-zero, HEAD's findings cannot be compared and fail the verdict, and so does a result whose check's own \`files\` changed with no base run recorded. A check the diff adds is the exception: when the base could not run it, the base's \`verify.config.ts\` never names it, none of its files is a git rename of a base file, and the covered behaviour is unchanged, its recorded findings pass as the record it brings. List those findings in the PR body so a reviewer sees what the record accepts. A new check on a diff that also changes the covered code fails with \`new check with a covered-code change: land the check in its own PR first\`: land the check alone, then the code change. A moved or renamed check is a changed check;
|
|
1321
1325
|
- when the covered behaviour changed, or the diff changed the check's own \`files\`, \`formal\` also runs the check on the base (\`baseCommand\` when set). A rule the base broke counts as fixed only when HEAD reports it passing (\`passing\`); a rule the base broke that HEAD does not report at all fails the verdict. A change that leaves no violated rule passes;
|
|
1322
1326
|
- when the covered behaviour changed, recorded findings fail the verdict unless the base run exited 0 and broke each of them with the same counterexample length (the \`states\` named group of \`violation\`, after the rule's group, in decimal digits; a \`states\` group that is the first group or captures anything else gives no length), and HEAD fixed every other rule the base broke; then the verdict reports them as the same known findings as the base, with the fixed ones. A new rule, a changed length, or a length either run did not print fails.
|
|
1323
1327
|
|
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 saveRun, a as readFeatures, b as matchesPath, c as allocateRun, d as loadRun, f as openWorkspace, g as removeTree, h as recordProcesses, i as planFor, l as git, m as operatorTmpdir, n as SMOKE_FEATURE, o as CACHE_DIR, p as operatorEnv, r as checkMap, s as RUNS_DIR, u as isolatedEnv, v as withLocalBins, y as writeWhole } from "../map-COx26Bu6.mjs";
|
|
8
8
|
import { appendFileSync, closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { basename, dirname, extname, isAbsolute, join,
|
|
9
|
+
import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import ts from "typescript";
|
|
13
13
|
import { createHash, randomBytes } from "node:crypto";
|
|
14
|
-
import { constants as constants$1, tmpdir } from "node:os";
|
|
14
|
+
import { availableParallelism, constants as constants$1, tmpdir } from "node:os";
|
|
15
15
|
import { parseArgs } from "node:util";
|
|
16
16
|
import { createServer } from "node:net";
|
|
17
17
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
@@ -55,7 +55,7 @@ function flaggedDoors(workspace, files) {
|
|
|
55
55
|
"publish"
|
|
56
56
|
].flatMap((kind) => {
|
|
57
57
|
const globs = doorGlobs(workspace, kind);
|
|
58
|
-
const hits = files.filter((file) => globs.some((glob) =>
|
|
58
|
+
const hits = files.filter((file) => globs.some((glob) => matchesPath(file, glob)));
|
|
59
59
|
return hits.length > 0 ? [{
|
|
60
60
|
kind,
|
|
61
61
|
files: hits
|
|
@@ -511,7 +511,7 @@ function seconds(ms) {
|
|
|
511
511
|
//#region src/verify/formal.ts
|
|
512
512
|
const OUTPUT_LIMIT = 67108864;
|
|
513
513
|
function changesCheckFiles(check, changed) {
|
|
514
|
-
return changed.some((file) => (check.files ?? []).some((glob) =>
|
|
514
|
+
return changed.some((file) => (check.files ?? []).some((glob) => matchesPath(file, glob)));
|
|
515
515
|
}
|
|
516
516
|
/** The formal checks of verify.config.ts whose covered files or own `files` the change touches. */
|
|
517
517
|
function touchedFormalChecks(workspace, changed) {
|
|
@@ -569,6 +569,44 @@ function baseRun(workspace, check, baseSha, folder) {
|
|
|
569
569
|
writeRun(folder, "base-", command, run);
|
|
570
570
|
return rulesOf(check, run);
|
|
571
571
|
}
|
|
572
|
+
function gitOutput(root, args) {
|
|
573
|
+
const run = spawnSync("git", args, {
|
|
574
|
+
cwd: root,
|
|
575
|
+
encoding: "utf8",
|
|
576
|
+
maxBuffer: OUTPUT_LIMIT
|
|
577
|
+
});
|
|
578
|
+
return run.status === 0 ? run.stdout : null;
|
|
579
|
+
}
|
|
580
|
+
function namedOnBase(workspace, check, baseSha) {
|
|
581
|
+
const config = relative(workspace.root, join(workspace.skill, "verify.config.ts"));
|
|
582
|
+
const text = gitOutput(workspace.root, ["show", `${baseSha}:${config}`]);
|
|
583
|
+
if (text === null) return false;
|
|
584
|
+
return [
|
|
585
|
+
"\"",
|
|
586
|
+
"'",
|
|
587
|
+
"`"
|
|
588
|
+
].some((quote) => text.includes(`${quote}${check.name}${quote}`));
|
|
589
|
+
}
|
|
590
|
+
function renamedFromBase(root, check, diff) {
|
|
591
|
+
const fields = (gitOutput(root, [
|
|
592
|
+
"diff",
|
|
593
|
+
"-M",
|
|
594
|
+
"--name-status",
|
|
595
|
+
"-z",
|
|
596
|
+
diff.baseSha,
|
|
597
|
+
diff.headSha
|
|
598
|
+
]) ?? "").split("\0");
|
|
599
|
+
return fields.some((field, index) => field.startsWith("R") && (check.files ?? []).some((glob) => matchesPath(fields[index + 2] ?? "", glob)));
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Whether the diff adds the check: the base could not run it, its name
|
|
603
|
+
* appears nowhere in the base's verify.config.ts, and no file of its own
|
|
604
|
+
* `files` is a rename of a base file. A moved or renamed check, or one whose
|
|
605
|
+
* base ran, is a changed check, gated against the base.
|
|
606
|
+
*/
|
|
607
|
+
function addedByDiff(workspace, check, diff, base) {
|
|
608
|
+
return base.exitCode !== 0 && !namedOnBase(workspace, check, diff.baseSha) && !renamedFromBase(workspace.root, check, diff);
|
|
609
|
+
}
|
|
572
610
|
function gateFields(workspace, check, diff, folder, head) {
|
|
573
611
|
const behaviour = behaviourChange(workspace.root, check, diff);
|
|
574
612
|
const checkChanged = changesCheckFiles(check, diff.changed);
|
|
@@ -584,6 +622,7 @@ function gateFields(workspace, check, diff, folder, head) {
|
|
|
584
622
|
return {
|
|
585
623
|
behaviour,
|
|
586
624
|
checkChanged,
|
|
625
|
+
newCheck: checkChanged && addedByDiff(workspace, check, diff, base),
|
|
587
626
|
base,
|
|
588
627
|
fixed: base.violated.filter((rule) => head.passing.includes(rule) && !head.violated.includes(rule)),
|
|
589
628
|
missing: base.violated.filter((rule) => !atHead.has(rule))
|
|
@@ -636,17 +675,58 @@ function knownFindingsOfBase(result) {
|
|
|
636
675
|
});
|
|
637
676
|
}
|
|
638
677
|
/**
|
|
678
|
+
* The outcome a result's base run forces before the findings are weighed: a
|
|
679
|
+
* check the diff adds, on a diff that leaves the covered behaviour unchanged,
|
|
680
|
+
* passes its recorded findings, since its record is reviewed with it and the
|
|
681
|
+
* base has nothing to compare, and fails with the advice to land it alone when
|
|
682
|
+
* the covered code changed too; otherwise a failure
|
|
683
|
+
* for a changed check with no base run recorded, a base run that exited non-zero
|
|
684
|
+
* while HEAD breaks rules, or, when the covered behaviour is unchanged, a rule
|
|
685
|
+
* HEAD breaks that the base did not. `null` when the base decides nothing.
|
|
686
|
+
*/
|
|
687
|
+
function baseGate(result) {
|
|
688
|
+
const { base, behaviour } = result;
|
|
689
|
+
if (result.newCheck === true && base && base.exitCode !== 0 && behaviour?.changed === false) return {
|
|
690
|
+
fails: false,
|
|
691
|
+
outcome: `new check, absent from the base: ${result.violated.length > 0 ? `recorded findings ${result.violated.join(", ")}` : "no violated rule"}`
|
|
692
|
+
};
|
|
693
|
+
if (result.newCheck === true && behaviour?.changed === true && result.violated.length > 0) return {
|
|
694
|
+
fails: true,
|
|
695
|
+
outcome: "new check with a covered-code change: land the check in its own PR first"
|
|
696
|
+
};
|
|
697
|
+
if (result.checkChanged === true && !base) return {
|
|
698
|
+
fails: true,
|
|
699
|
+
outcome: "the check's own files changed but no base run was recorded"
|
|
700
|
+
};
|
|
701
|
+
if (!base) return null;
|
|
702
|
+
if (base.exitCode !== 0 && result.violated.length > 0) return {
|
|
703
|
+
fails: true,
|
|
704
|
+
outcome: `the base run exited ${base.exitCode}, so ${result.violated.join(", ")} cannot be compared with the base`
|
|
705
|
+
};
|
|
706
|
+
const added = result.violated.filter((rule) => !base.violated.includes(rule));
|
|
707
|
+
if (behaviour?.changed === false && added.length > 0) return {
|
|
708
|
+
fails: true,
|
|
709
|
+
outcome: `covered behaviour unchanged (${behaviour.method}), but the check breaks rules the base did not: ${added.join(", ")}`
|
|
710
|
+
};
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
639
714
|
* How a formal check's result weighs on a verdict whose diff it covers. A
|
|
640
715
|
* non-zero exit (a tool error, or a check that no longer matches its record)
|
|
641
716
|
* fails, so every violated rule of a result that reaches the rest of the gate
|
|
642
717
|
* is a recorded finding. A rule the base broke that HEAD does not report at
|
|
643
|
-
* all fails.
|
|
644
|
-
*
|
|
645
|
-
* the base
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
718
|
+
* all fails. A base run that exited non-zero cannot vouch for HEAD's findings,
|
|
719
|
+
* and a changed check with no base run recorded fails. A check the diff adds
|
|
720
|
+
* (the base could not run it, never names it and holds none of its files
|
|
721
|
+
* under another path) passes its recorded findings when the covered
|
|
722
|
+
* behaviour is unchanged. Otherwise, when the covered behaviour is unchanged,
|
|
723
|
+
* recorded findings are known, except a rule HEAD breaks that the base run
|
|
724
|
+
* did not, which fails whatever the diff touched. When the behaviour
|
|
725
|
+
* changed, they are known only when the base run exited 0 and broke every
|
|
726
|
+
* one of them, each with the same counterexample length at HEAD as on the
|
|
727
|
+
* base, and every other rule the base broke is fixed at HEAD; a new rule, a
|
|
728
|
+
* changed length, or a length either run did not report fails. A rule the
|
|
729
|
+
* base broke and HEAD reports passing is reported as fixed.
|
|
650
730
|
*/
|
|
651
731
|
function formalGate(result) {
|
|
652
732
|
if (result.exitCode !== 0) return {
|
|
@@ -662,6 +742,8 @@ function formalGate(result) {
|
|
|
662
742
|
outcome: `violated ${result.violated.join(", ") || "nothing"}`
|
|
663
743
|
};
|
|
664
744
|
const how = result.behaviour.method;
|
|
745
|
+
const againstBase = baseGate(result);
|
|
746
|
+
if (againstBase) return againstBase;
|
|
665
747
|
if (!result.behaviour.changed) return {
|
|
666
748
|
fails: false,
|
|
667
749
|
outcome: `covered behaviour unchanged (${how}): ${result.violated.length > 0 ? `known findings ${result.violated.join(", ")}` : "no violated rule"}`
|
|
@@ -687,6 +769,125 @@ function readFormalResult(state, name) {
|
|
|
687
769
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
688
770
|
}
|
|
689
771
|
//#endregion
|
|
772
|
+
//#region src/verify/jobs.ts
|
|
773
|
+
const INTERRUPTS$1 = [
|
|
774
|
+
"SIGINT",
|
|
775
|
+
"SIGTERM",
|
|
776
|
+
"SIGHUP",
|
|
777
|
+
"SIGQUIT"
|
|
778
|
+
];
|
|
779
|
+
/**
|
|
780
|
+
* The most features a `journey` call runs at once: `requested`, capped at
|
|
781
|
+
* the number of features and at half the logical cores, one feature per
|
|
782
|
+
* physical core where each core runs two threads. A feature is mostly an
|
|
783
|
+
* app booting under `ajs project dev`, which keeps a core busy, so features
|
|
784
|
+
* past one per physical core slow each other's boot more than they overlap
|
|
785
|
+
* it. The cap only stops a count that oversubscribes the machine; the
|
|
786
|
+
* synced skill recommends 4.
|
|
787
|
+
*/
|
|
788
|
+
function jobLimit(requested, features) {
|
|
789
|
+
return Math.max(1, Math.min(requested, features, Math.floor(availableParallelism() / 2)));
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* For each feature, the earlier features of the list it waits for: the
|
|
793
|
+
* same feature listed again, or one that registers a journey id it
|
|
794
|
+
* registers too. A journey listed under two features runs once in a
|
|
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.
|
|
799
|
+
*/
|
|
800
|
+
function dependencies(runs, journeysOf) {
|
|
801
|
+
const ids = runs.map((run) => new Set(journeysOf(run.feature)));
|
|
802
|
+
return runs.map((run, index) => runs.flatMap((earlier, before) => before < index && (earlier.feature === run.feature || [...ids[before]].some((id) => ids[index].has(id))) ? [before] : []));
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Starts `args` under this Node in a process group of its own, so a
|
|
806
|
+
* terminal's interrupt reaches it once, through {@link runConcurrently}, and
|
|
807
|
+
* collects what it prints into `slot`. Resolves once it exited. A process
|
|
808
|
+
* that ended on a signal or could not start is named on its stderr.
|
|
809
|
+
*/
|
|
810
|
+
function runProcess(slot, args) {
|
|
811
|
+
return new Promise((resolve) => {
|
|
812
|
+
const child = spawn(process.execPath, args, {
|
|
813
|
+
stdio: [
|
|
814
|
+
"ignore",
|
|
815
|
+
"pipe",
|
|
816
|
+
"pipe"
|
|
817
|
+
],
|
|
818
|
+
detached: true
|
|
819
|
+
});
|
|
820
|
+
slot.child = child;
|
|
821
|
+
child.stdout.on("data", (chunk) => slot.stdout.push(chunk));
|
|
822
|
+
child.stderr.on("data", (chunk) => slot.stderr.push(chunk));
|
|
823
|
+
const end = (passed, note) => {
|
|
824
|
+
if (note !== void 0) slot.stderr.push(Buffer.from(`${slot.run.feature}: ${note}\n`));
|
|
825
|
+
slot.passed = passed;
|
|
826
|
+
resolve();
|
|
827
|
+
};
|
|
828
|
+
child.once("error", (error) => end(false, `its journey process could not start: ${error.message}`));
|
|
829
|
+
child.once("close", (code, signal) => signal === null ? end(code === 0) : end(false, `its journey process ended on ${signal}`));
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Runs each feature in its own `journey <run> <feature>` process, `jobs` at
|
|
834
|
+
* a time, and prints each feature's output whole, in the order of `runs`,
|
|
835
|
+
* as soon as it and every feature before it have ended. A process per
|
|
836
|
+
* feature gives each one the `process.env`, verify.config.ts module state
|
|
837
|
+
* and uncaught-error handler its own call would have, which features
|
|
838
|
+
* sharing one process could not keep apart while running at once. A feature
|
|
839
|
+
* whose process fails, ends on a signal or leaves an uncaught error does not
|
|
840
|
+
* stop the others. An interrupt reaches every running feature's process,
|
|
841
|
+
* which stops what its journey started; the call then prints what ended, in
|
|
842
|
+
* order, and exits with the shell's code for the signal.
|
|
843
|
+
* @param argsOf the arguments, after the Node executable, of the process that runs one feature.
|
|
844
|
+
* @returns 1 when any feature's process failed, else 0.
|
|
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();
|
|
885
|
+
});
|
|
886
|
+
for (const signal of INTERRUPTS$1) process.off(signal, forward);
|
|
887
|
+
if (interrupted !== void 0) process.exit(128 + constants$1.signals[interrupted]);
|
|
888
|
+
return slots.every((slot) => slot.passed) ? 0 : 1;
|
|
889
|
+
}
|
|
890
|
+
//#endregion
|
|
690
891
|
//#region src/verify/judgement.ts
|
|
691
892
|
const DOOR_KINDS = [
|
|
692
893
|
"data",
|
|
@@ -3466,11 +3667,10 @@ var VerifyContext = class {
|
|
|
3466
3667
|
});
|
|
3467
3668
|
this.running.push(entry);
|
|
3468
3669
|
this.started.push(entry);
|
|
3469
|
-
this.state
|
|
3670
|
+
recordProcesses(this.state, { add: [{
|
|
3470
3671
|
name: `${name} (${project})`,
|
|
3471
3672
|
pid: handle.pid
|
|
3472
|
-
});
|
|
3473
|
-
saveRun(this.state);
|
|
3673
|
+
}] });
|
|
3474
3674
|
await this.waitReady(app, handle, fixture !== void 0);
|
|
3475
3675
|
return this.caches.observed(app);
|
|
3476
3676
|
}
|
|
@@ -3580,8 +3780,7 @@ var VerifyContext = class {
|
|
|
3580
3780
|
untrack(pid) {
|
|
3581
3781
|
const index = this.running.findIndex((entry) => entry.app.pid === pid);
|
|
3582
3782
|
if (index !== -1) this.running.splice(index, 1);
|
|
3583
|
-
this.state
|
|
3584
|
-
saveRun(this.state);
|
|
3783
|
+
recordProcesses(this.state, { drop: [pid] });
|
|
3585
3784
|
}
|
|
3586
3785
|
async scaffold(name, project, flags = [
|
|
3587
3786
|
"--pm",
|
|
@@ -3690,13 +3889,24 @@ function statusOf(context, failure) {
|
|
|
3690
3889
|
if (failure.notVerified !== null) return "NOT VERIFIED";
|
|
3691
3890
|
return failure.error !== null || context.steps.some((step) => step.checks.some((check) => !check.pass)) || context.steps.length === 0 ? "FAIL" : "PASS";
|
|
3692
3891
|
}
|
|
3892
|
+
/** Removes the empty folders from `folder` up to, not including, `top`; it stops at the first that another journey of the run filled or removed meanwhile. */
|
|
3893
|
+
function removeEmptyParents(folder, top) {
|
|
3894
|
+
try {
|
|
3895
|
+
for (let parent = dirname(folder); parent !== top && readdirSync(parent).length === 0; parent = dirname(parent)) rmdirSync(parent);
|
|
3896
|
+
} catch {
|
|
3897
|
+
return;
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3693
3900
|
/** Deletes a journey's scratch folder and HOME, and their parents once empty; the evidence stays. A folder it cannot delete is reported on stderr and left for the next prune. */
|
|
3694
3901
|
function discard(context) {
|
|
3695
|
-
for (const folder of [context.work, context.home])
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3902
|
+
for (const folder of [context.work, context.home]) {
|
|
3903
|
+
try {
|
|
3904
|
+
removeTree(folder);
|
|
3905
|
+
} catch (error) {
|
|
3906
|
+
process.stderr.write(`could not delete ${folder}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
3907
|
+
continue;
|
|
3908
|
+
}
|
|
3909
|
+
removeEmptyParents(folder, context.state.dir);
|
|
3700
3910
|
}
|
|
3701
3911
|
}
|
|
3702
3912
|
async function runOne(workspace, state, feature, id, journey) {
|
|
@@ -3706,8 +3916,7 @@ async function runOne(workspace, state, feature, id, journey) {
|
|
|
3706
3916
|
const own = state.processes.filter((record) => !others.has(record.pid));
|
|
3707
3917
|
for (const record of own) killGroup(record.pid);
|
|
3708
3918
|
discard(context);
|
|
3709
|
-
state
|
|
3710
|
-
saveRun(state);
|
|
3919
|
+
recordProcesses(state, { drop: own.map((record) => record.pid) });
|
|
3711
3920
|
});
|
|
3712
3921
|
try {
|
|
3713
3922
|
return await driveJourney(context, feature, id, journey);
|
|
@@ -3882,7 +4091,7 @@ async function runFeature(workspace, state, feature, ids) {
|
|
|
3882
4091
|
results.push(source === void 0 ? stamp(state, await runOne(workspace, state, feature, id, journey), tree) : reuse(state, feature, id, source));
|
|
3883
4092
|
}
|
|
3884
4093
|
const merged = registered.flatMap((id) => results.filter((result) => result.journey === id).concat(results.some((result) => result.journey === id) ? [] : earlier.filter((result) => result.journey === id)));
|
|
3885
|
-
|
|
4094
|
+
writeWhole(join(state.evidence, feature, "feature.json"), `${JSON.stringify(merged, null, 2)}\n`);
|
|
3886
4095
|
return results;
|
|
3887
4096
|
}
|
|
3888
4097
|
//#endregion
|
|
@@ -4186,8 +4395,11 @@ const USAGE = `Usage: antelopejs-verify <command>
|
|
|
4186
4395
|
build, prepare an isolated run, print its folder; --all runs every feature, before a release
|
|
4187
4396
|
doctor <run> check the run is worth driving
|
|
4188
4397
|
journey <run> <feature> [ids...] run a feature's journeys and record evidence
|
|
4189
|
-
journey <run> --plan
|
|
4190
|
-
journey <run> --features <a,b>
|
|
4398
|
+
journey <run> --plan [--jobs <n>] run every feature the run's plan lists, smoke first
|
|
4399
|
+
journey <run> --features <a,b> [--jobs <n>]
|
|
4400
|
+
run the named features, each whole, in that order;
|
|
4401
|
+
--jobs runs up to n features at once, each in its own process,
|
|
4402
|
+
at most half the cores, never with services
|
|
4191
4403
|
formal <run> [--all] run the formal checks that cover the diff and gate them on changed behaviour
|
|
4192
4404
|
doors [patch] [--base <ref>] print the One-way-door line for a patch, or for the diff
|
|
4193
4405
|
clean <run> stop what the run started, keep only the evidence
|
|
@@ -4274,8 +4486,9 @@ async function journeyFeature(workspace, dir, { feature, ids }) {
|
|
|
4274
4486
|
* feature. An uncaught error a journey leaves behind (a timer that throws, a
|
|
4275
4487
|
* rejection nobody awaits) ends the call, as it would end a single call, and
|
|
4276
4488
|
* names the features that did not run. Module-level state a repository's
|
|
4277
|
-
* verify.config.ts keeps is shared by the features of one call.
|
|
4278
|
-
*
|
|
4489
|
+
* verify.config.ts keeps is shared by the features of one call. `--jobs`
|
|
4490
|
+
* runs features at once in processes of their own instead, through
|
|
4491
|
+
* {@link runConcurrently}.
|
|
4279
4492
|
* @returns 1 when any feature had a journey that did not pass or could not run, else 0.
|
|
4280
4493
|
*/
|
|
4281
4494
|
async function runJourneys(workspace, dir, runs) {
|
|
@@ -4304,6 +4517,22 @@ function restoreEnv(saved) {
|
|
|
4304
4517
|
for (const key of Object.keys(process.env)) if (!Object.hasOwn(saved, key)) delete process.env[key];
|
|
4305
4518
|
Object.assign(process.env, saved);
|
|
4306
4519
|
}
|
|
4520
|
+
/**
|
|
4521
|
+
* How many features a `journey` call runs at once: 1 without `--jobs`, else
|
|
4522
|
+
* `--jobs` capped by {@link jobLimit}. `--jobs` applies to `--plan` and
|
|
4523
|
+
* `--features` only, and more than 1 is refused when verify.config.ts
|
|
4524
|
+
* declares `services`: every journey resets them as it starts, which would
|
|
4525
|
+
* wipe the data of a journey running beside it.
|
|
4526
|
+
*/
|
|
4527
|
+
function jobsFor(workspace, runs, flags) {
|
|
4528
|
+
if (flags.jobs === void 0) return 1;
|
|
4529
|
+
if (flags.plan !== true && flags.features === void 0) throw new Error("--jobs runs whole features at once: use it with --plan or --features");
|
|
4530
|
+
if (!/^[1-9]\d*$/.test(flags.jobs)) throw new Error(`--jobs takes a number of features, 1 or more, not ${flags.jobs}`);
|
|
4531
|
+
const requested = Number(flags.jobs);
|
|
4532
|
+
const services = Object.keys(workspace.config.services ?? {});
|
|
4533
|
+
if (requested > 1 && services.length > 0) throw new Error(`--jobs ${requested} refused: verify.config.ts declares services (${services.join(", ")}), and each journey resets them as it starts, which would wipe the data of a journey running beside it. Run the features without --jobs.`);
|
|
4534
|
+
return jobLimit(requested, runs.length);
|
|
4535
|
+
}
|
|
4307
4536
|
function runFormal(workspace, dir, all) {
|
|
4308
4537
|
const state = loadRun(dir);
|
|
4309
4538
|
const plan = planFor(workspace, state.baseRef);
|
|
@@ -4364,7 +4593,8 @@ async function main(argv) {
|
|
|
4364
4593
|
features: {
|
|
4365
4594
|
type: "string",
|
|
4366
4595
|
multiple: true
|
|
4367
|
-
}
|
|
4596
|
+
},
|
|
4597
|
+
jobs: { type: "string" }
|
|
4368
4598
|
}
|
|
4369
4599
|
});
|
|
4370
4600
|
const [command, ...rest] = positionals;
|
|
@@ -4386,8 +4616,20 @@ async function main(argv) {
|
|
|
4386
4616
|
const lines = doctor(workspace, loadRun(rest[0]));
|
|
4387
4617
|
for (const line of lines) print(`${line.ok ? "ok " : "FAIL"} ${line.check}: ${line.detail}`);
|
|
4388
4618
|
return lines.every((line) => line.ok) ? 0 : 1;
|
|
4389
|
-
} else if (command === "journey")
|
|
4390
|
-
|
|
4619
|
+
} else if (command === "journey") {
|
|
4620
|
+
const runs = featureRuns(workspace, rest, values);
|
|
4621
|
+
const jobs = jobsFor(workspace, runs, values);
|
|
4622
|
+
if (jobs === 1) return runJourneys(workspace, rest[0], runs);
|
|
4623
|
+
return runConcurrently(runs, jobs, (name) => featureJourneys(workspace, name) ?? [], ({ feature }) => [
|
|
4624
|
+
...process.execArgv,
|
|
4625
|
+
process.argv[1],
|
|
4626
|
+
"journey",
|
|
4627
|
+
resolve(rest[0]),
|
|
4628
|
+
feature,
|
|
4629
|
+
"--kind",
|
|
4630
|
+
workspace.kind
|
|
4631
|
+
]);
|
|
4632
|
+
} else if (command === "formal") return runFormal(workspace, rest[0], values.all === true);
|
|
4391
4633
|
else if (command === "doors") return printDoors(workspace, rest[0] ? patchFiles(rest[0]) : planFor(workspace, values.base).changed);
|
|
4392
4634
|
else if (command === "clean") for (const line of clean(loadRun(rest[0]))) print(line);
|
|
4393
4635
|
else if (command === "verdict" || command === "publish") return judge(workspace, command, rest[0], Number(values.pr));
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { l as skillFolder } from "./shared-igPpEDpS.mjs";
|
|
2
2
|
import { f as parseJson, i as isObject } from "./json-CG2L7YFl.mjs";
|
|
3
3
|
import { c as leaseTmpDir, i as PARENT_TMPDIR, n as LEASE_DIR, r as LEASE_MARKER, t as DEV_STACK_VARIABLES } from "./env-DT0UJNeL.mjs";
|
|
4
|
-
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { basename, delimiter, dirname, join,
|
|
4
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { basename, delimiter, dirname, join, relative, resolve } from "node:path";
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
9
|
import { homedir, tmpdir } from "node:os";
|
|
10
|
+
import { minimatch } from "minimatch";
|
|
11
|
+
//#region src/verify/glob.ts
|
|
12
|
+
/**
|
|
13
|
+
* Whether `file` matches `glob`, dotfiles and dot folders included: `src/**`
|
|
14
|
+
* matches `src/.env` and `**` matches `.prettierrc`, while braces, classes,
|
|
15
|
+
* extglobs and negations keep their meaning (`{.env,.npmrc}` matches `.env`,
|
|
16
|
+
* `[!.]*` does not). `path.matchesGlob` never lets a wildcard match a
|
|
17
|
+
* leading dot, so a diff touching only a dotfile would map to no feature.
|
|
18
|
+
*/
|
|
19
|
+
function matchesPath(file, glob) {
|
|
20
|
+
return minimatch(file, glob, { dot: true });
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
10
23
|
//#region src/verify/workspace.ts
|
|
11
24
|
/**
|
|
12
25
|
* Caches shared by every run: the warm pnpm store, the npm cache and the
|
|
@@ -95,9 +108,77 @@ function loadRun(dir) {
|
|
|
95
108
|
all: stored.all === true
|
|
96
109
|
};
|
|
97
110
|
}
|
|
111
|
+
/** Writes `text` to `file` through a sibling temporary file and one rename, so a reader in another process sees the old content or the new, never part of it. */
|
|
112
|
+
function writeWhole(file, text) {
|
|
113
|
+
const staging = `${file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
114
|
+
try {
|
|
115
|
+
writeFileSync(staging, text);
|
|
116
|
+
renameSync(staging, file);
|
|
117
|
+
} finally {
|
|
118
|
+
rmSync(staging, { force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
98
121
|
/** Persists the run state. */
|
|
99
122
|
function saveRun(state) {
|
|
100
|
-
|
|
123
|
+
writeWhole(stateFile(state.dir), `${JSON.stringify(state, null, 2)}\n`);
|
|
124
|
+
}
|
|
125
|
+
/** Whether the process `pid` still runs. */
|
|
126
|
+
function running(pid) {
|
|
127
|
+
try {
|
|
128
|
+
process.kill(pid, 0);
|
|
129
|
+
return true;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return error instanceof Error && "code" in error && error.code === "EPERM";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Runs `body` holding the run's lock, a file created exclusively that names
|
|
136
|
+
* its holder. A lock whose holder no longer runs, as after a crash, is taken
|
|
137
|
+
* over.
|
|
138
|
+
*/
|
|
139
|
+
function withRunLock(dir, body) {
|
|
140
|
+
const lock = join(dir, "run.json.lock");
|
|
141
|
+
const pause = new Int32Array(new SharedArrayBuffer(4));
|
|
142
|
+
for (;;) {
|
|
143
|
+
try {
|
|
144
|
+
writeFileSync(lock, String(process.pid), { flag: "wx" });
|
|
145
|
+
break;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) throw error;
|
|
148
|
+
}
|
|
149
|
+
let holder = NaN;
|
|
150
|
+
try {
|
|
151
|
+
holder = Number(readFileSync(lock, "utf8"));
|
|
152
|
+
} catch {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (Number.isInteger(holder) && holder > 0 && !running(holder)) rmSync(lock, { force: true });
|
|
156
|
+
else Atomics.wait(pause, 0, 0, 2);
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
body();
|
|
160
|
+
} finally {
|
|
161
|
+
rmSync(lock, { force: true });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Adds `add` to the processes the run records and drops the records of the
|
|
166
|
+
* PIDs in `drop`, in `state` and in run.json. Several `journey` commands of
|
|
167
|
+
* one run may start and stop processes at once, so run.json changes under a
|
|
168
|
+
* lock, from what it holds then: writing back `state` whole would drop the
|
|
169
|
+
* records another command made since this one loaded the run. `state` keeps
|
|
170
|
+
* only the records this command loaded or made.
|
|
171
|
+
*/
|
|
172
|
+
function recordProcesses(state, change) {
|
|
173
|
+
const apply = (records) => [...records.filter((record) => !change.drop?.includes(record.pid)), ...change.add ?? []];
|
|
174
|
+
state.processes = apply(state.processes);
|
|
175
|
+
withRunLock(state.dir, () => {
|
|
176
|
+
const stored = loadRun(state.dir);
|
|
177
|
+
saveRun({
|
|
178
|
+
...stored,
|
|
179
|
+
processes: apply(stored.processes)
|
|
180
|
+
});
|
|
181
|
+
});
|
|
101
182
|
}
|
|
102
183
|
/** Allocates the folders of a new run under the system temp folder. */
|
|
103
184
|
function allocateRun(workspace, baseRef, title, all) {
|
|
@@ -296,7 +377,7 @@ function readFeatures(workspace) {
|
|
|
296
377
|
});
|
|
297
378
|
}
|
|
298
379
|
function matches(file, globs) {
|
|
299
|
-
return globs.some((glob) =>
|
|
380
|
+
return globs.some((glob) => matchesPath(file, glob));
|
|
300
381
|
}
|
|
301
382
|
/** Whether a user can observe a change to `file`. */
|
|
302
383
|
function userFacing(workspace, file) {
|
|
@@ -322,7 +403,7 @@ function featureProblems(workspace, feature, known, tracked) {
|
|
|
322
403
|
if (!feature.body.includes(`\`${journey}\``)) problems.push(`${feature.file}: journey \`${journey}\` is not described`);
|
|
323
404
|
}
|
|
324
405
|
if (feature.name !== "smoke" && feature.covers.length === 0) problems.push(`${feature.file}: lists no covers globs`);
|
|
325
|
-
for (const glob of feature.covers) if (!tracked.some((file) =>
|
|
406
|
+
for (const glob of feature.covers) if (!tracked.some((file) => matchesPath(file, glob))) problems.push(`${feature.file}: glob ${glob} matches no tracked file`);
|
|
326
407
|
if (feature.docs.length === 0) problems.push(`${feature.file}: lists no docs pages`);
|
|
327
408
|
for (const doc of feature.docs) if (!existsSync(join(workspace.root, doc))) problems.push(`${feature.file}: docs path ${doc} does not exist`);
|
|
328
409
|
return problems;
|
|
@@ -412,4 +493,4 @@ function planFor(workspace, baseRef, all = false) {
|
|
|
412
493
|
};
|
|
413
494
|
}
|
|
414
495
|
//#endregion
|
|
415
|
-
export {
|
|
496
|
+
export { saveRun as _, readFeatures as a, matchesPath as b, allocateRun as c, loadRun as d, openWorkspace as f, removeTree as g, recordProcesses as h, planFor as i, git as l, operatorTmpdir as m, SMOKE_FEATURE as n, CACHE_DIR as o, operatorEnv as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, isolatedEnv as u, withLocalBins as v, writeWhole as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@oxlint/plugins": "1.81.0",
|
|
82
82
|
"dts-bundle-generator": "^9.5.1",
|
|
83
|
+
"minimatch": "^10.2.6",
|
|
83
84
|
"typescript": "^5.9.3",
|
|
84
85
|
"yaml": "^2.9.1"
|
|
85
86
|
},
|