architecture-harness 0.20.3 → 0.20.4
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 +1 -1
- package/src/cli/bash-command-guard.mjs +28 -5
- package/src/cli/bash-command-guard.test.mjs +100 -0
- package/src/cli/bash-edit-guard.mjs +19 -16
- package/src/cli/bash-edit-guard.test.mjs +19 -0
- package/src/cli/ci-state.mjs +17 -9
- package/src/cli/ci-state.test.mjs +15 -1
- package/src/cli/cost-stop.mjs +98 -0
- package/src/cli/cost-stop.test.mjs +149 -0
- package/src/cli/dispatch-guard.mjs +3 -3
- package/src/cli/dispatch-guard.test.mjs +14 -6
- package/src/cli/dispatch-reminder.mjs +5 -3
- package/src/cli/dispatch-reminder.test.mjs +5 -1
- package/src/cli/git-read.mjs +28 -3
- package/src/cli/git-read.test.mjs +31 -1
- package/src/cli/ledger.mjs +50 -3
- package/src/cli/ledger.test.mjs +46 -0
- package/src/cli/powershell-command.mjs +8 -13
- package/src/cli/powershell-command.test.mjs +11 -1
- package/src/cli/qc.mjs +1 -1
- package/src/cli/report-stop.test.mjs +2 -1
- package/src/cli/review-gate.mjs +224 -0
- package/src/cli/review-gate.test.mjs +334 -0
- package/src/cli/shell-command.mjs +65 -9
- package/src/cli/shell-command.test.mjs +21 -1
- package/src/cli/skill-guard.mjs +56 -0
- package/src/cli/skill-guard.test.mjs +87 -0
- package/src/cli/stop-gate.test.mjs +80 -0
- package/src/cli/task-gate-review.test.mjs +225 -0
- package/src/cli/task-gate.mjs +35 -11
- package/src/cli/task-gate.test.mjs +6 -5
- package/src/cli/test-brief.mjs +12 -0
- package/src/cli/transcript-usage.mjs +28 -0
- package/src/cli/transcript-usage.test.mjs +9 -0
- package/src/cli/workflow-hooks.test.mjs +38 -0
- package/src/cli/workflow-settings.mjs +14 -3
- package/src/cli/workflow-settings.test.mjs +24 -0
- package/src/config.mjs +13 -0
- package/templates/docs/enforcement.md +11 -0
|
@@ -275,3 +275,83 @@ test("the memory file holds a hash of the failure text, not the text", (t) => {
|
|
|
275
275
|
assert.match(stored.trim(), /^[0-9a-f]{64}$/);
|
|
276
276
|
assert.ok(!stored.includes("ADR-0099"));
|
|
277
277
|
});
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* A workspace whose typecheck is `npx tsc`, answered by a stub `npx` first on the PATH. `runs` lists each run's exit code and output;
|
|
281
|
+
* a run past the list repeats the last. `count()` is the number of times the gate ran the typecheck.
|
|
282
|
+
*/
|
|
283
|
+
function tscWorkspace(t, runs) {
|
|
284
|
+
const ws = workspace(t, { codes: {}, withDoctor: false });
|
|
285
|
+
const base = path.dirname(ws.tmpDir);
|
|
286
|
+
const repo = path.join(base, "repo");
|
|
287
|
+
mkdirSync(path.join(repo, "node_modules", ".bin"), { recursive: true });
|
|
288
|
+
writeFileSync(path.join(repo, "node_modules", ".bin", "tsc"), "");
|
|
289
|
+
const stubDir = path.join(base, "stub");
|
|
290
|
+
mkdirSync(stubDir, { recursive: true });
|
|
291
|
+
runs.forEach((run, i) => {
|
|
292
|
+
writeFileSync(path.join(stubDir, `run-${i + 1}.code`), String(run.code));
|
|
293
|
+
writeFileSync(path.join(stubDir, `run-${i + 1}.out`), run.out);
|
|
294
|
+
});
|
|
295
|
+
const counter = path.join(stubDir, "count");
|
|
296
|
+
writeFileSync(
|
|
297
|
+
path.join(stubDir, "npx"),
|
|
298
|
+
[
|
|
299
|
+
"#!/usr/bin/env bash",
|
|
300
|
+
`[ "$1" = tsc ] || exit 0`,
|
|
301
|
+
`n=$(cat "${counter}" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > "${counter}"`,
|
|
302
|
+
`while [ ! -f "${stubDir}/run-$n.code" ]; do n=$((n - 1)); done`,
|
|
303
|
+
`cat "${stubDir}/run-$n.out"`,
|
|
304
|
+
`exit $(cat "${stubDir}/run-$n.code")`,
|
|
305
|
+
].join("\n") + "\n",
|
|
306
|
+
{ mode: 0o755 },
|
|
307
|
+
);
|
|
308
|
+
const run = (input = {}) => ws.run(input, { PATH: `${stubDir}${path.delimiter}${process.env.PATH}` });
|
|
309
|
+
const count = () => (existsSync(counter) ? Number(readFileSync(counter, "utf8")) : 0);
|
|
310
|
+
return { run, count };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const TS2307 = "src/a.ts(1,22): error TS2307: Cannot find module 'zod' or its corresponding type declarations.\n";
|
|
314
|
+
const TS2322 = "src/b.ts(4,7): error TS2322: Type 'string' is not assignable to type 'number'.\n";
|
|
315
|
+
|
|
316
|
+
test("a typecheck that fails only with TS2307 runs once more, and a second pass ends the stop green", (t) => {
|
|
317
|
+
const gate = tscWorkspace(t, [{ code: 2, out: TS2307 }, { code: 0, out: "" }]);
|
|
318
|
+
const result = gate.run();
|
|
319
|
+
assert.equal(result.status, 0, result.stderr);
|
|
320
|
+
assert.equal(gate.count(), 2);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("a typecheck that still fails with TS2307 on the second run blocks, with the second run's text", (t) => {
|
|
324
|
+
const gate = tscWorkspace(t, [{ code: 2, out: TS2307 }, { code: 2, out: TS2307.replace("zod", "hono") }]);
|
|
325
|
+
const result = gate.run();
|
|
326
|
+
assert.equal(result.status, 2);
|
|
327
|
+
assert.equal(gate.count(), 2);
|
|
328
|
+
assert.match(result.stderr, /typecheck failed/);
|
|
329
|
+
assert.match(result.stderr, /hono/);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("a TS2322 next to a TS2307 does not retry, and a TS2322 alone does not either", (t) => {
|
|
333
|
+
for (const out of [TS2322 + TS2307, TS2322]) {
|
|
334
|
+
const gate = tscWorkspace(t, [{ code: 2, out }, { code: 0, out: "" }]);
|
|
335
|
+
const result = gate.run();
|
|
336
|
+
assert.equal(result.status, 2);
|
|
337
|
+
assert.equal(gate.count(), 1);
|
|
338
|
+
assert.match(result.stderr, /TS2322/);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("a large TS2322 log does not retry, since the early exit of the filter must not read as a pipe failure", (t) => {
|
|
343
|
+
const out = TS2322.repeat(20_000);
|
|
344
|
+
const gate = tscWorkspace(t, [{ code: 2, out }, { code: 0, out: "" }]);
|
|
345
|
+
const result = gate.run();
|
|
346
|
+
assert.equal(result.status, 2);
|
|
347
|
+
assert.equal(gate.count(), 1);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test("a failing typecheck with no error line does not retry, and a passing one runs once", (t) => {
|
|
351
|
+
const broken = tscWorkspace(t, [{ code: 1, out: "tsc: command crashed\n" }, { code: 0, out: "" }]);
|
|
352
|
+
assert.equal(broken.run().status, 2);
|
|
353
|
+
assert.equal(broken.count(), 1);
|
|
354
|
+
const green = tscWorkspace(t, [{ code: 0, out: "" }]);
|
|
355
|
+
assert.equal(green.run().status, 0);
|
|
356
|
+
assert.equal(green.count(), 1);
|
|
357
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, 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 { decide } from "./dispatch-guard.mjs";
|
|
8
|
+
import { appendRecord, readLedger } from "./ledger.mjs";
|
|
9
|
+
import { judgeTask, recordDispatch } from "./task-gate.mjs";
|
|
10
|
+
|
|
11
|
+
// The guard runs under Codex, whatever runtime runs the test.
|
|
12
|
+
process.env.QC_RUNTIME = "codex";
|
|
13
|
+
|
|
14
|
+
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
15
|
+
const BRANCH_REVIEWER = "architecture:sdd-branch-reviewer";
|
|
16
|
+
const TASK_REVIEWER = "architecture:sdd-reviewer";
|
|
17
|
+
const IMPLEMENTER = "architecture:sdd-implementer";
|
|
18
|
+
const green = () => ({ reason: null, unknown: null });
|
|
19
|
+
|
|
20
|
+
/** A checkout with an origin that holds main, and a linked worktree on feat/1-x that starts at main. */
|
|
21
|
+
function workspace(t, config = { swarm: { dispatch: {} } }) {
|
|
22
|
+
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-review-gate-")));
|
|
23
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
24
|
+
const main = path.join(base, "main");
|
|
25
|
+
const origin = path.join(base, "origin.git");
|
|
26
|
+
git(base, "init", "-q", "-b", "main", main);
|
|
27
|
+
git(base, "init", "-q", "--bare", origin);
|
|
28
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) {
|
|
29
|
+
git(main, "config", key, value);
|
|
30
|
+
}
|
|
31
|
+
writeFileSync(path.join(main, "a.txt"), "a\n");
|
|
32
|
+
writeFileSync(path.join(main, "qc.config.json"), JSON.stringify(config));
|
|
33
|
+
git(main, "add", ".");
|
|
34
|
+
git(main, "commit", "-q", "-m", "init");
|
|
35
|
+
git(main, "remote", "add", "origin", origin);
|
|
36
|
+
git(main, "push", "-q", "origin", "main");
|
|
37
|
+
git(main, "fetch", "-q", "origin");
|
|
38
|
+
const linked = path.join(base, "linked");
|
|
39
|
+
git(main, "worktree", "add", "-q", "-b", "feat/1-x", linked);
|
|
40
|
+
const tmp = path.join(base, "tmp");
|
|
41
|
+
mkdirSync(tmp);
|
|
42
|
+
return { base, main, origin, linked, tmp, ledger: path.join(main, ".git", "qc", "ledger.jsonl") };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function advanceMain(ws, name) {
|
|
46
|
+
writeFileSync(path.join(ws.main, name), `${name}\n`);
|
|
47
|
+
git(ws.main, "add", ".");
|
|
48
|
+
git(ws.main, "commit", "-q", "-m", name);
|
|
49
|
+
git(ws.main, "push", "-q", "origin", "main");
|
|
50
|
+
return git(ws.main, "rev-parse", "HEAD");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const call = (ws, type, prompt) => ({
|
|
54
|
+
session_id: "s",
|
|
55
|
+
cwd: ws.main,
|
|
56
|
+
hook_event_name: "PreToolUse",
|
|
57
|
+
tool_name: "Agent",
|
|
58
|
+
tool_use_id: "toolu_1",
|
|
59
|
+
tool_input: { subagent_type: type, description: "Review", prompt },
|
|
60
|
+
});
|
|
61
|
+
const reviewPrompt = (ws, more = "") => `Review the branch.\nWorktree: ${ws.linked}\n${more}`;
|
|
62
|
+
const judge = (ws, type, prompt, deps = { ciState: green }) => judgeTask(call(ws, type, prompt), ws.tmp, deps);
|
|
63
|
+
const branchVerdict = (ws, sha) => appendRecord(ws.ledger, { type: "verdict", kind: "branch", verdict: "APPROVED", sha, branch: "feat/1-x" });
|
|
64
|
+
|
|
65
|
+
test("a reviewer whose head holds the tip of the base, with green CI, passes with no note", (t) => {
|
|
66
|
+
const ws = workspace(t);
|
|
67
|
+
const task = judge(ws, BRANCH_REVIEWER, reviewPrompt(ws));
|
|
68
|
+
assert.equal(task.refusal, null);
|
|
69
|
+
assert.equal(task.note, null);
|
|
70
|
+
recordDispatch(task);
|
|
71
|
+
const [record] = readLedger(ws.ledger);
|
|
72
|
+
assert.equal(record.branch, "feat/1-x");
|
|
73
|
+
assert.equal(record.head, git(ws.linked, "rev-parse", "HEAD"));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a reviewer on a head that lacks the pushed tip of the base is refused until the base is merged", (t) => {
|
|
77
|
+
const ws = workspace(t);
|
|
78
|
+
advanceMain(ws, "b.txt");
|
|
79
|
+
for (const type of [BRANCH_REVIEWER, TASK_REVIEWER]) {
|
|
80
|
+
assert.match(judge(ws, type, reviewPrompt(ws)).refusal ?? "", /merge origin\/main into the branch first/, type);
|
|
81
|
+
}
|
|
82
|
+
git(ws.main, "fetch", "-q", "origin");
|
|
83
|
+
git(ws.linked, "merge", "-q", "--no-edit", "origin/main");
|
|
84
|
+
assert.equal(judge(ws, BRANCH_REVIEWER, reviewPrompt(ws)).refusal, null);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a tip that origin holds and this checkout lacks is refused with a fetch", (t) => {
|
|
88
|
+
const ws = workspace(t);
|
|
89
|
+
const other = path.join(ws.base, "other");
|
|
90
|
+
git(ws.base, "clone", "-q", "-b", "main", ws.origin, other);
|
|
91
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) {
|
|
92
|
+
git(other, "config", key, value);
|
|
93
|
+
}
|
|
94
|
+
writeFileSync(path.join(other, "c.txt"), "c\n");
|
|
95
|
+
git(other, "add", ".");
|
|
96
|
+
git(other, "commit", "-q", "-m", "c");
|
|
97
|
+
git(other, "push", "-q", "origin", "main");
|
|
98
|
+
assert.match(judge(ws, BRANCH_REVIEWER, reviewPrompt(ws)).refusal ?? "", /git fetch/);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("with no origin the base check falls back to the local ref, and passes with a note when that is missing", (t) => {
|
|
102
|
+
const ws = workspace(t);
|
|
103
|
+
git(ws.main, "remote", "remove", "origin");
|
|
104
|
+
const task = judge(ws, TASK_REVIEWER, reviewPrompt(ws));
|
|
105
|
+
assert.equal(task.refusal, null);
|
|
106
|
+
assert.match(task.note ?? "", /origin\/main/);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("red CI on the head refuses both reviewer kinds, and unknown CI passes with a note", (t) => {
|
|
110
|
+
const ws = workspace(t);
|
|
111
|
+
const red = { ciState: () => ({ reason: "CI on 1234567: build ended failure", unknown: null }) };
|
|
112
|
+
for (const type of [BRANCH_REVIEWER, TASK_REVIEWER]) {
|
|
113
|
+
assert.match(judge(ws, type, reviewPrompt(ws), red).refusal ?? "", /build ended failure/, type);
|
|
114
|
+
}
|
|
115
|
+
const unknown = judge(ws, BRANCH_REVIEWER, reviewPrompt(ws), { ciState: () => ({ reason: null, unknown: "gh failed or timed out" }) });
|
|
116
|
+
assert.equal(unknown.refusal, null);
|
|
117
|
+
assert.match(unknown.note ?? "", /CI on .* is unknown: gh failed or timed out/);
|
|
118
|
+
assert.equal(recordDispatch(unknown), unknown.note);
|
|
119
|
+
assert.match(judge(ws, TASK_REVIEWER, reviewPrompt(ws), { ci: () => "CI on 1234567: lint is in_progress" }).refusal ?? "", /lint is in_progress/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a second branch review is refused without a Reviewed line, and passes with one", (t) => {
|
|
123
|
+
const ws = workspace(t);
|
|
124
|
+
const head = git(ws.linked, "rev-parse", "HEAD");
|
|
125
|
+
assert.equal(judge(ws, BRANCH_REVIEWER, reviewPrompt(ws)).refusal, null);
|
|
126
|
+
branchVerdict(ws, head);
|
|
127
|
+
const refusal = judge(ws, BRANCH_REVIEWER, reviewPrompt(ws)).refusal ?? "";
|
|
128
|
+
assert.match(refusal, /Reviewed: /);
|
|
129
|
+
assert.match(refusal, new RegExp(head.slice(0, 7)));
|
|
130
|
+
assert.equal(judge(ws, BRANCH_REVIEWER, reviewPrompt(ws, `Reviewed: ${head.slice(0, 7)}`)).refusal, null);
|
|
131
|
+
assert.equal(judge(ws, TASK_REVIEWER, reviewPrompt(ws)).refusal, null);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("each review check is a swarm.review key, and a repository switches it off", (t) => {
|
|
135
|
+
const off = { swarm: { dispatch: {}, review: { oneBranchReview: false, requireGreen: false, requireBase: false } } };
|
|
136
|
+
const ws = workspace(t, off);
|
|
137
|
+
advanceMain(ws, "b.txt");
|
|
138
|
+
branchVerdict(ws, git(ws.linked, "rev-parse", "HEAD"));
|
|
139
|
+
const red = { ciState: () => assert.fail("CI asked") };
|
|
140
|
+
assert.equal(judge(ws, BRANCH_REVIEWER, reviewPrompt(ws), red).refusal, null);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const briefIn = (ws, name, text = "# Brief\n\n## Product decisions\n\nNone.\n") => {
|
|
144
|
+
const file = path.join(ws.base, name);
|
|
145
|
+
writeFileSync(file, text);
|
|
146
|
+
return file;
|
|
147
|
+
};
|
|
148
|
+
const implement = (ws, prompt, brief = briefIn(ws, "brief.md")) => judge(ws, IMPLEMENTER, `${prompt}\nBrief: ${brief}\nWorktree: ${ws.linked}`);
|
|
149
|
+
|
|
150
|
+
test("an implementer dispatch with no Brief line, or a Brief line whose file is missing, is refused, and the refusal names the line", (t) => {
|
|
151
|
+
const ws = workspace(t);
|
|
152
|
+
const none = judge(ws, IMPLEMENTER, `Do the work.\n## Product decisions\nNone.\nWorktree: ${ws.linked}`).refusal ?? "";
|
|
153
|
+
assert.match(none, /`Brief: <path>`/);
|
|
154
|
+
const missing = implement(ws, "Do the work.", path.join(ws.base, "gone.md")).refusal ?? "";
|
|
155
|
+
assert.match(missing, /`Brief: <path>`/);
|
|
156
|
+
assert.match(missing, /gone\.md/);
|
|
157
|
+
assert.equal(implement(ws, "Do the work.").refusal, null);
|
|
158
|
+
assert.equal(judge(ws, TASK_REVIEWER, reviewPrompt(ws)).refusal, null);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("the brief file decides: its section passes the dispatch, and a missing or empty section refuses it", (t) => {
|
|
162
|
+
const ws = workspace(t);
|
|
163
|
+
const bad = briefIn(ws, "bad-brief.md", "# Brief\n\nDo it.\n");
|
|
164
|
+
const empty = briefIn(ws, "empty-brief.md", "# Brief\n\n## Product decisions\n\n## Findings\n1. x\n");
|
|
165
|
+
assert.equal(implement(ws, "Read it.", briefIn(ws, "good-brief.md")).refusal, null);
|
|
166
|
+
const refusal = implement(ws, "Read it.", bad).refusal ?? "";
|
|
167
|
+
assert.match(refusal, /bad-brief\.md/);
|
|
168
|
+
assert.match(refusal, /## Product decisions/);
|
|
169
|
+
assert.match(implement(ws, "Read it.", empty).refusal ?? "", /empty-brief\.md.*empty|empty.*empty-brief\.md/);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("a long brief file warns and still passes, and the warning reaches the session", (t) => {
|
|
173
|
+
const ws = workspace(t);
|
|
174
|
+
const findings = Array.from({ length: 9 }, (_unused, index) => `${index + 1}. finding ${index}`).join("\n");
|
|
175
|
+
const brief = briefIn(ws, "long-brief.md", `## Product decisions\nNone.\n${findings}\n`);
|
|
176
|
+
const task = implement(ws, "Read it.", brief);
|
|
177
|
+
assert.equal(task.refusal, null);
|
|
178
|
+
assert.match(task.note ?? "", /9 numbered findings/);
|
|
179
|
+
const output = decide(call(ws, IMPLEMENTER, `Read it.\nBrief: ${brief}\nWorktree: ${ws.linked}`), ws.tmp, Date.now(), { ciState: green });
|
|
180
|
+
assert.match(output.hookSpecificOutput.additionalContext, /disjoint paths/);
|
|
181
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, undefined);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// A reviewer whose checkout the gate cannot read skips every check, so it is refused.
|
|
185
|
+
|
|
186
|
+
test("a reviewer prompt with no Worktree line, or one that names no checkout, is refused, and the refusal names the line", (t) => {
|
|
187
|
+
const ws = workspace(t);
|
|
188
|
+
const red = { ciState: () => ({ reason: "CI on 1234567: build ended failure", unknown: null }) };
|
|
189
|
+
for (const type of [BRANCH_REVIEWER, TASK_REVIEWER]) {
|
|
190
|
+
for (const prompt of ["Review the branch.", `Review it.\nWorktree: ${path.join(ws.base, "gone")}`]) {
|
|
191
|
+
const refusal = judge(ws, type, prompt, red).refusal ?? "";
|
|
192
|
+
assert.match(refusal, /^Task gate:/, type);
|
|
193
|
+
assert.match(refusal, /`Worktree: <path>`/, type);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("a reviewer on a detached head is refused, and the refusal names the Worktree line", (t) => {
|
|
199
|
+
const ws = workspace(t);
|
|
200
|
+
git(ws.linked, "checkout", "-q", "--detach");
|
|
201
|
+
for (const type of [BRANCH_REVIEWER, TASK_REVIEWER]) {
|
|
202
|
+
const refusal = judge(ws, type, reviewPrompt(ws)).refusal ?? "";
|
|
203
|
+
assert.match(refusal, /`Worktree: <path>`/, type);
|
|
204
|
+
assert.match(refusal, /checked-out branch/, type);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("a reviewer in a repository with no swarm workflow is not judged, with or without a Worktree line", (t) => {
|
|
209
|
+
const ws = workspace(t);
|
|
210
|
+
const outside = path.join(ws.base, "outside");
|
|
211
|
+
mkdirSync(outside);
|
|
212
|
+
git(outside, "init", "-q");
|
|
213
|
+
for (const prompt of ["Review it.", `Review it.\nWorktree: ${outside}`]) {
|
|
214
|
+
const task = judgeTask({ ...call(ws, BRANCH_REVIEWER, prompt), cwd: outside }, ws.tmp, { ciState: green });
|
|
215
|
+
assert.equal(task.refusal, null, prompt);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("the dispatch guard refuses a reviewer and claims no slot for it", (t) => {
|
|
220
|
+
const ws = workspace(t);
|
|
221
|
+
advanceMain(ws, "b.txt");
|
|
222
|
+
const output = decide(call(ws, BRANCH_REVIEWER, reviewPrompt(ws)), ws.tmp, Date.now(), { ciState: green });
|
|
223
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, "deny");
|
|
224
|
+
assert.match(output.hookSpecificOutput.permissionDecisionReason, /^Task gate:/);
|
|
225
|
+
});
|
package/src/cli/task-gate.mjs
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
7
|
-
import { ciNotGreen } from "./ci-state.mjs";
|
|
7
|
+
import { ciNotGreen, ciState as readCiState } from "./ci-state.mjs";
|
|
8
8
|
import { typeOf } from "./dispatch.mjs";
|
|
9
9
|
import { handoffPathOf, resolveHandoff } from "./handoff-note.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { gitOutWithin, linkedWorktrees, pathKey } from "./git-read.mjs";
|
|
11
11
|
import { appendRecord, latestVerdictFor, latestVerdictOn, readLedger, shaMatches } from "./ledger.mjs";
|
|
12
12
|
import { resolveNamedWorktree, workflowOfRepo, worktreeNamed } from "./workflow-place.mjs";
|
|
13
|
+
import { READ_MS, branchOfCheckout, briefCheck, defaultReads, headOf, reviewerCheck, unreadableRefusal } from "./review-gate.mjs";
|
|
13
14
|
import { rememberSession, workflowAt } from "./workflow-settings.mjs";
|
|
14
15
|
|
|
15
16
|
export { worktreeNamed };
|
|
@@ -33,6 +34,8 @@ const unreviewedRefusal = (branch, stopHead, head) =>
|
|
|
33
34
|
`\`qc ledger ${branch}\` lists what is recorded.`;
|
|
34
35
|
|
|
35
36
|
const HISTORY_LIMIT = 5000;
|
|
37
|
+
// A read is capped, so the whole dispatch guard ends inside the Agent hook's 30 second limit.
|
|
38
|
+
const gitRead = (cwd, ...args) => gitOutWithin(READ_MS, cwd, ...args);
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
41
|
* The newest implementer stop in this branch's history that no later verdict on the branch covers,
|
|
@@ -79,7 +82,7 @@ export function continuedStop(records, branch, handoff) {
|
|
|
79
82
|
* Only implementer commits need a review, so a controller commit after a reviewed head passes. `cwd` is any
|
|
80
83
|
* checkout; `git` reads it, and `ci` answers why CI on a sha is not green, or null.
|
|
81
84
|
*/
|
|
82
|
-
export function gateVerdict({ records, branch, head, reason, type, cwd, git =
|
|
85
|
+
export function gateVerdict({ records, branch, head, reason, type, cwd, git = gitRead, handoff = null, ci = (sha) => ciNotGreen(sha, cwd) }) {
|
|
83
86
|
// A continuation of the newest stop's hand-off is the same task, so it is neither a fix round nor a new task.
|
|
84
87
|
const continued = continuedStop(records, branch, handoff);
|
|
85
88
|
const why = reason ?? (continued ? `continues the hand-off ${continued.handoff}` : null);
|
|
@@ -109,10 +112,10 @@ const taskTypeIn = (type, review) =>
|
|
|
109
112
|
/**
|
|
110
113
|
* Judges one main-session Agent call. The repository of the worktree the prompt names decides, and the
|
|
111
114
|
* repository of the cwd decides only when the prompt names none.
|
|
112
|
-
* `ci`
|
|
115
|
+
* `ci`, `ciState`, and `reads` replace the CI and base reads, for a test.
|
|
113
116
|
* @returns the refusal, or the record to write once the dispatch runs.
|
|
114
117
|
*/
|
|
115
|
-
export function judgeTask(call, tmp = os.tmpdir(), { ci } = {}) {
|
|
118
|
+
export function judgeTask(call, tmp = os.tmpdir(), { ci, ciState, reads = defaultReads } = {}) {
|
|
116
119
|
const cwd = call.cwd ?? process.cwd();
|
|
117
120
|
let own;
|
|
118
121
|
try {
|
|
@@ -153,14 +156,35 @@ export function judgeTask(call, tmp = os.tmpdir(), { ci } = {}) {
|
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
if (!workflow) return pass(null, null);
|
|
156
|
-
|
|
159
|
+
let briefNote = null;
|
|
160
|
+
if (workflow.review.implementerTypes.includes(type)) {
|
|
161
|
+
const brief = briefCheck({ prompt, dirs: [cwd, ...(place ? [place.abs] : [])], review: workflow.review });
|
|
162
|
+
if (brief.refusal) return refuse(brief.refusal);
|
|
163
|
+
briefNote = brief.note;
|
|
164
|
+
}
|
|
165
|
+
if (!taskTypeIn(type, workflow.review)) return pass(workflow, base, briefNote);
|
|
157
166
|
if (!workflow.review.implementerTypes.includes(type)) {
|
|
158
|
-
// A reviewer
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
// A reviewer waits for its checks. Its worktree tells the stop which branch the verdict belongs to,
|
|
168
|
+
// and a checkout the gate cannot read would skip every check, so that refuses.
|
|
169
|
+
if (named === null) return refuse(unreadableRefusal(type, "the prompt has no `Worktree:` line"));
|
|
170
|
+
if (!root) return refuse(unreadableRefusal(type, `no git checkout exists at "${named}"`));
|
|
171
|
+
const branch = branchOfCheckout(root);
|
|
172
|
+
const head = headOf(root);
|
|
173
|
+
const state = ciState ?? (ci ? (sha) => ({ reason: ci(sha), unknown: null }) : (sha) => readCiState(sha, root));
|
|
174
|
+
let records = [];
|
|
175
|
+
let ledgerNote = null;
|
|
176
|
+
try {
|
|
177
|
+
records = readLedger(workflow.ledger);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
ledgerNote = `Task gate could not read the ledger (${error.message}), so the one-review check did not run.`;
|
|
180
|
+
}
|
|
181
|
+
const checked = reviewerCheck({ type, prompt, review: workflow.review, base: workflow.base, records, root, branch, head, ciState: state, reads });
|
|
182
|
+
if (checked.refusal) return refuse(checked.refusal);
|
|
183
|
+
return pass(workflow, { ...base, worktree: root, branch, head }, [ledgerNote, checked.note].filter(Boolean).join(" ") || null);
|
|
161
184
|
}
|
|
185
|
+
if (named === null) return pass(workflow, base, briefNote);
|
|
162
186
|
const key = pathKey(abs);
|
|
163
|
-
const worktree = linkedWorktrees(workflow.root).find((entry) => pathKey(entry.path) === key);
|
|
187
|
+
const worktree = linkedWorktrees(workflow.root, READ_MS).find((entry) => pathKey(entry.path) === key);
|
|
164
188
|
if (!worktree) {
|
|
165
189
|
return refuse(`Task gate: the prompt names worktree "${named}", which is no linked worktree of this repository. Name the path \`git worktree list\` prints for the task's branch.`);
|
|
166
190
|
}
|
|
@@ -178,7 +202,7 @@ export function judgeTask(call, tmp = os.tmpdir(), { ci } = {}) {
|
|
|
178
202
|
if (refusal) return refuse(refusal);
|
|
179
203
|
const continues = handoff ? { handoff } : {};
|
|
180
204
|
const unreviewed = ciPass ? { ciPass } : {};
|
|
181
|
-
return pass(workflow, { ...base, task: true, worktree: worktree.path, branch: worktree.branch, head: worktree.head, resumeReason: reason, ...continues, ...unreviewed });
|
|
205
|
+
return pass(workflow, { ...base, task: true, worktree: worktree.path, branch: worktree.branch, head: worktree.head, resumeReason: reason, ...continues, ...unreviewed }, briefNote);
|
|
182
206
|
}
|
|
183
207
|
|
|
184
208
|
/** Writes the dispatch record of a judged call. @returns a note for the session, or null. */
|
|
@@ -7,6 +7,7 @@ import { test } from "node:test";
|
|
|
7
7
|
import { decide as dispatchDecide } from "./dispatch-guard.mjs";
|
|
8
8
|
import { appendRecord, readLedger } from "./ledger.mjs";
|
|
9
9
|
import { gitOut } from "./git-read.mjs";
|
|
10
|
+
import { BRIEF } from "./test-brief.mjs";
|
|
10
11
|
import { continuedStop, gateRefusal, gateVerdict, judgeTask, noResumeReason, recordDispatch, worktreeNamed } from "./task-gate.mjs";
|
|
11
12
|
import { sessionDirOf } from "./workflow-settings.mjs";
|
|
12
13
|
|
|
@@ -54,7 +55,7 @@ const dispatch = (cwd, prompt, subagent_type = "architecture:sdd-implementer", e
|
|
|
54
55
|
tool_input: { subagent_type, description: "Task", prompt },
|
|
55
56
|
...extra,
|
|
56
57
|
});
|
|
57
|
-
const taskPrompt = (worktree, more = "") => `Read the brief
|
|
58
|
+
const taskPrompt = (worktree, more = "") => `Read the brief.\nBrief: ${BRIEF}\nWorktree: ${worktree}\n${more}`;
|
|
58
59
|
const implementerStop = (ws, head, branch = "feat/1-x", handoff = null) =>
|
|
59
60
|
appendRecord(ws.ledger, {
|
|
60
61
|
type: "stop",
|
|
@@ -89,7 +90,7 @@ test("with swarm.dispatch off, the gate passes and writes nothing", (t) => {
|
|
|
89
90
|
|
|
90
91
|
test("a dispatch with no worktree line is recorded as no task, and the session remembers the checkout", (t) => {
|
|
91
92
|
const ws = workspace(t);
|
|
92
|
-
for (const call of [dispatch(ws.main, "
|
|
93
|
+
for (const call of [dispatch(ws.main, "Plan it.", "architecture:sdd-planner"), dispatch(ws.main, `Read the brief.\nBrief: ${BRIEF}`)]) {
|
|
93
94
|
const task = judgeTask(call, ws.tmp);
|
|
94
95
|
assert.equal(task.refusal, null);
|
|
95
96
|
assert.equal(recordDispatch(task), null);
|
|
@@ -368,11 +369,11 @@ test("a reviewer dispatch in another repository lands in that repository's ledge
|
|
|
368
369
|
assert.equal(existsSync(ws.ledger), false);
|
|
369
370
|
});
|
|
370
371
|
|
|
371
|
-
test("a reviewer dispatch whose worktree does not exist
|
|
372
|
+
test("a reviewer dispatch whose worktree does not exist is refused, and the refusal names the Worktree line", (t) => {
|
|
372
373
|
const ws = workspace(t);
|
|
373
374
|
const task = judgeTask(dispatch(ws.main, taskPrompt(path.join(ws.tmp, "nowhere")), "architecture:sdd-reviewer"), ws.tmp);
|
|
374
|
-
assert.
|
|
375
|
-
assert.equal(task.record
|
|
375
|
+
assert.match(task.refusal ?? "", /`Worktree: <path>`/);
|
|
376
|
+
assert.equal(task.record, null);
|
|
376
377
|
});
|
|
377
378
|
|
|
378
379
|
test("a worktree spelled as a Git Bash drive path resolves on Windows", { skip: process.platform !== "win32" }, (t) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A brief file for a test that dispatches an implementer: the task gate reads the file on the `Brief:` line.
|
|
2
|
+
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), "qc-test-brief-"));
|
|
8
|
+
process.on("exit", () => rmSync(dir, { recursive: true, force: true }));
|
|
9
|
+
|
|
10
|
+
/** The path of a brief that holds a `## Product decisions` section. */
|
|
11
|
+
export const BRIEF = path.join(dir, "brief.md");
|
|
12
|
+
writeFileSync(BRIEF, "# Brief\n\n## Product decisions\n\nNone.\n");
|
|
@@ -133,3 +133,31 @@ export function agentTypeOf(transcript) {
|
|
|
133
133
|
return null;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
/** The number of distinct tool calls in a transcript: each `tool_use` block counts once, whatever lines repeat its message. */
|
|
138
|
+
export function toolCallsIn(file) {
|
|
139
|
+
let text;
|
|
140
|
+
try {
|
|
141
|
+
text = readFileSync(file, "utf8");
|
|
142
|
+
} catch {
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
const ids = new Set();
|
|
146
|
+
let anonymous = 0;
|
|
147
|
+
for (const line of text.split(/\r?\n/)) {
|
|
148
|
+
if (!line.includes('"tool_use"')) continue;
|
|
149
|
+
let content;
|
|
150
|
+
try {
|
|
151
|
+
content = JSON.parse(line)?.message?.content;
|
|
152
|
+
} catch {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (!Array.isArray(content)) continue;
|
|
156
|
+
for (const block of content) {
|
|
157
|
+
if (block?.type !== "tool_use") continue;
|
|
158
|
+
if (typeof block.id === "string") ids.add(block.id);
|
|
159
|
+
else anonymous += 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return ids.size + anonymous;
|
|
163
|
+
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
readRequests,
|
|
14
14
|
requestOf,
|
|
15
15
|
subagentTranscriptOf,
|
|
16
|
+
toolCallsIn,
|
|
16
17
|
} from "./transcript-usage.mjs";
|
|
17
18
|
|
|
18
19
|
function folder(t) {
|
|
@@ -136,3 +137,11 @@ test("agentTypeOf reads the type from the meta file beside a transcript", (t) =>
|
|
|
136
137
|
writeFileSync(path.join(base, "agent-a1.meta.json"), JSON.stringify({ agentType: "architecture:sdd-reviewer" }));
|
|
137
138
|
assert.equal(agentTypeOf(file), "architecture:sdd-reviewer");
|
|
138
139
|
});
|
|
140
|
+
|
|
141
|
+
test("toolCallsIn counts each tool_use id once, and a file that does not read has none", (t) => {
|
|
142
|
+
const file = path.join(folder(t), "t.jsonl");
|
|
143
|
+
const line = (ids) => JSON.stringify({ type: "assistant", message: { id: "m", content: ids.map((id) => ({ type: "tool_use", id })) } });
|
|
144
|
+
writeFileSync(file, [line(["a"]), line(["a", "b"]), line([]), "not json with tool_use", JSON.stringify({ type: "user", message: { content: "tool_use" } })].join("\n"));
|
|
145
|
+
assert.equal(toolCallsIn(file), 2);
|
|
146
|
+
assert.equal(toolCallsIn(path.join(folder(t), "missing.jsonl")), 0);
|
|
147
|
+
});
|
|
@@ -71,3 +71,41 @@ test("each workflow script is silent in a checkout without swarm.dispatch", (t)
|
|
|
71
71
|
assert.equal(result.stdout, "", script);
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
test("hooks.json runs the skill guard on the Skill tool, and gives the dispatch guard time for its git and gh reads", () => {
|
|
76
|
+
assert.deepEqual(matchersOf("PreToolUse", "skill-guard.mjs"), ["Skill"]);
|
|
77
|
+
const entry = hooks.PreToolUse.find((candidate) => candidate.hooks.some((hook) => hook.command.includes("/dispatch-guard.mjs\"")));
|
|
78
|
+
assert.equal(entry.matcher, "Agent");
|
|
79
|
+
assert.equal(entry.hooks.find((hook) => hook.command.includes("/dispatch-guard.mjs\"")).timeout, 30);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("the skill guard is silent without swarm.dispatch, and denies a code-review skill with it", (t) => {
|
|
83
|
+
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-skill-hooks-")));
|
|
84
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
85
|
+
execFileSync("git", ["init", "-q"], { cwd: base, stdio: "pipe" });
|
|
86
|
+
const run = (config) => {
|
|
87
|
+
writeFileSync(path.join(base, "qc.config.json"), JSON.stringify(config));
|
|
88
|
+
const event = { session_id: "s", cwd: base, hook_event_name: "PreToolUse", tool_name: "Skill", tool_input: { skill: "code-review" } };
|
|
89
|
+
return spawnSync(process.execPath, [path.join(CLI, "skill-guard.mjs")], { input: JSON.stringify(event), encoding: "utf8" });
|
|
90
|
+
};
|
|
91
|
+
assert.equal(run({ swarm: {} }).stdout, "");
|
|
92
|
+
assert.equal(JSON.parse(run({ swarm: { dispatch: {} } }).stdout).hookSpecificOutput.permissionDecision, "deny");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("cost-stop.mjs runs on every SubagentStop, and is silent in a checkout without swarm.dispatch", (t) => {
|
|
96
|
+
assert.deepEqual(matchersOf("SubagentStop", "cost-stop.mjs"), [undefined]);
|
|
97
|
+
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-cost-hooks-")));
|
|
98
|
+
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
99
|
+
execFileSync("git", ["init", "-q"], { cwd: base, stdio: "pipe" });
|
|
100
|
+
writeFileSync(path.join(base, "qc.config.json"), JSON.stringify({ swarm: {} }));
|
|
101
|
+
const transcript = path.join(base, "agent.jsonl");
|
|
102
|
+
writeFileSync(path.join(base, "agent.jsonl"), `${JSON.stringify({ type: "assistant", message: { id: "m", model: "m", usage: { input_tokens: 1, output_tokens: 1 } } })}\n`);
|
|
103
|
+
const result = spawnSync(process.execPath, [path.join(CLI, "cost-stop.mjs")], {
|
|
104
|
+
input: JSON.stringify({ session_id: "s", cwd: base, hook_event_name: "SubagentStop", agent_id: "a", agent_type: "sdd-implementer", agent_transcript_path: transcript }),
|
|
105
|
+
env: { ...process.env, TEMP: base, TMP: base, TMPDIR: base },
|
|
106
|
+
encoding: "utf8",
|
|
107
|
+
});
|
|
108
|
+
assert.equal(result.status, 0, result.stderr);
|
|
109
|
+
assert.equal(result.stdout, "");
|
|
110
|
+
assert.equal(existsSync(path.join(base, ".git", "qc", "ledger.jsonl")), false);
|
|
111
|
+
});
|
|
@@ -12,7 +12,9 @@ import { ledgerFileOf } from "./ledger.mjs";
|
|
|
12
12
|
|
|
13
13
|
const KEY = "swarm.review";
|
|
14
14
|
const MERGE_KINDS = ["branch", "task"];
|
|
15
|
-
const
|
|
15
|
+
const SWITCH_KEYS = ["oneBranchReview", "requireGreen", "requireBase", "productDecisions"];
|
|
16
|
+
const LIMIT_KEYS = ["roundFindings", "roundFiles"];
|
|
17
|
+
const REVIEW_KEYS = ["merge", "maxTaskCalls", "controllerPaths", "reviewerTypes", "plannerTypes", "codeReviewSkills", ...SWITCH_KEYS, ...LIMIT_KEYS];
|
|
16
18
|
const STATE_FILE = "state.json";
|
|
17
19
|
|
|
18
20
|
const isNameList = (value) => Array.isArray(value) && value.every((name) => typeof name === "string" && name !== "");
|
|
@@ -28,7 +30,8 @@ export function reviewSettings(swarm = {}) {
|
|
|
28
30
|
}
|
|
29
31
|
const unknown = Object.keys(raw).find((key) => !REVIEW_KEYS.includes(key));
|
|
30
32
|
if (unknown !== undefined) throw new Error(`${KEY}.${unknown} in qc.config.json is not a review setting; the keys are ${REVIEW_KEYS.join(", ")}`);
|
|
31
|
-
const
|
|
33
|
+
const merged = merge(reviewDefaults, raw);
|
|
34
|
+
const { merge: mergeKind, maxTaskCalls, controllerPaths, reviewerTypes, plannerTypes, codeReviewSkills } = merged;
|
|
32
35
|
if (!MERGE_KINDS.includes(mergeKind)) throw wrong("merge", mergeKind, `one of ${MERGE_KINDS.join(", ")}`);
|
|
33
36
|
if (!Number.isInteger(maxTaskCalls) || maxTaskCalls < 1) throw wrong("maxTaskCalls", maxTaskCalls, "a positive whole number");
|
|
34
37
|
if (!isNameList(controllerPaths)) throw wrong("controllerPaths", controllerPaths, "a list of globs");
|
|
@@ -36,7 +39,15 @@ export function reviewSettings(swarm = {}) {
|
|
|
36
39
|
if (!isNameList(reviewerTypes?.[kind])) throw wrong(`reviewerTypes.${kind}`, reviewerTypes?.[kind], "a list of agent types");
|
|
37
40
|
}
|
|
38
41
|
if (!isNameList(plannerTypes)) throw wrong("plannerTypes", plannerTypes, "a list of agent types");
|
|
39
|
-
|
|
42
|
+
if (!isNameList(codeReviewSkills)) throw wrong("codeReviewSkills", codeReviewSkills, "a list of skill names");
|
|
43
|
+
for (const key of SWITCH_KEYS) {
|
|
44
|
+
if (typeof merged[key] !== "boolean") throw wrong(key, merged[key], "true or false");
|
|
45
|
+
}
|
|
46
|
+
for (const key of LIMIT_KEYS) {
|
|
47
|
+
if (!Number.isInteger(merged[key]) || merged[key] < 0) throw wrong(key, merged[key], "a whole number, 0 or more");
|
|
48
|
+
}
|
|
49
|
+
const enforcement = Object.fromEntries([...SWITCH_KEYS, ...LIMIT_KEYS].map((key) => [key, merged[key]]));
|
|
50
|
+
return { merge: mergeKind, maxTaskCalls, controllerPaths, reviewerTypes, plannerTypes, codeReviewSkills, ...enforcement, implementerTypes: dispatch.implementerTypes };
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
/** @returns the workflow of the checkout that holds `cwd`, or null when it has no config or the checks are off. */
|
|
@@ -53,6 +53,14 @@ test("a bad key throws and names it", () => {
|
|
|
53
53
|
["on", /swarm\.review in qc\.config\.json must be an object/],
|
|
54
54
|
[{ mergeKind: "task" }, /swarm\.review\.mergeKind/],
|
|
55
55
|
[{ merge: "task", maxTaskCall: 5 }, /swarm\.review\.maxTaskCall/],
|
|
56
|
+
[{ oneBranchReview: "yes" }, /swarm\.review\.oneBranchReview/],
|
|
57
|
+
[{ requireGreen: 1 }, /swarm\.review\.requireGreen/],
|
|
58
|
+
[{ requireBase: null }, /swarm\.review\.requireBase/],
|
|
59
|
+
[{ productDecisions: "on" }, /swarm\.review\.productDecisions/],
|
|
60
|
+
[{ codeReviewSkills: "code-review" }, /swarm\.review\.codeReviewSkills/],
|
|
61
|
+
[{ codeReviewSkills: [""] }, /swarm\.review\.codeReviewSkills/],
|
|
62
|
+
[{ roundFindings: -1 }, /swarm\.review\.roundFindings/],
|
|
63
|
+
[{ roundFiles: 1.5 }, /swarm\.review\.roundFiles/],
|
|
56
64
|
]) {
|
|
57
65
|
assert.throws(() => reviewSettings({ dispatch: {}, review }), key);
|
|
58
66
|
}
|
|
@@ -77,3 +85,19 @@ test("a hook whose cwd holds no config reads the checkout its session remembered
|
|
|
77
85
|
assert.equal(workflowOf(call, tmp).root, dirs[0]);
|
|
78
86
|
assert.equal(workflowOf({ session_id: "s-2", cwd: outside }, tmp), null);
|
|
79
87
|
});
|
|
88
|
+
|
|
89
|
+
test("the enforcement keys default on, and a repository switches each one off", () => {
|
|
90
|
+
const settings = reviewSettings({ dispatch: {} });
|
|
91
|
+
assert.deepEqual(
|
|
92
|
+
[settings.oneBranchReview, settings.codeReviewSkills, settings.requireGreen, settings.requireBase, settings.productDecisions, settings.roundFindings, settings.roundFiles],
|
|
93
|
+
[true, ["code-review"], true, true, true, 8, 10],
|
|
94
|
+
);
|
|
95
|
+
const off = reviewSettings({
|
|
96
|
+
dispatch: {},
|
|
97
|
+
review: { oneBranchReview: false, codeReviewSkills: [], requireGreen: false, requireBase: false, productDecisions: false, roundFindings: 0, roundFiles: 0 },
|
|
98
|
+
});
|
|
99
|
+
assert.deepEqual(
|
|
100
|
+
[off.oneBranchReview, off.codeReviewSkills, off.requireGreen, off.requireBase, off.productDecisions, off.roundFindings, off.roundFiles],
|
|
101
|
+
[false, [], false, false, false, 0, 0],
|
|
102
|
+
);
|
|
103
|
+
});
|
package/src/config.mjs
CHANGED
|
@@ -559,6 +559,19 @@ export const reviewDefaults = {
|
|
|
559
559
|
},
|
|
560
560
|
// The agent types whose stop runs the plan check.
|
|
561
561
|
plannerTypes: ["sdd-planner", "architecture:sdd-planner"],
|
|
562
|
+
// Refuse a branch-reviewer dispatch with no `Reviewed: <sha>` line once the ledger holds a branch verdict on the branch.
|
|
563
|
+
oneBranchReview: true,
|
|
564
|
+
// Skill names, bare or after a `plugin:` prefix, that the model may not call. `[]` turns the check off.
|
|
565
|
+
codeReviewSkills: ["code-review"],
|
|
566
|
+
// Refuse a reviewer dispatch while CI on the head is red or running.
|
|
567
|
+
requireGreen: true,
|
|
568
|
+
// Refuse a reviewer dispatch when the head lacks the tip of `worktree.base`.
|
|
569
|
+
requireBase: true,
|
|
570
|
+
// Refuse an implementer dispatch whose brief has no `## Product decisions` heading.
|
|
571
|
+
productDecisions: true,
|
|
572
|
+
// Warn on an implementer brief with more numbered findings, or more named files. `0` turns a warning off.
|
|
573
|
+
roundFindings: 8,
|
|
574
|
+
roundFiles: 10,
|
|
562
575
|
};
|
|
563
576
|
|
|
564
577
|
// What each key of `swarm.direct` means when a repository omits it. A fix inside these limits skips the
|