rungate 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/.claude/agents/aditi.md +47 -0
  2. package/.claude/agents/marcus.md +50 -0
  3. package/.claude/agents/quinn.md +58 -0
  4. package/.claude/agents/rook.md +47 -0
  5. package/.claude/agents/serena.md +46 -0
  6. package/.claude/rungate.json +11 -0
  7. package/.fallowrc.json +28 -0
  8. package/.github/copilot-instructions.md +20 -0
  9. package/.rungate/conformity-findings.json +648 -0
  10. package/AGENTS.md +106 -0
  11. package/CODE-MAP.md +50 -0
  12. package/HARNESS.md +88 -0
  13. package/bun.lock +26 -0
  14. package/bunfig.toml +2 -0
  15. package/config/brief-policies.json +28 -0
  16. package/config/ceremony-profiles.json +212 -0
  17. package/config/consumer-cascade-map.json +24 -0
  18. package/config/doc-cascade-map.json +24 -0
  19. package/config/eval.json +84 -0
  20. package/config/profiles/account-plan.yaml +36 -0
  21. package/config/profiles/campaign.yaml +94 -0
  22. package/config/prove-evidence.schema.json +65 -0
  23. package/config/spec-policies.json +36 -0
  24. package/config/workflow-schema.json +281 -0
  25. package/gates/SCHEMA-GUIDE.md +121 -0
  26. package/gates/ac-quality.test.ts +106 -0
  27. package/gates/adversarial.test.ts +274 -0
  28. package/gates/brief-assembler.test.ts +429 -0
  29. package/gates/brief-assembler.ts +334 -0
  30. package/gates/bunfig.toml +2 -0
  31. package/gates/chain.test.ts +91 -0
  32. package/gates/e2e-smoke.test.ts +234 -0
  33. package/gates/error-classifier.test.ts +249 -0
  34. package/gates/error-classifier.ts +89 -0
  35. package/gates/orchestrator.test.ts +950 -0
  36. package/gates/orchestrator.ts +569 -0
  37. package/gates/preload.ts +77 -0
  38. package/gates/prompts/ac-adversary.md +20 -0
  39. package/gates/prompts/evidence-validator.md +22 -0
  40. package/gates/prompts/prove-reproducer.md +53 -0
  41. package/gates/prove.test.ts +164 -0
  42. package/gates/run-gate.ts +936 -0
  43. package/gates/schema-parity.test.ts +197 -0
  44. package/gates/schema.ts +362 -0
  45. package/gates/self-heal.test.ts +511 -0
  46. package/gates/self-heal.ts +121 -0
  47. package/gates/ship-orchestrator.test.ts +379 -0
  48. package/gates/ship-orchestrator.ts +363 -0
  49. package/gates/test-fixtures/broken-no-environments.json +60 -0
  50. package/gates/test-fixtures/valid-standard.json +54 -0
  51. package/gates/test-utils.ts +43 -0
  52. package/gates/witness.ts +220 -0
  53. package/gates/workflow.test.ts +1053 -0
  54. package/hooks/AgentBriefGuard.hook.ts +586 -0
  55. package/hooks/AgentVerdictCapture.hook.ts +134 -0
  56. package/hooks/AutoVerifyGate.hook.ts +76 -0
  57. package/hooks/GateEnforcement.hook.ts +273 -0
  58. package/hooks/IssueCloseGuard.hook.ts +116 -0
  59. package/hooks/MergeGuard.hook.ts +55 -0
  60. package/hooks/StaleTTLCleanup.hook.ts +133 -0
  61. package/hooks/VerifyPhaseLock.hook.ts +81 -0
  62. package/hooks/WorkflowStateGuard.hook.ts +37 -0
  63. package/hooks/lib/agentDetection.ts +70 -0
  64. package/hooks/lib/findWorkflow.ts +101 -0
  65. package/hooks/lib/parseStdin.ts +37 -0
  66. package/hooks/lib/paths.ts +111 -0
  67. package/hooks/lib/utils.ts +81 -0
  68. package/lib/conformity.ts +959 -0
  69. package/lib/paths.ts +23 -0
  70. package/lib/rungate-schema.ts +60 -0
  71. package/lib/signal-phrases.ts +7 -0
  72. package/package.json +20 -0
  73. package/prompts/ac-adversary.md +20 -0
  74. package/prompts/ac-format.md +34 -0
  75. package/prompts/aditi.md +29 -0
  76. package/prompts/blast-radius.md +29 -0
  77. package/prompts/coding-principles.md +34 -0
  78. package/prompts/container-rebuild.md +29 -0
  79. package/prompts/container-verify.md +28 -0
  80. package/prompts/discovery.md +27 -0
  81. package/prompts/environment.md +28 -0
  82. package/prompts/escalation-decision-tree.md +38 -0
  83. package/prompts/evidence-hierarchy.md +31 -0
  84. package/prompts/evidence-validator.md +22 -0
  85. package/prompts/marcus.md +29 -0
  86. package/prompts/prevention.md +26 -0
  87. package/prompts/prove-reproducer.md +43 -0
  88. package/prompts/quinn-decision-tree.md +31 -0
  89. package/prompts/quinn-ui-brief.md +106 -0
  90. package/prompts/quinn.md +29 -0
  91. package/prompts/rca.md +28 -0
  92. package/prompts/read-before-write.md +30 -0
  93. package/prompts/regression.md +26 -0
  94. package/prompts/rook.md +29 -0
  95. package/prompts/serena.md +28 -0
  96. package/prompts/testing-strategy.md +34 -0
  97. package/reference/migration-manifest.json +554 -0
  98. package/reference/prompts/agent-aditi.md +38 -0
  99. package/reference/prompts/agent-marcus.md +38 -0
  100. package/reference/prompts/agent-quinn.md +38 -0
  101. package/reference/prompts/agent-rook.md +37 -0
  102. package/reference/prompts/agent-serena.md +37 -0
  103. package/reference/prompts/council-skill.md +170 -0
  104. package/reference/prompts/goal-skill.md +235 -0
  105. package/reference/prompts/prove-skill.md +283 -0
  106. package/reference/prompts/quinn-standard.md +246 -0
  107. package/reference/prompts/ship-convergence.md +65 -0
  108. package/reference/prompts/ship-escalation.md +43 -0
  109. package/reference/prompts/ship-iteration.md +382 -0
  110. package/reference/prompts/ship-pending-patches.md +246 -0
  111. package/reference/prompts/ship-reference.md +250 -0
  112. package/reference/prompts/ship-skill.md +347 -0
  113. package/reference/prompts/ship-templates.md +215 -0
  114. package/reference/scripts/batch-status.sh +68 -0
  115. package/reference/scripts/chain-compat-check.sh +67 -0
  116. package/reference/scripts/context-audit.sh +314 -0
  117. package/reference/scripts/dead-export-check.sh +61 -0
  118. package/reference/scripts/generate-qc-tables.sh +92 -0
  119. package/reference/scripts/harness-init.sh +111 -0
  120. package/reference/scripts/pai-054-baseline-check.sh +40 -0
  121. package/reference/scripts/prove-smoke-test.sh +112 -0
  122. package/reference/scripts/setup-keychain-salt.sh +12 -0
  123. package/reference/scripts/skill-optimizer-friday.sh +88 -0
  124. package/reference/scripts/skill-qc-test.sh +351 -0
  125. package/reference/scripts/skill-synthesize-tonight.sh +66 -0
  126. package/reference/specs/HARNESS-EXTRACTION-SPEC.md +263 -0
  127. package/reference/specs/harness-v3-bash-deletion-plan.md +65 -0
  128. package/reference/specs/harness-v3-migration-plan.md +188 -0
  129. package/scripts/decision-reconcile.sh +74 -0
  130. package/scripts/decision-reconcile.ts +152 -0
  131. package/scripts/extract-constraints.ts +260 -0
  132. package/scripts/generate-code-map.ts +339 -0
  133. package/scripts/git-hooks/pre-commit +76 -0
  134. package/scripts/git-hooks/pre-push +271 -0
  135. package/scripts/harness-skill-check.sh +52 -0
  136. package/scripts/lib/gap-emit.sh +65 -0
  137. package/scripts/lib/jq-update.sh +30 -0
  138. package/scripts/lib/resolve-slug.sh +30 -0
  139. package/scripts/lib/verify-spec-compliance.sh +102 -0
  140. package/scripts/prove-backfill.sh +87 -0
  141. package/scripts/scaffold-project.ts +1488 -0
  142. package/scripts/scaffold-rungate-config.ts +91 -0
  143. package/scripts/self-containment-check.sh +109 -0
  144. package/scripts/skill-qc-validator.sh +402 -0
  145. package/scripts/slug-resolver.sh +14 -0
  146. package/scripts/sync-spec-tests.ts +236 -0
  147. package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +2493 -0
  148. package/specs/BOOTSTRAP-TEST-PLAN.md +571 -0
  149. package/specs/HARNESS-GATES.md +256 -0
  150. package/specs/HARNESS-SKILL-CHAIN.md +286 -0
  151. package/specs/HARNESS-SKILL-CONTRACT.md +93 -0
  152. package/specs/HARNESS-STANDARD.md +488 -0
  153. package/specs/SPEC-TEMPLATE.md +53 -0
  154. package/specs/bootstrap-data-flow.png +0 -0
  155. package/specs/harness-automation-matrix.md +314 -0
  156. package/specs/harness-automation-matrix.rules.json +64 -0
  157. package/test/anti.test.ts +80 -0
  158. package/test/contract-negative.test.ts +86 -0
  159. package/test/contract.test.ts +158 -0
  160. package/test/external-deps.test.ts +48 -0
  161. package/test/fixtures/golden-project/.env.example +3 -0
  162. package/test/fixtures/golden-project/Makefile +7 -0
  163. package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +23 -0
  164. package/test/fixtures/golden-project/docs/setup-guide.md +10 -0
  165. package/test/fixtures/golden-project/package.json +10 -0
  166. package/test/fixtures/golden-project/specs/api-spec.md +20 -0
  167. package/test/fixtures/golden-project/src/auth.ts +8 -0
  168. package/test/fixtures/golden-project/src/db.ts +11 -0
  169. package/test/fixtures/golden-project/src/index.ts +19 -0
  170. package/test/fixtures/golden-project/src/utils/format.ts +3 -0
  171. package/test/fixtures/golden-project/test/auth.test.ts +15 -0
  172. package/test/fixtures/golden-project/tsconfig.json +12 -0
  173. package/test/meta-sc-coverage.test.ts +159 -0
  174. package/test/phase-0.test.ts +846 -0
  175. package/test/phase-1.test.ts +617 -0
  176. package/test/phase-2.test.ts +620 -0
  177. package/test/phase-3.test.ts +99 -0
  178. package/test/scaffold-conformity.test.ts +8 -0
  179. package/test/schema-canary.test.ts +51 -0
  180. package/test/spec-compliance-auto.test.ts +64 -0
  181. package/test/spec-compliance.test.ts +295 -0
  182. package/test/spec-discovery.test.ts +68 -0
  183. package/test/spec-drift.test.ts +5 -0
  184. package/test/structure.test.ts +165 -0
  185. package/test/unit/agent-brief-guard-ship.test.ts +293 -0
  186. package/test/unit/extract-constraints.test.ts +145 -0
  187. package/test/unit/issue-close-guard.test.ts +204 -0
  188. package/test/unit/scaffold-project.test.ts +417 -0
  189. package/test/unit/skill-cooccurrence.test.ts +177 -0
  190. package/test/unit/skill-sequence-logger.test.ts +244 -0
  191. package/test/unit/workflow-state-guard.test.ts +95 -0
  192. package/workflows/batch-ship.js +295 -0
  193. package/workflows/council.js +481 -0
  194. package/workflows/prove.js +560 -0
  195. package/workflows/ship.js +789 -0
  196. package/workflows/verify.js +236 -0
