architecture-harness 0.25.0 → 0.26.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 +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const qc = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
10
|
+
|
|
11
|
+
test("help describes full checks, previews, and readiness", () => {
|
|
12
|
+
const run = spawnSync(process.execPath, [qc, "help"], { encoding: "utf8" });
|
|
13
|
+
assert.equal(run.status, 0);
|
|
14
|
+
assert.match(run.stdout, /qc check --full \[--os <linux\|windows>\]/);
|
|
15
|
+
assert.match(run.stdout, /qc ci-preview \[--os <linux\|windows\|both>\]/);
|
|
16
|
+
assert.match(run.stdout, /qc ready-check/);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("help describes the operator pause commands and exit 5", () => {
|
|
20
|
+
const run = spawnSync(process.execPath, [qc, "help"], { encoding: "utf8" });
|
|
21
|
+
assert.equal(run.status, 0);
|
|
22
|
+
assert.match(run.stdout, /qc pause \[--reason <text>\]/);
|
|
23
|
+
assert.match(run.stdout, /qc resume/);
|
|
24
|
+
assert.match(run.stdout, /exit 5.*paused/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("help describes the Codex limit expiry time", () => {
|
|
28
|
+
const run = spawnSync(process.execPath, [qc, "help"], { encoding: "utf8" });
|
|
29
|
+
assert.equal(run.status, 0);
|
|
30
|
+
assert.match(run.stdout, /qc codex status[^\n]*with the expiry time and its source/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("overview and debt commands advertise usage and propagate exits", (t) => {
|
|
34
|
+
const root = fixture(t, "{}");
|
|
35
|
+
const run = (args) => spawnSync(process.execPath, [qc, ...args], { cwd: root, encoding: "utf8" });
|
|
36
|
+
const help = run(["help"]);
|
|
37
|
+
for (const command of ["qc overview", "qc debt file <report>", "qc debt due"]) assert.ok(help.stdout.includes(command));
|
|
38
|
+
for (const args of [["overview", "extra"], ["debt"], ["debt", "file"], ["debt", "due", "extra"]]) assert.equal(run(args).status, 1);
|
|
39
|
+
assert.equal(run(["debt", "due"]).status, 3);
|
|
40
|
+
assert.equal(run(["debt", "file", "missing.md"]).status, 3);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function fixture(t, contents) {
|
|
44
|
+
const root = mkdtempSync(path.join(tmpdir(), "qc-cli-"));
|
|
45
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }));
|
|
46
|
+
writeFileSync(path.join(root, "qc.config.json"), contents);
|
|
47
|
+
return root;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test("an invalid integrate key prints one config error across commands", (t) => {
|
|
51
|
+
const root = fixture(t, JSON.stringify({ integrate: { ciEvery: 0 } }));
|
|
52
|
+
for (const command of ["config", "check", "lint", "typecheck", "e2e"]) {
|
|
53
|
+
const run = spawnSync(process.execPath, [qc, command], { cwd: root, encoding: "utf8" });
|
|
54
|
+
assert.equal(run.status, 1, command);
|
|
55
|
+
assert.equal(run.stdout, "", command);
|
|
56
|
+
assert.equal(run.stderr, "qc: invalid qc.config.json: integrate.ciEvery must be a positive integer\n", command);
|
|
57
|
+
assert.doesNotMatch(run.stderr, /^\s+at /m, command);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a JSON syntax error keeps its stack trace", (t) => {
|
|
62
|
+
const root = fixture(t, "{");
|
|
63
|
+
const run = spawnSync(process.execPath, [qc, "config"], { cwd: root, encoding: "utf8" });
|
|
64
|
+
assert.equal(run.status, 1);
|
|
65
|
+
assert.match(run.stderr, /SyntaxError:/);
|
|
66
|
+
assert.match(run.stderr, /^\s+at /m);
|
|
67
|
+
assert.doesNotMatch(run.stderr, /qc: invalid qc\.config\.json:/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("an error after loading config keeps its stack trace", (t) => {
|
|
71
|
+
const root = fixture(t, "{}");
|
|
72
|
+
const run = spawnSync(process.execPath, [qc, "check", "--files-from", "missing-files"], { cwd: root, encoding: "utf8" });
|
|
73
|
+
assert.equal(run.status, 1);
|
|
74
|
+
assert.match(run.stderr, /ENOENT/);
|
|
75
|
+
assert.match(run.stderr, /^\s+at /m);
|
|
76
|
+
assert.doesNotMatch(run.stderr, /qc: invalid qc\.config\.json:/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("milestone help and dispatch expose dry-run and drop", (t) => {
|
|
80
|
+
const help = spawnSync(process.execPath, [qc, "help"], { encoding: "utf8" });
|
|
81
|
+
assert.match(help.stdout, /qc milestone.*--dry-run.*--drop/);
|
|
82
|
+
const root = fixture(t, "{}");
|
|
83
|
+
const result = spawnSync(process.execPath, [qc, "milestone", "--unknown"], { cwd: root, encoding: "utf8" });
|
|
84
|
+
assert.equal(result.status, 2);
|
|
85
|
+
assert.match(result.stderr, /qc milestone/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("milestone names pass the commit-time branch check without widening issue branch patterns", async () => {
|
|
89
|
+
const { branchNameRefusal } = await import("./work-order-guard.mjs");
|
|
90
|
+
const settings = { pattern: "^[a-z]+/[0-9]+-", allow: ["main"] };
|
|
91
|
+
assert.equal(branchNameRefusal("milestone/2026-11-23-1", settings), null);
|
|
92
|
+
for (const branch of ["milestone/wrong", "milestone/2026-11-23-0", "feat/wrong"]) assert.match(branchNameRefusal(branch, settings) ?? "", /names no issue/);
|
|
93
|
+
});
|
package/src/cli/report-stop.mjs
CHANGED
|
@@ -59,6 +59,11 @@ export function reportProblems(role, text, verdict, lookup, named, handoff = nul
|
|
|
59
59
|
return problems;
|
|
60
60
|
}
|
|
61
61
|
if (!verdict) return ["a first line `VERDICT: APPROVED <sha>` or `VERDICT: CHANGES_REQUIRED <sha>`, where <sha> is the commit you reviewed"];
|
|
62
|
+
const unreviewedFiles = [...text.matchAll(/^[ \t]*UNREVIEWED:[ \t]*(\S[^\r\n]*)$/gm)]
|
|
63
|
+
.some((match) => match[1].trim().toLowerCase() !== "none");
|
|
64
|
+
if (verdict.verdict === "APPROVED" && unreviewedFiles) {
|
|
65
|
+
return ["a CHANGES_REQUIRED verdict when UNREVIEWED: lists files"];
|
|
66
|
+
}
|
|
62
67
|
if (lookup?.unknown && named) return [`a sha this repository holds, and ${verdict.sha} names no commit (git rev-parse)`];
|
|
63
68
|
if (role === "task" && verdict.verdict === "APPROVED" && !RED_CHECKED_LINE.test(text)) {
|
|
64
69
|
return ["a line that starts `RED-CHECKED:` and says how you saw the test fail before the code"];
|
|
@@ -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 { branchOf, decide, verdictOf } from "./report-stop.mjs";
|
|
9
|
+
import { branchOf, decide, reportProblems, verdictOf } from "./report-stop.mjs";
|
|
10
10
|
import { judgeTask } from "./task-gate.mjs";
|
|
11
11
|
import { BRIEF } from "./test-brief.mjs";
|
|
12
12
|
import { rememberSession } from "./workflow-settings.mjs";
|
|
@@ -107,6 +107,28 @@ test("a reviewer hand-back without its verdict line, or with a sha the repositor
|
|
|
107
107
|
);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
test("a partial review requires CHANGES_REQUIRED for every reviewer role", () => {
|
|
111
|
+
for (const role of ["task", "branch", "architecture", "security"]) {
|
|
112
|
+
const report = "VERDICT: APPROVED abc1234\nRED-CHECKED: the test failed\n UNREVIEWED: x.mjs\n";
|
|
113
|
+
assert.match(reportProblems(role, report, verdictOf(report), null, false).join(" "), /CHANGES_REQUIRED.*UNREVIEWED/);
|
|
114
|
+
const partial = report.replace("APPROVED", "CHANGES_REQUIRED");
|
|
115
|
+
assert.deepEqual(reportProblems(role, partial, verdictOf(partial), null, false), []);
|
|
116
|
+
const complete = report.replace("x.mjs", " \t");
|
|
117
|
+
assert.deepEqual(reportProblems(role, complete, verdictOf(complete), null, false), []);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
for (const value of ["none", "NONE", "NoNe"]) {
|
|
122
|
+
test(`UNREVIEWED: ${value} is an empty list for every reviewer role`, () => {
|
|
123
|
+
for (const role of ["task", "branch", "architecture", "security"]) {
|
|
124
|
+
const report = `VERDICT: APPROVED abc1234\nRED-CHECKED: the test failed\n UNREVIEWED: ${value} \t\n`;
|
|
125
|
+
assert.deepEqual(reportProblems(role, report, verdictOf(report), null, false), []);
|
|
126
|
+
const partial = `${report}UNREVIEWED: x.mjs\n`;
|
|
127
|
+
assert.match(reportProblems(role, partial, verdictOf(partial), null, false).join(" "), /CHANGES_REQUIRED.*UNREVIEWED/);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
110
132
|
test("a task APPROVED needs a RED-CHECKED line, and CHANGES_REQUIRED does not", (t) => {
|
|
111
133
|
const ws = workspace(t);
|
|
112
134
|
const sha = ws.head.slice(0, 7);
|
package/src/cli/retry-failed.mjs
CHANGED
|
@@ -50,9 +50,11 @@ export async function runRetryFailed(argv, deps = {}) {
|
|
|
50
50
|
const { flags, command } = splitAtDashes(argv);
|
|
51
51
|
let values;
|
|
52
52
|
let maxFiles;
|
|
53
|
+
let line;
|
|
53
54
|
try {
|
|
54
55
|
({ values } = parseArgs({ args: flags, options: { report: { type: "string" }, rerun: { type: "string" }, "max-files": { type: "string" } }, strict: true }));
|
|
55
56
|
if (!values.report || !values.rerun || command.length === 0) throw new Error("--report, --rerun, and a command after -- are required");
|
|
57
|
+
line = commandLine(command);
|
|
56
58
|
maxFiles = Number(values["max-files"] ?? DEFAULT_MAX_FILES);
|
|
57
59
|
if (!Number.isInteger(maxFiles) || maxFiles < 1) throw new Error(`--max-files must be a positive integer, got ${values["max-files"]}`);
|
|
58
60
|
} catch (error) {
|
|
@@ -61,7 +63,7 @@ export async function runRetryFailed(argv, deps = {}) {
|
|
|
61
63
|
}
|
|
62
64
|
const reportFile = path.resolve(cwd, values.report);
|
|
63
65
|
remove(reportFile);
|
|
64
|
-
const first = await run(
|
|
66
|
+
const first = await run(line, env, cwd);
|
|
65
67
|
if (first === 0) return 0;
|
|
66
68
|
const text = read(reportFile);
|
|
67
69
|
const files = text === null ? null : failedFiles(text, cwd);
|
package/src/cli/review-gate.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// The checks of `swarm.review` that read a dispatch prompt and its branch: one branch review, a head that
|
|
2
|
-
//
|
|
2
|
+
// meets the CI policy and holds the base tip, and a brief with product decisions. The task gate calls them.
|
|
3
3
|
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { gitOutWithin, isAncestor, remoteTip } from "./git-read.mjs";
|
|
7
|
-
import { shaMatches } from "./ledger.mjs";
|
|
7
|
+
import { shaMatches, ledgerFileOf, readLedger } from "./ledger.mjs";
|
|
8
|
+
import { ciBriefRefusal, currentBranch, openFailures } from "./ci-failures.mjs";
|
|
9
|
+
import { holdRefusal } from "./pause.mjs";
|
|
10
|
+
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
8
11
|
import { commitLookup, nativePath } from "./workflow-place.mjs";
|
|
9
12
|
|
|
10
13
|
// Every read of a reviewer dispatch is capped, so the whole guard ends inside the Agent hook's 30 second limit.
|
|
@@ -121,8 +124,8 @@ export function baseCheck({ root, base, head, reads = defaultReads }) {
|
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
/**
|
|
124
|
-
* The reviewer checks, in cheap-first order: one branch review, the base tip,
|
|
125
|
-
* `ciState(sha)` is `{ reason, unknown }`; `reads` answers the base check.
|
|
127
|
+
* The reviewer checks, in cheap-first order: one branch review, the base tip, the CI policy.
|
|
128
|
+
* `ciState(sha)` is `{ reason, unknown, pending? }`; `reads` answers the base check.
|
|
126
129
|
* @returns `{ refusal, note }`
|
|
127
130
|
*/
|
|
128
131
|
export function reviewerCheck({ type, prompt, review, base, records, root, branch, head, ciState, reads = defaultReads }) {
|
|
@@ -140,11 +143,12 @@ export function reviewerCheck({ type, prompt, review, base, records, root, branc
|
|
|
140
143
|
}
|
|
141
144
|
if (review.requireGreen) {
|
|
142
145
|
const state = ciState(head);
|
|
143
|
-
if (state.reason) {
|
|
146
|
+
if (state.reason && !(review.requireGreen === "not-red" && state.pending)) {
|
|
144
147
|
return refuse(
|
|
145
148
|
`Task gate: ${state.reason}. A review waits for green CI on the head, since a red head changes before it is reviewed. Wait for the run, or fix the failure, then dispatch the review.`,
|
|
146
149
|
);
|
|
147
150
|
}
|
|
151
|
+
if (state.reason && state.pending) notes.push(`Task gate: ${state.reason}. The review proceeds while CI runs.`);
|
|
148
152
|
if (state.unknown) notes.push(`Task gate: CI on ${short(head)} is unknown: ${state.unknown}. The review proceeds.`);
|
|
149
153
|
}
|
|
150
154
|
return pass(notes.length > 0 ? notes.join(" ") : null);
|
|
@@ -201,10 +205,24 @@ function briefOf(prompt, dirs, exists, read) {
|
|
|
201
205
|
* @returns `{ refusal, note }`
|
|
202
206
|
*/
|
|
203
207
|
export function briefCheck({ prompt, dirs, review, exists = existsSync, read = (file) => readFileSync(file, "utf8") }) {
|
|
204
|
-
|
|
208
|
+
let ciRoot;
|
|
209
|
+
let branch;
|
|
210
|
+
for (const dir of [...dirs].reverse()) {
|
|
211
|
+
const root = checkoutRootOf(dir);
|
|
212
|
+
const ledger = root && ledgerFileOf(root);
|
|
213
|
+
if (!ledger || !readLedger(ledger).some((r) => r.type === "ci-failure")) continue;
|
|
214
|
+
branch = currentBranch(root);
|
|
215
|
+
const hold = branch ? holdRefusal(root, branch) : null;
|
|
216
|
+
if (hold) return refuse(hold);
|
|
217
|
+
if (openFailures(root, branch).length) ciRoot = root;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
if (!ciRoot && !review.productDecisions && review.roundFindings <= 0 && review.roundFiles <= 0) return pass();
|
|
205
221
|
const brief = briefOf(prompt, dirs, exists, read);
|
|
206
222
|
if (brief.refusal) return refuse(brief.refusal);
|
|
207
223
|
const { text, source } = brief;
|
|
224
|
+
const ciRefusal = ciRoot && ciBriefRefusal(ciRoot, branch, text);
|
|
225
|
+
if (ciRefusal) return refuse(`Task gate: ${ciRefusal}`);
|
|
208
226
|
const decisions = review.productDecisions ? productDecisionsOf(text) : undefined;
|
|
209
227
|
if (decisions === null) {
|
|
210
228
|
return refuse(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import { reviewDefaults } from "../config.mjs";
|
|
5
|
+
import { ciState as readCiState } from "./ci-state.mjs";
|
|
4
6
|
import {
|
|
5
7
|
baseCheck,
|
|
6
8
|
briefCheck,
|
|
@@ -62,6 +64,18 @@ test("a second branch review that carries a Reviewed line passes", () => {
|
|
|
62
64
|
assert.equal(check({ records: [branchVerdict], prompt: branchPrompt("Reviewed: ccccccc") }).refusal, null);
|
|
63
65
|
});
|
|
64
66
|
|
|
67
|
+
test("scoped reviews share an integration head when CI is unknown", () => {
|
|
68
|
+
const over = {
|
|
69
|
+
branch: "feat/7-integration",
|
|
70
|
+
records: [{ ...branchVerdict, branch: "feat/7-integration", scope: "a" }],
|
|
71
|
+
ciState: () => ({ reason: null, unknown: "no check runs" }),
|
|
72
|
+
};
|
|
73
|
+
assert.equal(check({ ...over, prompt: branchPrompt("Scope: b") }).refusal, null);
|
|
74
|
+
const { refusal, note } = check({ ...over, prompt: branchPrompt("Scope: a\nReviewed: ccccccc") });
|
|
75
|
+
assert.equal(refusal, null);
|
|
76
|
+
assert.match(note, /unknown/);
|
|
77
|
+
});
|
|
78
|
+
|
|
65
79
|
test("the refusal and the Reviewed line speak of the last head a branch review named", () => {
|
|
66
80
|
assert.match(check({ records: [branchVerdict] }).refusal, /the last head a branch review named/);
|
|
67
81
|
});
|
|
@@ -125,6 +139,70 @@ test("requireGreen off never asks CI", () => {
|
|
|
125
139
|
assert.equal(asked, 0);
|
|
126
140
|
});
|
|
127
141
|
|
|
142
|
+
const checkRuns = (runs, requireGreen = "not-red") => check({
|
|
143
|
+
review: { ...review, requireGreen },
|
|
144
|
+
ciState: (sha) => {
|
|
145
|
+
assert.equal(sha, SHA);
|
|
146
|
+
return readCiState(sha, "/w", {
|
|
147
|
+
gh: (args) => args[1].includes("/actions/runs")
|
|
148
|
+
? JSON.stringify({ workflow_runs: [] })
|
|
149
|
+
: JSON.stringify({ check_runs: runs }),
|
|
150
|
+
origin: () => "owner/repo",
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
for (const status of ["queued", "in_progress", "waiting", "pending"]) {
|
|
156
|
+
test(`requireGreen not-red allows ${status} CI and names the check in a note`, () => {
|
|
157
|
+
const { refusal, note } = checkRuns([{ name: "build", status, conclusion: null }]);
|
|
158
|
+
assert.equal(refusal, null);
|
|
159
|
+
assert.match(note, new RegExp(`CI on aaaaaaa: build is ${status}`));
|
|
160
|
+
assert.match(note, /review proceeds/i);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const conclusion of ["failure", "cancelled", "timed_out", "action_required"]) {
|
|
165
|
+
test(`requireGreen not-red refuses ${conclusion} even while another check runs`, () => {
|
|
166
|
+
const { refusal, note } = checkRuns([
|
|
167
|
+
{ name: "lint", status: "in_progress", conclusion: null },
|
|
168
|
+
{ name: "build", status: "completed", conclusion },
|
|
169
|
+
]);
|
|
170
|
+
assert.match(refusal, new RegExp(`build ended ${conclusion}`));
|
|
171
|
+
assert.equal(note, null);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const conclusion of ["success", "skipped", "neutral"]) {
|
|
176
|
+
test(`requireGreen not-red allows ${conclusion} without a note`, () => {
|
|
177
|
+
assert.deepEqual(checkRuns([{ name: "build", status: "completed", conclusion }]), { refusal: null, note: null });
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
test("requireGreen not-red allows unknown CI with a note", () => {
|
|
182
|
+
const { refusal, note } = checkRuns([]);
|
|
183
|
+
assert.equal(refusal, null);
|
|
184
|
+
assert.match(note, /CI on aaaaaaa is unknown.*no check runs/);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("requireGreen true still refuses queued and running CI", () => {
|
|
188
|
+
for (const status of ["queued", "in_progress"]) {
|
|
189
|
+
const { refusal, note } = checkRuns([{ name: "build", status, conclusion: null }], true);
|
|
190
|
+
assert.match(refusal, new RegExp(`build is ${status}`));
|
|
191
|
+
assert.match(refusal, /waits for green CI/);
|
|
192
|
+
assert.equal(note, null);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("requireGreen not-red uses the newest run of a check", () => {
|
|
197
|
+
const older = { name: "build", status: "completed", conclusion: "failure", started_at: "2026-01-01T00:00:00Z", id: 1 };
|
|
198
|
+
const newer = { ...older, status: "queued", conclusion: null, started_at: "2026-01-02T00:00:00Z", id: 2 };
|
|
199
|
+
for (const runs of [[older, newer], [newer, older]]) {
|
|
200
|
+
const { refusal, note } = checkRuns(runs);
|
|
201
|
+
assert.equal(refusal, null);
|
|
202
|
+
assert.match(note, /build is queued/);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
128
206
|
// Head contains the base tip
|
|
129
207
|
|
|
130
208
|
const tipReads = (over = {}) => ({ remoteTip: () => TIP, lookup: () => ({ sha: TIP }), isAncestor: () => true, ...over });
|
|
@@ -208,6 +286,26 @@ const briefCheckOf = (text, over = {}) =>
|
|
|
208
286
|
briefCheck({ prompt: "Read it.\nBrief: /plans/brief.md\nReport: /plans/report.md", dirs: ["/w"], review, exists: onBrief, read: () => text, ...over });
|
|
209
287
|
const offAll = { ...review, productDecisions: false, roundFindings: 0, roundFiles: 0 };
|
|
210
288
|
|
|
289
|
+
test("the dispatch brief checks CI failures even with the optional brief checks off", async (t) => {
|
|
290
|
+
const { mkdtempSync, writeFileSync, rmSync } = await import("node:fs");
|
|
291
|
+
const { execFileSync } = await import("node:child_process");
|
|
292
|
+
const os = await import("node:os");
|
|
293
|
+
const { recordRun } = await import("./ci-failures.mjs");
|
|
294
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "ci-brief-"));
|
|
295
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 10 }));
|
|
296
|
+
execFileSync("git", ["init", "-q", "-b", "fix/ci", root]);
|
|
297
|
+
recordRun(root, { id: 1, branch: "fix/ci", head: "aaaaaaa" }, { gh: () => "not ok 1 - cleanup retries\n error: EBUSY" });
|
|
298
|
+
const file = path.join(root, "brief.md");
|
|
299
|
+
writeFileSync(file, "## Product decisions\nnone\n");
|
|
300
|
+
const call = { prompt: `Brief: ${file}`, dirs: [root], review: offAll };
|
|
301
|
+
assert.match(briefCheck(call).refusal, /cleanup retries/);
|
|
302
|
+
writeFileSync(file, "## CI failures\n### cleanup retries\nCause: open handle\n");
|
|
303
|
+
assert.deepEqual(briefCheck(call), { refusal: null, note: null });
|
|
304
|
+
const { appendRecord, ledgerFileOf } = await import("./ledger.mjs");
|
|
305
|
+
appendRecord(ledgerFileOf(root), { type: "ci-failure", id: "multi", branch: "fix/ci", head: "aaaaaaa", test: "first\nsecond\nthird\nfourth\nfifth" });
|
|
306
|
+
assert.ok(briefCheck(call).refusal.split(/\r?\n/).length <= 4);
|
|
307
|
+
});
|
|
308
|
+
|
|
211
309
|
test("a brief with a Product decisions heading passes, with no note when it is under the limits", () => {
|
|
212
310
|
assert.deepEqual(briefCheckOf(brief("# Brief", "## Product decisions", "None.", "1. one", `Files: ${files(3)}`)), { refusal: null, note: null });
|
|
213
311
|
assert.equal(briefCheckOf("## product decisions \nNone.").refusal, null);
|
|
@@ -332,3 +430,21 @@ test("a file is a path with a separator or a known extension; a URL, a version,
|
|
|
332
430
|
assert.equal(countFiles("docs/a.md, `packages/x/y.json`, (hooks/hooks.json)."), 3);
|
|
333
431
|
assert.equal(countFiles("README.md and README.md"), 1);
|
|
334
432
|
});
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
test("a detached HEAD skips branch holds when the ledger contains CI failures", async (t) => {
|
|
436
|
+
const { mkdtempSync, rmSync } = await import("node:fs");
|
|
437
|
+
const { execFileSync } = await import("node:child_process");
|
|
438
|
+
const os = await import("node:os");
|
|
439
|
+
const { appendRecord, ledgerFileOf } = await import("./ledger.mjs");
|
|
440
|
+
const { holdBranch } = await import("./pause.mjs");
|
|
441
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "ci-detached-"));
|
|
442
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 10 }));
|
|
443
|
+
const git = (...args) => execFileSync("git", ["-C", root, ...args]);
|
|
444
|
+
git("init", "-q", "-b", "main");
|
|
445
|
+
git("-c", "user.name=Test", "-c", "user.email=test@example.com", "-c", "commit.gpgsign=false", "commit", "--allow-empty", "-qm", "init");
|
|
446
|
+
holdBranch(root, "main", "other branch");
|
|
447
|
+
appendRecord(ledgerFileOf(root), { type: "ci-failure", id: "detached", branch: "main", test: "failed" });
|
|
448
|
+
git("checkout", "--detach", "-q");
|
|
449
|
+
assert.deepEqual(briefCheck({ prompt: "", dirs: [root], review: offAll }), { refusal: null, note: null });
|
|
450
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { PROMOTION_SCOPE } from "../config.mjs";
|
|
4
|
+
import { globMatcher } from "../glob.mjs";
|
|
5
|
+
import { runGh } from "./gh-run.mjs";
|
|
6
|
+
import { gitOut } from "./git-read.mjs";
|
|
7
|
+
import { ledgerFileOf, readLedger } from "./ledger.mjs";
|
|
8
|
+
import { promotionBranchName } from "./promotion-branch.mjs";
|
|
9
|
+
import { reviewSettings } from "./workflow-settings.mjs";
|
|
10
|
+
|
|
11
|
+
const USAGE = "Usage: qc review promotion <pr>";
|
|
12
|
+
const MAX_PATHS = 200;
|
|
13
|
+
const FILES_TIMEOUT_MS = 120_000;
|
|
14
|
+
const API_FILE_LIMIT = 3000;
|
|
15
|
+
|
|
16
|
+
/** The fragment that formats the scope and checks for a promotion reviewer. */
|
|
17
|
+
export function promotionBrief({ pr, head, reviewed, previous, integration, release, files, total }) {
|
|
18
|
+
const listCommand = reviewed
|
|
19
|
+
? `git diff --name-only ${reviewed}..${head} --`
|
|
20
|
+
: `gh api --paginate repos/{owner}/{repo}/pulls/${pr}/files --jq '.[].filename'`;
|
|
21
|
+
return [
|
|
22
|
+
`# Promotion review #${pr}: ${integration} -> ${release}`,
|
|
23
|
+
"",
|
|
24
|
+
`Head: ${head}`,
|
|
25
|
+
`Scope: ${PROMOTION_SCOPE}`,
|
|
26
|
+
...(reviewed ? [`Reviewed: ${reviewed}`] : []),
|
|
27
|
+
...(previous ? [`Previous verdict: ${previous.verdict ?? "unknown"}`] : []),
|
|
28
|
+
...(previous?.verdict === "CHANGES_REQUIRED" ? ["Check each earlier finding in the file named by `Previous review:` and confirm its resolution, not only the increment."] : []),
|
|
29
|
+
"",
|
|
30
|
+
"## Review these files",
|
|
31
|
+
"",
|
|
32
|
+
`${files.length} of ${total} changed files match the promotion risk surfaces.`,
|
|
33
|
+
"",
|
|
34
|
+
...files.slice(0, MAX_PATHS).map((file) => `- \`${file}\``),
|
|
35
|
+
...(files.length > MAX_PATHS ? ["", `${files.length - MAX_PATHS} more paths; read the full list with \`${listCommand}\`.`] : []),
|
|
36
|
+
"",
|
|
37
|
+
"## Checks",
|
|
38
|
+
"",
|
|
39
|
+
"- Infra: permissions, public exposure, and removed protections.",
|
|
40
|
+
"- Migrations: order, destructive statements, and a rollback path.",
|
|
41
|
+
"- Workflows: new triggers, secret use, and unpinned actions.",
|
|
42
|
+
"- Secrets in logs: any log or error output that can hold a token, key, password, or personal data.",
|
|
43
|
+
"",
|
|
44
|
+
`Write the report's first line as \`VERDICT: APPROVED ${head}\` or \`VERDICT: CHANGES_REQUIRED ${head}\`.`,
|
|
45
|
+
"",
|
|
46
|
+
].join("\n");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The pipeline that reads a promotion PR and writes its scoped reviewer brief. */
|
|
50
|
+
export function runReview(config, args, { gh = runGh, git = gitOut, out = console.log, err = console.error } = {}) {
|
|
51
|
+
const [command, number] = args;
|
|
52
|
+
if (command !== PROMOTION_SCOPE || args.length !== 2 || !/^[1-9]\d*$/.test(number ?? "")) {
|
|
53
|
+
err(USAGE);
|
|
54
|
+
return 2;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const promotion = reviewSettings(config.swarm)?.promotion;
|
|
58
|
+
if (!promotion) throw new Error("Set swarm.review.promotion and enable swarm.dispatch in qc.config.json.");
|
|
59
|
+
const root = config.root;
|
|
60
|
+
const integration = promotionBranchName(promotion.integration);
|
|
61
|
+
const release = promotionBranchName(promotion.release);
|
|
62
|
+
const { surfaces } = promotion;
|
|
63
|
+
const answer = gh(["pr", "view", number, "--json", "number,headRefName,baseRefName,headRefOid,url,isCrossRepository,changedFiles"], { cwd: root });
|
|
64
|
+
if (answer === null) throw new Error(`gh could not read PR #${number}.`);
|
|
65
|
+
let pr;
|
|
66
|
+
try {
|
|
67
|
+
pr = JSON.parse(answer);
|
|
68
|
+
} catch {
|
|
69
|
+
throw new Error(`gh returned an invalid PR #${number} answer.`);
|
|
70
|
+
}
|
|
71
|
+
if (!pr || String(pr.number) !== number || !/^[0-9a-f]{40}$/i.test(pr.headRefOid ?? "")) {
|
|
72
|
+
throw new Error(`gh returned an invalid PR #${number} head.`);
|
|
73
|
+
}
|
|
74
|
+
if (pr.isCrossRepository !== false) throw new Error(`PR #${number} must have its head and base in the same repository.`);
|
|
75
|
+
if (!Number.isSafeInteger(pr.changedFiles) || pr.changedFiles < 0) throw new Error(`PR #${number} has an invalid changedFiles count: ${JSON.stringify(pr.changedFiles)}.`);
|
|
76
|
+
if (promotionBranchName(pr.headRefName) !== integration || promotionBranchName(pr.baseRefName) !== release) {
|
|
77
|
+
throw new Error(`PR #${number} must promote ${integration} -> ${release}; got ${pr.headRefName} -> ${pr.baseRefName}.`);
|
|
78
|
+
}
|
|
79
|
+
const ledger = ledgerFileOf(root);
|
|
80
|
+
if (!ledger) throw new Error("The checkout has no git common directory for the promotion brief.");
|
|
81
|
+
const last = readLedger(ledger).findLast((record) =>
|
|
82
|
+
record.type === "verdict" && record.kind === "branch" && record.branch === pr.headRefName && record.scope === PROMOTION_SCOPE);
|
|
83
|
+
const reviewed = last?.sha;
|
|
84
|
+
if (last && !/^[0-9a-f]{7,40}$/i.test(reviewed ?? "")) throw new Error(`The last promotion verdict for PR #${number} has an invalid reviewed head.`);
|
|
85
|
+
const changed = reviewed
|
|
86
|
+
? git(root, "diff", "--name-only", `${reviewed}..${pr.headRefOid}`, "--")
|
|
87
|
+
: gh(["api", "--paginate", `repos/{owner}/{repo}/pulls/${number}/files`, "--jq", ".[].filename"], { cwd: root, timeoutMs: FILES_TIMEOUT_MS });
|
|
88
|
+
if (changed === null) throw new Error(reviewed
|
|
89
|
+
? `git could not read the increment for PR #${number}; fetch commits ${reviewed} and ${pr.headRefOid}.`
|
|
90
|
+
: `gh could not read changed files for PR #${number}.`);
|
|
91
|
+
const files = changed.split(/\r?\n/).filter(Boolean);
|
|
92
|
+
if (!reviewed && (files.length !== pr.changedFiles || files.length >= API_FILE_LIMIT)) {
|
|
93
|
+
throw new Error(`PR #${number}: read ${files.length} files; changedFiles ${pr.changedFiles}. ${files.length >= API_FILE_LIMIT ? "The GitHub API has a 3,000-file limit. " : ""}Refusing to brief a partial file list.`);
|
|
94
|
+
}
|
|
95
|
+
const brief = promotionBrief({ pr: pr.number, head: pr.headRefOid, reviewed, previous: last, integration, release, files: files.filter(globMatcher(surfaces)), total: files.length });
|
|
96
|
+
const file = path.join(path.dirname(ledger), "promotion", `pr-${number}.md`);
|
|
97
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
98
|
+
writeFileSync(file, brief);
|
|
99
|
+
out(`Wrote ${file}`);
|
|
100
|
+
out(`Dispatch architecture:sdd-branch-reviewer with model opus:\nBrief: ${file}\nScope: ${PROMOTION_SCOPE}\n${reviewed ? `Reviewed: ${reviewed}\n` : ""}Worktree: <a worktree on ${integration} at ${pr.headRefOid}>${last?.verdict === "CHANGES_REQUIRED" ? "\nAdd a `Previous review: <path>` line naming the earlier review file to the reviewer prompt." : ""}`);
|
|
101
|
+
out(`Merge with --match-head-commit ${pr.headRefOid} after the review approves.`);
|
|
102
|
+
return 0;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
err(error.message);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
}
|