rungate 0.7.0 → 0.8.1
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/gates/.gate-salt +1 -0
- package/gates/SCHEMA-GUIDE.md +485 -0
- package/gates/ac-quality.test.ts +106 -0
- package/gates/adversarial.test.ts +283 -0
- package/gates/brief-assembler.test.ts +487 -0
- package/gates/brief-assembler.ts +448 -0
- package/gates/bunfig.toml +2 -0
- package/gates/chain.test.ts +91 -0
- package/gates/e2e-smoke.test.ts +234 -0
- package/gates/error-classifier.test.ts +250 -0
- package/gates/error-classifier.ts +99 -0
- package/gates/gate-executor.ts +3071 -0
- package/gates/orchestrator.test.ts +968 -0
- package/gates/orchestrator.ts +827 -0
- package/gates/preload.ts +89 -0
- package/gates/prompts/ac-adversary.md +20 -0
- package/gates/prompts/evidence-validator.md +22 -0
- package/gates/prompts/prove-reproducer.md +53 -0
- package/gates/prompts.sha256 +3 -0
- package/gates/prove.test.ts +164 -0
- package/gates/rook-state.test.ts +108 -0
- package/gates/run-attribution.ts +290 -0
- package/gates/run-gate.ts +163 -0
- package/gates/schema-parity.test.ts +378 -0
- package/gates/schema.ts +1209 -0
- package/gates/self-heal.test.ts +511 -0
- package/gates/self-heal.ts +125 -0
- package/gates/ship-orchestrator.test.ts +399 -0
- package/gates/ship-orchestrator.ts +384 -0
- package/gates/spec-compliance-probe.ts +159 -0
- package/gates/test-fixtures/broken-no-environments.json +110 -0
- package/gates/test-fixtures/consumer-directory-layout.json +90 -0
- package/gates/test-fixtures/valid-standard.json +91 -0
- package/gates/test-utils.ts +43 -0
- package/gates/typecheck-gate.ts +111 -0
- package/gates/witness.ts +349 -0
- package/gates/workflow.test.ts +2018 -0
- package/hooks/ActionVerificationGate.hook.ts +96 -0
- package/hooks/AgentBriefGuard.hook.ts +38 -0
- package/hooks/AgentVerdictCapture.hook.ts +87 -0
- package/hooks/AutoVerifyGate.hook.ts +79 -0
- package/hooks/BashToolGuard.hook.ts +65 -0
- package/hooks/BashWriteGuard.hook.ts +60 -0
- package/hooks/CommitEnforcement.hook.ts +130 -0
- package/hooks/DocHygiene.hook.ts +148 -0
- package/hooks/GateEnforcement.hook.ts +58 -0
- package/hooks/GateResultProtection.hook.ts +95 -0
- package/hooks/HarnessAFKGate.hook.ts +85 -0
- package/hooks/HookCurrency.hook.ts +99 -0
- package/hooks/IssueCloseGuard.hook.ts +149 -0
- package/hooks/MergeGuard.hook.ts +58 -0
- package/hooks/PostCompact.hook.ts +60 -0
- package/hooks/ProjectStateSync.hook.ts +103 -0
- package/hooks/SkillGuard.hook.ts +69 -0
- package/hooks/SpecConformityTrigger.hook.ts +43 -0
- package/hooks/SpecSCGuard.hook.ts +123 -0
- package/hooks/StaleTTLCleanup.hook.ts +141 -0
- package/hooks/TaskCompleted.hook.ts +51 -0
- package/hooks/TeamInit.hook.ts +85 -0
- package/hooks/TestSuiteGuard.hook.ts +70 -0
- package/hooks/TestSuiteRelease.hook.ts +85 -0
- package/hooks/TopLevelCdGuard.hook.ts +108 -0
- package/hooks/VerifyPhaseLock.hook.ts +84 -0
- package/hooks/WorkflowStateGuard.hook.ts +64 -0
- package/hooks/lib/agent-config.json +9 -0
- package/hooks/lib/agentDetection.ts +201 -0
- package/hooks/lib/comment-template.ts +86 -0
- package/hooks/lib/findWorkflow.ts +101 -0
- package/hooks/lib/parseStdin.ts +37 -0
- package/hooks/lib/paths.ts +111 -0
- package/hooks/lib/utils.ts +338 -0
- package/lib/affected-tests.ts +29 -0
- package/lib/bash-write-guard.ts +627 -0
- package/lib/branch-cleanup.ts +279 -7
- package/lib/config-trackable.ts +9 -0
- package/lib/distribution-currency.ts +55 -5
- package/lib/failure-intake.ts +7 -1
- package/lib/gate-enforcement.ts +360 -38
- package/lib/gate-names.ts +72 -0
- package/lib/gate-result-protection.ts +437 -0
- package/lib/generators/code-map.ts +55 -4
- package/lib/generators/types.ts +27 -1
- package/lib/intake-sources.ts +380 -0
- package/lib/js-top-level-code.ts +20 -2
- package/lib/junit-checks.ts +239 -1
- package/lib/late-env-spawn.ts +331 -0
- package/lib/launch-base.ts +128 -5
- package/lib/package-closure.ts +114 -0
- package/lib/paths.ts +96 -3
- package/lib/phase2-decomposition.ts +1 -1
- package/lib/published-artifact.ts +162 -18
- package/lib/sc-id-cross-tree.ts +84 -8
- package/lib/scaffold/ai-review-findings.ts +149 -4
- package/lib/scaffold/ai-review-step.ts +1006 -132
- package/lib/scaffold/defaults.ts +82 -1
- package/lib/scaffold/steps.ts +642 -54
- package/lib/scanner.ts +4 -2
- package/lib/security-verdict.ts +1 -1
- package/lib/shell-path-interpolation.ts +594 -0
- package/lib/text-dependents.ts +875 -0
- package/lib/transcript-checker.ts +6 -0
- package/lib/workflow-security.ts +29 -0
- package/lib/workflow-taint.ts +732 -0
- package/lib/worktree-cleanup.ts +65 -38
- package/lib/worktree-repo.ts +32 -2
- package/package.json +4 -1
- package/scripts/check-installed-hook-currency.ts +825 -0
- package/scripts/generate-code-map.ts +13 -8
package/gates/preload.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { afterAll } from "bun:test";
|
|
2
|
+
import { readFileSync, appendFileSync, existsSync, readdirSync, statSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
|
|
5
|
+
// ── Gate contract interfaces (SC-373) ─────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
export interface RecordTestInput {
|
|
8
|
+
name: string;
|
|
9
|
+
passed: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TestRecordResult {
|
|
13
|
+
testName: string;
|
|
14
|
+
result: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const WORK_DIR = join(process.env.RUNGATE_WORK_DIR || join(process.env.HOME || "", ".rungate"));
|
|
18
|
+
const STATE_DIR = join(process.env.HOME || "", ".claude", "state");
|
|
19
|
+
const RESULTS_PATH = join(STATE_DIR, "gate-results.jsonl");
|
|
20
|
+
const RECURRENCE_THRESHOLD = 3;
|
|
21
|
+
|
|
22
|
+
function findActiveWorkflow(): string | null {
|
|
23
|
+
const testDir = process.env.TEST_WORK_DIR;
|
|
24
|
+
if (testDir) {
|
|
25
|
+
const wfPath = join(testDir, "workflow-state.json");
|
|
26
|
+
return existsSync(wfPath) ? wfPath : null;
|
|
27
|
+
}
|
|
28
|
+
if (!existsSync(WORK_DIR)) return null;
|
|
29
|
+
let newest: { path: string; mtime: number } | null = null;
|
|
30
|
+
for (const entry of readdirSync(WORK_DIR, { withFileTypes: true })) {
|
|
31
|
+
if (!entry.isDirectory()) continue;
|
|
32
|
+
const wfPath = join(WORK_DIR, entry.name, "workflow-state.json");
|
|
33
|
+
if (!existsSync(wfPath)) continue;
|
|
34
|
+
const stat = statSync(wfPath);
|
|
35
|
+
if (!newest || stat.mtimeMs > newest.mtime) {
|
|
36
|
+
newest = { path: wfPath, mtime: stat.mtimeMs };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return newest?.path ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function findActiveIssue(): number | null {
|
|
43
|
+
const wfPath = findActiveWorkflow();
|
|
44
|
+
if (!wfPath) return null;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(readFileSync(wfPath, "utf-8")).issue ?? null;
|
|
47
|
+
} catch { return null; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function checkRecurrence(): string[] {
|
|
51
|
+
if (!existsSync(RESULTS_PATH)) return [];
|
|
52
|
+
const lines = readFileSync(RESULTS_PATH, "utf-8").trim().split("\n");
|
|
53
|
+
const failCounts = new Map<string, number>();
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
try {
|
|
56
|
+
const entry = JSON.parse(line);
|
|
57
|
+
if (entry.result === "fail") failCounts.set(entry.testName, (failCounts.get(entry.testName) || 0) + 1);
|
|
58
|
+
} catch { /* skip */ }
|
|
59
|
+
}
|
|
60
|
+
const recurring: string[] = [];
|
|
61
|
+
for (const [name, count] of failCounts) {
|
|
62
|
+
if (count >= RECURRENCE_THRESHOLD) recurring.push(`[learn] recurring failure (${count}x): ${name}`);
|
|
63
|
+
}
|
|
64
|
+
return recurring;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const capturedTests: { testName: string; result: string }[] = [];
|
|
68
|
+
|
|
69
|
+
afterAll(() => {
|
|
70
|
+
const issueNumber = findActiveIssue();
|
|
71
|
+
|
|
72
|
+
if (existsSync(STATE_DIR)) {
|
|
73
|
+
for (const t of capturedTests) {
|
|
74
|
+
appendFileSync(RESULTS_PATH, JSON.stringify({
|
|
75
|
+
ts: new Date().toISOString(),
|
|
76
|
+
testName: t.testName,
|
|
77
|
+
result: t.result,
|
|
78
|
+
issueNumber,
|
|
79
|
+
}) + "\n");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const recurring = checkRecurrence();
|
|
84
|
+
for (const msg of recurring) console.log(msg);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export function recordTest(name: string, passed: boolean) {
|
|
88
|
+
capturedTests.push({ testName: name, result: passed ? "pass" : "fail" });
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
You are an adversarial AC reviewer. Your objective: find ways to pass
|
|
2
|
+
every AC without actually fixing the bug.
|
|
3
|
+
|
|
4
|
+
For each AC, answer:
|
|
5
|
+
1. Can I write code that passes the evidence command but doesn't fix
|
|
6
|
+
the stated problem? How?
|
|
7
|
+
2. Is the threshold meaningful? Could garbage data meet it?
|
|
8
|
+
3. Does the evidence command test behavior (runtime output) or just
|
|
9
|
+
structure (file existence, grep count)?
|
|
10
|
+
|
|
11
|
+
Output as JSON:
|
|
12
|
+
{
|
|
13
|
+
"gameable": <number of gameable ACs>,
|
|
14
|
+
"approved": <true if 0 gameable>,
|
|
15
|
+
"exploits": [
|
|
16
|
+
{"acId": "SC-1", "exploit": "how to pass without fixing", "recommendation": "how to tighten"}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
If ALL ACs are robust, output: {"gameable": 0, "approved": true, "exploits": []}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
You are an evidence validator. Your objective: run evidence commands
|
|
2
|
+
independently and report whether results meet AC thresholds.
|
|
3
|
+
|
|
4
|
+
You run in a clean worktree. You cannot modify the code.
|
|
5
|
+
Execute each evidence command, capture output, compare against threshold.
|
|
6
|
+
|
|
7
|
+
Report as JSON:
|
|
8
|
+
{
|
|
9
|
+
"verdicts": [
|
|
10
|
+
{
|
|
11
|
+
"acId": "SC-1",
|
|
12
|
+
"command": "the command executed",
|
|
13
|
+
"rawOutput": "captured output",
|
|
14
|
+
"threshold": {"op": ">=", "value": "2", "unit": "..."},
|
|
15
|
+
"actual": "measured value",
|
|
16
|
+
"verdict": "PASS or FAIL"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Do not infer, assume, or extrapolate. If the command fails to run,
|
|
22
|
+
verdict is FAIL with the error message as rawOutput.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: reference
|
|
3
|
+
status: active
|
|
4
|
+
owner: jason
|
|
5
|
+
updated: 2026-09-19
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a prove reproducer. Your objective: reproduce the bug described
|
|
9
|
+
in the issue, verify the fix works, and capture evidence.
|
|
10
|
+
|
|
11
|
+
**Tool limitation:** You have Bash and Read tools only — no browser,
|
|
12
|
+
no Playwright, no screenshot capability. For UI-related ACs (screenshots,
|
|
13
|
+
visual elements, page navigation, OUTCOME-type criteria), output a SKIP
|
|
14
|
+
verdict with reason "B3 limitation: no browser tools — requires Quinn".
|
|
15
|
+
Focus your verification on CODE ACs that can be tested via command line
|
|
16
|
+
(grep, bun test, bun -e, curl, file reads).
|
|
17
|
+
|
|
18
|
+
1. Read the issue body (provided). Identify the user's complaint and
|
|
19
|
+
derive a test plan from the issue description.
|
|
20
|
+
2. Compare your test plan against the ACs provided. If the issue
|
|
21
|
+
describes a bug the ACs don't test, flag the gap.
|
|
22
|
+
3. For API/data issues: call the endpoints described in the issue via
|
|
23
|
+
curl, capture the response bodies as evidence.
|
|
24
|
+
4. For CODE issues: run evidence commands (grep, bun test, file reads)
|
|
25
|
+
to verify the fix is present and correct.
|
|
26
|
+
5. For UI issues: output SKIP for those criteria — you cannot navigate
|
|
27
|
+
pages or take screenshots. Note which ACs need Quinn verification.
|
|
28
|
+
6. Compare the before-state (provided) against the current after-state.
|
|
29
|
+
The before state shows what was broken. The after state must show
|
|
30
|
+
the fix working.
|
|
31
|
+
6b. For S-tier evidence (bug fixes): apply negative control — revert the
|
|
32
|
+
fix temporarily, confirm the bug returns, then re-apply. This proves
|
|
33
|
+
the fix is the actual cause of the improvement, not a coincidence.
|
|
34
|
+
7. For each criterion, capture real evidence — API responses, console
|
|
35
|
+
output, grep results. Never claim UI verification without browser tools.
|
|
36
|
+
|
|
37
|
+
Output JSON:
|
|
38
|
+
{
|
|
39
|
+
"verdict": "PROVEN|UNPROVEN|INCONCLUSIVE",
|
|
40
|
+
"criteriaResults": [
|
|
41
|
+
{"scId": "SC-1", "verdict": "PASS|FAIL", "evidence": "description of what was observed"}
|
|
42
|
+
],
|
|
43
|
+
"reproduced": true|false,
|
|
44
|
+
"evidence": [
|
|
45
|
+
{"type": "screenshot|api-response|console", "description": "what this shows"}
|
|
46
|
+
],
|
|
47
|
+
"gaps": []
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Verdict rules:
|
|
51
|
+
- PROVEN: bug was reproduced in before-state AND fix verified in after-state
|
|
52
|
+
- UNPROVEN: fix does not resolve the issue (evidence shows problem persists)
|
|
53
|
+
- INCONCLUSIVE: could not reproduce the bug or connect to dev server
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { test, expect, describe } from "bun:test";
|
|
2
|
+
import { readFileSync, existsSync, writeFileSync } from "fs";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
|
|
5
|
+
const TEST_DIR = process.env.TEST_WORK_DIR || "";
|
|
6
|
+
const PROJECT_ROOT = process.env.PROJECT_ROOT || process.cwd();
|
|
7
|
+
const GATE = process.env.GATE || "";
|
|
8
|
+
|
|
9
|
+
function tryRead(filename: string) {
|
|
10
|
+
const path = `${TEST_DIR}/${filename}`;
|
|
11
|
+
if (!existsSync(path)) return null;
|
|
12
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function runEvidence(command: string): { exitCode: number; output: string } {
|
|
16
|
+
try {
|
|
17
|
+
const output = execSync(command, { cwd: PROJECT_ROOT, timeout: 30000, encoding: "utf-8" });
|
|
18
|
+
return { exitCode: 0, output: output.trim() };
|
|
19
|
+
} catch (e: any) {
|
|
20
|
+
return { exitCode: e.status ?? 1, output: (e.stdout ?? "").trim() };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function compareThreshold(actual: string, op: string, expected: string): boolean {
|
|
25
|
+
if (op === "contains") return actual.includes(String(expected));
|
|
26
|
+
if (op === "!contains") return !actual.includes(String(expected));
|
|
27
|
+
if (op === "exists") return actual.length > 0;
|
|
28
|
+
const num = parseFloat(actual);
|
|
29
|
+
const exp = parseFloat(expected);
|
|
30
|
+
if (isNaN(num) || isNaN(exp)) return actual === expected;
|
|
31
|
+
switch (op) {
|
|
32
|
+
case ">=": return num >= exp;
|
|
33
|
+
case "<=": return num <= exp;
|
|
34
|
+
case "==": return num === exp;
|
|
35
|
+
case ">": return num > exp;
|
|
36
|
+
case "<": return num < exp;
|
|
37
|
+
case "!=": return num !== exp;
|
|
38
|
+
default: return actual === expected;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("prove: run evidence commands from workflow-state", () => {
|
|
43
|
+
if (GATE && GATE !== "prove") {
|
|
44
|
+
test("skipped — prove tests only run for prove/ship gates", () => {});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const wf = tryRead("workflow-state.json");
|
|
48
|
+
if (!wf) {
|
|
49
|
+
test("skipped — no active workflow (TEST_WORK_DIR not set or workflow-state.json missing)", () => {});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const commitSha = execSync("git rev-parse --short HEAD", { cwd: PROJECT_ROOT, encoding: "utf-8" }).trim();
|
|
54
|
+
const ceremonyTier = wf.sizing?.ceremonyTier || "STANDARD";
|
|
55
|
+
const proveEnvironment = ceremonyTier === "LIGHT" ? "local" : "prod";
|
|
56
|
+
const criteriaResults: any[] = [];
|
|
57
|
+
|
|
58
|
+
// B3 prove reproducer has Bash+Read only — no browser/screenshot capability.
|
|
59
|
+
// OUTCOME-type ACs and UI-related evidence commands get SKIP, not FAIL (#486).
|
|
60
|
+
const B3_UI_PATTERN = /screenshot|browser|playwright|visual|navigate|page\./i;
|
|
61
|
+
const isB3UiAc = (ac: any): boolean => {
|
|
62
|
+
if (ac.type === "OUTCOME") return true;
|
|
63
|
+
const cmd = ac.evidenceMethod?.command || "";
|
|
64
|
+
return B3_UI_PATTERN.test(cmd);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
for (const ac of wf.acs) {
|
|
68
|
+
test(`${ac.id}: ${ac.statement.slice(0, 80)}`, () => {
|
|
69
|
+
// B3 exempt: OUTCOME/UI ACs cannot be verified without browser tools
|
|
70
|
+
if (isB3UiAc(ac)) {
|
|
71
|
+
criteriaResults.push({
|
|
72
|
+
scId: ac.id,
|
|
73
|
+
verdict: "SKIP",
|
|
74
|
+
evidence: "B3 cannot verify UI — requires Quinn (#486)",
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cmd = ac.evidenceMethod?.command;
|
|
80
|
+
if (!cmd) {
|
|
81
|
+
criteriaResults.push({ scId: ac.id, verdict: "SKIP", evidence: "no evidence command" });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const result = runEvidence(cmd);
|
|
86
|
+
const lastLine = result.output.split("\n").pop() || "";
|
|
87
|
+
const isTestRunner = /^bun test\b/.test(cmd);
|
|
88
|
+
|
|
89
|
+
let verdict: string;
|
|
90
|
+
let evidence: string;
|
|
91
|
+
|
|
92
|
+
if (isTestRunner) {
|
|
93
|
+
verdict = result.exitCode === 0 ? "PASS" : "FAIL";
|
|
94
|
+
evidence = `${cmd} → exit ${result.exitCode} (test runner: exit code is verdict)`;
|
|
95
|
+
} else if (ac.threshold && result.exitCode === 0) {
|
|
96
|
+
const passed = compareThreshold(lastLine, ac.threshold.op, ac.threshold.value);
|
|
97
|
+
verdict = passed ? "PASS" : "FAIL";
|
|
98
|
+
evidence = `${cmd} → "${lastLine}" ${ac.threshold.op} ${ac.threshold.value} = ${passed}`;
|
|
99
|
+
} else if (result.exitCode === 0) {
|
|
100
|
+
verdict = "PASS";
|
|
101
|
+
evidence = `${cmd} → exit 0`;
|
|
102
|
+
} else {
|
|
103
|
+
verdict = "FAIL";
|
|
104
|
+
evidence = `${cmd} → exit ${result.exitCode}, output: "${lastLine}"`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
criteriaResults.push({ scId: ac.id, verdict, evidence });
|
|
108
|
+
|
|
109
|
+
if (verdict === "FAIL") {
|
|
110
|
+
expect(`${ac.id}: ${evidence}`).toBe("PASS");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
test("write prove-evidence.json", () => {
|
|
116
|
+
const fails = criteriaResults.filter(r => r.verdict === "FAIL");
|
|
117
|
+
const verdict = criteriaResults.length === 0 ? "INCONCLUSIVE"
|
|
118
|
+
: fails.length > 0 ? "UNPROVEN" : "PROVEN";
|
|
119
|
+
|
|
120
|
+
const evidence = {
|
|
121
|
+
issueNumber: wf.issue,
|
|
122
|
+
verdict,
|
|
123
|
+
commitSHA: commitSha,
|
|
124
|
+
capturedAt: new Date().toISOString(),
|
|
125
|
+
beforeEvidence: wf.beforeState ?? {
|
|
126
|
+
type: "none", path: null,
|
|
127
|
+
capturedAt: new Date().toISOString(),
|
|
128
|
+
description: "no before-state captured",
|
|
129
|
+
},
|
|
130
|
+
afterEvidence: {
|
|
131
|
+
type: "text", path: null,
|
|
132
|
+
capturedAt: new Date().toISOString(),
|
|
133
|
+
environment: proveEnvironment,
|
|
134
|
+
description: criteriaResults.map(r => `${r.scId}: ${r.verdict}`).join(", "),
|
|
135
|
+
},
|
|
136
|
+
comparisonSummary: `${criteriaResults.filter(r => r.verdict === "PASS").length}/${criteriaResults.length} criteria passed`,
|
|
137
|
+
reproduced: true,
|
|
138
|
+
gaps: fails.map(f => ({ ac: f.scId, status: "UNPROVEN", detail: f.evidence })),
|
|
139
|
+
criteriaResults,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
writeFileSync(`${TEST_DIR}/prove-evidence.json`, JSON.stringify(evidence, null, 2));
|
|
143
|
+
expect(verdict).toBe("PROVEN");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("prod environment enforcement: STANDARD+ requires prod evidence (#294, ported to Bun in #484)", () => {
|
|
147
|
+
if (ceremonyTier === "LIGHT") {
|
|
148
|
+
// LIGHT tier is exempt from prod enforcement — API check only
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// For STANDARD and THOROUGH tiers, afterEvidence.environment must be "prod"
|
|
153
|
+
const evidencePath = `${TEST_DIR}/prove-evidence.json`;
|
|
154
|
+
if (!existsSync(evidencePath)) {
|
|
155
|
+
expect("prove-evidence.json").toBe("must exist before prod enforcement check");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const proveEvidence = JSON.parse(readFileSync(evidencePath, "utf-8"));
|
|
160
|
+
const env = proveEvidence.afterEvidence?.environment;
|
|
161
|
+
|
|
162
|
+
expect(env).toBe("prod");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
|
|
2
|
+
import { mkdirSync, readFileSync, rmSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { AgentSchema, WorkflowStateSchema } from "./schema";
|
|
5
|
+
import { writeWorkflowState } from "./orchestrator";
|
|
6
|
+
|
|
7
|
+
const TEST_BASE = `/tmp/rook-state-test-${process.pid}`;
|
|
8
|
+
const TEST_SLUG = `rook-state-${process.pid}`;
|
|
9
|
+
const WORK_DIR = join(TEST_BASE, TEST_SLUG);
|
|
10
|
+
const SF = join(WORK_DIR, "workflow-state.json");
|
|
11
|
+
|
|
12
|
+
function minimalState(overrides: Record<string, any> = {}): Record<string, any> {
|
|
13
|
+
return {
|
|
14
|
+
schemaVersion: 2,
|
|
15
|
+
issue: 129,
|
|
16
|
+
repo: "hornjason/pai-harness",
|
|
17
|
+
issueRepo: "hornjason/pai-harness",
|
|
18
|
+
projectRoot: "/tmp/test-project",
|
|
19
|
+
slug: TEST_SLUG,
|
|
20
|
+
phase: "VERIFY",
|
|
21
|
+
issueGoal: "Record rook spawned, verdict and failures in workflow state",
|
|
22
|
+
acs: [],
|
|
23
|
+
gates: {},
|
|
24
|
+
changelog: [],
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("agents.rook state shape", () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
mkdirSync(WORK_DIR, { recursive: true });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
try { rmSync(TEST_BASE, { recursive: true, force: true }); } catch {}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("AgentSchema accepts an optional string-array failures alongside spawned and verdict", () => {
|
|
39
|
+
const parsed = AgentSchema.parse({
|
|
40
|
+
spawned: true,
|
|
41
|
+
verdict: "FAIL",
|
|
42
|
+
failures: ["hardcoded secret in lib/github.ts", "unvalidated path join in gates/run-gate.ts"],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(parsed).toBeDefined();
|
|
46
|
+
expect(parsed!.spawned).toBe(true);
|
|
47
|
+
expect(parsed!.verdict).toBe("FAIL");
|
|
48
|
+
// Must survive parsing — an undeclared key is stripped by Zod, which would
|
|
49
|
+
// silently drop the failure list every gate writes through the schema.
|
|
50
|
+
expect(parsed!.failures).toEqual([
|
|
51
|
+
"hardcoded secret in lib/github.ts",
|
|
52
|
+
"unvalidated path join in gates/run-gate.ts",
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("AgentSchema still accepts spawned/verdict with no failures key", () => {
|
|
57
|
+
const parsed = AgentSchema.parse({ spawned: true, verdict: "PASS" });
|
|
58
|
+
expect(parsed!.failures).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("AgentSchema rejects a non-array failures value", () => {
|
|
62
|
+
expect(() => AgentSchema.parse({ spawned: true, verdict: "FAIL", failures: "one big string" })).toThrow();
|
|
63
|
+
expect(() => AgentSchema.parse({ spawned: true, verdict: "FAIL", failures: 3 })).toThrow();
|
|
64
|
+
expect(() => AgentSchema.parse({ spawned: true, verdict: "FAIL", failures: { a: "b" } })).toThrow();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("AgentSchema rejects non-string entries inside failures", () => {
|
|
68
|
+
expect(() => AgentSchema.parse({ spawned: true, verdict: "FAIL", failures: [1, 2] })).toThrow();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("writeWorkflowState round-trips agents.rook {spawned, verdict, failures} to disk", () => {
|
|
72
|
+
const rook = {
|
|
73
|
+
spawned: true,
|
|
74
|
+
verdict: "FAIL" as const,
|
|
75
|
+
failures: ["command injection in scripts/scaffold-project.ts", "secret logged at gates/run-gate.ts:120"],
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
writeWorkflowState(SF, minimalState({ agents: { rook } }));
|
|
79
|
+
|
|
80
|
+
const onDisk = JSON.parse(readFileSync(SF, "utf-8"));
|
|
81
|
+
expect(onDisk.agents.rook).toEqual(rook);
|
|
82
|
+
|
|
83
|
+
// And the schema itself must preserve all three fields, not just the raw file.
|
|
84
|
+
const validated = WorkflowStateSchema.parse(onDisk);
|
|
85
|
+
expect(validated.agents!.rook).toEqual(rook);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("writeWorkflowState rejects a non-array agents.rook.failures", () => {
|
|
89
|
+
expect(() =>
|
|
90
|
+
writeWorkflowState(SF, minimalState({ agents: { rook: { spawned: true, verdict: "FAIL", failures: "not an array" } } })),
|
|
91
|
+
).toThrow(/failures/);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("SCHEMA-GUIDE documents agents.rook", () => {
|
|
96
|
+
const guide = readFileSync(join(import.meta.dir, "SCHEMA-GUIDE.md"), "utf-8");
|
|
97
|
+
|
|
98
|
+
test("documents all three agents.rook fields", () => {
|
|
99
|
+
expect(guide).toContain("agents.rook");
|
|
100
|
+
expect(guide).toMatch(/`spawned`/);
|
|
101
|
+
expect(guide).toMatch(/`verdict`/);
|
|
102
|
+
expect(guide).toMatch(/`failures`/);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("states that a FAIL verdict must carry a non-empty failures list", () => {
|
|
106
|
+
expect(guide).toMatch(/FAIL[\s\S]{0,160}non-empty[\s\S]{0,80}failures/i);
|
|
107
|
+
});
|
|
108
|
+
});
|