@@ -0,0 +1,620 @@
1
+ import { test, expect, describe, beforeAll } from "bun:test";
2
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from "fs";
3
+ import { execSync } from "child_process";
4
+ import { join } from "path";
5
+
6
+ const HARNESS = join(import.meta.dir, "..");
7
+ const GATES = join(HARNESS, "gates");
8
+ const PROMPTS = join(HARNESS, "prompts");
9
+
10
+ // Phase 2 tests gate enforcement, brief assembly, evidence validation,
11
+ // and ship-cycle behavior. Most of these test code in gates/ and lib/.
12
+
13
+ describe("Phase 2: Gate Enforcement + Ship Behavior", () => {
14
+
15
+ // SC-7: Container-rebuild agent NOT spawned when prod.rebuild is null
16
+ describe("SC-7: null prod.rebuild skips container", () => {
17
+ test("ship orchestrator skips container rebuild when prod.rebuild is null", () => {
18
+ const orchestrator = join(GATES, "ship-orchestrator.ts");
19
+ if (existsSync(orchestrator)) {
20
+ const content = readFileSync(orchestrator, "utf-8");
21
+ expect(content).toMatch(/prod\.rebuild|rebuild.*null|skip.*rebuild/i);
22
+ } else {
23
+ expect(existsSync(orchestrator)).toBe(true);
24
+ }
25
+ });
26
+ });
27
+
28
+ // SC-9: rungate-schema.ts includes test fields
29
+ describe("SC-9: schema test fields", () => {
30
+ test("schema has test section fields", () => {
31
+ const schema = readFileSync(join(HARNESS, "lib/rungate-schema.ts"), "utf-8");
32
+ expect(schema).toContain("TestSchema");
33
+ expect(schema).toMatch(/start.*optional|apiBase/);
34
+ });
35
+ });
36
+
37
+ // SC-10: Schema fields read by at least one workflow
38
+ describe("SC-10: schema fields consumed", () => {
39
+ test("dev.typeCheck referenced in workflow code", () => {
40
+ const files = ["gates/run-gate.ts", "gates/ship-orchestrator.ts", "gates/orchestrator.ts"]
41
+ .map(f => join(HARNESS, f))
42
+ .filter(f => existsSync(f));
43
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
44
+ expect(content).toMatch(/typeCheck|tsc/);
45
+ });
46
+ });
47
+
48
+ // SC-28: Scope gate runs conformity tests — FAIL blocks scope
49
+ describe("SC-28: scope gate conformity", () => {
50
+ test("run-gate.ts runs conformity at scope", () => {
51
+ const gateRunner = join(GATES, "run-gate.ts");
52
+ if (existsSync(gateRunner)) {
53
+ const content = readFileSync(gateRunner, "utf-8");
54
+ expect(content).toMatch(/scope|conformity|bun test/i);
55
+ } else {
56
+ expect(existsSync(gateRunner)).toBe(true);
57
+ }
58
+ });
59
+ });
60
+
61
+ // SC-29: Verify gate runs conformity tests — FAIL blocks verify
62
+ describe("SC-29: verify gate conformity", () => {
63
+ test("run-gate.ts runs conformity at verify", () => {
64
+ const gateRunner = join(GATES, "run-gate.ts");
65
+ if (existsSync(gateRunner)) {
66
+ const content = readFileSync(gateRunner, "utf-8");
67
+ expect(content).toMatch(/verify|conformity/i);
68
+ } else {
69
+ expect(existsSync(gateRunner)).toBe(true);
70
+ }
71
+ });
72
+ });
73
+
74
+ // SC-31: Scope gate captures test baseline
75
+ describe("SC-31: test baseline capture", () => {
76
+ test("schema supports testBaseline field", () => {
77
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
78
+ expect(schema).toContain("testBaseline");
79
+ });
80
+ });
81
+
82
+ // SC-32: Verify gate compares test count — fail increase = regression
83
+ describe("SC-32: test count regression check", () => {
84
+ test("gate logic compares test counts", () => {
85
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts", "gates/orchestrator.ts"]
86
+ .map(f => join(HARNESS, f))
87
+ .filter(f => existsSync(f));
88
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
89
+ expect(content).toMatch(/baseline|regression|fail.*count|test.*count/i);
90
+ });
91
+ });
92
+
93
+ // SC-33: Pre-existing test failures auto-filed as GitHub issues
94
+ describe("SC-33: pre-existing failure filing", () => {
95
+ test("gate or orchestrator handles pre-existing failures", () => {
96
+ const files = ["gates/run-gate.ts", "gates/orchestrator.ts", "gates/ship-orchestrator.ts"]
97
+ .map(f => join(HARNESS, f))
98
+ .filter(f => existsSync(f));
99
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
100
+ expect(content).toMatch(/pre.existing|existing.*fail|baseline.*fail/i);
101
+ });
102
+ });
103
+
104
+ // SC-34: Found issues either fixed, filed, or scoped out
105
+ describe("SC-34: fix-on-find tracking", () => {
106
+ test("workflow state tracks found issues disposition", () => {
107
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
108
+ expect(schema).toMatch(/found|issue|filed|scoped/i);
109
+ });
110
+ });
111
+
112
+ // SC-35: create-spec creates spec with frontmatter
113
+ describe("SC-35: create-spec command", () => {
114
+ test("create-spec script or function exists", () => {
115
+ const hasScript = existsSync(join(HARNESS, "scripts/create-spec.ts"));
116
+ const scaffoldHasIt = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8").includes("create-spec");
117
+ expect(hasScript || scaffoldHasIt).toBe(true);
118
+ });
119
+ });
120
+
121
+ // SC-36: create-adr with auto-incremented number
122
+ describe("SC-36: create-adr command", () => {
123
+ test("create-adr script or function exists", () => {
124
+ const hasScript = existsSync(join(HARNESS, "scripts/create-adr.ts"));
125
+ const scaffoldHasIt = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8").includes("create-adr");
126
+ expect(hasScript || scaffoldHasIt).toBe(true);
127
+ });
128
+ });
129
+
130
+ // SC-38: Ship cycle runs scaffold after verify PASS
131
+ describe("SC-38: post-verify scaffold refresh", () => {
132
+ test("ship orchestrator calls scaffold after verify", () => {
133
+ const orchestrator = join(GATES, "ship-orchestrator.ts");
134
+ if (existsSync(orchestrator)) {
135
+ const content = readFileSync(orchestrator, "utf-8");
136
+ expect(content).toMatch(/scaffold|refresh|code.map/i);
137
+ } else {
138
+ expect(existsSync(orchestrator)).toBe(true);
139
+ }
140
+ });
141
+ });
142
+
143
+ // SC-41: Secret scan in conformity (HYGIENE-12)
144
+ describe("SC-41: HYGIENE-12 secret scan", () => {
145
+ test("conformity or gate checks for secret patterns", () => {
146
+ const conformity = readFileSync(join(HARNESS, "lib/conformity.ts"), "utf-8");
147
+ const gatesYml = existsSync(join(HARNESS, "scripts/scaffold-project.ts"))
148
+ ? readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8") : "";
149
+ const combined = conformity + gatesYml;
150
+ expect(combined).toMatch(/AKIA|sk-|ghp_|secret|credential|password/i);
151
+ });
152
+ });
153
+
154
+ // SC-42: Completed slugs auto-archived after 24h
155
+ describe("SC-42: slug auto-archive", () => {
156
+ test("orchestrator or gate handles slug archival", () => {
157
+ const files = ["gates/orchestrator.ts", "gates/run-gate.ts"]
158
+ .map(f => join(HARNESS, f))
159
+ .filter(f => existsSync(f));
160
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
161
+ expect(content).toMatch(/archive|DONE|slug.*clean/i);
162
+ });
163
+ });
164
+
165
+ // SC-43: Archived slugs deleted after 30 days
166
+ describe("SC-43: stale slug cleanup", () => {
167
+ test("cleanup mechanism for old slugs", () => {
168
+ const files = ["gates/orchestrator.ts", "gates/run-gate.ts"]
169
+ .map(f => join(HARNESS, f))
170
+ .filter(f => existsSync(f));
171
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
172
+ expect(content).toMatch(/delete|cleanup|30.*day|stale.*slug/i);
173
+ });
174
+ });
175
+
176
+ // SC-44: Ship checks for existing slug before creating new
177
+ describe("SC-44: duplicate slug prevention", () => {
178
+ test("orchestrator checks for existing slug", () => {
179
+ const files = ["gates/orchestrator.ts", "gates/ship-orchestrator.ts"]
180
+ .map(f => join(HARNESS, f))
181
+ .filter(f => existsSync(f));
182
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
183
+ expect(content).toMatch(/existing.*slug|slug.*exist|slugExists|duplicate/i);
184
+ });
185
+ });
186
+
187
+ // SC-48: ACs use Given/When/Then format
188
+ describe("SC-48: AC format validation", () => {
189
+ test("AC schema or quality test validates format", () => {
190
+ const files = ["gates/ac-quality.test.ts", "gates/schema.ts"]
191
+ .map(f => join(HARNESS, f))
192
+ .filter(f => existsSync(f));
193
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
194
+ expect(content).toMatch(/trigger|verify.*command|exclusion|Given|When|Then/i);
195
+ });
196
+ });
197
+
198
+ // SC-49: Every AC has executable verification command
199
+ describe("SC-49: AC verification command", () => {
200
+ test("schema requires verification command or evidenceMethod", () => {
201
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
202
+ expect(schema).toMatch(/evidenceMethod|command/);
203
+ });
204
+ });
205
+
206
+ // SC-50: Evidence hierarchy enforced per AC
207
+ describe("SC-50: evidence tier enforcement", () => {
208
+ test("evidence types are enumerated in schema", () => {
209
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
210
+ expect(schema).toMatch(/file-citation|grep-output|api-response|screenshot|test-output|command-output|manual-attestation/);
211
+ });
212
+ });
213
+
214
+ // SC-51: Self-attestation (tier F) = automatic FAIL
215
+ describe("SC-51: self-attestation FAIL", () => {
216
+ test("manual-attestation type exists in schema", () => {
217
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
218
+ expect(schema).toContain("manual-attestation");
219
+ });
220
+ });
221
+
222
+ // SC-52: Garbage test applied to every AC
223
+ describe("SC-52: AC garbage test", () => {
224
+ test("ac-quality test checks for garbage-passable ACs", () => {
225
+ const acQuality = join(GATES, "ac-quality.test.ts");
226
+ if (existsSync(acQuality)) {
227
+ const content = readFileSync(acQuality, "utf-8");
228
+ expect(content).toMatch(/garbage|weak|vague|behavioral/i);
229
+ } else {
230
+ expect(existsSync(acQuality)).toBe(true);
231
+ }
232
+ });
233
+ });
234
+
235
+ // SC-53: RCA section in Marcus brief for bug-fix issues
236
+ describe("SC-53: RCA in bug-fix briefs", () => {
237
+ test("brief-assembler includes RCA for bug-fix type", () => {
238
+ const assembler = join(GATES, "brief-assembler.ts");
239
+ if (existsSync(assembler)) {
240
+ const content = readFileSync(assembler, "utf-8");
241
+ expect(content).toMatch(/rca|rootCause|root.cause|bug.fix/i);
242
+ } else {
243
+ expect(existsSync(assembler)).toBe(true);
244
+ }
245
+ });
246
+ });
247
+
248
+ // SC-54: Gate checks RCA fields on bug-fix issues
249
+ describe("SC-54: RCA gate check", () => {
250
+ test("gate validates RCA fields", () => {
251
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts"]
252
+ .map(f => join(HARNESS, f))
253
+ .filter(f => existsSync(f));
254
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
255
+ expect(content).toMatch(/rootCause|rca|root.*cause/i);
256
+ });
257
+ });
258
+
259
+ // SC-55: Quinn briefs use typed journey format
260
+ describe("SC-55: Quinn journey format", () => {
261
+ test("schema or brief-assembler defines journey structure", () => {
262
+ const files = ["gates/schema.ts", "gates/brief-assembler.ts"]
263
+ .map(f => join(HARNESS, f))
264
+ .filter(f => existsSync(f));
265
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
266
+ expect(content).toMatch(/journey|action.*wait_for|assertion.*on_fail/i);
267
+ });
268
+ });
269
+
270
+ // SC-56: Quinn perception — browser_snapshot primary
271
+ describe("SC-56: Quinn perception hierarchy", () => {
272
+ test("quinn prompt or brief references snapshot perception", () => {
273
+ const quinnPrompt = join(PROMPTS, "quinn.md");
274
+ const quinnDecision = join(PROMPTS, "quinn-decision-tree.md");
275
+ const paths = [quinnPrompt, quinnDecision].filter(f => existsSync(f));
276
+ if (paths.length > 0) {
277
+ const content = paths.map(f => readFileSync(f, "utf-8")).join("\n");
278
+ expect(content).toMatch(/snapshot|a11y|accessibility.*tree/i);
279
+ } else {
280
+ expect(paths.length).toBeGreaterThan(0);
281
+ }
282
+ });
283
+ });
284
+
285
+ // SC-57: Quinn circuit breaker — 3 consecutive FAILs
286
+ describe("SC-57: Quinn circuit breaker", () => {
287
+ test("circuit breaker threshold defined", () => {
288
+ const files = ["gates/schema.ts", "prompts/quinn-decision-tree.md"]
289
+ .map(f => join(HARNESS, f))
290
+ .filter(f => existsSync(f));
291
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
292
+ expect(content).toMatch(/circuit.*breaker|3.*consecutive|abort.*journey/i);
293
+ });
294
+ });
295
+
296
+ // SC-58: Proof-of-fix includes negative control
297
+ describe("SC-58: negative control for S-tier", () => {
298
+ test("prove gate or prompt references negative control", () => {
299
+ const files = ["gates/prove.test.ts", "gates/prompts/prove-reproducer.md"]
300
+ .map(f => join(HARNESS, f))
301
+ .filter(f => existsSync(f));
302
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
303
+ expect(content).toMatch(/negative.*control|revert.*fix|confirm.*bug.*return/i);
304
+ });
305
+ });
306
+
307
+ // SC-59: Blast radius — filesRead ≥ filesChanged
308
+ describe("SC-59: blast radius enforcement", () => {
309
+ test("gate checks filesRead vs filesChanged", () => {
310
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts", "gates/orchestrator.ts"]
311
+ .map(f => join(HARNESS, f))
312
+ .filter(f => existsSync(f));
313
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
314
+ expect(content).toMatch(/filesRead|filesChanged|blast.*radius|read.*write.*ratio/i);
315
+ });
316
+ });
317
+
318
+ // SC-60: Read-before-write ratio ≥ 3:1
319
+ describe("SC-60: read-before-write ratio", () => {
320
+ test("gate enforces read/write ratio", () => {
321
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts"]
322
+ .map(f => join(HARNESS, f))
323
+ .filter(f => existsSync(f));
324
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
325
+ expect(content).toMatch(/read.*write|3:1|ratio/i);
326
+ });
327
+ });
328
+
329
+ // SC-61: Brief-assembler generates per-role templates
330
+ describe("SC-61: per-role brief generation", () => {
331
+ test("brief-assembler handles multiple roles", () => {
332
+ const assembler = join(GATES, "brief-assembler.ts");
333
+ if (existsSync(assembler)) {
334
+ const content = readFileSync(assembler, "utf-8");
335
+ expect(content).toMatch(/marcus|quinn|rook|role/i);
336
+ } else {
337
+ expect(existsSync(assembler)).toBe(true);
338
+ }
339
+ });
340
+ });
341
+
342
+ // SC-62: Templates are three-layered
343
+ describe("SC-62: three-layer templates", () => {
344
+ test("brief-assembler references harness + project + issue layers", () => {
345
+ const assembler = join(GATES, "brief-assembler.ts");
346
+ if (existsSync(assembler)) {
347
+ const content = readFileSync(assembler, "utf-8");
348
+ expect(content).toMatch(/harness|project.*config|issue.*specific|layer|rungate\.json|acs/i);
349
+ } else {
350
+ expect(existsSync(assembler)).toBe(true);
351
+ }
352
+ });
353
+ });
354
+
355
+ // SC-63: Spec content hash tracked — mismatch = FAIL
356
+ describe("SC-63: spec hash tracking", () => {
357
+ test("gate checks spec content hash", () => {
358
+ const files = ["gates/run-gate.ts", "gates/e2e-smoke.test.ts"]
359
+ .map(f => join(HARNESS, f))
360
+ .filter(f => existsSync(f));
361
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
362
+ expect(content).toMatch(/hash|sha|spec.*drift|content.*hash/i);
363
+ });
364
+ });
365
+
366
+ // SC-64: Test count post ≥ pre — decrease = FAIL
367
+ describe("SC-64: test deletion prevention", () => {
368
+ test("gate detects test count decrease", () => {
369
+ const files = ["gates/e2e-smoke.test.ts", "gates/workflow.test.ts"]
370
+ .map(f => join(HARNESS, f))
371
+ .filter(f => existsSync(f));
372
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
373
+ expect(content).toMatch(/test.*count|deletion|removed|decrease/i);
374
+ });
375
+ });
376
+
377
+ // SC-65: Prevention-oriented fixes
378
+ describe("SC-65: prevention-oriented pattern", () => {
379
+ test("prevention template exists or is referenced", () => {
380
+ const prevention = join(PROMPTS, "prevention.md");
381
+ const hasPrevention = existsSync(prevention);
382
+ const assembler = join(GATES, "brief-assembler.ts");
383
+ const refsPrevention = existsSync(assembler) && readFileSync(assembler, "utf-8").includes("prevention");
384
+ expect(hasPrevention || refsPrevention).toBe(true);
385
+ });
386
+ });
387
+
388
+ // SC-66: Writer and verifier are separate agents
389
+ describe("SC-66: writer/verifier separation", () => {
390
+ test("gate or schema tracks agent roles", () => {
391
+ const files = ["gates/schema.ts", "gates/run-gate.ts", "gates/witness.ts"]
392
+ .map(f => join(HARNESS, f))
393
+ .filter(f => existsSync(f));
394
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
395
+ expect(content).toMatch(/writer|verifier|author.*agent|witness|separate/i);
396
+ });
397
+ });
398
+
399
+ // SC-67: Quinn journey steps auto-generated from UI ACs
400
+ describe("SC-67: auto-generated Quinn journeys", () => {
401
+ test("brief-assembler generates journey from ACs", () => {
402
+ const assembler = join(GATES, "brief-assembler.ts");
403
+ if (existsSync(assembler)) {
404
+ const content = readFileSync(assembler, "utf-8");
405
+ expect(content).toMatch(/journey|quinn|UI|step/i);
406
+ } else {
407
+ expect(existsSync(assembler)).toBe(true);
408
+ }
409
+ });
410
+ });
411
+
412
+ // SC-68: Evidence without assertion = tier F
413
+ describe("SC-68: evidence without assertion", () => {
414
+ test("schema or gate rejects evidence without assertions", () => {
415
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
416
+ expect(schema).toContain("manual-attestation");
417
+ });
418
+ });
419
+
420
+ // SC-79: Conformity includes runPackageValidation
421
+ describe("SC-79: runPackageValidation", () => {
422
+ test("conformity exports runPackageValidation", () => {
423
+ const conformity = readFileSync(join(HARNESS, "lib/conformity.ts"), "utf-8");
424
+ expect(conformity).toContain("runPackageValidation");
425
+ });
426
+ });
427
+
428
+ // SC-81: Phase 0 additive — never overwrites existing content
429
+ describe("SC-81: additive scaffold", () => {
430
+ test("scaffold checks for existing content before writing", () => {
431
+ const scaffold = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8");
432
+ expect(scaffold).toMatch(/existsSync|exists|append|merge|additive/i);
433
+ });
434
+ });
435
+
436
+ // SC-96: rungate.json mcp section
437
+ describe("SC-96: mcp config section", () => {
438
+ test("schema supports mcp field", () => {
439
+ const schema = readFileSync(join(HARNESS, "lib/rungate-schema.ts"), "utf-8");
440
+ expect(schema).toMatch(/mcp/i);
441
+ });
442
+ });
443
+
444
+ // SC-102: Re-scaffold auto-fixes broken refs
445
+ describe("SC-102: re-scaffold auto-fix", () => {
446
+ test("scaffold handles re-scaffold with fixes", () => {
447
+ const scaffold = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8");
448
+ expect(scaffold).toMatch(/re.scaffold|update|existing|fix/i);
449
+ });
450
+ });
451
+
452
+ // SC-103: Evidence-to-tier mapping in gate
453
+ describe("SC-103: evidence tier mapping", () => {
454
+ test("evidence types map to tiers in schema", () => {
455
+ const schema = readFileSync(join(GATES, "schema.ts"), "utf-8");
456
+ expect(schema).toMatch(/EVIDENCE_METHOD_TYPES|evidence.*type|tier/i);
457
+ });
458
+ });
459
+
460
+ // SC-104: File ownership — harness-owned regenerated, co-owned preserved
461
+ describe("SC-104: file ownership model", () => {
462
+ test("scaffold distinguishes harness-owned from co-owned", () => {
463
+ const scaffold = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8");
464
+ expect(scaffold).toMatch(/overwrite|managed|harness.owned|co.owned|preserve|skip/i);
465
+ });
466
+ });
467
+
468
+ // SC-105: Scaffold idempotency
469
+ describe("SC-105: scaffold idempotent", () => {
470
+ test("scaffold handles existing project", () => {
471
+ const scaffold = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8");
472
+ expect(scaffold).toMatch(/existsSync|existing|idempotent|re.run/i);
473
+ });
474
+ });
475
+
476
+ // SC-108: Quinn journey stored in slug directory
477
+ describe("SC-108: Quinn journey storage", () => {
478
+ test("schema or orchestrator references quinn-journey path", () => {
479
+ const files = ["gates/schema.ts", "gates/orchestrator.ts"]
480
+ .map(f => join(HARNESS, f))
481
+ .filter(f => existsSync(f));
482
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
483
+ expect(content).toMatch(/quinn.*journey|journey.*yaml|journey.*path/i);
484
+ });
485
+ });
486
+
487
+ // SC-109: Fix-on-find — silently dropped = FAIL
488
+ describe("SC-109: fix-on-find enforcement", () => {
489
+ test("gate checks for dropped issues", () => {
490
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts"]
491
+ .map(f => join(HARNESS, f))
492
+ .filter(f => existsSync(f));
493
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
494
+ expect(content).toMatch(/fix.on.find|dropped|found.*issue|silently/i);
495
+ });
496
+ });
497
+
498
+ // SC-110: Port allocation checks for collisions
499
+ describe("SC-110: port collision detection", () => {
500
+ test("worktree or orchestrator checks port collisions", () => {
501
+ const files = ["gates/orchestrator.ts", "gates/ship-orchestrator.ts"]
502
+ .map(f => join(HARNESS, f))
503
+ .filter(f => existsSync(f));
504
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
505
+ expect(content).toMatch(/port.*collision|port.*alloc|port.*offset|port.*check/i);
506
+ });
507
+ });
508
+
509
+ // SC-111: Escalation decision tree in agent briefs
510
+ describe("SC-111: escalation decision tree", () => {
511
+ test("escalation template exists or is referenced in briefs", () => {
512
+ const escalation = join(PROMPTS, "escalation-decision-tree.md");
513
+ const hasEscalation = existsSync(escalation);
514
+ const scaffold = readFileSync(join(HARNESS, "scripts/scaffold-project.ts"), "utf-8");
515
+ const refsEscalation = scaffold.includes("escalation");
516
+ expect(hasEscalation || refsEscalation).toBe(true);
517
+ });
518
+ });
519
+
520
+ // SC-112: Circuit breaker → research escalation
521
+ describe("SC-112: research escalation at iteration 2", () => {
522
+ test("gate checks research evidence before iteration 3", () => {
523
+ const files = ["gates/run-gate.ts", "gates/self-heal.ts"]
524
+ .map(f => join(HARNESS, f))
525
+ .filter(f => existsSync(f));
526
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
527
+ expect(content).toMatch(/research|iteration|escalat|circuit.*break/i);
528
+ });
529
+ });
530
+
531
+ // SC-113: rungate.json research section
532
+ describe("SC-113: research tools config", () => {
533
+ test("schema supports research field", () => {
534
+ const schema = readFileSync(join(HARNESS, "lib/rungate-schema.ts"), "utf-8");
535
+ expect(schema).toMatch(/research/i);
536
+ });
537
+ });
538
+
539
+ // SC-127: 3 gate prompt templates exist
540
+ describe("SC-127: gate prompt templates", () => {
541
+ const templates = ["ac-adversary.md", "evidence-validator.md", "prove-reproducer.md"];
542
+ for (const t of templates) {
543
+ test(`gates/prompts/${t} exists`, () => {
544
+ expect(existsSync(join(GATES, "prompts", t))).toBe(true);
545
+ });
546
+ }
547
+ });
548
+
549
+ // SC-129: Gate WARNs on shallow modules
550
+ describe("SC-129: shallow module detection", () => {
551
+ test("conformity exports runModuleDepthCheck", () => {
552
+ const conformity = readFileSync(join(HARNESS, "lib/conformity.ts"), "utf-8");
553
+ expect(conformity).toContain("runModuleDepthCheck");
554
+ expect(conformity).toMatch(/shallow|export.*internal|module.*depth/i);
555
+ });
556
+ });
557
+
558
+ // SC-130: Gate WARNs on modules with >3 importers and no contract test
559
+ describe("SC-130: contract test coverage", () => {
560
+ test("conformity checks importer count vs contract tests", () => {
561
+ const conformity = readFileSync(join(HARNESS, "lib/conformity.ts"), "utf-8");
562
+ expect(conformity).toMatch(/importer|contract.*test|import.*count/i);
563
+ });
564
+ });
565
+
566
+ // SC-131: Anti-criteria use absence verification
567
+ describe("SC-131: absence verification for anti-criteria", () => {
568
+ test("conformity exports runAbsenceValidation", () => {
569
+ const conformity = readFileSync(join(HARNESS, "lib/conformity.ts"), "utf-8");
570
+ expect(conformity).toContain("runAbsenceValidation");
571
+ expect(conformity).toMatch(/absence|anti.*criter/i);
572
+ });
573
+ });
574
+
575
+ // SC-132: Tier D evidence capped at 25%
576
+ describe("SC-132: tier D cap", () => {
577
+ test("gate checks grep evidence percentage", () => {
578
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts"]
579
+ .map(f => join(HARNESS, f))
580
+ .filter(f => existsSync(f));
581
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
582
+ expect(content).toMatch(/tier.*D|grep.*cap|25.*percent|evidence.*portfolio/i);
583
+ });
584
+ });
585
+
586
+ // SC-133: Brief-assembler rejects Quinn journeys > 8 steps
587
+ describe("SC-133: Quinn journey step cap", () => {
588
+ test("brief-assembler limits journey length", () => {
589
+ const assembler = join(GATES, "brief-assembler.ts");
590
+ if (existsSync(assembler)) {
591
+ const content = readFileSync(assembler, "utf-8");
592
+ expect(content).toMatch(/8.*step|step.*limit|journey.*split|max.*step/i);
593
+ } else {
594
+ expect(existsSync(assembler)).toBe(true);
595
+ }
596
+ });
597
+ });
598
+
599
+ // SC-134: Files changed outside brief = WARN
600
+ describe("SC-134: out-of-brief file changes", () => {
601
+ test("gate detects changes outside brief scope", () => {
602
+ const files = ["gates/run-gate.ts", "gates/workflow.test.ts"]
603
+ .map(f => join(HARNESS, f))
604
+ .filter(f => existsSync(f));
605
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
606
+ expect(content).toMatch(/outside.*brief|brief.*file|unexpected.*change|file.*outside/i);
607
+ });
608
+ });
609
+
610
+ // SC-135: Gate cross-validates proofOfFix vs prove-evidence
611
+ describe("SC-135: proof cross-validation", () => {
612
+ test("gate compares proofOfFix against prove-evidence.json", () => {
613
+ const files = ["gates/run-gate.ts", "gates/prove.test.ts"]
614
+ .map(f => join(HARNESS, f))
615
+ .filter(f => existsSync(f));
616
+ const content = files.map(f => readFileSync(f, "utf-8")).join("\n");
617
+ expect(content).toMatch(/proofOfFix|prove.evidence|cross.*valid|mismatch/i);
618
+ });
619
+ });
620
+ });