@dommaker/harness 1.1.1 → 1.2.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.
Files changed (373) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +2 -4
  3. package/bin/harness.js +12 -37
  4. package/dist/cli/commands/check.d.ts +2 -2
  5. package/dist/cli/commands/check.d.ts.map +1 -1
  6. package/dist/cli/commands/check.js +8 -33
  7. package/dist/cli/commands/check.js.map +1 -1
  8. package/dist/cli/commands/constraints-report.js +1 -1
  9. package/dist/cli/commands/constraints-report.js.map +1 -1
  10. package/dist/cli/commands/constraints-retire.d.ts +6 -3
  11. package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
  12. package/dist/cli/commands/constraints-retire.js +34 -25
  13. package/dist/cli/commands/constraints-retire.js.map +1 -1
  14. package/dist/cli/commands/definitions.d.ts +2 -0
  15. package/dist/cli/commands/definitions.d.ts.map +1 -1
  16. package/dist/cli/commands/definitions.js.map +1 -1
  17. package/dist/cli/commands/init.d.ts +21 -1
  18. package/dist/cli/commands/init.d.ts.map +1 -1
  19. package/dist/cli/commands/init.js +118 -40
  20. package/dist/cli/commands/init.js.map +1 -1
  21. package/dist/cli/commands/knowledge.d.ts.map +1 -1
  22. package/dist/cli/commands/knowledge.js +1 -12
  23. package/dist/cli/commands/knowledge.js.map +1 -1
  24. package/dist/cli/commands/report.d.ts.map +1 -1
  25. package/dist/cli/commands/report.js +0 -2
  26. package/dist/cli/commands/report.js.map +1 -1
  27. package/dist/cli/commands/status.js +2 -2
  28. package/dist/cli/commands/status.js.map +1 -1
  29. package/dist/context/index.d.ts +9 -6
  30. package/dist/context/index.d.ts.map +1 -1
  31. package/dist/context/index.js +18 -20
  32. package/dist/context/index.js.map +1 -1
  33. package/dist/core/constraints/capabilities-parser.d.ts +3 -2
  34. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  35. package/dist/core/constraints/capabilities-parser.js +25 -47
  36. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  37. package/dist/core/constraints/checker.d.ts +29 -32
  38. package/dist/core/constraints/checker.d.ts.map +1 -1
  39. package/dist/core/constraints/checker.js +34 -126
  40. package/dist/core/constraints/checker.js.map +1 -1
  41. package/dist/core/constraints/checkers/governance-presence.d.ts +20 -0
  42. package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -0
  43. package/dist/core/constraints/checkers/governance-presence.js +76 -0
  44. package/dist/core/constraints/checkers/governance-presence.js.map +1 -0
  45. package/dist/core/constraints/checkers/index.d.ts +2 -1
  46. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  47. package/dist/core/constraints/checkers/index.js +5 -0
  48. package/dist/core/constraints/checkers/index.js.map +1 -1
  49. package/dist/core/constraints/checkers/types.d.ts +25 -0
  50. package/dist/core/constraints/checkers/types.d.ts.map +1 -1
  51. package/dist/core/constraints/checkers/types.js +24 -0
  52. package/dist/core/constraints/checkers/types.js.map +1 -1
  53. package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
  54. package/dist/core/constraints/definitions/guidelines.js +21 -2
  55. package/dist/core/constraints/definitions/guidelines.js.map +1 -1
  56. package/dist/core/constraints/definitions/prompts.d.ts.map +1 -1
  57. package/dist/core/constraints/definitions/prompts.js +0 -5
  58. package/dist/core/constraints/definitions/prompts.js.map +1 -1
  59. package/dist/core/constraints/index.d.ts +1 -2
  60. package/dist/core/constraints/index.d.ts.map +1 -1
  61. package/dist/core/constraints/index.js +1 -7
  62. package/dist/core/constraints/index.js.map +1 -1
  63. package/dist/core/constraints/injection-drift.d.ts +29 -4
  64. package/dist/core/constraints/injection-drift.d.ts.map +1 -1
  65. package/dist/core/constraints/injection-drift.js +52 -20
  66. package/dist/core/constraints/injection-drift.js.map +1 -1
  67. package/dist/core/constraints/usage-report.d.ts +1 -2
  68. package/dist/core/constraints/usage-report.d.ts.map +1 -1
  69. package/dist/core/constraints/usage-report.js +2 -5
  70. package/dist/core/constraints/usage-report.js.map +1 -1
  71. package/dist/core/effective-constraints.d.ts +24 -4
  72. package/dist/core/effective-constraints.d.ts.map +1 -1
  73. package/dist/core/effective-constraints.js +28 -7
  74. package/dist/core/effective-constraints.js.map +1 -1
  75. package/dist/core/effective-set.d.ts +30 -0
  76. package/dist/core/effective-set.d.ts.map +1 -0
  77. package/dist/core/effective-set.js +35 -0
  78. package/dist/core/effective-set.js.map +1 -0
  79. package/dist/core/index.d.ts +13 -6
  80. package/dist/core/index.d.ts.map +1 -1
  81. package/dist/core/index.js +44 -21
  82. package/dist/core/index.js.map +1 -1
  83. package/dist/core/project-config-loader.d.ts +3 -6
  84. package/dist/core/project-config-loader.d.ts.map +1 -1
  85. package/dist/core/project-config-loader.js +47 -61
  86. package/dist/core/project-config-loader.js.map +1 -1
  87. package/dist/failure/constraint-handler.d.ts +1 -1
  88. package/dist/failure/constraint-handler.js +1 -1
  89. package/dist/gates/checker-gate.d.ts +1 -4
  90. package/dist/gates/checker-gate.d.ts.map +1 -1
  91. package/dist/gates/checker-gate.js +3 -11
  92. package/dist/gates/checker-gate.js.map +1 -1
  93. package/dist/gates/definitions.d.ts +9 -38
  94. package/dist/gates/definitions.d.ts.map +1 -1
  95. package/dist/gates/definitions.js +24 -13
  96. package/dist/gates/definitions.js.map +1 -1
  97. package/dist/gates/effective-gates.d.ts.map +1 -1
  98. package/dist/gates/effective-gates.js +14 -18
  99. package/dist/gates/effective-gates.js.map +1 -1
  100. package/dist/gates/index.d.ts +1 -1
  101. package/dist/gates/index.d.ts.map +1 -1
  102. package/dist/gates/index.js.map +1 -1
  103. package/dist/hooks/bootstrap.d.ts.map +1 -1
  104. package/dist/hooks/bootstrap.js +0 -3
  105. package/dist/hooks/bootstrap.js.map +1 -1
  106. package/dist/index.d.ts +43 -60
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +180 -143
  109. package/dist/index.js.map +1 -1
  110. package/dist/knowledge/query.d.ts +15 -0
  111. package/dist/knowledge/query.d.ts.map +1 -1
  112. package/dist/knowledge/query.js +23 -0
  113. package/dist/knowledge/query.js.map +1 -1
  114. package/dist/monitoring/analyzer-base.d.ts +0 -4
  115. package/dist/monitoring/analyzer-base.d.ts.map +1 -1
  116. package/dist/monitoring/analyzer-base.js +0 -21
  117. package/dist/monitoring/analyzer-base.js.map +1 -1
  118. package/dist/monitoring/index.d.ts +6 -12
  119. package/dist/monitoring/index.d.ts.map +1 -1
  120. package/dist/monitoring/index.js +13 -29
  121. package/dist/monitoring/index.js.map +1 -1
  122. package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
  123. package/dist/monitoring/trace-analyzer.js +2 -68
  124. package/dist/monitoring/trace-analyzer.js.map +1 -1
  125. package/dist/monitoring/traces.d.ts +0 -4
  126. package/dist/monitoring/traces.d.ts.map +1 -1
  127. package/dist/monitoring/traces.js +0 -14
  128. package/dist/monitoring/traces.js.map +1 -1
  129. package/dist/presets/index.d.ts +2 -2
  130. package/dist/presets/index.d.ts.map +1 -1
  131. package/dist/presets/index.js +3 -4
  132. package/dist/presets/index.js.map +1 -1
  133. package/dist/presets/standard.d.ts +10 -22
  134. package/dist/presets/standard.d.ts.map +1 -1
  135. package/dist/presets/standard.js +15 -75
  136. package/dist/presets/standard.js.map +1 -1
  137. package/dist/types/constraint.d.ts +1 -29
  138. package/dist/types/constraint.d.ts.map +1 -1
  139. package/dist/types/constraint.js +1 -1
  140. package/dist/types/constraint.js.map +1 -1
  141. package/dist/types/index.d.ts +0 -3
  142. package/dist/types/index.d.ts.map +1 -1
  143. package/dist/types/index.js +0 -4
  144. package/dist/types/index.js.map +1 -1
  145. package/dist/types/project-config.d.ts +4 -8
  146. package/dist/types/project-config.d.ts.map +1 -1
  147. package/dist/types/trace.d.ts +5 -18
  148. package/dist/types/trace.d.ts.map +1 -1
  149. package/package.json +2 -2
  150. package/src/CONTEXT.md +4 -5
  151. package/src/__tests__/checker-extra.test.ts +33 -139
  152. package/src/__tests__/checker.test.ts +0 -376
  153. package/src/__tests__/governance-presence.test.ts +129 -0
  154. package/src/__tests__/iron-laws.test.ts +7 -7
  155. package/src/__tests__/project-config-loader-extra.test.ts +42 -29
  156. package/src/__tests__/public-exports.test.ts +138 -0
  157. package/src/__tests__/trace-analyzer-extra.test.ts +6 -86
  158. package/src/__tests__/trace-analyzer.test.ts +4 -5
  159. package/src/__tests__/trace-collector.test.ts +0 -11
  160. package/src/__tests__/traces.test.ts +3 -22
  161. package/src/cli/commands/CONTEXT.md +6 -3
  162. package/src/cli/commands/__tests__/check-skip-output.test.ts +10 -7
  163. package/src/cli/commands/__tests__/check.test.ts +29 -69
  164. package/src/cli/commands/__tests__/constraints-report.test.ts +3 -3
  165. package/src/cli/commands/__tests__/constraints-retire.test.ts +45 -4
  166. package/src/cli/commands/__tests__/init-injection.test.ts +202 -0
  167. package/src/cli/commands/__tests__/knowledge.test.ts +90 -1
  168. package/src/cli/commands/__tests__/registry.test.ts +8 -6
  169. package/src/cli/commands/__tests__/status-extra.test.ts +6 -6
  170. package/src/cli/commands/__tests__/status.test.ts +6 -6
  171. package/src/cli/commands/__tests__/sync-docs-agents.test.ts +28 -0
  172. package/src/cli/commands/check.ts +9 -35
  173. package/src/cli/commands/constraints-report.ts +1 -1
  174. package/src/cli/commands/constraints-retire.ts +38 -27
  175. package/src/cli/commands/definitions.ts +2 -0
  176. package/src/cli/commands/init.ts +129 -40
  177. package/src/cli/commands/knowledge.ts +1 -16
  178. package/src/cli/commands/report.ts +0 -2
  179. package/src/cli/commands/status.ts +2 -2
  180. package/src/context/index.ts +29 -6
  181. package/src/core/CONTEXT.md +4 -3
  182. package/src/core/__tests__/effective-set.test.ts +80 -0
  183. package/src/core/constraints/__tests__/injection-drift.test.ts +90 -0
  184. package/src/core/constraints/capabilities-parser.ts +43 -49
  185. package/src/core/constraints/checker.ts +51 -145
  186. package/src/core/constraints/checkers/governance-presence.ts +74 -0
  187. package/src/core/constraints/checkers/index.ts +4 -1
  188. package/src/core/constraints/checkers/types.ts +42 -0
  189. package/src/core/constraints/definitions/guidelines.ts +22 -2
  190. package/src/core/constraints/definitions/prompts.ts +0 -5
  191. package/src/core/constraints/index.ts +2 -17
  192. package/src/core/constraints/injection-drift.ts +60 -21
  193. package/src/core/constraints/usage-report.ts +5 -8
  194. package/src/core/effective-constraints.ts +35 -7
  195. package/src/core/effective-set.ts +56 -0
  196. package/src/core/index.ts +80 -6
  197. package/src/core/project-config-loader.ts +53 -68
  198. package/src/failure/CONTEXT.md +1 -1
  199. package/src/failure/constraint-handler.ts +1 -1
  200. package/src/gates/CONTEXT.md +3 -3
  201. package/src/gates/checker-gate.ts +4 -12
  202. package/src/gates/definitions.ts +27 -50
  203. package/src/gates/effective-gates.ts +14 -21
  204. package/src/gates/index.ts +1 -1
  205. package/src/hooks/bootstrap.ts +0 -3
  206. package/src/index.ts +384 -148
  207. package/src/knowledge/CONTEXT.md +2 -2
  208. package/src/knowledge/__tests__/query.test.ts +64 -0
  209. package/src/knowledge/query.ts +28 -0
  210. package/src/monitoring/CONTEXT.md +7 -13
  211. package/src/monitoring/__tests__/traces.test.ts +0 -10
  212. package/src/monitoring/analyzer-base.ts +0 -22
  213. package/src/monitoring/index.ts +6 -12
  214. package/src/monitoring/trace-analyzer.ts +2 -73
  215. package/src/monitoring/traces.ts +0 -20
  216. package/src/presets/__tests__/standard.test.ts +48 -69
  217. package/src/presets/index.ts +3 -5
  218. package/src/presets/standard.ts +14 -79
  219. package/src/spec/CONTEXT.md +5 -13
  220. package/src/types/constraint.ts +1 -51
  221. package/src/types/index.ts +0 -12
  222. package/src/types/project-config.ts +4 -10
  223. package/src/types/trace.ts +5 -30
  224. package/dist/core/constraints/interceptor.d.ts +0 -39
  225. package/dist/core/constraints/interceptor.d.ts.map +0 -1
  226. package/dist/core/constraints/interceptor.js +0 -166
  227. package/dist/core/constraints/interceptor.js.map +0 -1
  228. package/dist/dashboard/data.d.ts +0 -31
  229. package/dist/dashboard/data.d.ts.map +0 -1
  230. package/dist/dashboard/data.js +0 -81
  231. package/dist/dashboard/data.js.map +0 -1
  232. package/dist/dashboard/index.d.ts +0 -4
  233. package/dist/dashboard/index.d.ts.map +0 -1
  234. package/dist/dashboard/index.js +0 -20
  235. package/dist/dashboard/index.js.map +0 -1
  236. package/dist/dashboard/stats.d.ts +0 -20
  237. package/dist/dashboard/stats.d.ts.map +0 -1
  238. package/dist/dashboard/stats.js +0 -115
  239. package/dist/dashboard/stats.js.map +0 -1
  240. package/dist/dashboard/types.d.ts +0 -110
  241. package/dist/dashboard/types.d.ts.map +0 -1
  242. package/dist/dashboard/types.js +0 -8
  243. package/dist/dashboard/types.js.map +0 -1
  244. package/dist/monitoring/constraint-doctor.d.ts +0 -76
  245. package/dist/monitoring/constraint-doctor.d.ts.map +0 -1
  246. package/dist/monitoring/constraint-doctor.js +0 -189
  247. package/dist/monitoring/constraint-doctor.js.map +0 -1
  248. package/dist/monitoring/diagnosis-rules.d.ts +0 -18
  249. package/dist/monitoring/diagnosis-rules.d.ts.map +0 -1
  250. package/dist/monitoring/diagnosis-rules.js +0 -119
  251. package/dist/monitoring/diagnosis-rules.js.map +0 -1
  252. package/dist/monitoring/knowledge-doctor.d.ts +0 -78
  253. package/dist/monitoring/knowledge-doctor.d.ts.map +0 -1
  254. package/dist/monitoring/knowledge-doctor.js +0 -266
  255. package/dist/monitoring/knowledge-doctor.js.map +0 -1
  256. package/dist/monitoring/knowledge-evolver.d.ts +0 -72
  257. package/dist/monitoring/knowledge-evolver.d.ts.map +0 -1
  258. package/dist/monitoring/knowledge-evolver.js +0 -205
  259. package/dist/monitoring/knowledge-evolver.js.map +0 -1
  260. package/dist/monitoring/performance-analyzer.d.ts +0 -92
  261. package/dist/monitoring/performance-analyzer.d.ts.map +0 -1
  262. package/dist/monitoring/performance-analyzer.js +0 -343
  263. package/dist/monitoring/performance-analyzer.js.map +0 -1
  264. package/dist/monitoring/performance-collector.d.ts +0 -103
  265. package/dist/monitoring/performance-collector.d.ts.map +0 -1
  266. package/dist/monitoring/performance-collector.js +0 -298
  267. package/dist/monitoring/performance-collector.js.map +0 -1
  268. package/dist/safety/index.d.ts +0 -6
  269. package/dist/safety/index.d.ts.map +0 -1
  270. package/dist/safety/index.js +0 -22
  271. package/dist/safety/index.js.map +0 -1
  272. package/dist/safety/input-guardrail.d.ts +0 -36
  273. package/dist/safety/input-guardrail.d.ts.map +0 -1
  274. package/dist/safety/input-guardrail.js +0 -118
  275. package/dist/safety/input-guardrail.js.map +0 -1
  276. package/dist/safety/output-guardrail.d.ts +0 -39
  277. package/dist/safety/output-guardrail.d.ts.map +0 -1
  278. package/dist/safety/output-guardrail.js +0 -147
  279. package/dist/safety/output-guardrail.js.map +0 -1
  280. package/dist/safety/sandbox.d.ts +0 -45
  281. package/dist/safety/sandbox.d.ts.map +0 -1
  282. package/dist/safety/sandbox.js +0 -134
  283. package/dist/safety/sandbox.js.map +0 -1
  284. package/dist/safety/tool-guardrail.d.ts +0 -51
  285. package/dist/safety/tool-guardrail.d.ts.map +0 -1
  286. package/dist/safety/tool-guardrail.js +0 -147
  287. package/dist/safety/tool-guardrail.js.map +0 -1
  288. package/dist/safety/types.d.ts +0 -104
  289. package/dist/safety/types.d.ts.map +0 -1
  290. package/dist/safety/types.js +0 -6
  291. package/dist/safety/types.js.map +0 -1
  292. package/dist/spec/annotation-checker.d.ts +0 -47
  293. package/dist/spec/annotation-checker.d.ts.map +0 -1
  294. package/dist/spec/annotation-checker.js +0 -279
  295. package/dist/spec/annotation-checker.js.map +0 -1
  296. package/dist/types/enforcement.d.ts +0 -42
  297. package/dist/types/enforcement.d.ts.map +0 -1
  298. package/dist/types/enforcement.js +0 -6
  299. package/dist/types/enforcement.js.map +0 -1
  300. package/dist/types/monitoring-types.d.ts +0 -53
  301. package/dist/types/monitoring-types.d.ts.map +0 -1
  302. package/dist/types/monitoring-types.js +0 -10
  303. package/dist/types/monitoring-types.js.map +0 -1
  304. package/dist/types/performance.d.ts +0 -204
  305. package/dist/types/performance.d.ts.map +0 -1
  306. package/dist/types/performance.js +0 -12
  307. package/dist/types/performance.js.map +0 -1
  308. package/dist/verification/index.d.ts +0 -4
  309. package/dist/verification/index.d.ts.map +0 -1
  310. package/dist/verification/index.js +0 -20
  311. package/dist/verification/index.js.map +0 -1
  312. package/dist/verification/loop.d.ts +0 -30
  313. package/dist/verification/loop.d.ts.map +0 -1
  314. package/dist/verification/loop.js +0 -114
  315. package/dist/verification/loop.js.map +0 -1
  316. package/dist/verification/rules-based.d.ts +0 -40
  317. package/dist/verification/rules-based.d.ts.map +0 -1
  318. package/dist/verification/rules-based.js +0 -130
  319. package/dist/verification/rules-based.js.map +0 -1
  320. package/dist/verification/types.d.ts +0 -69
  321. package/dist/verification/types.d.ts.map +0 -1
  322. package/dist/verification/types.js +0 -6
  323. package/dist/verification/types.js.map +0 -1
  324. package/src/__tests__/annotation-checker.test.ts +0 -183
  325. package/src/__tests__/constraint-doctor.test.ts +0 -271
  326. package/src/__tests__/doctor-extra.test.ts +0 -155
  327. package/src/__tests__/extend-exceptions.test.ts +0 -149
  328. package/src/__tests__/interceptor.test.ts +0 -89
  329. package/src/__tests__/performance-analyzer.test.ts +0 -499
  330. package/src/__tests__/performance-collector.test.ts +0 -276
  331. package/src/__tests__/presets.test.ts +0 -65
  332. package/src/core/constraints/__tests__/interceptor.test.ts +0 -267
  333. package/src/core/constraints/interceptor.ts +0 -217
  334. package/src/dashboard/CONTEXT.md +0 -21
  335. package/src/dashboard/__tests__/data.test.ts +0 -111
  336. package/src/dashboard/__tests__/stats.test.ts +0 -159
  337. package/src/dashboard/data.ts +0 -103
  338. package/src/dashboard/index.ts +0 -3
  339. package/src/dashboard/stats.ts +0 -127
  340. package/src/dashboard/types.ts +0 -130
  341. package/src/monitoring/__tests__/knowledge-doctor.test.ts +0 -278
  342. package/src/monitoring/__tests__/knowledge-evolver.test.ts +0 -368
  343. package/src/monitoring/__tests__/performance-analyzer.test.ts +0 -137
  344. package/src/monitoring/__tests__/performance-collector.test.ts +0 -331
  345. package/src/monitoring/constraint-doctor.ts +0 -228
  346. package/src/monitoring/diagnosis-rules.ts +0 -132
  347. package/src/monitoring/knowledge-doctor.ts +0 -322
  348. package/src/monitoring/knowledge-evolver.ts +0 -289
  349. package/src/monitoring/performance-analyzer.ts +0 -400
  350. package/src/monitoring/performance-collector.ts +0 -326
  351. package/src/safety/CONTEXT.md +0 -23
  352. package/src/safety/__tests__/input-guardrail.test.ts +0 -105
  353. package/src/safety/__tests__/output-guardrail.test.ts +0 -108
  354. package/src/safety/__tests__/sandbox.test.ts +0 -158
  355. package/src/safety/__tests__/tool-guardrail.test.ts +0 -127
  356. package/src/safety/index.ts +0 -5
  357. package/src/safety/input-guardrail.ts +0 -133
  358. package/src/safety/output-guardrail.ts +0 -170
  359. package/src/safety/sandbox.ts +0 -148
  360. package/src/safety/tool-guardrail.ts +0 -176
  361. package/src/safety/types.ts +0 -124
  362. package/src/spec/__tests__/annotation-checker.test.ts +0 -294
  363. package/src/spec/annotation-checker.ts +0 -320
  364. package/src/types/enforcement.ts +0 -48
  365. package/src/types/monitoring-types.ts +0 -68
  366. package/src/types/performance.ts +0 -295
  367. package/src/verification/CONTEXT.md +0 -23
  368. package/src/verification/__tests__/loop.test.ts +0 -303
  369. package/src/verification/__tests__/rules-based.test.ts +0 -240
  370. package/src/verification/index.ts +0 -3
  371. package/src/verification/loop.ts +0 -137
  372. package/src/verification/rules-based.ts +0 -152
  373. package/src/verification/types.ts +0 -81
