architecture-harness 0.20.2 → 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 +70 -11
- package/src/cli/bash-command-guard.test.mjs +219 -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 +54 -0
- package/src/cli/ci-state.test.mjs +76 -0
- 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 +7 -3
- package/src/cli/dispatch-reminder.test.mjs +16 -1
- package/src/cli/git-read.mjs +41 -3
- package/src/cli/git-read.test.mjs +31 -1
- package/src/cli/ledger.mjs +52 -3
- package/src/cli/ledger.test.mjs +60 -0
- package/src/cli/merge-guard.mjs +1 -14
- package/src/cli/plugin-agents.test.mjs +11 -0
- package/src/cli/powershell-command.mjs +8 -13
- package/src/cli/powershell-command.test.mjs +12 -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 +77 -13
- package/src/cli/shell-command.test.mjs +44 -3
- 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 +54 -16
- package/src/cli/task-gate.test.mjs +65 -6
- 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 +12 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
3
|
+
import { 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 { fileURLToPath } from "node:url";
|
|
8
|
+
import { decide, isListedSkill } from "./skill-guard.mjs";
|
|
9
|
+
|
|
10
|
+
function checkout(t, config) {
|
|
11
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-skill-guard-")));
|
|
12
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
13
|
+
execFileSync("git", ["init", "-q"], { cwd: dir, stdio: "pipe" });
|
|
14
|
+
if (config !== null) writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify(config));
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const call = (cwd, skill, extra = {}) => ({
|
|
19
|
+
session_id: "s",
|
|
20
|
+
cwd,
|
|
21
|
+
hook_event_name: "PreToolUse",
|
|
22
|
+
tool_name: "Skill",
|
|
23
|
+
tool_input: { skill, args: "max" },
|
|
24
|
+
...extra,
|
|
25
|
+
});
|
|
26
|
+
const reasonOf = (result) => result?.hookSpecificOutput?.permissionDecisionReason ?? "";
|
|
27
|
+
|
|
28
|
+
test("a skill is listed by its name or by the part after the colon", () => {
|
|
29
|
+
const list = ["code-review"];
|
|
30
|
+
assert.equal(isListedSkill("code-review", list), true);
|
|
31
|
+
assert.equal(isListedSkill("Code-Review", list), true);
|
|
32
|
+
assert.equal(isListedSkill(" /code-review ", list), true);
|
|
33
|
+
assert.equal(isListedSkill("code-review:code-review", list), true);
|
|
34
|
+
assert.equal(isListedSkill("any-plugin:code-review", list), true);
|
|
35
|
+
assert.equal(isListedSkill("code-reviewer", list), false);
|
|
36
|
+
assert.equal(isListedSkill("superpowers:requesting-code-review", list), false);
|
|
37
|
+
assert.equal(isListedSkill("a:b", ["a:b"]), true);
|
|
38
|
+
assert.equal(isListedSkill("code-review", []), false);
|
|
39
|
+
assert.equal(isListedSkill(undefined, list), false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("with swarm.dispatch on, the guard refuses a code-review skill and names the way out", (t) => {
|
|
43
|
+
const dir = checkout(t, { swarm: { dispatch: {} } });
|
|
44
|
+
for (const skill of ["code-review", "code-review:code-review", "x:code-review"]) {
|
|
45
|
+
const result = decide(call(dir, skill));
|
|
46
|
+
assert.equal(result.hookSpecificOutput.permissionDecision, "deny", skill);
|
|
47
|
+
assert.match(reasonOf(result), /sdd-branch-reviewer/);
|
|
48
|
+
assert.match(reasonOf(result), /\/code-review/);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("a skill outside the list passes, and so does every other tool", (t) => {
|
|
53
|
+
const dir = checkout(t, { swarm: { dispatch: {} } });
|
|
54
|
+
assert.equal(decide(call(dir, "superpowers:brainstorming")), null);
|
|
55
|
+
assert.equal(decide(call(dir, "code-reviewer")), null);
|
|
56
|
+
assert.equal(decide({ ...call(dir, "code-review"), tool_name: "Read" }), null);
|
|
57
|
+
assert.equal(decide({ ...call(dir, "code-review"), tool_input: {} }), null);
|
|
58
|
+
assert.equal(decide({ ...call(dir, "code-review"), hook_event_name: "PostToolUse" }), null);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("swarm.review.codeReviewSkills replaces the list, and [] turns the check off", (t) => {
|
|
62
|
+
const custom = checkout(t, { swarm: { dispatch: {}, review: { codeReviewSkills: ["my-review"] } } });
|
|
63
|
+
assert.equal(decide(call(custom, "code-review")), null);
|
|
64
|
+
assert.equal(decide(call(custom, "p:my-review")).hookSpecificOutput.permissionDecision, "deny");
|
|
65
|
+
const off = checkout(t, { swarm: { dispatch: {}, review: { codeReviewSkills: [] } } });
|
|
66
|
+
assert.equal(decide(call(off, "code-review")), null);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the guard is silent where swarm.dispatch is off, or where there is no config", (t) => {
|
|
70
|
+
assert.equal(decide(call(checkout(t, null), "code-review")), null);
|
|
71
|
+
assert.equal(decide(call(checkout(t, { swarm: {} }), "code-review")), null);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("a wrong swarm.review value lets the call through with a note", (t) => {
|
|
75
|
+
const dir = checkout(t, { swarm: { dispatch: {}, review: { codeReviewSkills: "code-review" } } });
|
|
76
|
+
const result = decide(call(dir, "code-review"));
|
|
77
|
+
assert.equal(result.hookSpecificOutput.permissionDecision, undefined);
|
|
78
|
+
assert.match(result.hookSpecificOutput.additionalContext, /Skill guard is off: .*codeReviewSkills/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("the script reads the hook payload from stdin and writes the refusal", (t) => {
|
|
82
|
+
const dir = checkout(t, { swarm: { dispatch: {} } });
|
|
83
|
+
const script = fileURLToPath(new URL("./skill-guard.mjs", import.meta.url));
|
|
84
|
+
const run = (skill) => spawnSync(process.execPath, [script], { input: JSON.stringify(call(dir, skill)), encoding: "utf8" });
|
|
85
|
+
assert.equal(JSON.parse(run("code-review").stdout).hookSpecificOutput.permissionDecision, "deny");
|
|
86
|
+
assert.equal(run("brainstorming").stdout, "");
|
|
87
|
+
});
|
|
@@ -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,11 +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, ciState as readCiState } from "./ci-state.mjs";
|
|
7
8
|
import { typeOf } from "./dispatch.mjs";
|
|
8
9
|
import { handoffPathOf, resolveHandoff } from "./handoff-note.mjs";
|
|
9
|
-
import {
|
|
10
|
+
import { gitOutWithin, linkedWorktrees, pathKey } from "./git-read.mjs";
|
|
10
11
|
import { appendRecord, latestVerdictFor, latestVerdictOn, readLedger, shaMatches } from "./ledger.mjs";
|
|
11
12
|
import { resolveNamedWorktree, workflowOfRepo, worktreeNamed } from "./workflow-place.mjs";
|
|
13
|
+
import { READ_MS, branchOfCheckout, briefCheck, defaultReads, headOf, reviewerCheck, unreadableRefusal } from "./review-gate.mjs";
|
|
12
14
|
import { rememberSession, workflowAt } from "./workflow-settings.mjs";
|
|
13
15
|
|
|
14
16
|
export { worktreeNamed };
|
|
@@ -27,10 +29,13 @@ const fixRoundRefusal = (branch, sha, type) =>
|
|
|
27
29
|
const unreviewedRefusal = (branch, stopHead, head) =>
|
|
28
30
|
`Task gate: an implementer stopped on ${branch} at ${short(stopHead)}, and no review in the ledger names ${short(stopHead)} or a later commit. ` +
|
|
29
31
|
`Dispatch the task reviewer on ${short(head)} first; its first line \`VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>\` records the review. ` +
|
|
32
|
+
`The review runs once CI on the head is green: when CI on ${short(stopHead)} has failed or still runs, the next implementer continues the task and this gate passes it. ` +
|
|
30
33
|
`If that stop handed off, its report named \`HANDOFF: <note path>\`; the same line in the next implementer prompt continues the task. ` +
|
|
31
34
|
`\`qc ledger ${branch}\` lists what is recorded.`;
|
|
32
35
|
|
|
33
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);
|
|
34
39
|
|
|
35
40
|
/**
|
|
36
41
|
* The newest implementer stop in this branch's history that no later verdict on the branch covers,
|
|
@@ -72,22 +77,32 @@ export function continuedStop(records, branch, handoff) {
|
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
80
|
+
* The task gate's answer for an implementer on `branch`: `refusal` is the reason it may not start now, or null.
|
|
81
|
+
* `ciPass` is `{ sha, reason }` when an unreviewed stop head passes because CI on it is not green, else absent.
|
|
82
|
+
* Only implementer commits need a review, so a controller commit after a reviewed head passes. `cwd` is any
|
|
83
|
+
* checkout; `git` reads it, and `ci` answers why CI on a sha is not green, or null.
|
|
77
84
|
*/
|
|
78
|
-
export function
|
|
85
|
+
export function gateVerdict({ records, branch, head, reason, type, cwd, git = gitRead, handoff = null, ci = (sha) => ciNotGreen(sha, cwd) }) {
|
|
79
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.
|
|
80
87
|
const continued = continuedStop(records, branch, handoff);
|
|
81
88
|
const why = reason ?? (continued ? `continues the hand-off ${continued.handoff}` : null);
|
|
82
89
|
const last = latestVerdictOn(records, branch);
|
|
83
|
-
if (last?.verdict === "CHANGES_REQUIRED" && why === null) return fixRoundRefusal(branch, last.sha, type);
|
|
90
|
+
if (last?.verdict === "CHANGES_REQUIRED" && why === null) return { refusal: fixRoundRefusal(branch, last.sha, type) };
|
|
84
91
|
const unreviewed = unreviewedImplementerStop({ records, branch, head, cwd, git });
|
|
85
|
-
if (unreviewed && unreviewed !== continued)
|
|
92
|
+
if (unreviewed && unreviewed !== continued) {
|
|
93
|
+
// A head that CI failed changes before a review, so a review now would be spent on a commit that is replaced.
|
|
94
|
+
const notGreen = ci(unreviewed.head);
|
|
95
|
+
if (notGreen === null) return { refusal: unreviewedRefusal(branch, unreviewed.head, head) };
|
|
96
|
+
return { refusal: null, ciPass: { sha: unreviewed.head, reason: notGreen } };
|
|
97
|
+
}
|
|
86
98
|
const current = latestVerdictFor(records, head, ["task", "branch"]);
|
|
87
|
-
if (current?.verdict === "CHANGES_REQUIRED" && why === null) return fixRoundRefusal(branch, current.sha, type);
|
|
88
|
-
return null;
|
|
99
|
+
if (current?.verdict === "CHANGES_REQUIRED" && why === null) return { refusal: fixRoundRefusal(branch, current.sha, type) };
|
|
100
|
+
return { refusal: null };
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
/** @returns the reason an implementer may not start on `branch` now, or null. `gateVerdict` has the inputs. */
|
|
104
|
+
export const gateRefusal = (input) => gateVerdict(input).refusal;
|
|
105
|
+
|
|
91
106
|
const pass = (workflow, record, note = null) => ({ refusal: null, workflow, record, note });
|
|
92
107
|
const refuse = (refusal) => ({ refusal, workflow: null, record: null, note: null });
|
|
93
108
|
|
|
@@ -97,9 +112,10 @@ const taskTypeIn = (type, review) =>
|
|
|
97
112
|
/**
|
|
98
113
|
* Judges one main-session Agent call. The repository of the worktree the prompt names decides, and the
|
|
99
114
|
* repository of the cwd decides only when the prompt names none.
|
|
115
|
+
* `ci`, `ciState`, and `reads` replace the CI and base reads, for a test.
|
|
100
116
|
* @returns the refusal, or the record to write once the dispatch runs.
|
|
101
117
|
*/
|
|
102
|
-
export function judgeTask(call, tmp = os.tmpdir()) {
|
|
118
|
+
export function judgeTask(call, tmp = os.tmpdir(), { ci, ciState, reads = defaultReads } = {}) {
|
|
103
119
|
const cwd = call.cwd ?? process.cwd();
|
|
104
120
|
let own;
|
|
105
121
|
try {
|
|
@@ -140,14 +156,35 @@ export function judgeTask(call, tmp = os.tmpdir()) {
|
|
|
140
156
|
}
|
|
141
157
|
}
|
|
142
158
|
if (!workflow) return pass(null, null);
|
|
143
|
-
|
|
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);
|
|
144
166
|
if (!workflow.review.implementerTypes.includes(type)) {
|
|
145
|
-
// A reviewer
|
|
146
|
-
|
|
147
|
-
|
|
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);
|
|
148
184
|
}
|
|
185
|
+
if (named === null) return pass(workflow, base, briefNote);
|
|
149
186
|
const key = pathKey(abs);
|
|
150
|
-
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);
|
|
151
188
|
if (!worktree) {
|
|
152
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.`);
|
|
153
190
|
}
|
|
@@ -161,10 +198,11 @@ export function judgeTask(call, tmp = os.tmpdir()) {
|
|
|
161
198
|
const reason = noResumeReason(prompt);
|
|
162
199
|
const spelled = handoffPathOf(prompt);
|
|
163
200
|
const handoff = spelled === null ? null : resolveHandoff(spelled, cwd);
|
|
164
|
-
const refusal =
|
|
201
|
+
const { refusal, ciPass } = gateVerdict({ records, branch: worktree.branch, head: worktree.head, reason, type, cwd: workflow.root, handoff, ...(ci ? { ci } : {}) });
|
|
165
202
|
if (refusal) return refuse(refusal);
|
|
166
203
|
const continues = handoff ? { handoff } : {};
|
|
167
|
-
|
|
204
|
+
const unreviewed = ciPass ? { ciPass } : {};
|
|
205
|
+
return pass(workflow, { ...base, task: true, worktree: worktree.path, branch: worktree.branch, head: worktree.head, resumeReason: reason, ...continues, ...unreviewed }, briefNote);
|
|
168
206
|
}
|
|
169
207
|
|
|
170
208
|
/** Writes the dispatch record of a judged call. @returns a note for the session, or null. */
|
|
@@ -7,7 +7,8 @@ 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 {
|
|
10
|
+
import { BRIEF } from "./test-brief.mjs";
|
|
11
|
+
import { continuedStop, gateRefusal, gateVerdict, judgeTask, noResumeReason, recordDispatch, worktreeNamed } from "./task-gate.mjs";
|
|
11
12
|
import { sessionDirOf } from "./workflow-settings.mjs";
|
|
12
13
|
|
|
13
14
|
// The guard processes below run under Codex, whatever runtime runs the test.
|
|
@@ -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) => {
|
|
@@ -508,3 +509,61 @@ test("a later verdict on the branch ends the continuation, whatever commit it na
|
|
|
508
509
|
assert.equal(continuedStop(readLedger(ws.ledger), "feat/1-x", note), null);
|
|
509
510
|
assert.match(refusalOf(ws, `HANDOFF: ${note}`) ?? "", /CHANGES_REQUIRED/);
|
|
510
511
|
});
|
|
512
|
+
|
|
513
|
+
test("a stop head with CI that is not green lets the next implementer continue, and the dispatch record holds the reason", (t) => {
|
|
514
|
+
const ws = workspace(t);
|
|
515
|
+
recordDispatch(judgeTask(dispatch(ws.main, taskPrompt(ws.linked)), ws.tmp));
|
|
516
|
+
const moved = commitIn(ws.linked, "b.txt");
|
|
517
|
+
implementerStop(ws, moved);
|
|
518
|
+
const asked = [];
|
|
519
|
+
const ci = (sha) => {
|
|
520
|
+
asked.push(sha);
|
|
521
|
+
return `CI on ${sha.slice(0, 7)}: build ended failure`;
|
|
522
|
+
};
|
|
523
|
+
const task = judgeTask(dispatch(ws.main, taskPrompt(ws.linked)), ws.tmp, { ci });
|
|
524
|
+
assert.equal(task.refusal, null);
|
|
525
|
+
assert.deepEqual(asked, [moved]);
|
|
526
|
+
assert.deepEqual(task.record.ciPass, { sha: moved, reason: `CI on ${moved.slice(0, 7)}: build ended failure` });
|
|
527
|
+
recordDispatch(task);
|
|
528
|
+
const [, written] = readLedger(ws.ledger).filter((record) => record.type === "dispatch");
|
|
529
|
+
assert.deepEqual(written.ciPass, task.record.ciPass);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
test("a stop head with green or unknown CI keeps the refusal, and the refusal says the review waits for green CI", (t) => {
|
|
533
|
+
const ws = workspace(t);
|
|
534
|
+
implementerStop(ws, commitIn(ws.linked, "b.txt"));
|
|
535
|
+
const refusal = judgeTask(dispatch(ws.main, taskPrompt(ws.linked)), ws.tmp, { ci: () => null }).refusal;
|
|
536
|
+
assert.match(refusal ?? "", /no review in the ledger/);
|
|
537
|
+
assert.match(refusal ?? "", /once CI on the head is green/);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
test("the CI pass does not skip a review that is already on record", (t) => {
|
|
541
|
+
const ws = workspace(t);
|
|
542
|
+
const moved = commitIn(ws.linked, "b.txt");
|
|
543
|
+
implementerStop(ws, moved);
|
|
544
|
+
verdict(ws, moved);
|
|
545
|
+
let asked = 0;
|
|
546
|
+
const task = judgeTask(dispatch(ws.main, taskPrompt(ws.linked)), ws.tmp, { ci: () => (asked += 1, "red") });
|
|
547
|
+
assert.equal(task.refusal, null);
|
|
548
|
+
assert.equal(asked, 0);
|
|
549
|
+
assert.equal(task.record.ciPass, undefined);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
test("a CI pass does not lift a CHANGES_REQUIRED fix round", (t) => {
|
|
553
|
+
const ws = workspace(t);
|
|
554
|
+
const moved = commitIn(ws.linked, "b.txt");
|
|
555
|
+
implementerStop(ws, moved);
|
|
556
|
+
verdict(ws, moved, "CHANGES_REQUIRED");
|
|
557
|
+
assert.match(judgeTask(dispatch(ws.main, taskPrompt(ws.linked)), ws.tmp, { ci: () => "red" }).refusal ?? "", /CHANGES_REQUIRED/);
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test("gateVerdict reports the stop and the reason of a CI pass, and gateRefusal still answers with the refusal alone", (t) => {
|
|
561
|
+
const ws = workspace(t);
|
|
562
|
+
const moved = commitIn(ws.linked, "b.txt");
|
|
563
|
+
implementerStop(ws, moved);
|
|
564
|
+
const input = { records: readLedger(ws.ledger), branch: "feat/1-x", head: moved, reason: null, type: "sdd-implementer", cwd: ws.linked };
|
|
565
|
+
assert.deepEqual(gateVerdict({ ...input, ci: () => "red" }), { refusal: null, ciPass: { sha: moved, reason: "red" } });
|
|
566
|
+
assert.match(gateVerdict({ ...input, ci: () => null }).refusal ?? "", /no review/);
|
|
567
|
+
assert.match(gateRefusal({ ...input, ci: () => null }) ?? "", /no review/);
|
|
568
|
+
assert.equal(gateRefusal({ ...input, ci: () => "red" }), null);
|
|
569
|
+
});
|
|
@@ -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");
|