architecture-harness 0.21.2 → 0.23.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/package.json +16 -4
- package/src/cli/check.mjs +61 -0
- package/src/cli/child-run.mjs +39 -0
- package/src/cli/child-run.test.mjs +16 -0
- package/src/cli/ci-template.test.mjs +28 -0
- package/src/cli/cli.test.mjs +6 -1
- package/src/cli/codex-implement.mjs +79 -5
- package/src/cli/codex-implement.test.mjs +170 -4
- package/src/cli/dispatch-guard.mjs +24 -1
- package/src/cli/dispatch-guard.test.mjs +30 -0
- package/src/cli/dispatch-reminder.mjs +7 -4
- package/src/cli/dispatch-reminder.test.mjs +8 -4
- package/src/cli/dispatch-slot.mjs +12 -0
- package/src/cli/gate-slot.mjs +151 -0
- package/src/cli/gate-slot.test.mjs +90 -0
- package/src/cli/git-hooks.test.mjs +5 -0
- package/src/cli/integrate.mjs +122 -0
- package/src/cli/integrate.test.mjs +94 -0
- package/src/cli/ledger.mjs +25 -3
- package/src/cli/ledger.test.mjs +9 -0
- package/src/cli/merge-guard.mjs +13 -3
- package/src/cli/merge-guard.test.mjs +24 -1
- package/src/cli/migrations.mjs +127 -0
- package/src/cli/migrations.test.mjs +94 -0
- package/src/cli/plugin-agents.test.mjs +35 -8
- package/src/cli/qc.mjs +58 -1
- package/src/cli/report-stop.mjs +3 -0
- package/src/cli/report-stop.test.mjs +8 -0
- package/src/cli/retry-failed.mjs +80 -0
- package/src/cli/retry-failed.test.mjs +51 -0
- package/src/cli/review-gate.mjs +16 -7
- package/src/cli/screens-discovery.mjs +60 -0
- package/src/cli/screens.mjs +84 -0
- package/src/cli/slot-guard.mjs +43 -0
- package/src/cli/slot-guard.test.mjs +28 -0
- package/src/cli/stack.mjs +14 -0
- package/src/cli/task-gate-review.test.mjs +10 -0
- package/src/cli/task-gate.mjs +39 -7
- package/src/cli/task-gate.test.mjs +45 -0
- package/src/cli/throwaway-db.mjs +127 -0
- package/src/cli/throwaway-db.test.mjs +83 -0
- package/src/cli/ui-reuse-hint.mjs +89 -0
- package/src/cli/ui-reuse-hint.test.mjs +60 -0
- package/src/cli/ui.mjs +181 -0
- package/src/cli/ui.test.mjs +137 -0
- package/src/cli/watch.mjs +211 -0
- package/src/cli/watch.test.mjs +246 -0
- package/src/config.mjs +27 -2
- package/src/descriptions.mjs +3 -0
- package/src/gates/contract-keys.mjs +33 -0
- package/src/gates/contract-keys.test.mjs +38 -0
- package/src/gates/migration-numbers.mjs +1 -1
- package/src/gates/migration-numbers.test.mjs +1 -0
- package/src/gates/ui-catalog.mjs +45 -0
- package/src/gates/ui-catalog.test.mjs +48 -0
- package/src/gates/ui-dupes.mjs +36 -0
- package/src/gates/ui-dupes.test.mjs +29 -0
- package/src/screens/auth-context.test.mjs +41 -0
- package/src/screens/auth-run.test.mjs +144 -0
- package/src/screens/auth.mjs +223 -0
- package/src/screens/auth.test.mjs +76 -0
- package/src/screens/capture-idle.test.mjs +26 -0
- package/src/screens/capture.browser-test.mjs +73 -0
- package/src/screens/capture.mjs +175 -0
- package/src/screens/capture.test.mjs +28 -0
- package/src/screens/catalog.browser-test.mjs +32 -0
- package/src/screens/catalog.mjs +72 -0
- package/src/screens/catalog.test.mjs +36 -0
- package/src/screens/compare.mjs +40 -0
- package/src/screens/compare.test.mjs +30 -0
- package/src/screens/discovery.browser-test.mjs +29 -0
- package/src/screens/discovery.mjs +158 -0
- package/src/screens/discovery.test.mjs +27 -0
- package/src/screens/inventory.mjs +69 -0
- package/src/screens/inventory.test.mjs +10 -0
- package/src/screens/map.mjs +63 -0
- package/src/screens/map.test.mjs +35 -0
- package/src/screens/open.browser-test.mjs +50 -0
- package/src/screens/regions.mjs +137 -0
- package/src/screens/regions.test.mjs +38 -0
- package/src/screens/session-files.mjs +39 -0
- package/src/screens/session-files.test.mjs +39 -0
- package/src/screens/setup.browser-test.mjs +49 -0
- package/src/screens/setup.mjs +78 -0
- package/src/screens/stack-auth.browser-test.mjs +30 -0
- package/src/screens/stack-auth.mjs +106 -0
- package/src/screens/stack-auth.test.mjs +65 -0
- package/src/screens/write-guard.mjs +26 -0
- package/src/stack/stack.mjs +131 -0
- package/src/stack/stack.test.mjs +40 -0
- package/src/stack/supervisor.mjs +30 -0
- package/src/ui/catalog.mjs +87 -0
- package/src/ui/catalog.test.mjs +54 -0
- package/src/ui/class-sites.mjs +151 -0
- package/src/ui/class-sites.test.mjs +41 -0
- package/src/ui/codemod.mjs +138 -0
- package/src/ui/codemod.test.mjs +140 -0
- package/src/ui/components.mjs +176 -0
- package/src/ui/components.test.mjs +87 -0
- package/src/ui/dupes.mjs +141 -0
- package/src/ui/dupes.test.mjs +85 -0
- package/src/ui/find.mjs +45 -0
- package/src/ui/find.test.mjs +48 -0
- package/src/ui/options.mjs +40 -0
- package/src/ui/scan.mjs +78 -0
- package/src/ui/typescript.mjs +29 -0
- package/templates/github/workflows/ci.yml +54 -0
package/src/cli/merge-guard.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { LANE_BUDGET_MS, mergeLane, sizeLine } from "./direct-lane.mjs";
|
|
|
11
11
|
import { ghApiMerges, ghMerges } from "./gh-merge-command.mjs";
|
|
12
12
|
import { runGh } from "./gh-run.mjs";
|
|
13
13
|
import { originOf, repoOfSpelling } from "./git-read.mjs";
|
|
14
|
-
import { appendRecord, latestVerdictFor, readLedger } from "./ledger.mjs";
|
|
14
|
+
import { appendRecord, decidingVerdictFor, dispatchedScopesFor, latestVerdictFor, readLedger } from "./ledger.mjs";
|
|
15
15
|
import { workflowAt } from "./workflow-settings.mjs";
|
|
16
16
|
import { worktreeRuleAt } from "./worktree-settings.mjs";
|
|
17
17
|
|
|
@@ -36,8 +36,18 @@ export function mergeVerdict(merges, records, kind, lane = null) {
|
|
|
36
36
|
if (!merge.sha) {
|
|
37
37
|
return { refusal: `Merge guard: \`gh pr merge\` must pass \`--match-head-commit <sha>\` with the head the ${kind} review approved, so a push after the review cannot merge unreviewed. Add it.` };
|
|
38
38
|
}
|
|
39
|
-
const verdict =
|
|
40
|
-
|
|
39
|
+
const verdict = decidingVerdictFor(records, merge.sha, [kind]);
|
|
40
|
+
const missing = dispatchedScopesFor(records, merge.sha).find(
|
|
41
|
+
(scope) => latestVerdictFor(records, merge.sha, [kind], scope)?.verdict !== "APPROVED",
|
|
42
|
+
);
|
|
43
|
+
if (verdict?.verdict === "APPROVED" && missing === undefined) continue;
|
|
44
|
+
if (missing !== undefined) {
|
|
45
|
+
return {
|
|
46
|
+
refusal:
|
|
47
|
+
`Merge guard: the ledger holds no APPROVED ${kind} review of scope "${missing}" on ${merge.sha}, and a review of that scope was dispatched. ` +
|
|
48
|
+
`Dispatch ${REVIEWER[kind]} with \`Scope: ${missing}\` on that head, and merge after every scope approves.`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
41
51
|
const fit = lane ? lane(merge) : null;
|
|
42
52
|
if (fit && fit.problem === null) {
|
|
43
53
|
direct.push(fit.note);
|
|
@@ -6,7 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
import { test } from "node:test";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { appendRecord, readLedger } from "./ledger.mjs";
|
|
9
|
-
import { decide, namedIssues } from "./merge-guard.mjs";
|
|
9
|
+
import { decide, mergeVerdict, namedIssues } from "./merge-guard.mjs";
|
|
10
10
|
|
|
11
11
|
const HOOK = fileURLToPath(new URL("./merge-guard.mjs", import.meta.url));
|
|
12
12
|
const SHA = "0123456789abcdef0123456789abcdef01234567";
|
|
@@ -491,3 +491,26 @@ test("a gh answer with no base commit closes the lane", (t) => {
|
|
|
491
491
|
const reason = denied(decide(merge7(dir, head), { gh: fakeGh(JSON.stringify({ baseRefName: "main" })).gh })) ?? "";
|
|
492
492
|
assert.match(reason, /does not apply: gh returned no base commit for the PR/);
|
|
493
493
|
});
|
|
494
|
+
|
|
495
|
+
test("a merge waits while the newest review of any scope on the head asks for changes", () => {
|
|
496
|
+
const sha = "b".repeat(40);
|
|
497
|
+
const records = [
|
|
498
|
+
{ type: "verdict", kind: "branch", verdict: "CHANGES_REQUIRED", sha, branch: "f", scope: "a" },
|
|
499
|
+
{ type: "verdict", kind: "branch", verdict: "APPROVED", sha, branch: "f", scope: "b" },
|
|
500
|
+
];
|
|
501
|
+
assert.match(mergeVerdict([{ sha }], records, "branch").refusal ?? "", /CHANGES_REQUIRED/);
|
|
502
|
+
records.push({ type: "verdict", kind: "branch", verdict: "APPROVED", sha, branch: "f", scope: "a" });
|
|
503
|
+
assert.equal(mergeVerdict([{ sha }], records, "branch").refusal, null);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
test("a merge needs an APPROVED review of every scope dispatched on the branch", () => {
|
|
507
|
+
const sha = "c".repeat(40);
|
|
508
|
+
const records = [
|
|
509
|
+
{ type: "dispatch", task: false, agentType: "sdd-branch-reviewer", branch: "f", head: sha, scope: "a" },
|
|
510
|
+
{ type: "dispatch", task: false, agentType: "sdd-branch-reviewer", branch: "f", head: sha, scope: "b" },
|
|
511
|
+
{ type: "verdict", kind: "branch", verdict: "APPROVED", sha, branch: "f", scope: "a" },
|
|
512
|
+
];
|
|
513
|
+
assert.match(mergeVerdict([{ sha }], records, "branch").refusal ?? "", /scope "b"/);
|
|
514
|
+
records.push({ type: "verdict", kind: "branch", verdict: "APPROVED", sha, branch: "f", scope: "b" });
|
|
515
|
+
assert.equal(mergeVerdict([{ sha }], records, "branch").refusal, null);
|
|
516
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// `qc migrations renumber`: moves a branch's migrations after the last one of another ref, so two branches
|
|
2
|
+
// that took the same number merge with no duplicate and no gap.
|
|
3
|
+
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
|
|
9
|
+
export const USAGE = `qc migrations — keep migration numbers unique across branches
|
|
10
|
+
|
|
11
|
+
qc migrations renumber --onto <ref> [--branch <ref>]
|
|
12
|
+
rename the migrations <branch> added since its merge base with <ref> to follow the last
|
|
13
|
+
migration of <ref>, in order, and rewrite each reference to an old name in the tracked files.
|
|
14
|
+
<branch> is HEAD by default; during a merge, pass --onto HEAD --branch MERGE_HEAD.`;
|
|
15
|
+
|
|
16
|
+
const MIGRATION = /^(\d+)_(.*\.sql)$/;
|
|
17
|
+
const TEMP_SUFFIX = ".renumber-tmp";
|
|
18
|
+
|
|
19
|
+
function git(cwd, args) {
|
|
20
|
+
const result = spawnSync("git", args, { cwd, encoding: "utf8", windowsHide: true });
|
|
21
|
+
if (result.status !== 0) throw new Error(`git ${args.join(" ")}: ${(result.stderr ?? "").trim() || `exit ${result.status}`}`);
|
|
22
|
+
return result.stdout ?? "";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const lines = (text) => text.split(/\r?\n/).filter(Boolean);
|
|
26
|
+
|
|
27
|
+
/** The folder as git spells it: forward slashes, no trailing slash. */
|
|
28
|
+
export const posixDir = (dir) => String(dir ?? "").replace(/\\/g, "/").replace(/\/+$/, "");
|
|
29
|
+
|
|
30
|
+
function parsed(name) {
|
|
31
|
+
const match = MIGRATION.exec(name);
|
|
32
|
+
return match ? { name, number: Number(match[1]), digits: match[1].length, rest: match[2] } : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The renames that put `added` after the highest number in `existing`, in number order, then name order.
|
|
37
|
+
* @returns `{ from, to }` for each name that changes
|
|
38
|
+
*/
|
|
39
|
+
export function planRenumber(existing, added) {
|
|
40
|
+
const base = existing.map(parsed).filter(Boolean);
|
|
41
|
+
const mine = added.map(parsed).filter(Boolean).sort((a, b) => a.number - b.number || a.name.localeCompare(b.name));
|
|
42
|
+
const last = base.reduce((max, entry) => Math.max(max, entry.number), 0);
|
|
43
|
+
const width = base[0]?.digits ?? mine[0]?.digits ?? 4;
|
|
44
|
+
return mine.flatMap((entry, index) => {
|
|
45
|
+
const to = `${String(last + index + 1).padStart(width, "0")}_${entry.rest}`;
|
|
46
|
+
return to === entry.name ? [] : [{ from: entry.name, to }];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The migration names in `dir` at `ref`; a ref with no such folder holds none. */
|
|
51
|
+
export function migrationsAt(root, ref, dir) {
|
|
52
|
+
try {
|
|
53
|
+
return lines(git(root, ["ls-tree", "--name-only", `${ref}:${dir}`])).filter((name) => MIGRATION.test(name));
|
|
54
|
+
} catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The migration names `branch` added in `dir` since its merge base with `onto`. */
|
|
60
|
+
export function addedMigrations(root, onto, branch, dir) {
|
|
61
|
+
const base = git(root, ["merge-base", onto, branch]).trim();
|
|
62
|
+
return lines(git(root, ["diff", "--name-only", "--diff-filter=A", base, branch, "--", dir]))
|
|
63
|
+
.filter((file) => path.posix.dirname(file) === dir)
|
|
64
|
+
.map((file) => path.posix.basename(file))
|
|
65
|
+
.filter((name) => MIGRATION.test(name));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A stem, matched only where no name character follows it, so `0002_add` leaves `0002_add_index` alone. */
|
|
69
|
+
const stemPattern = (stem) => new RegExp(stem.replace(/\W/g, (c) => `\\${c}`) + "(?![A-Za-z0-9_])", "g");
|
|
70
|
+
|
|
71
|
+
/** Renames through a temporary name, so no rename lands on a file that still exists, then rewrites the references. */
|
|
72
|
+
export function applyRenumber(root, dir, plan) {
|
|
73
|
+
for (const { from } of plan) git(root, ["mv", `${dir}/${from}`, `${dir}/${from}${TEMP_SUFFIX}`]);
|
|
74
|
+
for (const { from, to } of plan) git(root, ["mv", `${dir}/${from}${TEMP_SUFFIX}`, `${dir}/${to}`]);
|
|
75
|
+
const touched = new Set();
|
|
76
|
+
for (const { from, to } of plan) {
|
|
77
|
+
const oldStem = from.replace(/\.sql$/, "");
|
|
78
|
+
const newStem = to.replace(/\.sql$/, "");
|
|
79
|
+
const found = spawnSync("git", ["grep", "-l", "-I", "-F", oldStem, "--", "."], { cwd: root, encoding: "utf8", windowsHide: true });
|
|
80
|
+
for (const file of lines(found.stdout ?? "")) {
|
|
81
|
+
const full = path.join(root, file);
|
|
82
|
+
writeFileSync(full, readFileSync(full, "utf8").replace(stemPattern(oldStem), () => newStem));
|
|
83
|
+
touched.add(file);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (touched.size > 0) git(root, ["add", "--", ...touched]);
|
|
87
|
+
return [...touched];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** @returns the renames made and the files whose references were rewritten */
|
|
91
|
+
export function renumber(root, dir, { onto, branch = "HEAD" }) {
|
|
92
|
+
const folder = posixDir(dir);
|
|
93
|
+
const dirty = git(root, ["status", "--porcelain"]).trim() !== "";
|
|
94
|
+
const merging = spawnSync("git", ["rev-parse", "-q", "--verify", "MERGE_HEAD"], { cwd: root, windowsHide: true }).status === 0;
|
|
95
|
+
if (dirty && !merging) throw new Error("the working tree has uncommitted changes; commit or stash them, or run this during a merge");
|
|
96
|
+
const plan = planRenumber(migrationsAt(root, onto, folder), addedMigrations(root, onto, branch, folder));
|
|
97
|
+
const references = plan.length > 0 ? applyRenumber(root, folder, plan) : [];
|
|
98
|
+
return { plan, references };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `qc migrations`. @returns the exit code */
|
|
102
|
+
export function runMigrations(config, argv, { say = (line) => console.log(line) } = {}) {
|
|
103
|
+
const [sub, ...rest] = argv;
|
|
104
|
+
if (sub !== "renumber") {
|
|
105
|
+
console.error(USAGE);
|
|
106
|
+
return 2;
|
|
107
|
+
}
|
|
108
|
+
let values;
|
|
109
|
+
try {
|
|
110
|
+
({ values } = parseArgs({ args: rest, options: { onto: { type: "string" }, branch: { type: "string" } }, strict: true }));
|
|
111
|
+
if (!values.onto) throw new Error("--onto <ref> is required");
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(`qc migrations: ${error.message}\n\n${USAGE}`);
|
|
114
|
+
return 2;
|
|
115
|
+
}
|
|
116
|
+
const dir = posixDir(config.paths.migrations);
|
|
117
|
+
try {
|
|
118
|
+
const { plan, references } = renumber(config.root, dir, { onto: values.onto, branch: values.branch ?? "HEAD" });
|
|
119
|
+
for (const { from, to } of plan) say(`rename ${dir}/${from} -> ${to}`);
|
|
120
|
+
for (const file of references) say(`ref ${file}`);
|
|
121
|
+
say(plan.length === 0 ? `OK migrations already follow ${values.onto}` : `OK ${plan.length} migration(s) renumbered after ${values.onto}`);
|
|
122
|
+
return 0;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error(`qc migrations: ${error.message}`);
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { planRenumber, renumber } from "./migrations.mjs";
|
|
9
|
+
|
|
10
|
+
const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
11
|
+
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
12
|
+
|
|
13
|
+
function repo(t) {
|
|
14
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-migrations-")));
|
|
15
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
16
|
+
git(dir, "init", "-q", "-b", "main");
|
|
17
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"], ["core.autocrlf", "false"]]) git(dir, "config", key, value);
|
|
18
|
+
commitFile(dir, "db/0001_init.sql", "select 1;\n");
|
|
19
|
+
return dir;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function commitFile(dir, file, text) {
|
|
23
|
+
mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
|
|
24
|
+
writeFileSync(path.join(dir, file), text);
|
|
25
|
+
git(dir, "add", ".");
|
|
26
|
+
git(dir, "commit", "-q", "-m", file);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test("the plan puts the added migrations after the last one, in number order", () => {
|
|
30
|
+
assert.deepEqual(planRenumber(["0001_a.sql", "0002_b.sql"], ["0003_y.sql", "0002_x.sql"]), [
|
|
31
|
+
{ from: "0002_x.sql", to: "0003_x.sql" },
|
|
32
|
+
{ from: "0003_y.sql", to: "0004_y.sql" },
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("a migration already in place is left alone, and a name that is no migration is ignored", () => {
|
|
37
|
+
assert.deepEqual(planRenumber(["0001_a.sql"], ["0002_x.sql", "meta.json"]), []);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("the plan keeps the width of the existing numbers", () => {
|
|
41
|
+
assert.deepEqual(planRenumber(["000009_a.sql"], ["000009_x.sql"]), [{ from: "000009_x.sql", to: "000010_x.sql" }]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("renumber moves the branch's migrations after the base's last, rewrites references, and a second run changes nothing", (t) => {
|
|
45
|
+
const dir = repo(t);
|
|
46
|
+
git(dir, "switch", "-q", "-c", "feat/1-x");
|
|
47
|
+
commitFile(dir, "db/0002_x.sql", "select 2;\n");
|
|
48
|
+
commitFile(dir, "db/meta.json", '{"tag":"0002_x"}\n');
|
|
49
|
+
git(dir, "switch", "-q", "main");
|
|
50
|
+
commitFile(dir, "db/0002_main.sql", "select 3;\n");
|
|
51
|
+
git(dir, "switch", "-q", "feat/1-x");
|
|
52
|
+
git(dir, "merge", "-q", "--no-edit", "main");
|
|
53
|
+
const first = renumber(dir, "db", { onto: "main" });
|
|
54
|
+
assert.deepEqual(first.plan, [{ from: "0002_x.sql", to: "0003_x.sql" }]);
|
|
55
|
+
assert.deepEqual(readdirSync(path.join(dir, "db")).sort(), ["0001_init.sql", "0002_main.sql", "0003_x.sql", "meta.json"]);
|
|
56
|
+
assert.equal(readFileSync(path.join(dir, "db", "meta.json"), "utf8"), '{"tag":"0003_x"}\n');
|
|
57
|
+
git(dir, "commit", "-q", "-m", "renumber");
|
|
58
|
+
assert.deepEqual(renumber(dir, "db", { onto: "main" }).plan, []);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("qc migrations with no subcommand prints its usage and exits 2", (t) => {
|
|
62
|
+
const dir = repo(t);
|
|
63
|
+
const result = spawnSync(process.execPath, [QC, "migrations"], { cwd: dir, encoding: "utf8" });
|
|
64
|
+
assert.equal(result.status, 2);
|
|
65
|
+
assert.match(result.stderr, /qc migrations renumber --onto <ref>/);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("renumber refuses a dirty tree outside a merge", (t) => {
|
|
69
|
+
const dir = repo(t);
|
|
70
|
+
git(dir, "switch", "-q", "-c", "feat/1-x");
|
|
71
|
+
commitFile(dir, "db/0002_x.sql", "select 2;\n");
|
|
72
|
+
writeFileSync(path.join(dir, "stray.txt"), "uncommitted\n");
|
|
73
|
+
assert.throws(() => renumber(dir, "db", { onto: "main" }), /uncommitted|clean/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a stem is rewritten only where no name character follows it", () => {
|
|
77
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-migrations-stem-")));
|
|
78
|
+
try {
|
|
79
|
+
git(dir, "init", "-q", "-b", "main");
|
|
80
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"], ["core.autocrlf", "false"]]) git(dir, "config", key, value);
|
|
81
|
+
commitFile(dir, "db/0001_init.sql", "select 1;\n");
|
|
82
|
+
git(dir, "switch", "-q", "-c", "feat/1-x");
|
|
83
|
+
commitFile(dir, "db/0002_add.sql", "select 2;\n");
|
|
84
|
+
commitFile(dir, "refs.txt", "0002_add 0002_add_index\n");
|
|
85
|
+
git(dir, "switch", "-q", "main");
|
|
86
|
+
commitFile(dir, "db/0002_main.sql", "select 3;\n");
|
|
87
|
+
git(dir, "switch", "-q", "feat/1-x");
|
|
88
|
+
git(dir, "merge", "-q", "--no-edit", "main");
|
|
89
|
+
renumber(dir, "db", { onto: "main" });
|
|
90
|
+
assert.equal(readFileSync(path.join(dir, "refs.txt"), "utf8"), "0003_add 0002_add_index\n");
|
|
91
|
+
} finally {
|
|
92
|
+
rmSync(dir, { recursive: true, force: true });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
@@ -5,6 +5,7 @@ import { test } from "node:test";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { dispatchDefaults, runtimeModels } from "../config.mjs";
|
|
7
7
|
import { REMINDER } from "./dispatch-reminder.mjs";
|
|
8
|
+
import { dispatchRefusal, dispatchSettings } from "./dispatch.mjs";
|
|
8
9
|
|
|
9
10
|
const AGENTS = fileURLToPath(new URL("../../../../agents/", import.meta.url));
|
|
10
11
|
const README = fileURLToPath(new URL("../../../../README.md", import.meta.url));
|
|
@@ -45,6 +46,9 @@ const EXPECTED = {
|
|
|
45
46
|
"sdd-reviewer": { model: "inherit", effort: "high", tools: READ_TOOLS },
|
|
46
47
|
"sdd-branch-reviewer": { model: "inherit", effort: "high", tools: READ_TOOLS },
|
|
47
48
|
};
|
|
49
|
+
// The watcher runs one `qc codex-implement` job. It reads no source, so it needs Bash alone and the cheapest model.
|
|
50
|
+
const WATCHER = { codex: { model: "haiku", effort: undefined, tools: ["Bash"] } };
|
|
51
|
+
const SHIPPED = { ...EXPECTED, ...WATCHER };
|
|
48
52
|
// Fields Claude Code ignores on a plugin agent, and the one that drops a repository's CLAUDE.md and rules.
|
|
49
53
|
const FORBIDDEN_FIELDS = ["disallowedTools", "hooks", "mcpServers", "permissionMode", "omitClaudeMd"];
|
|
50
54
|
|
|
@@ -83,7 +87,7 @@ const frontOf = (name) => frontmatterOf(path.join(AGENTS, `${name}.md`));
|
|
|
83
87
|
test("each subagent type inherits the session model, has a model in every runtime, and keeps its effort and tool list", () => {
|
|
84
88
|
assert.deepEqual(
|
|
85
89
|
readdirSync(AGENTS).sort(),
|
|
86
|
-
Object.keys(
|
|
90
|
+
Object.keys(SHIPPED).map((name) => `${name}.md`).sort(),
|
|
87
91
|
"agents/ holds exactly the shipped types",
|
|
88
92
|
);
|
|
89
93
|
for (const [name, want] of Object.entries(EXPECTED)) {
|
|
@@ -100,20 +104,21 @@ test("each subagent type inherits the session model, has a model in every runtim
|
|
|
100
104
|
}
|
|
101
105
|
});
|
|
102
106
|
|
|
103
|
-
test("each listed tool is one a subagent keeps, never Agent and never an MCP tool, and
|
|
104
|
-
for (const name of Object.keys(
|
|
107
|
+
test("each listed tool is one a subagent keeps, never Agent and never an MCP tool, and Bash is always there", () => {
|
|
108
|
+
for (const name of Object.keys(SHIPPED)) {
|
|
105
109
|
const tools = listOf(frontOf(name).tools);
|
|
106
110
|
assert.ok(!tools.includes("Agent"), `${name} can dispatch a subagent`);
|
|
107
111
|
for (const tool of tools) {
|
|
108
112
|
assert.ok(!tool.startsWith("mcp__"), `${name} lists the MCP tool ${tool}`);
|
|
109
113
|
assert.ok(SUBAGENT_TOOLS.has(tool), `${name} lists ${tool}, which no subagent keeps`);
|
|
110
114
|
}
|
|
111
|
-
|
|
115
|
+
assert.ok(tools.includes("Bash"), `${name} lacks Bash`);
|
|
116
|
+
if (name in EXPECTED) assert.ok(tools.includes("Read"), `${name} lacks Read`);
|
|
112
117
|
}
|
|
113
118
|
});
|
|
114
119
|
|
|
115
120
|
test("no type sets a field a plugin agent ignores, or one that drops the repository's CLAUDE.md", () => {
|
|
116
|
-
for (const name of Object.keys(
|
|
121
|
+
for (const name of Object.keys(SHIPPED)) {
|
|
117
122
|
const front = frontOf(name);
|
|
118
123
|
for (const field of FORBIDDEN_FIELDS) assert.equal(front[field], undefined, `${name} sets ${field}`);
|
|
119
124
|
}
|
|
@@ -121,8 +126,8 @@ test("no type sets a field a plugin agent ignores, or one that drops the reposit
|
|
|
121
126
|
|
|
122
127
|
test("the README table gives each shipped type the tools its definition lists, and no other type", () => {
|
|
123
128
|
const documented = readmeToolsOf(readFileSync(README, "utf8"));
|
|
124
|
-
assert.deepEqual(Object.keys(documented).sort(), Object.keys(
|
|
125
|
-
for (const [name, want] of Object.entries(
|
|
129
|
+
assert.deepEqual(Object.keys(documented).sort(), Object.keys(SHIPPED).sort());
|
|
130
|
+
for (const [name, want] of Object.entries(SHIPPED)) assert.deepEqual(documented[name], want.tools, name);
|
|
126
131
|
});
|
|
127
132
|
|
|
128
133
|
test("the README reader takes a CRLF checkout and skips the rows of other tables", () => {
|
|
@@ -149,7 +154,7 @@ test("the default allowed types are the shipped types, bare and scoped", () => {
|
|
|
149
154
|
|
|
150
155
|
test("no type pins a prompt cache lifetime, so a user's own setting decides it", () => {
|
|
151
156
|
// The measured one-hour lifetime cost more for all four types; `qc tokens` reports it per session.
|
|
152
|
-
for (const name of Object.keys(
|
|
157
|
+
for (const name of Object.keys(SHIPPED)) {
|
|
153
158
|
const front = frontOf(name);
|
|
154
159
|
assert.equal(front.experimental, undefined, `${name} sets experimental`);
|
|
155
160
|
assert.equal(front.cacheTtl, undefined, `${name} sets cacheTtl`);
|
|
@@ -166,3 +171,25 @@ test("both reviewers review only the increment when the dispatch carries a Revie
|
|
|
166
171
|
assert.ok(text.indexOf("`Reviewed: <sha>`") < text.indexOf("`VERDICT: APPROVED <sha>`"), `${name} keeps the verdict line rule last`);
|
|
167
172
|
}
|
|
168
173
|
});
|
|
174
|
+
|
|
175
|
+
test("the codex watcher runs on haiku with Bash alone, and the guard accepts haiku or sonnet for it", () => {
|
|
176
|
+
const front = frontOf("codex");
|
|
177
|
+
assert.equal(front.name, "codex");
|
|
178
|
+
assert.equal(front.model, WATCHER.codex.model);
|
|
179
|
+
assert.deepEqual(listOf(front.tools), WATCHER.codex.tools);
|
|
180
|
+
for (const type of ["codex", `${PLUGIN}:codex`]) assert.deepEqual(runtimeModels.claude[type], ["haiku", "sonnet"], type);
|
|
181
|
+
const settings = dispatchSettings({ dispatch: {} }, "claude");
|
|
182
|
+
for (const model of ["haiku", "sonnet"]) {
|
|
183
|
+
assert.equal(dispatchRefusal({ subagent_type: `${PLUGIN}:codex`, model, prompt: "Brief: b" }, settings), null, model);
|
|
184
|
+
}
|
|
185
|
+
assert.match(dispatchRefusal({ subagent_type: `${PLUGIN}:codex`, model: "opus", prompt: "Brief: b" }, settings) ?? "", /haiku, sonnet/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("the codex watcher starts one background job and polls the wrapper file with until grep", () => {
|
|
189
|
+
const text = readFileSync(path.join(AGENTS, "codex.md"), "utf8").replace(/\r/g, "");
|
|
190
|
+
assert.ok(text.includes("run_in_background: true"));
|
|
191
|
+
assert.ok(text.includes("codex-implement --brief"));
|
|
192
|
+
assert.ok(text.includes("until grep -q"));
|
|
193
|
+
assert.ok(text.includes("Never pipe `tail -f` into `grep -m1`"));
|
|
194
|
+
assert.ok(!/^\s*tail -f/m.test(text), "no step runs tail -f");
|
|
195
|
+
});
|
package/src/cli/qc.mjs
CHANGED
|
@@ -24,14 +24,33 @@ const USAGE = `qc — architecture gates
|
|
|
24
24
|
qc decisions [id] where decisions are cited; --squash closes the gaps
|
|
25
25
|
qc ledger [--cost] [branch] the workflow ledger: dispatches, stops, verdicts, merges, issue updates; --cost totals tokens and tool calls
|
|
26
26
|
qc codex-implement --brief <file> --worktree <path> --progress <file> [--log <file>] [--max-runs <n>]
|
|
27
|
-
run a brief through codex exec as an implementer
|
|
27
|
+
run a brief through codex exec as an implementer; done means the last non-empty progress line equals ALL TASKS DONE after trimming whitespace
|
|
28
|
+
the runner supplies the marker; write it as the last line, alone, only when the exit criteria hold; never quote it elsewhere or wait for it; exit 2 on a Codex limit
|
|
29
|
+
qc gate-slot [--slots <n>] -- <command...>
|
|
30
|
+
run a heavy local command in one of the machine's gate slots; --status lists them
|
|
31
|
+
qc watch [--pr <n>]... [--codex <wrapper.log>]... [--run <workflow>@<branch>]... [--max <minutes>] [--repo <owner/name>] [--interval <seconds>]
|
|
32
|
+
block until the first event among the items, print one EVENT line; exit 0 done, 4 bound (default 55 minutes), 5 failed, 6 queued past 15 minutes
|
|
33
|
+
qc screens --map <json> --targets <left,right> --out <dir> [--only <names>] [--changed <target>]
|
|
34
|
+
capture authenticated screen pairs, compare pixels, and write a static gallery
|
|
35
|
+
qc stack up|down|status [names...] [--timeout <milliseconds>]
|
|
36
|
+
run repository plugins from ~/.qc/stacks.json
|
|
28
37
|
qc plan-check <plan.md> each task names files, a test step and a commit step, within the tool-call budget
|
|
29
38
|
qc tokens [--session <id>] [--project <dir>] [--claude-dir <dir>] [--json]
|
|
30
39
|
one session's tokens and cache hit rate per agent type, from its transcripts
|
|
40
|
+
qc throwaway-db [--port <n>|auto] -- <command...>
|
|
41
|
+
run a command on a database of its own, in a container on a free port
|
|
42
|
+
qc retry-failed --report <json> --rerun "<command>" -- <command...>
|
|
43
|
+
rerun only the failed test files once before the run fails
|
|
44
|
+
qc ui <catalog|find|dupes|codemod>
|
|
45
|
+
the component catalog, a search over it, a duplicate finder and a class-token codemod
|
|
31
46
|
qc worktree add <name> <branch> [--from <ref>]
|
|
32
47
|
fetch, add .worktree/<name> in the main checkout, install, print the path
|
|
33
48
|
qc worktree remove <name>
|
|
34
49
|
refuse a dirty tree; delete it, then its branch once merged, pushed, or a merged PR head
|
|
50
|
+
qc migrations renumber --onto <ref> [--branch <ref>]
|
|
51
|
+
move this branch's migrations after the last one of <ref>, and rewrite references
|
|
52
|
+
qc integrate --issue <n> [--type <t>] [--slug <s>] [--from <ref>] <branch>...
|
|
53
|
+
one <t>/<n>-<s> branch for a batch: merge, renumber, regenerate; stop on a conflict
|
|
35
54
|
qc enforcement-map refresh the generated rule/gate table in docs/enforcement.md
|
|
36
55
|
qc doctor the hooks and the lockfile must run the same harness
|
|
37
56
|
qc config print the resolved configuration
|
|
@@ -40,6 +59,14 @@ Every gate reads qc.config.json. A key it does not set keeps the reference defau
|
|
|
40
59
|
|
|
41
60
|
async function main() {
|
|
42
61
|
const [command, ...rest] = process.argv.slice(2);
|
|
62
|
+
if (command === "stack") {
|
|
63
|
+
const { runStack } = await import("./stack.mjs");
|
|
64
|
+
process.exit(await runStack(rest));
|
|
65
|
+
}
|
|
66
|
+
if (command === "screens") {
|
|
67
|
+
const { runScreens } = await import("./screens.mjs");
|
|
68
|
+
process.exit(await runScreens(rest));
|
|
69
|
+
}
|
|
43
70
|
// A broken qc.config.json must not keep a lease in place, so the lease runs before the load.
|
|
44
71
|
if (command === "lease") {
|
|
45
72
|
const { runLease } = await import("./lease.mjs");
|
|
@@ -50,6 +77,16 @@ async function main() {
|
|
|
50
77
|
const { runCodexImplement } = await import("./codex-implement.mjs");
|
|
51
78
|
process.exit(await runCodexImplement(rest));
|
|
52
79
|
}
|
|
80
|
+
// The slots are machine-wide, so the runner reads no configuration.
|
|
81
|
+
if (command === "gate-slot") {
|
|
82
|
+
const { runGateSlot } = await import("./gate-slot.mjs");
|
|
83
|
+
process.exit(await runGateSlot(rest));
|
|
84
|
+
}
|
|
85
|
+
// The watcher reads no configuration either.
|
|
86
|
+
if (command === "watch") {
|
|
87
|
+
const { runWatch } = await import("./watch.mjs");
|
|
88
|
+
process.exit(await runWatch(rest));
|
|
89
|
+
}
|
|
53
90
|
const config = load(process.cwd());
|
|
54
91
|
|
|
55
92
|
switch (command) {
|
|
@@ -115,6 +152,14 @@ async function main() {
|
|
|
115
152
|
const { runTokens } = await import("./tokens.mjs");
|
|
116
153
|
process.exit(runTokens(config, rest));
|
|
117
154
|
}
|
|
155
|
+
case "throwaway-db": {
|
|
156
|
+
const { runThrowawayDb } = await import("./throwaway-db.mjs");
|
|
157
|
+
process.exit(await runThrowawayDb(config, rest));
|
|
158
|
+
}
|
|
159
|
+
case "retry-failed": {
|
|
160
|
+
const { runRetryFailed } = await import("./retry-failed.mjs");
|
|
161
|
+
process.exit(await runRetryFailed(rest));
|
|
162
|
+
}
|
|
118
163
|
case "decisions": {
|
|
119
164
|
const { runDecisions } = await import("./decisions.mjs");
|
|
120
165
|
process.exit(await runDecisions(config, rest));
|
|
@@ -124,6 +169,18 @@ async function main() {
|
|
|
124
169
|
const { runWorktree } = await import("./worktree.mjs");
|
|
125
170
|
process.exit(await runWorktree(config, rest));
|
|
126
171
|
}
|
|
172
|
+
case "migrations": {
|
|
173
|
+
const { runMigrations } = await import("./migrations.mjs");
|
|
174
|
+
process.exit(runMigrations(config, rest));
|
|
175
|
+
}
|
|
176
|
+
case "integrate": {
|
|
177
|
+
const { runIntegrate } = await import("./integrate.mjs");
|
|
178
|
+
process.exit(await runIntegrate(config, rest));
|
|
179
|
+
}
|
|
180
|
+
case "ui": {
|
|
181
|
+
const { runUi } = await import("./ui.mjs");
|
|
182
|
+
process.exit(await runUi(config, rest));
|
|
183
|
+
}
|
|
127
184
|
case "enforcement-map": {
|
|
128
185
|
const { runSyncEnforcementMap } = await import("./sync-enforcement-map.mjs");
|
|
129
186
|
await runSyncEnforcementMap(config);
|
package/src/cli/report-stop.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { checkoutRootOf } from "./checkout-root.mjs";
|
|
|
8
8
|
import { branchAt, branchesAt, gitOut, pathKey } from "./git-read.mjs";
|
|
9
9
|
import { checkHandoffFile, handoffPathOf } from "./handoff-note.mjs";
|
|
10
10
|
import { appendRecord, readLedger } from "./ledger.mjs";
|
|
11
|
+
import { scopeOf } from "./review-gate.mjs";
|
|
11
12
|
import { dropReport, keepReport, reportOf } from "./report-stash.mjs";
|
|
12
13
|
import { commitLookup, firstUserText, resolveNamedWorktree, workflowOfRepo } from "./workflow-place.mjs";
|
|
13
14
|
import { agentTranscriptOf } from "./transcript-usage.mjs";
|
|
@@ -165,6 +166,7 @@ function recordStop({ workflow, call, session, agentId, role, worktree, verdict,
|
|
|
165
166
|
appendRecord(workflow.ledger, { type: "stop", session, agentType: call.agent_type, agentId, role, ...place, ...handedOff });
|
|
166
167
|
// A failed read keeps the sha as the reviewer wrote it, which the gates match by prefix.
|
|
167
168
|
const sha = lookup?.sha ?? (lookup?.error ? verdict.sha : null);
|
|
169
|
+
const scope = role === "branch" ? scopeOf(firstUserText(agentTranscriptOf(call))) : null;
|
|
168
170
|
if (verdict && sha) {
|
|
169
171
|
appendRecord(workflow.ledger, {
|
|
170
172
|
type: "verdict",
|
|
@@ -175,6 +177,7 @@ function recordStop({ workflow, call, session, agentId, role, worktree, verdict,
|
|
|
175
177
|
sha,
|
|
176
178
|
branch: lookup.sha ? branchOf(workflow, sha, { worktree, dispatches: dispatchesOf(records, session) }) : null,
|
|
177
179
|
redChecked: RED_CHECKED_LINE.test(text),
|
|
180
|
+
...(scope ? { scope } : {}),
|
|
178
181
|
});
|
|
179
182
|
}
|
|
180
183
|
dropReport(session, agentId, tmp);
|
|
@@ -542,3 +542,11 @@ test("the no-transcript line is left off for an agent type the workflow does not
|
|
|
542
542
|
assert.equal(decide(bare(stop(ws.on, "Explore", "done")), ws.tmp), null);
|
|
543
543
|
assert.equal(decide(bare(handback(ws.on, "Explore", "done")), ws.tmp), null);
|
|
544
544
|
});
|
|
545
|
+
|
|
546
|
+
test("a branch review records the scope its prompt names on its verdict", (t) => {
|
|
547
|
+
const ws = workspace(t);
|
|
548
|
+
const named = { agent_transcript_path: transcript(ws, "scoped", `Review the branch.\nWorktree: ${ws.on}\nScope: Photos\n`) };
|
|
549
|
+
decide({ ...stop(ws.on, "architecture:sdd-branch-reviewer", `VERDICT: APPROVED ${ws.head}\nAll good.`), ...named }, ws.tmp);
|
|
550
|
+
const verdict = readLedger(ws.ledger).find((record) => record.type === "verdict");
|
|
551
|
+
assert.equal(verdict?.scope, "photos");
|
|
552
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// `qc retry-failed`: a run that fails only in a few test files reruns those files once before it fails.
|
|
2
|
+
// A load flake passes on the rerun; a real failure fails twice, and any other failure is never rerun.
|
|
3
|
+
|
|
4
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { commandLine, runInShell, splitAtDashes } from "./child-run.mjs";
|
|
8
|
+
|
|
9
|
+
export const USAGE = `qc retry-failed — rerun only the failed test files, once, before a run fails
|
|
10
|
+
|
|
11
|
+
qc retry-failed --report <json> --rerun "<command>" [--max-files <n>] -- <command...>
|
|
12
|
+
run <command>. When it fails and <json>, the Jest or Vitest JSON report the run wrote, names at
|
|
13
|
+
most --max-files failed test files (5 by default), run "<rerun> <files>" once and exit with its
|
|
14
|
+
code. Any other failure exits with the first code. The report is removed before the run.`;
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_MAX_FILES = 5;
|
|
17
|
+
|
|
18
|
+
const readText = (file) => {
|
|
19
|
+
try {
|
|
20
|
+
return readFileSync(file, "utf8");
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The failed test files of a Jest or Vitest JSON report, relative to `root`, or null when the text is no such report. */
|
|
27
|
+
export function failedFiles(text, root) {
|
|
28
|
+
let report;
|
|
29
|
+
try {
|
|
30
|
+
report = JSON.parse(text);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!report || !Array.isArray(report.testResults)) return null;
|
|
35
|
+
return report.testResults
|
|
36
|
+
.filter((result) => result?.status === "failed" && typeof result.name === "string")
|
|
37
|
+
.map((result) => (path.isAbsolute(result.name) ? path.relative(root, result.name) : result.name).split(path.sep).join("/"));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `qc retry-failed`. @returns the exit code */
|
|
41
|
+
export async function runRetryFailed(argv, deps = {}) {
|
|
42
|
+
const {
|
|
43
|
+
run = runInShell,
|
|
44
|
+
read = readText,
|
|
45
|
+
remove = (file) => rmSync(file, { force: true }),
|
|
46
|
+
cwd = process.cwd(),
|
|
47
|
+
env = process.env,
|
|
48
|
+
say = (line) => console.error(line),
|
|
49
|
+
} = deps;
|
|
50
|
+
const { flags, command } = splitAtDashes(argv);
|
|
51
|
+
let values;
|
|
52
|
+
let maxFiles;
|
|
53
|
+
try {
|
|
54
|
+
({ values } = parseArgs({ args: flags, options: { report: { type: "string" }, rerun: { type: "string" }, "max-files": { type: "string" } }, strict: true }));
|
|
55
|
+
if (!values.report || !values.rerun || command.length === 0) throw new Error("--report, --rerun, and a command after -- are required");
|
|
56
|
+
maxFiles = Number(values["max-files"] ?? DEFAULT_MAX_FILES);
|
|
57
|
+
if (!Number.isInteger(maxFiles) || maxFiles < 1) throw new Error(`--max-files must be a positive integer, got ${values["max-files"]}`);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
say(`qc retry-failed: ${error.message}\n\n${USAGE}`);
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
const reportFile = path.resolve(cwd, values.report);
|
|
63
|
+
remove(reportFile);
|
|
64
|
+
const first = await run(commandLine(command), env, cwd);
|
|
65
|
+
if (first === 0) return 0;
|
|
66
|
+
const text = read(reportFile);
|
|
67
|
+
const files = text === null ? null : failedFiles(text, cwd);
|
|
68
|
+
if (files === null || files.length === 0) {
|
|
69
|
+
say(`qc retry-failed: the run failed with no failed test file in ${values.report}, so nothing is rerun`);
|
|
70
|
+
return first;
|
|
71
|
+
}
|
|
72
|
+
if (files.length > maxFiles) {
|
|
73
|
+
say(`qc retry-failed: ${files.length} test files failed, over --max-files ${maxFiles}, so nothing is rerun`);
|
|
74
|
+
return first;
|
|
75
|
+
}
|
|
76
|
+
say(`qc retry-failed: ${files.length} test file(s) failed; rerunning them once: ${files.join(" ")}`);
|
|
77
|
+
const second = await run(`${values.rerun} ${commandLine(files)}`, env, cwd);
|
|
78
|
+
if (second === 0) say(`qc retry-failed: the rerun passed, so these files are flaky: ${files.join(" ")}`);
|
|
79
|
+
return second;
|
|
80
|
+
}
|