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
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
|
|
2
|
+
import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
|
|
5
|
+
const TEST_BASE = `/tmp/brief-asm-test-${process.pid}`;
|
|
6
|
+
const TEST_SLUG = `brief-test-${process.pid}`;
|
|
7
|
+
const WORK_DIR = join(TEST_BASE, TEST_SLUG);
|
|
8
|
+
const SF = join(WORK_DIR, "workflow-state.json");
|
|
9
|
+
const PROJECT_ROOT = join(TEST_BASE, "project");
|
|
10
|
+
|
|
11
|
+
function minimalState(overrides: Record<string, any> = {}): Record<string, any> {
|
|
12
|
+
return {
|
|
13
|
+
schemaVersion: 2,
|
|
14
|
+
issue: 9999,
|
|
15
|
+
repo: "test/repo",
|
|
16
|
+
issueRepo: "test/repo",
|
|
17
|
+
projectRoot: PROJECT_ROOT,
|
|
18
|
+
slug: TEST_SLUG,
|
|
19
|
+
phase: "BUILD",
|
|
20
|
+
issueGoal: "Implement the brief assembler module for deterministic Marcus brief generation",
|
|
21
|
+
acs: [
|
|
22
|
+
{
|
|
23
|
+
id: "AC-1",
|
|
24
|
+
type: "CODE",
|
|
25
|
+
statement: "brief-assembler.ts exports assembleBrief function with correct signature",
|
|
26
|
+
threshold: { op: "contains", value: "assembleBrief", unit: "export" },
|
|
27
|
+
evidenceMethod: { type: "grep", command: "grep 'export.*assembleBrief' gates/brief-assembler.ts" },
|
|
28
|
+
evidence: null,
|
|
29
|
+
verdict: "PENDING",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "AC-2",
|
|
33
|
+
type: "CODE",
|
|
34
|
+
statement: "Generated brief includes Goal, ACs, Files, Scope, and Verify sections",
|
|
35
|
+
threshold: { op: ">=", value: 5, unit: "sections" },
|
|
36
|
+
evidenceMethod: { type: "grep", command: "grep -c '## ' /tmp/brief.md" },
|
|
37
|
+
evidence: null,
|
|
38
|
+
verdict: "PENDING",
|
|
39
|
+
contextFiles: [
|
|
40
|
+
{ path: "gates/brief-assembler.ts", reason: "implementation" },
|
|
41
|
+
{ path: "gates/orchestrator.ts", reason: "state management" },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
gates: {},
|
|
46
|
+
changelog: [],
|
|
47
|
+
governingSpec: {
|
|
48
|
+
path: "/tmp/test-spec.md",
|
|
49
|
+
detectedFrom: "test",
|
|
50
|
+
},
|
|
51
|
+
...overrides,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function createState(overrides: Record<string, any> = {}): void {
|
|
56
|
+
mkdirSync(WORK_DIR, { recursive: true });
|
|
57
|
+
writeFileSync(SF, JSON.stringify(minimalState(overrides), null, 2));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function setupProjectRoot(): void {
|
|
61
|
+
mkdirSync(join(PROJECT_ROOT, ".claude"), { recursive: true });
|
|
62
|
+
writeFileSync(
|
|
63
|
+
join(PROJECT_ROOT, ".claude", "rungate.json"),
|
|
64
|
+
JSON.stringify({
|
|
65
|
+
project: "TestProject",
|
|
66
|
+
dev: { apiBase: "http://localhost:7778", start: "make dev-all" },
|
|
67
|
+
test: { apiBase: "http://localhost:7776" },
|
|
68
|
+
prod: { apiBase: "http://localhost:7777" },
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
import {
|
|
74
|
+
assembleBrief,
|
|
75
|
+
loadBriefPolicies,
|
|
76
|
+
validateBriefAgainst,
|
|
77
|
+
type AssembleResult,
|
|
78
|
+
} from "./brief-assembler";
|
|
79
|
+
|
|
80
|
+
describe("brief-assembler", () => {
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
mkdirSync(WORK_DIR, { recursive: true });
|
|
83
|
+
setupProjectRoot();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
try { rmSync(TEST_BASE, { recursive: true, force: true }); } catch {}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("assembleBrief", () => {
|
|
91
|
+
test("generates brief with all required sections", async () => {
|
|
92
|
+
createState();
|
|
93
|
+
|
|
94
|
+
const result = await assembleBrief({
|
|
95
|
+
slug: TEST_SLUG,
|
|
96
|
+
workDir: WORK_DIR,
|
|
97
|
+
projectRoot: PROJECT_ROOT,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(result.validated).toBe(true);
|
|
101
|
+
expect(result.acCount).toBe(2);
|
|
102
|
+
expect(existsSync(result.briefPath)).toBe(true);
|
|
103
|
+
|
|
104
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
105
|
+
expect(brief).toContain("## Context");
|
|
106
|
+
expect(brief).toContain("## Task");
|
|
107
|
+
expect(brief).toContain("## Scope");
|
|
108
|
+
expect(brief).toContain("## Verify");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("includes issue goal in task section", async () => {
|
|
112
|
+
createState({ issueGoal: "Fix the widget rendering bug in customer detail view" });
|
|
113
|
+
|
|
114
|
+
const result = await assembleBrief({
|
|
115
|
+
slug: TEST_SLUG,
|
|
116
|
+
workDir: WORK_DIR,
|
|
117
|
+
projectRoot: PROJECT_ROOT,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
121
|
+
expect(brief).toContain("Fix the widget rendering bug in customer detail view");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("includes ACs with thresholds", async () => {
|
|
125
|
+
createState();
|
|
126
|
+
|
|
127
|
+
const result = await assembleBrief({
|
|
128
|
+
slug: TEST_SLUG,
|
|
129
|
+
workDir: WORK_DIR,
|
|
130
|
+
projectRoot: PROJECT_ROOT,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
134
|
+
expect(brief).toContain("AC-1");
|
|
135
|
+
expect(brief).toContain("AC-2");
|
|
136
|
+
expect(brief).toContain("assembleBrief");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("deduplicates context files in Files section", async () => {
|
|
140
|
+
createState({
|
|
141
|
+
acs: [
|
|
142
|
+
{
|
|
143
|
+
id: "AC-1", type: "CODE",
|
|
144
|
+
statement: "First criterion with context files for testing dedup",
|
|
145
|
+
threshold: { op: "contains", value: "foo" },
|
|
146
|
+
evidenceMethod: { type: "grep", command: "grep foo bar" },
|
|
147
|
+
evidence: null, verdict: "PENDING",
|
|
148
|
+
contextFiles: [
|
|
149
|
+
{ path: "gates/orchestrator.ts", reason: "state" },
|
|
150
|
+
{ path: "gates/schema.ts", reason: "types" },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "AC-2", type: "CODE",
|
|
155
|
+
statement: "Second criterion sharing context file for dedup test",
|
|
156
|
+
threshold: { op: "contains", value: "bar" },
|
|
157
|
+
evidenceMethod: { type: "grep", command: "grep bar baz" },
|
|
158
|
+
evidence: null, verdict: "PENDING",
|
|
159
|
+
contextFiles: [
|
|
160
|
+
{ path: "gates/orchestrator.ts", reason: "state again" },
|
|
161
|
+
{ path: "gates/run-gate.ts", reason: "runner" },
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const result = await assembleBrief({
|
|
168
|
+
slug: TEST_SLUG,
|
|
169
|
+
workDir: WORK_DIR,
|
|
170
|
+
projectRoot: PROJECT_ROOT,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(result.contextFileCount).toBe(3);
|
|
174
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
175
|
+
const orchestratorMatches = brief.match(/gates\/orchestrator\.ts/g);
|
|
176
|
+
expect(orchestratorMatches).toHaveLength(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("includes governing spec in Spec Alignment section", async () => {
|
|
180
|
+
createState({
|
|
181
|
+
governingSpec: {
|
|
182
|
+
path: "/Users/test/specs/MY-SPEC.md",
|
|
183
|
+
detectedFrom: "discovery",
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const result = await assembleBrief({
|
|
188
|
+
slug: TEST_SLUG,
|
|
189
|
+
workDir: WORK_DIR,
|
|
190
|
+
projectRoot: PROJECT_ROOT,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
194
|
+
expect(brief).toContain("Spec Alignment");
|
|
195
|
+
expect(brief).toContain("MY-SPEC.md");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("includes verify commands from AC evidence methods", async () => {
|
|
199
|
+
createState({
|
|
200
|
+
acs: [
|
|
201
|
+
{
|
|
202
|
+
id: "AC-1", type: "CODE",
|
|
203
|
+
statement: "Verify command appears in brief for validation purposes",
|
|
204
|
+
threshold: { op: "contains", value: "PASS" },
|
|
205
|
+
evidenceMethod: { type: "command", command: "bun test --isolate gates/self-heal.test.ts" },
|
|
206
|
+
evidence: null, verdict: "PENDING",
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const result = await assembleBrief({
|
|
212
|
+
slug: TEST_SLUG,
|
|
213
|
+
workDir: WORK_DIR,
|
|
214
|
+
projectRoot: PROJECT_ROOT,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
218
|
+
expect(brief).toContain("bun test --isolate gates/self-heal.test.ts");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("writes brief to workDir/marcus-brief.md", async () => {
|
|
222
|
+
createState();
|
|
223
|
+
|
|
224
|
+
const result = await assembleBrief({
|
|
225
|
+
slug: TEST_SLUG,
|
|
226
|
+
workDir: WORK_DIR,
|
|
227
|
+
projectRoot: PROJECT_ROOT,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(result.briefPath).toBe(join(WORK_DIR, "marcus-brief.md"));
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("handles missing governingSpec gracefully", async () => {
|
|
234
|
+
createState({ governingSpec: undefined });
|
|
235
|
+
|
|
236
|
+
const result = await assembleBrief({
|
|
237
|
+
slug: TEST_SLUG,
|
|
238
|
+
workDir: WORK_DIR,
|
|
239
|
+
projectRoot: PROJECT_ROOT,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(result.validated).toBe(true);
|
|
243
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
244
|
+
expect(brief).toContain("## Context");
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("handles empty ACs array", async () => {
|
|
248
|
+
createState({ acs: [] });
|
|
249
|
+
|
|
250
|
+
const result = await assembleBrief({
|
|
251
|
+
slug: TEST_SLUG,
|
|
252
|
+
workDir: WORK_DIR,
|
|
253
|
+
projectRoot: PROJECT_ROOT,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
expect(result.acCount).toBe(0);
|
|
257
|
+
expect(result.validated).toBe(true);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("handles missing workflow-state.json", async () => {
|
|
261
|
+
await expect(
|
|
262
|
+
assembleBrief({
|
|
263
|
+
slug: TEST_SLUG,
|
|
264
|
+
workDir: "/tmp/nonexistent-dir-xyz",
|
|
265
|
+
projectRoot: PROJECT_ROOT,
|
|
266
|
+
}),
|
|
267
|
+
).rejects.toThrow(/workflow-state\.json/i);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("includes git protocol section with issue number", async () => {
|
|
271
|
+
createState({ issue: 1372 });
|
|
272
|
+
|
|
273
|
+
const result = await assembleBrief({
|
|
274
|
+
slug: TEST_SLUG,
|
|
275
|
+
workDir: WORK_DIR,
|
|
276
|
+
projectRoot: PROJECT_ROOT,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
280
|
+
expect(brief).toContain("Git protocol");
|
|
281
|
+
expect(brief).toContain("1372");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("includes scope-out boundaries when available", async () => {
|
|
285
|
+
createState({
|
|
286
|
+
scopeOut: ["gates/run-gate.ts", "gates/orchestrator.ts", "src/"],
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
const result = await assembleBrief({
|
|
290
|
+
slug: TEST_SLUG,
|
|
291
|
+
workDir: WORK_DIR,
|
|
292
|
+
projectRoot: PROJECT_ROOT,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
296
|
+
expect(brief).toContain("gates/run-gate.ts");
|
|
297
|
+
expect(brief).toContain("do NOT touch");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("validates brief against policy patterns", async () => {
|
|
301
|
+
createState();
|
|
302
|
+
|
|
303
|
+
const result = await assembleBrief({
|
|
304
|
+
slug: TEST_SLUG,
|
|
305
|
+
workDir: WORK_DIR,
|
|
306
|
+
projectRoot: PROJECT_ROOT,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(result.validated).toBe(true);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("AC-1: includes AGENTS.md from projectRoot when present", async () => {
|
|
313
|
+
writeFileSync(
|
|
314
|
+
join(PROJECT_ROOT, "AGENTS.md"),
|
|
315
|
+
"# Agents\n\n## Marcus Webb\nSenior engineer\n\n## Quinn Torres\nQA lead\n",
|
|
316
|
+
);
|
|
317
|
+
createState();
|
|
318
|
+
|
|
319
|
+
const result = await assembleBrief({
|
|
320
|
+
slug: TEST_SLUG,
|
|
321
|
+
workDir: WORK_DIR,
|
|
322
|
+
projectRoot: PROJECT_ROOT,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
326
|
+
expect(brief).toContain("AGENTS.md");
|
|
327
|
+
expect(brief).toContain("## Context");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test("AC-1: omits AGENTS.md reference when file does not exist", async () => {
|
|
331
|
+
createState();
|
|
332
|
+
|
|
333
|
+
const result = await assembleBrief({
|
|
334
|
+
slug: TEST_SLUG,
|
|
335
|
+
workDir: WORK_DIR,
|
|
336
|
+
projectRoot: PROJECT_ROOT,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
340
|
+
expect(brief).not.toContain("AGENTS.md");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("AC-2: includes contextDocs from rungate.json (array form)", async () => {
|
|
344
|
+
writeFileSync(
|
|
345
|
+
join(PROJECT_ROOT, ".claude", "rungate.json"),
|
|
346
|
+
JSON.stringify({
|
|
347
|
+
project: "TestProject",
|
|
348
|
+
contextDocs: ["HARNESS.md", "DESIGN.md"],
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
createState();
|
|
352
|
+
|
|
353
|
+
const result = await assembleBrief({
|
|
354
|
+
slug: TEST_SLUG,
|
|
355
|
+
workDir: WORK_DIR,
|
|
356
|
+
projectRoot: PROJECT_ROOT,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
360
|
+
expect(brief).toContain("HARNESS.md");
|
|
361
|
+
expect(brief).toContain("DESIGN.md");
|
|
362
|
+
expect(result.contextFileCount).toBeGreaterThanOrEqual(2);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("AC-2: includes contextDocs from rungate.json (object form)", async () => {
|
|
366
|
+
writeFileSync(
|
|
367
|
+
join(PROJECT_ROOT, ".claude", "rungate.json"),
|
|
368
|
+
JSON.stringify({
|
|
369
|
+
project: "TestProject",
|
|
370
|
+
contextDocs: {
|
|
371
|
+
routing: "DOCS.md",
|
|
372
|
+
model: "MODEL.md",
|
|
373
|
+
architecture: "ARCHITECTURE.md",
|
|
374
|
+
},
|
|
375
|
+
}),
|
|
376
|
+
);
|
|
377
|
+
createState();
|
|
378
|
+
|
|
379
|
+
const result = await assembleBrief({
|
|
380
|
+
slug: TEST_SLUG,
|
|
381
|
+
workDir: WORK_DIR,
|
|
382
|
+
projectRoot: PROJECT_ROOT,
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
386
|
+
expect(brief).toContain("DOCS.md");
|
|
387
|
+
expect(brief).toContain("MODEL.md");
|
|
388
|
+
expect(brief).toContain("ARCHITECTURE.md");
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("AC-3: no hardcoded harness-owned template paths in context", async () => {
|
|
392
|
+
createState();
|
|
393
|
+
|
|
394
|
+
const result = await assembleBrief({
|
|
395
|
+
slug: TEST_SLUG,
|
|
396
|
+
workDir: WORK_DIR,
|
|
397
|
+
projectRoot: PROJECT_ROOT,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
401
|
+
expect(brief).not.toContain("MarcusContext.md");
|
|
402
|
+
expect(brief).not.toContain("MarcusChecklist.md");
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("AC-4: produces >= 5 sections from structured data only", async () => {
|
|
406
|
+
writeFileSync(
|
|
407
|
+
join(PROJECT_ROOT, "AGENTS.md"),
|
|
408
|
+
"# Agents\n## Marcus Webb\nSenior engineer\n",
|
|
409
|
+
);
|
|
410
|
+
writeFileSync(
|
|
411
|
+
join(PROJECT_ROOT, ".claude", "rungate.json"),
|
|
412
|
+
JSON.stringify({
|
|
413
|
+
project: "TestProject",
|
|
414
|
+
contextDocs: ["HARNESS.md"],
|
|
415
|
+
}),
|
|
416
|
+
);
|
|
417
|
+
createState({
|
|
418
|
+
governingSpec: { path: "/tmp/spec.md", detectedFrom: "test" },
|
|
419
|
+
scopeOut: ["src/secret.ts"],
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const result = await assembleBrief({
|
|
423
|
+
slug: TEST_SLUG,
|
|
424
|
+
workDir: WORK_DIR,
|
|
425
|
+
projectRoot: PROJECT_ROOT,
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const brief = readFileSync(result.briefPath, "utf-8");
|
|
429
|
+
const sectionHeaders = brief.match(/^## /gm) || [];
|
|
430
|
+
expect(sectionHeaders.length).toBeGreaterThanOrEqual(5);
|
|
431
|
+
expect(result.validated).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* #1174: the policies the package SHIPS are the ones that get read.
|
|
438
|
+
*
|
|
439
|
+
* `BRIEF_POLICIES_PATH` was `$HOME/.claude/skills/ship/brief-policies.json`
|
|
440
|
+
* and nothing else, while `config/brief-policies.json` — which the tarball
|
|
441
|
+
* does carry — was never opened. Measured on the author's own machine on
|
|
442
|
+
* 2026-10-22, the `$HOME` copy does not exist either, so validation had been
|
|
443
|
+
* running through a hardcoded second copy of the patterns on every machine,
|
|
444
|
+
* reporting `validated: true` from a policy file it had never read.
|
|
445
|
+
*/
|
|
446
|
+
describe("#1174: brief policies resolve to the packaged config", () => {
|
|
447
|
+
const PACKAGED = join(import.meta.dir, "..", "config", "brief-policies.json");
|
|
448
|
+
|
|
449
|
+
test("the packaged policy file exists where the module resolves it", () => {
|
|
450
|
+
// Also the input CLOSURE-8 reads statically: this is a module-relative
|
|
451
|
+
// runtime read, so `config/` leaving `files[]` fails that check too.
|
|
452
|
+
expect(existsSync(PACKAGED)).toBe(true);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("every agent type the package ships is present in the loaded policies", () => {
|
|
456
|
+
// Asserted as containment rather than equality because the `$HOME` copy
|
|
457
|
+
// is an OVERRIDE: it may add or replace an agent type, and it must never
|
|
458
|
+
// be able to delete one the package ships.
|
|
459
|
+
const shipped = JSON.parse(readFileSync(PACKAGED, "utf-8"));
|
|
460
|
+
const loaded = loadBriefPolicies();
|
|
461
|
+
for (const agentType of Object.keys(shipped.policies)) {
|
|
462
|
+
expect(Object.keys(loaded.policies)).toContain(agentType);
|
|
463
|
+
}
|
|
464
|
+
expect(Object.keys(shipped.policies).length).toBeGreaterThan(0);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test("the loaded marcus patterns are the shipped ones, not a copy in the code", () => {
|
|
468
|
+
const shipped = JSON.parse(readFileSync(PACKAGED, "utf-8"));
|
|
469
|
+
const names = loadBriefPolicies().policies.marcus.requiredPatterns.map((p: any) => p.name);
|
|
470
|
+
expect(names).toEqual(shipped.policies.marcus.requiredPatterns.map((p: any) => p.name));
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test("an empty policy set REFUSES rather than validating every brief", () => {
|
|
474
|
+
// The UNMEASURED half. An empty `requiredPatterns` passes everything and
|
|
475
|
+
// cannot be told apart from no validation at all, which is the state the
|
|
476
|
+
// old `catch {}` fell into on a malformed file.
|
|
477
|
+
expect(() => validateBriefAgainst("anything at all", { policies: { marcus: { requiredPatterns: [] } } }))
|
|
478
|
+
.toThrow(/no requiredPatterns/);
|
|
479
|
+
expect(() => validateBriefAgainst("anything at all", {})).toThrow(/no requiredPatterns/);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
test("a brief missing a required section still fails, with the real patterns", () => {
|
|
483
|
+
// The other direction: the refusal above must not be the only outcome
|
|
484
|
+
// the loaded policies can produce, or the check would be vacuous.
|
|
485
|
+
expect(validateBriefAgainst("nothing useful here", loadBriefPolicies())).toBe(false);
|
|
486
|
+
});
|
|
487
|
+
});
|