@@ -170,382 +170,6 @@ describe('ConstraintChecker', () => {
170
170
  });
171
171
  });
172
172
 
173
- describe('Exception handling', () => {
174
- it('should apply exception for scalability_required', async () => {
175
- const context: ConstraintContext = {
176
- operation: 'code_implementation',
177
- scalabilityRequired: true,
178
- };
179
-
180
- const result = await checker.check(
181
- {
182
- id: 'simplest_solution_first',
183
- kind: 'check',
184
- level: 'guideline',
185
- rule: 'SIMPLEST FIRST',
186
- message: 'test',
187
- trigger: 'code_implementation',
188
- enforcement: 'test',
189
- exceptions: ['scalability_required'],
190
- },
191
- context
192
- );
193
-
194
- expect(result.satisfied).toBe(true);
195
- });
196
-
197
- it('should apply exception for security_required', async () => {
198
- const context: ConstraintContext = {
199
- operation: 'code_implementation',
200
- securityRequired: true,
201
- };
202
-
203
- const result = await checker.check(
204
- {
205
- id: 'simplest_solution_first',
206
- kind: 'check',
207
- level: 'guideline',
208
- rule: 'SIMPLEST FIRST',
209
- message: 'test',
210
- trigger: 'code_implementation',
211
- enforcement: 'test',
212
- exceptions: ['security_required'],
213
- },
214
- context
215
- );
216
-
217
- expect(result.satisfied).toBe(true);
218
- });
219
-
220
- it('should apply exception for performance_required', async () => {
221
- const context: ConstraintContext = {
222
- operation: 'code_implementation',
223
- performanceRequired: true,
224
- };
225
-
226
- const result = await checker.check(
227
- {
228
- id: 'simplest_solution_first',
229
- kind: 'check',
230
- level: 'guideline',
231
- rule: 'SIMPLEST FIRST',
232
- message: 'test',
233
- trigger: 'code_implementation',
234
- enforcement: 'test',
235
- exceptions: ['performance_required'],
236
- },
237
- context
238
- );
239
-
240
- expect(result.satisfied).toBe(true);
241
- });
242
-
243
- it('should apply exception for reliability_required', async () => {
244
- const context: ConstraintContext = {
245
- operation: 'code_implementation',
246
- reliabilityRequired: true,
247
- };
248
-
249
- const result = await checker.check(
250
- {
251
- id: 'simplest_solution_first',
252
- kind: 'check',
253
- level: 'guideline',
254
- rule: 'SIMPLEST FIRST',
255
- message: 'test',
256
- trigger: 'code_implementation',
257
- enforcement: 'test',
258
- exceptions: ['reliability_required'],
259
- },
260
- context
261
- );
262
-
263
- expect(result.satisfied).toBe(true);
264
- });
265
-
266
- it('should apply exception for config_value_error', async () => {
267
- const context: ConstraintContext = {
268
- operation: 'code_implementation',
269
- isConfigValueError: true,
270
- };
271
-
272
- const result = await checker.check(
273
- {
274
- id: 'no_fix_without_root_cause',
275
- kind: 'check',
276
- level: 'guideline',
277
- rule: 'NO FIX',
278
- message: 'test',
279
- trigger: 'code_implementation',
280
- enforcement: 'test',
281
- exceptions: ['config_value_error'],
282
- },
283
- context
284
- );
285
-
286
- expect(result.satisfied).toBe(true);
287
- });
288
-
289
- it('should apply exception for missing_config', async () => {
290
- const context: ConstraintContext = {
291
- operation: 'code_implementation',
292
- isMissingConfig: true,
293
- };
294
-
295
- const result = await checker.check(
296
- {
297
- id: 'no_fix_without_root_cause',
298
- kind: 'check',
299
- level: 'guideline',
300
- rule: 'NO FIX',
301
- message: 'test',
302
- trigger: 'code_implementation',
303
- enforcement: 'test',
304
- exceptions: ['missing_config'],
305
- },
306
- context
307
- );
308
-
309
- expect(result.satisfied).toBe(true);
310
- });
311
-
312
- it('should apply exception for config_file', async () => {
313
- const context: ConstraintContext = {
314
- operation: 'code_implementation',
315
- isConfigFile: true,
316
- };
317
-
318
- const result = await checker.check(
319
- {
320
- id: 'no_code_without_test',
321
- kind: 'check',
322
- level: 'guideline',
323
- rule: 'NO CODE',
324
- message: 'test',
325
- trigger: 'code_implementation',
326
- enforcement: 'test',
327
- exceptions: ['config_file'],
328
- },
329
- context
330
- );
331
-
332
- expect(result.satisfied).toBe(true);
333
- });
334
-
335
- it('should apply exception for type_definition', async () => {
336
- const context: ConstraintContext = {
337
- operation: 'code_implementation',
338
- isTypeDefinition: true,
339
- };
340
-
341
- const result = await checker.check(
342
- {
343
- id: 'no_code_without_test',
344
- kind: 'check',
345
- level: 'guideline',
346
- rule: 'NO CODE',
347
- message: 'test',
348
- trigger: 'code_implementation',
349
- enforcement: 'test',
350
- exceptions: ['type_definition'],
351
- },
352
- context
353
- );
354
-
355
- expect(result.satisfied).toBe(true);
356
- });
357
-
358
- it('should apply exception for simple_accessor', async () => {
359
- const context: ConstraintContext = {
360
- operation: 'code_implementation',
361
- isSimpleAccessor: true,
362
- };
363
-
364
- const result = await checker.check(
365
- {
366
- id: 'no_code_without_test',
367
- kind: 'check',
368
- level: 'guideline',
369
- rule: 'NO CODE',
370
- message: 'test',
371
- trigger: 'code_implementation',
372
- enforcement: 'test',
373
- exceptions: ['simple_accessor'],
374
- },
375
- context
376
- );
377
-
378
- expect(result.satisfied).toBe(true);
379
- });
380
-
381
- it('should apply exception for pure_display_component', async () => {
382
- const context: ConstraintContext = {
383
- operation: 'code_implementation',
384
- isPureDisplayComponent: true,
385
- };
386
-
387
- const result = await checker.check(
388
- {
389
- id: 'no_code_without_test',
390
- kind: 'check',
391
- level: 'guideline',
392
- rule: 'NO CODE',
393
- message: 'test',
394
- trigger: 'code_implementation',
395
- enforcement: 'test',
396
- exceptions: ['pure_display_component'],
397
- },
398
- context
399
- );
400
-
401
- expect(result.satisfied).toBe(true);
402
- });
403
-
404
- it('should apply exception for internal_refactor', async () => {
405
- const context: ConstraintContext = {
406
- operation: 'commit',
407
- projectPath: tempDir,
408
- isInternalRefactor: true,
409
- };
410
-
411
- const result = await checker.check(
412
- {
413
- id: 'capability_sync',
414
- kind: 'check',
415
- level: 'guideline',
416
- rule: 'CAPABILITY SYNC',
417
- message: 'test',
418
- trigger: 'commit',
419
- enforcement: 'test',
420
- exceptions: ['internal_refactor'],
421
- },
422
- context
423
- );
424
-
425
- expect(result.satisfied).toBe(true);
426
- });
427
-
428
- it('should apply exception for bug_fix_only', async () => {
429
- const context: ConstraintContext = {
430
- operation: 'commit',
431
- projectPath: tempDir,
432
- isBugFixOnly: true,
433
- };
434
-
435
- const result = await checker.check(
436
- {
437
- id: 'capability_sync',
438
- kind: 'check',
439
- level: 'guideline',
440
- rule: 'CAPABILITY SYNC',
441
- message: 'test',
442
- trigger: 'commit',
443
- enforcement: 'test',
444
- exceptions: ['bug_fix_only'],
445
- },
446
- context
447
- );
448
-
449
- expect(result.satisfied).toBe(true);
450
- });
451
-
452
- it('should apply exception for performance_optimization', async () => {
453
- const context: ConstraintContext = {
454
- operation: 'commit',
455
- projectPath: tempDir,
456
- isPerformanceOptimization: true,
457
- };
458
-
459
- const result = await checker.check(
460
- {
461
- id: 'capability_sync',
462
- kind: 'check',
463
- level: 'guideline',
464
- rule: 'CAPABILITY SYNC',
465
- message: 'test',
466
- trigger: 'commit',
467
- enforcement: 'test',
468
- exceptions: ['performance_optimization'],
469
- },
470
- context
471
- );
472
-
473
- expect(result.satisfied).toBe(true);
474
- });
475
-
476
- it('should apply exception for redundant_code_cleanup', async () => {
477
- const context: ConstraintContext = {
478
- operation: 'commit',
479
- projectPath: tempDir,
480
- isRedundantCodeCleanup: true,
481
- };
482
-
483
- const result = await checker.check(
484
- {
485
- id: 'no_simplification_without_approval',
486
- kind: 'check',
487
- level: 'guideline',
488
- rule: 'NO SIMPLIFICATION',
489
- message: 'test',
490
- trigger: 'commit',
491
- enforcement: 'test',
492
- exceptions: ['redundant_code_cleanup'],
493
- },
494
- context
495
- );
496
-
497
- expect(result.satisfied).toBe(true);
498
- });
499
-
500
- it('should apply exception for same_effect_refactor', async () => {
501
- const context: ConstraintContext = {
502
- operation: 'commit',
503
- projectPath: tempDir,
504
- isSameEffectRefactor: true,
505
- };
506
-
507
- const result = await checker.check(
508
- {
509
- id: 'no_simplification_without_approval',
510
- kind: 'check',
511
- level: 'guideline',
512
- rule: 'NO SIMPLIFICATION',
513
- message: 'test',
514
- trigger: 'commit',
515
- enforcement: 'test',
516
- exceptions: ['same_effect_refactor'],
517
- },
518
- context
519
- );
520
-
521
- expect(result.satisfied).toBe(true);
522
- });
523
-
524
- it('should apply exception for unused_code_removal', async () => {
525
- const context: ConstraintContext = {
526
- operation: 'commit',
527
- projectPath: tempDir,
528
- isUnusedCodeRemoval: true,
529
- };
530
-
531
- const result = await checker.check(
532
- {
533
- id: 'no_simplification_without_approval',
534
- kind: 'check',
535
- level: 'guideline',
536
- rule: 'NO SIMPLIFICATION',
537
- message: 'test',
538
- trigger: 'commit',
539
- enforcement: 'test',
540
- exceptions: ['unused_code_removal'],
541
- },
542
- context
543
- );
544
-
545
- expect(result.satisfied).toBe(true);
546
- });
547
- });
548
-
549
173
  describe('Prompt constraints(ADR-0001:不执行 checker,check() 短路 satisfied)', () => {
550
174
  it('所有内置 prompt 约束 check() 均短路通过', async () => {
551
175
  const context: ConstraintContext = { operation: 'code_implementation' };
@@ -0,0 +1,129 @@
1
+ /**
2
+ * governance_presence checker 测试(studio #302,ADR 2026-08-21 落点模型)
3
+ *
4
+ * 在场守护:PRESERVE 只保「存在」不保「在场」——治理契约段被删除/掏空后
5
+ * sync-docs 重新生成会静默丢失,本 checker 在 harness check 时校验在场性。
6
+ */
7
+
8
+ import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals';
9
+ import * as fs from 'fs';
10
+ import * as path from 'path';
11
+ import {
12
+ governancePresence,
13
+ hasGovernancePreserveBlock,
14
+ hasClaudeGovernance,
15
+ } from '../core/constraints/checkers/governance-presence';
16
+ import type { CheckEnv } from '../core/constraints/checkers';
17
+
18
+ function makeEnv(projectPath: string): CheckEnv {
19
+ return {
20
+ context: { operation: 'commit', projectPath },
21
+ projectPath,
22
+ stagedDiff: async () => '',
23
+ stagedDiffNames: async () => '',
24
+ srcScan: () => [],
25
+ };
26
+ }
27
+
28
+ const GOVERNANCE_BLOCK = [
29
+ '<!-- PRESERVE:governance -->',
30
+ '## Governance Rules',
31
+ '',
32
+ '<!-- HARNESS_CONSTRAINTS_START -->',
33
+ '- **law_a**: 描述 a',
34
+ '<!-- HARNESS_CONSTRAINTS_END -->',
35
+ '<!-- /PRESERVE:governance -->',
36
+ ].join('\n');
37
+
38
+ describe('governance_presence checker', () => {
39
+ let tempDir: string;
40
+ let errorSpy: jest.SpiedFunction<typeof console.error>;
41
+
42
+ const writeConfig = () => {
43
+ fs.mkdirSync(path.join(tempDir, '.harness'), { recursive: true });
44
+ fs.writeFileSync(path.join(tempDir, '.harness', 'config.yml'), 'preset: standard\n');
45
+ };
46
+
47
+ beforeEach(() => {
48
+ tempDir = fs.mkdtempSync(path.join(process.cwd(), 'temp-test-gov-presence-'));
49
+ errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
50
+ });
51
+
52
+ afterEach(() => {
53
+ jest.restoreAllMocks();
54
+ fs.rmSync(tempDir, { recursive: true, force: true });
55
+ });
56
+
57
+ it('未采用 harness 治理(无 .harness/config.yml)→ skip', async () => {
58
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe('skip');
59
+ });
60
+
61
+ it('新模型:AGENTS.md 有非空 PRESERVE:governance 段 → pass', async () => {
62
+ writeConfig();
63
+ fs.writeFileSync(path.join(tempDir, 'AGENTS.md'), `# AGENTS.md\n\n${GOVERNANCE_BLOCK}\n`);
64
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(true);
65
+ });
66
+
67
+ it('旧模型豁免:CLAUDE.md 有 Governance Rules 块(无 AGENTS.md)→ pass', async () => {
68
+ writeConfig();
69
+ fs.writeFileSync(path.join(tempDir, 'CLAUDE.md'), '# CLAUDE.md\n\n## Governance Rules\n\n条款\n');
70
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(true);
71
+ });
72
+
73
+ it('旧模型豁免:CLAUDE.md 有 HARNESS_CONSTRAINTS 标记 → pass', async () => {
74
+ writeConfig();
75
+ fs.writeFileSync(path.join(tempDir, 'CLAUDE.md'), '<!-- HARNESS_CONSTRAINTS_START -->\nx\n');
76
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(true);
77
+ });
78
+
79
+ it('两处都没有治理契约 → fail 并报警(防静默丢失)', async () => {
80
+ writeConfig();
81
+ fs.writeFileSync(path.join(tempDir, 'AGENTS.md'), '# AGENTS.md\n\n只有机器生成内容\n');
82
+ fs.writeFileSync(path.join(tempDir, 'CLAUDE.md'), '# CLAUDE.md\n\n@AGENTS.md\n');
83
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(false);
84
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('治理契约缺失'));
85
+ });
86
+
87
+ it('PRESERVE:governance 段为空(被掏空)且 CLAUDE.md 无治理块 → fail', async () => {
88
+ writeConfig();
89
+ fs.writeFileSync(
90
+ path.join(tempDir, 'AGENTS.md'),
91
+ '# AGENTS.md\n\n<!-- PRESERVE:governance -->\n\n<!-- /PRESERVE:governance -->\n'
92
+ );
93
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(false);
94
+ });
95
+
96
+ it('PRESERVE:governance 标记未闭合视为不在场 → fail', async () => {
97
+ writeConfig();
98
+ fs.writeFileSync(
99
+ path.join(tempDir, 'AGENTS.md'),
100
+ '# AGENTS.md\n\n<!-- PRESERVE:governance -->\n## Governance Rules\n内容\n'
101
+ );
102
+ expect(await governancePresence.evaluate(makeEnv(tempDir))).toBe(false);
103
+ });
104
+ });
105
+
106
+ describe('hasGovernancePreserveBlock / hasClaudeGovernance 判定函数', () => {
107
+ let tempDir: string;
108
+
109
+ beforeEach(() => {
110
+ tempDir = fs.mkdtempSync(path.join(process.cwd(), 'temp-test-gov-helpers-'));
111
+ });
112
+
113
+ afterEach(() => {
114
+ fs.rmSync(tempDir, { recursive: true, force: true });
115
+ });
116
+
117
+ it('文件不存在 → false', () => {
118
+ expect(hasGovernancePreserveBlock(path.join(tempDir, 'AGENTS.md'))).toBe(false);
119
+ expect(hasClaudeGovernance(path.join(tempDir, 'CLAUDE.md'))).toBe(false);
120
+ });
121
+
122
+ it('块体仅空白/注释外无内容 → false;有内容 → true', () => {
123
+ const p = path.join(tempDir, 'AGENTS.md');
124
+ fs.writeFileSync(p, '<!-- PRESERVE:governance -->\n \n<!-- /PRESERVE:governance -->\n');
125
+ expect(hasGovernancePreserveBlock(p)).toBe(false);
126
+ fs.writeFileSync(p, `<!-- PRESERVE:governance -->\n条款一\n<!-- /PRESERVE:governance -->\n`);
127
+ expect(hasGovernancePreserveBlock(p)).toBe(true);
128
+ });
129
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 约束系统测试(ADR-0001:kind 二元模型,25 条清单构成 + 注册表闭环)
2
+ * 约束系统测试(ADR-0001:kind 二元模型,26 条清单构成 + 注册表闭环)
3
3
  */
4
4
 
5
5
  import { describe, it, expect } from '@jest/globals';
@@ -16,17 +16,17 @@ import { getConstraintCheck, registeredCheckCount } from '../core/constraints/ch
16
16
  import type { ConstraintContext } from '../types/constraint';
17
17
 
18
18
  describe('Constraint System', () => {
19
- describe('清单构成(ADR-0001:42 → 25)', () => {
20
- it('getAllConstraints 返回 25 条:9 check + 16 prompt', () => {
19
+ describe('清单构成(ADR-0001:42 → 26)', () => {
20
+ it('getAllConstraints 返回 26 条:10 check + 16 prompt', () => {
21
21
  const all = getAllConstraints();
22
- expect(all).toHaveLength(25);
23
- expect(all.filter(c => c.kind === 'check')).toHaveLength(9);
22
+ expect(all).toHaveLength(26);
23
+ expect(all.filter(c => c.kind === 'check')).toHaveLength(10);
24
24
  expect(all.filter(c => c.kind === 'prompt')).toHaveLength(16);
25
25
  });
26
26
 
27
- it('check 层 = 5 iron + 4 guideline', () => {
27
+ it('check 层 = 5 iron + 5 guideline', () => {
28
28
  expect(Object.keys(IRON_LAWS)).toHaveLength(5);
29
- expect(Object.keys(GUIDELINES)).toHaveLength(4);
29
+ expect(Object.keys(GUIDELINES)).toHaveLength(5);
30
30
  Object.values(IRON_LAWS).forEach(c => {
31
31
  expect(c.kind).toBe('check');
32
32
  expect(c.level).toBe('iron_law');
@@ -2,7 +2,7 @@
2
2
  * ProjectConfigLoader 补充测试
3
3
  */
4
4
 
5
- import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
5
+ import { describe, it, expect, beforeAll, afterAll, jest } from '@jest/globals';
6
6
  import { ProjectConfigLoader } from '../core/project-config-loader';
7
7
  import * as fs from 'fs';
8
8
  import * as path from 'path';
@@ -123,34 +123,6 @@ custom_constraints:
123
123
  });
124
124
  });
125
125
 
126
- describe('约束扩展', () => {
127
- it('应该扩展例外列表', () => {
128
- fs.writeFileSync(
129
- path.join(harnessDir, 'config.yml'),
130
- `
131
- custom_constraints:
132
- extended_rule:
133
- rule: EXTENDED RULE
134
- message: Extended
135
- level: guideline
136
- trigger: commit
137
- exceptions:
138
- - simple_typo
139
- extend_exceptions:
140
- - config_change
141
- `
142
- );
143
-
144
- const loader = new ProjectConfigLoader(tempDir);
145
- loader.load();
146
- const merged = loader.mergeConstraints();
147
-
148
- expect(merged.guidelines['extended_rule']?.exceptions).toBeDefined();
149
- expect(merged.guidelines['extended_rule']?.exceptions).toContain('simple_typo');
150
- expect(merged.guidelines['extended_rule']?.exceptions).toContain('config_change');
151
- });
152
- });
153
-
154
126
  describe('isConstraintEnabled', () => {
155
127
  it('启用的约束应该返回 true', () => {
156
128
  const loader = new ProjectConfigLoader(tempDir);
@@ -263,6 +235,47 @@ custom_constraints:
263
235
  });
264
236
  });
265
237
 
238
+ describe('preset 裁剪(内联自原 applyPreset)', () => {
239
+ it('options.preset 覆盖 config.yml 的 preset', () => {
240
+ fs.writeFileSync(
241
+ path.join(harnessDir, 'config.yml'),
242
+ `preset: standard`
243
+ );
244
+
245
+ const loader = new ProjectConfigLoader(tempDir);
246
+ loader.load();
247
+ const merged = loader.mergeConstraints({ preset: 'relaxed' });
248
+
249
+ // relaxed 仅启用 3 条铁律 + 2 条指导原则,禁用提示
250
+ expect(Object.keys(merged.ironLaws)).toHaveLength(3);
251
+ expect(Object.keys(merged.guidelines)).toHaveLength(2);
252
+ expect(Object.keys(merged.prompts ?? {})).toHaveLength(0);
253
+ expect(merged.disabled.length).toBeGreaterThan(0);
254
+ });
255
+
256
+ it('未知预设名回落 standard + stderr 警告', () => {
257
+ fs.writeFileSync(
258
+ path.join(harnessDir, 'config.yml'),
259
+ `preset: no_such_preset`
260
+ );
261
+
262
+ const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
263
+ try {
264
+ const loader = new ProjectConfigLoader(tempDir);
265
+ loader.load();
266
+ const merged = loader.mergeConstraints();
267
+
268
+ // 回落 standard = 全部启用
269
+ expect(merged.disabled).toEqual([]);
270
+ expect(errorSpy).toHaveBeenCalledWith(
271
+ expect.stringContaining('未知预设 "no_such_preset"')
272
+ );
273
+ } finally {
274
+ errorSpy.mockRestore();
275
+ }
276
+ });
277
+ });
278
+
266
279
  describe('getCustomConstraints', () => {
267
280
  it('应该返回自定义约束', () => {
268
281
  fs.writeFileSync(