oc-pilot 0.160.0 → 0.161.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 (378) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/CONTRIBUTING.md +5 -0
  3. package/Dockerfile +2 -1
  4. package/README.md +42 -1261
  5. package/README.ru.md +52 -1144
  6. package/action.yml +8 -2
  7. package/dist/cli.js +62 -179
  8. package/dist/cli.js.map +1 -1
  9. package/dist/command-groups.js +52 -0
  10. package/dist/command-groups.js.map +1 -0
  11. package/dist/command-registry.js +92 -0
  12. package/dist/command-registry.js.map +1 -0
  13. package/dist/commands/apoptosis.js +16 -1
  14. package/dist/commands/apoptosis.js.map +1 -1
  15. package/dist/commands/blindfold.js +30 -2
  16. package/dist/commands/blindfold.js.map +1 -1
  17. package/dist/commands/butterfly.js +9 -5
  18. package/dist/commands/butterfly.js.map +1 -1
  19. package/dist/commands/cache.js +24 -14
  20. package/dist/commands/cache.js.map +1 -1
  21. package/dist/commands/deps.js +30 -0
  22. package/dist/commands/deps.js.map +1 -1
  23. package/dist/commands/doctor.js +11 -448
  24. package/dist/commands/doctor.js.map +1 -1
  25. package/dist/commands/fix.js +38 -345
  26. package/dist/commands/fix.js.map +1 -1
  27. package/dist/commands/flight.js +15 -33
  28. package/dist/commands/flight.js.map +1 -1
  29. package/dist/commands/hygiene.js +47 -0
  30. package/dist/commands/hygiene.js.map +1 -0
  31. package/dist/commands/metrics.js +49 -0
  32. package/dist/commands/metrics.js.map +1 -0
  33. package/dist/commands/preflight.js +11 -6
  34. package/dist/commands/preflight.js.map +1 -1
  35. package/dist/commands/review.js +44 -215
  36. package/dist/commands/review.js.map +1 -1
  37. package/dist/commands/setup.js +10 -331
  38. package/dist/commands/setup.js.map +1 -1
  39. package/dist/commands/test-gen.js +25 -246
  40. package/dist/commands/test-gen.js.map +1 -1
  41. package/dist/core/blindfold.js +63 -0
  42. package/dist/core/blindfold.js.map +1 -1
  43. package/dist/core/butterfly.js +12 -0
  44. package/dist/core/butterfly.js.map +1 -1
  45. package/dist/core/cache.js +161 -56
  46. package/dist/core/cache.js.map +1 -1
  47. package/dist/core/deps-registry.js +169 -0
  48. package/dist/core/deps-registry.js.map +1 -0
  49. package/dist/core/doctor.js +448 -0
  50. package/dist/core/doctor.js.map +1 -0
  51. package/dist/core/expiry.js +39 -0
  52. package/dist/core/expiry.js.map +1 -0
  53. package/dist/core/fix.js +298 -0
  54. package/dist/core/fix.js.map +1 -0
  55. package/dist/core/flight/bundle-report.js +163 -0
  56. package/dist/core/flight/bundle-report.js.map +1 -0
  57. package/dist/core/flight/bundles.js +162 -0
  58. package/dist/core/flight/bundles.js.map +1 -0
  59. package/dist/core/flight/compare-reports.js +107 -0
  60. package/dist/core/flight/compare-reports.js.map +1 -0
  61. package/dist/core/flight/comparison.js +94 -0
  62. package/dist/core/flight/comparison.js.map +1 -0
  63. package/dist/core/flight/diffs.js +67 -0
  64. package/dist/core/flight/diffs.js.map +1 -0
  65. package/dist/core/flight/events.js +78 -0
  66. package/dist/core/flight/events.js.map +1 -0
  67. package/dist/core/flight/html-reports.js +73 -0
  68. package/dist/core/flight/html-reports.js.map +1 -0
  69. package/dist/core/flight/inspection.js +28 -0
  70. package/dist/core/flight/inspection.js.map +1 -0
  71. package/dist/core/flight/proof.js +135 -0
  72. package/dist/core/flight/proof.js.map +1 -0
  73. package/dist/core/flight/queries.js +218 -0
  74. package/dist/core/flight/queries.js.map +1 -0
  75. package/dist/core/flight/query-reports.js +35 -0
  76. package/dist/core/flight/query-reports.js.map +1 -0
  77. package/dist/core/flight/runner.js +141 -0
  78. package/dist/core/flight/runner.js.map +1 -0
  79. package/dist/core/flight/session-reports.js +166 -0
  80. package/dist/core/flight/session-reports.js.map +1 -0
  81. package/dist/core/flight/sessions.js +252 -0
  82. package/dist/core/flight/sessions.js.map +1 -0
  83. package/dist/core/flight/types.js +2 -0
  84. package/dist/core/flight/types.js.map +1 -0
  85. package/dist/core/flight/worktree-reports.js +39 -0
  86. package/dist/core/flight/worktree-reports.js.map +1 -0
  87. package/dist/core/flight/worktrees.js +96 -0
  88. package/dist/core/flight/worktrees.js.map +1 -0
  89. package/dist/core/flight.js +16 -1761
  90. package/dist/core/flight.js.map +1 -1
  91. package/dist/core/hygiene.js +44 -0
  92. package/dist/core/hygiene.js.map +1 -0
  93. package/dist/core/metrics.js +172 -0
  94. package/dist/core/metrics.js.map +1 -0
  95. package/dist/core/preflight-run.js +5 -2
  96. package/dist/core/preflight-run.js.map +1 -1
  97. package/dist/core/preflight-sarif.js +64 -0
  98. package/dist/core/preflight-sarif.js.map +1 -0
  99. package/dist/core/review-publication.js +57 -0
  100. package/dist/core/review-publication.js.map +1 -0
  101. package/dist/core/review.js +148 -0
  102. package/dist/core/review.js.map +1 -0
  103. package/dist/core/sarif.js +21 -5
  104. package/dist/core/sarif.js.map +1 -1
  105. package/dist/core/setup.js +333 -0
  106. package/dist/core/setup.js.map +1 -0
  107. package/dist/core/test-gen.js +224 -0
  108. package/dist/core/test-gen.js.map +1 -0
  109. package/dist/core/test-weakening.js +58 -16
  110. package/dist/core/test-weakening.js.map +1 -1
  111. package/dist/mcp.js +135 -17
  112. package/dist/mcp.js.map +1 -1
  113. package/dist/version.js +1 -1
  114. package/docs/integrations.md +121 -6
  115. package/docs/reference.md +1318 -0
  116. package/docs/reference.ru.md +1191 -0
  117. package/package.json +5 -4
  118. package/skills/agent-self-review/SKILL.md +1 -1
  119. package/skills/commit-discipline/SKILL.md +1 -1
  120. package/skills/secure-diff-gate/SKILL.md +1 -1
  121. package/skills/stack-review-packs/SKILL.md +1 -1
  122. package/skills/test-failure-triage/SKILL.md +1 -1
  123. package/dist/cli.test.js +0 -2493
  124. package/dist/cli.test.js.map +0 -1
  125. package/dist/commands/commit.test.js +0 -160
  126. package/dist/commands/commit.test.js.map +0 -1
  127. package/dist/commands/day.test.js +0 -45
  128. package/dist/commands/day.test.js.map +0 -1
  129. package/dist/commands/doctor.test.js +0 -189
  130. package/dist/commands/doctor.test.js.map +0 -1
  131. package/dist/commands/init.test.js +0 -138
  132. package/dist/commands/init.test.js.map +0 -1
  133. package/dist/commands/install-hook.test.js +0 -107
  134. package/dist/commands/install-hook.test.js.map +0 -1
  135. package/dist/commands/replay.test.js +0 -125
  136. package/dist/commands/replay.test.js.map +0 -1
  137. package/dist/commands/review.test.js +0 -160
  138. package/dist/commands/review.test.js.map +0 -1
  139. package/dist/commands/slop.test.js +0 -135
  140. package/dist/commands/slop.test.js.map +0 -1
  141. package/dist/core/alien-dna.test.js +0 -117
  142. package/dist/core/alien-dna.test.js.map +0 -1
  143. package/dist/core/anthropic.test.js +0 -116
  144. package/dist/core/anthropic.test.js.map +0 -1
  145. package/dist/core/anti-regression.test.js +0 -154
  146. package/dist/core/anti-regression.test.js.map +0 -1
  147. package/dist/core/antibody.test.js +0 -142
  148. package/dist/core/antibody.test.js.map +0 -1
  149. package/dist/core/apoptosis.test.js +0 -104
  150. package/dist/core/apoptosis.test.js.map +0 -1
  151. package/dist/core/aql.test.js +0 -64
  152. package/dist/core/aql.test.js.map +0 -1
  153. package/dist/core/arch-diff.test.js +0 -93
  154. package/dist/core/arch-diff.test.js.map +0 -1
  155. package/dist/core/authz.test.js +0 -125
  156. package/dist/core/authz.test.js.map +0 -1
  157. package/dist/core/autopsy.test.js +0 -106
  158. package/dist/core/autopsy.test.js.map +0 -1
  159. package/dist/core/bankruptcy.test.js +0 -91
  160. package/dist/core/bankruptcy.test.js.map +0 -1
  161. package/dist/core/baseline.test.js +0 -91
  162. package/dist/core/baseline.test.js.map +0 -1
  163. package/dist/core/battle.test.js +0 -116
  164. package/dist/core/battle.test.js.map +0 -1
  165. package/dist/core/beacon.test.js +0 -114
  166. package/dist/core/beacon.test.js.map +0 -1
  167. package/dist/core/blindfold.test.js +0 -77
  168. package/dist/core/blindfold.test.js.map +0 -1
  169. package/dist/core/boundaries.test.js +0 -62
  170. package/dist/core/boundaries.test.js.map +0 -1
  171. package/dist/core/bounty.test.js +0 -82
  172. package/dist/core/bounty.test.js.map +0 -1
  173. package/dist/core/brag.test.js +0 -43
  174. package/dist/core/brag.test.js.map +0 -1
  175. package/dist/core/butterfly.test.js +0 -146
  176. package/dist/core/butterfly.test.js.map +0 -1
  177. package/dist/core/cache.test.js +0 -159
  178. package/dist/core/cache.test.js.map +0 -1
  179. package/dist/core/chronos.test.js +0 -139
  180. package/dist/core/chronos.test.js.map +0 -1
  181. package/dist/core/cinema.test.js +0 -73
  182. package/dist/core/cinema.test.js.map +0 -1
  183. package/dist/core/clairvoyant.test.js +0 -144
  184. package/dist/core/clairvoyant.test.js.map +0 -1
  185. package/dist/core/compliance.test.js +0 -123
  186. package/dist/core/compliance.test.js.map +0 -1
  187. package/dist/core/config.test.js +0 -211
  188. package/dist/core/config.test.js.map +0 -1
  189. package/dist/core/contract-drift.test.js +0 -166
  190. package/dist/core/contract-drift.test.js.map +0 -1
  191. package/dist/core/cost.test.js +0 -103
  192. package/dist/core/cost.test.js.map +0 -1
  193. package/dist/core/coverage.test.js +0 -190
  194. package/dist/core/coverage.test.js.map +0 -1
  195. package/dist/core/cuckoo.test.js +0 -98
  196. package/dist/core/cuckoo.test.js.map +0 -1
  197. package/dist/core/deps-fix.test.js +0 -176
  198. package/dist/core/deps-fix.test.js.map +0 -1
  199. package/dist/core/deps-health.test.js +0 -230
  200. package/dist/core/deps-health.test.js.map +0 -1
  201. package/dist/core/deps-why.test.js +0 -175
  202. package/dist/core/deps-why.test.js.map +0 -1
  203. package/dist/core/deps.test.js +0 -88
  204. package/dist/core/deps.test.js.map +0 -1
  205. package/dist/core/diff.test.js +0 -94
  206. package/dist/core/diff.test.js.map +0 -1
  207. package/dist/core/echo.test.js +0 -90
  208. package/dist/core/echo.test.js.map +0 -1
  209. package/dist/core/ecosystem-verify.test.js +0 -158
  210. package/dist/core/ecosystem-verify.test.js.map +0 -1
  211. package/dist/core/engine-preset.test.js +0 -60
  212. package/dist/core/engine-preset.test.js.map +0 -1
  213. package/dist/core/engine.test.js +0 -206
  214. package/dist/core/engine.test.js.map +0 -1
  215. package/dist/core/env-sync.test.js +0 -99
  216. package/dist/core/env-sync.test.js.map +0 -1
  217. package/dist/core/file-context.test.js +0 -58
  218. package/dist/core/file-context.test.js.map +0 -1
  219. package/dist/core/findings-baseline.test.js +0 -77
  220. package/dist/core/findings-baseline.test.js.map +0 -1
  221. package/dist/core/findings.test.js +0 -62
  222. package/dist/core/findings.test.js.map +0 -1
  223. package/dist/core/flaky.test.js +0 -97
  224. package/dist/core/flaky.test.js.map +0 -1
  225. package/dist/core/flight.test.js +0 -853
  226. package/dist/core/flight.test.js.map +0 -1
  227. package/dist/core/format.test.js +0 -26
  228. package/dist/core/format.test.js.map +0 -1
  229. package/dist/core/fuzz.test.js +0 -121
  230. package/dist/core/fuzz.test.js.map +0 -1
  231. package/dist/core/gitlab.test.js +0 -199
  232. package/dist/core/gitlab.test.js.map +0 -1
  233. package/dist/core/hemorrhage.test.js +0 -138
  234. package/dist/core/hemorrhage.test.js.map +0 -1
  235. package/dist/core/hivemind.test.js +0 -79
  236. package/dist/core/hivemind.test.js.map +0 -1
  237. package/dist/core/hologram.test.js +0 -124
  238. package/dist/core/hologram.test.js.map +0 -1
  239. package/dist/core/honeypot.test.js +0 -106
  240. package/dist/core/honeypot.test.js.map +0 -1
  241. package/dist/core/hooks.test.js +0 -132
  242. package/dist/core/hooks.test.js.map +0 -1
  243. package/dist/core/hyper-chamber.test.js +0 -105
  244. package/dist/core/hyper-chamber.test.js.map +0 -1
  245. package/dist/core/impact.test.js +0 -105
  246. package/dist/core/impact.test.js.map +0 -1
  247. package/dist/core/import-graph.test.js +0 -68
  248. package/dist/core/import-graph.test.js.map +0 -1
  249. package/dist/core/injection-scan.test.js +0 -100
  250. package/dist/core/injection-scan.test.js.map +0 -1
  251. package/dist/core/injection.test.js +0 -45
  252. package/dist/core/injection.test.js.map +0 -1
  253. package/dist/core/intent.test.js +0 -86
  254. package/dist/core/intent.test.js.map +0 -1
  255. package/dist/core/invariants.test.js +0 -87
  256. package/dist/core/invariants.test.js.map +0 -1
  257. package/dist/core/lang.test.js +0 -22
  258. package/dist/core/lang.test.js.map +0 -1
  259. package/dist/core/last-review.test.js +0 -97
  260. package/dist/core/last-review.test.js.map +0 -1
  261. package/dist/core/lockfile-support.test.js +0 -112
  262. package/dist/core/lockfile-support.test.js.map +0 -1
  263. package/dist/core/lockfile.test.js +0 -203
  264. package/dist/core/lockfile.test.js.map +0 -1
  265. package/dist/core/mayday.test.js +0 -117
  266. package/dist/core/mayday.test.js.map +0 -1
  267. package/dist/core/mirage.test.js +0 -120
  268. package/dist/core/mirage.test.js.map +0 -1
  269. package/dist/core/mitosis.test.js +0 -170
  270. package/dist/core/mitosis.test.js.map +0 -1
  271. package/dist/core/mock-leak.test.js +0 -79
  272. package/dist/core/mock-leak.test.js.map +0 -1
  273. package/dist/core/mutation.test.js +0 -104
  274. package/dist/core/mutation.test.js.map +0 -1
  275. package/dist/core/opencode.test.js +0 -68
  276. package/dist/core/opencode.test.js.map +0 -1
  277. package/dist/core/oracle.test.js +0 -136
  278. package/dist/core/oracle.test.js.map +0 -1
  279. package/dist/core/osv.test.js +0 -173
  280. package/dist/core/osv.test.js.map +0 -1
  281. package/dist/core/output-format.test.js +0 -102
  282. package/dist/core/output-format.test.js.map +0 -1
  283. package/dist/core/pack.test.js +0 -129
  284. package/dist/core/pack.test.js.map +0 -1
  285. package/dist/core/passport.test.js +0 -173
  286. package/dist/core/passport.test.js.map +0 -1
  287. package/dist/core/patch.test.js +0 -70
  288. package/dist/core/patch.test.js.map +0 -1
  289. package/dist/core/phantom.test.js +0 -58
  290. package/dist/core/phantom.test.js.map +0 -1
  291. package/dist/core/polygraph.test.js +0 -110
  292. package/dist/core/polygraph.test.js.map +0 -1
  293. package/dist/core/pr-comment.test.js +0 -53
  294. package/dist/core/pr-comment.test.js.map +0 -1
  295. package/dist/core/pr-review.test.js +0 -62
  296. package/dist/core/pr-review.test.js.map +0 -1
  297. package/dist/core/preflight.test.js +0 -242
  298. package/dist/core/preflight.test.js.map +0 -1
  299. package/dist/core/presets.test.js +0 -79
  300. package/dist/core/presets.test.js.map +0 -1
  301. package/dist/core/project.test.js +0 -75
  302. package/dist/core/project.test.js.map +0 -1
  303. package/dist/core/prompt.golden.test.js +0 -74
  304. package/dist/core/prompt.golden.test.js.map +0 -1
  305. package/dist/core/prompt.test.js +0 -122
  306. package/dist/core/prompt.test.js.map +0 -1
  307. package/dist/core/quarantine.test.js +0 -98
  308. package/dist/core/quarantine.test.js.map +0 -1
  309. package/dist/core/readiness-fix.test.js +0 -127
  310. package/dist/core/readiness-fix.test.js.map +0 -1
  311. package/dist/core/readiness.test.js +0 -318
  312. package/dist/core/readiness.test.js.map +0 -1
  313. package/dist/core/receipt.test.js +0 -193
  314. package/dist/core/receipt.test.js.map +0 -1
  315. package/dist/core/reviewers.test.js +0 -105
  316. package/dist/core/reviewers.test.js.map +0 -1
  317. package/dist/core/roast.test.js +0 -19
  318. package/dist/core/roast.test.js.map +0 -1
  319. package/dist/core/router.test.js +0 -157
  320. package/dist/core/router.test.js.map +0 -1
  321. package/dist/core/rules.test.js +0 -72
  322. package/dist/core/rules.test.js.map +0 -1
  323. package/dist/core/sarif.test.js +0 -60
  324. package/dist/core/sarif.test.js.map +0 -1
  325. package/dist/core/sast.test.js +0 -119
  326. package/dist/core/sast.test.js.map +0 -1
  327. package/dist/core/sbom.test.js +0 -81
  328. package/dist/core/sbom.test.js.map +0 -1
  329. package/dist/core/scalpel.test.js +0 -132
  330. package/dist/core/scalpel.test.js.map +0 -1
  331. package/dist/core/second-opinion.test.js +0 -89
  332. package/dist/core/second-opinion.test.js.map +0 -1
  333. package/dist/core/secrets.test.js +0 -194
  334. package/dist/core/secrets.test.js.map +0 -1
  335. package/dist/core/shadow.test.js +0 -50
  336. package/dist/core/shadow.test.js.map +0 -1
  337. package/dist/core/skeptic.test.js +0 -106
  338. package/dist/core/skeptic.test.js.map +0 -1
  339. package/dist/core/slicing.test.js +0 -287
  340. package/dist/core/slicing.test.js.map +0 -1
  341. package/dist/core/slop/dead-exports.test.js +0 -29
  342. package/dist/core/slop/dead-exports.test.js.map +0 -1
  343. package/dist/core/slop/slop.test.js +0 -160
  344. package/dist/core/slop/slop.test.js.map +0 -1
  345. package/dist/core/slop/test-debt.test.js +0 -114
  346. package/dist/core/slop/test-debt.test.js.map +0 -1
  347. package/dist/core/snapshot.test.js +0 -101
  348. package/dist/core/snapshot.test.js.map +0 -1
  349. package/dist/core/snippets.test.js +0 -55
  350. package/dist/core/snippets.test.js.map +0 -1
  351. package/dist/core/stats.test.js +0 -86
  352. package/dist/core/stats.test.js.map +0 -1
  353. package/dist/core/suppressions.test.js +0 -98
  354. package/dist/core/suppressions.test.js.map +0 -1
  355. package/dist/core/test-delta.test.js +0 -41
  356. package/dist/core/test-delta.test.js.map +0 -1
  357. package/dist/core/test-plan.test.js +0 -99
  358. package/dist/core/test-plan.test.js.map +0 -1
  359. package/dist/core/test-weakening.test.js +0 -114
  360. package/dist/core/test-weakening.test.js.map +0 -1
  361. package/dist/core/tree-scan.test.js +0 -58
  362. package/dist/core/tree-scan.test.js.map +0 -1
  363. package/dist/core/tribunal.test.js +0 -52
  364. package/dist/core/tribunal.test.js.map +0 -1
  365. package/dist/core/vaccine.test.js +0 -139
  366. package/dist/core/vaccine.test.js.map +0 -1
  367. package/dist/core/warden.test.js +0 -121
  368. package/dist/core/warden.test.js.map +0 -1
  369. package/dist/mcp-http.test.js +0 -146
  370. package/dist/mcp-http.test.js.map +0 -1
  371. package/dist/mcp-prompts.test.js +0 -160
  372. package/dist/mcp-prompts.test.js.map +0 -1
  373. package/dist/mcp.test.js +0 -2108
  374. package/dist/mcp.test.js.map +0 -1
  375. package/dist/setup.test.js +0 -215
  376. package/dist/setup.test.js.map +0 -1
  377. package/dist/skills.test.js +0 -293
  378. package/dist/skills.test.js.map +0 -1
package/dist/mcp.test.js DELETED
@@ -1,2108 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdirSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join, resolve } from "node:path";
5
- import { spawnSync } from "node:child_process";
6
- import { test } from "node:test";
7
- import { applyResultOptions, patchSummary } from "./mcp.js";
8
- const MCP = resolve("dist/mcp.js");
9
- const CLI = resolve("dist/cli.js");
10
- const AWS_KEY = ["AKIA", "IOSFODNN7EXAMPLE"].join("");
11
- function runServer(dir, requests, args = []) {
12
- const input = `${requests.map((request) => JSON.stringify(request)).join("\n")}\n`;
13
- const result = spawnSync(process.execPath, [MCP, "--cwd", dir, ...args], {
14
- input,
15
- encoding: "utf8",
16
- timeout: 60_000,
17
- maxBuffer: 16 * 1024 * 1024,
18
- });
19
- const responses = (result.stdout ?? "")
20
- .split(/\r?\n/)
21
- .filter(Boolean)
22
- .map((line) => JSON.parse(line));
23
- return { status: result.status, responses, stderr: result.stderr ?? "" };
24
- }
25
- test("MCP initialize, tools/list and tools/call work over stdio", () => {
26
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-"));
27
- try {
28
- const diffPath = join(dir, "changes.diff");
29
- writeFileSync(diffPath, [
30
- "diff --git a/wallet.go b/wallet.go",
31
- "--- a/wallet.go",
32
- "+++ b/wallet.go",
33
- "@@ -1,1 +1,2 @@",
34
- " package wallet",
35
- `+const apiKey = "${AWS_KEY}"`,
36
- "",
37
- ].join("\n"));
38
- const { status, responses, stderr } = runServer(dir, [
39
- {
40
- jsonrpc: "2.0",
41
- id: 1,
42
- method: "initialize",
43
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
44
- },
45
- { jsonrpc: "2.0", method: "notifications/initialized" },
46
- { jsonrpc: "2.0", id: 2, method: "tools/list" },
47
- {
48
- jsonrpc: "2.0",
49
- id: 3,
50
- method: "tools/call",
51
- params: { name: "scan", arguments: { diff: readFileSync(diffPath, "utf8") } },
52
- },
53
- { jsonrpc: "2.0", id: 4, method: "does/not/exist" },
54
- ]);
55
- assert.equal(status, 0, stderr);
56
- const byId = new Map(responses.map((response) => [response.id, response]));
57
- const init = byId.get(1)?.result;
58
- assert.equal(init?.serverInfo?.name, "oc-pilot");
59
- assert.equal(init?.protocolVersion, "2025-06-18");
60
- const list = byId.get(2)?.result;
61
- const names = new Set(list?.tools?.map((tool) => tool.name));
62
- for (const name of ["review", "test_fix", "fix", "docgen", "custom", "scan"])
63
- assert.ok(names.has(name), name);
64
- const scan = byId.get(3)?.result;
65
- assert.equal(scan?.isError, false);
66
- assert.ok(scan?.structuredContent?.findings?.some((finding) => finding.kind === "AWS Access Key ID"));
67
- assert.ok(scan?.content?.some((part) => part.type === "text" && part.text.includes("AWS Access Key ID")));
68
- assert.ok(!(scan?.content?.[0]?.text ?? "").includes(AWS_KEY));
69
- assert.equal(byId.get(4)?.error?.code, -32601);
70
- }
71
- finally {
72
- rmSync(dir, { recursive: true, force: true });
73
- }
74
- });
75
- test("MCP is read-only by default and rejects paths outside the project", () => {
76
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-policy-"));
77
- try {
78
- const { status, responses, stderr } = runServer(dir, [
79
- {
80
- jsonrpc: "2.0",
81
- id: 1,
82
- method: "tools/call",
83
- params: { name: "review", arguments: { diff: "diff --git a/a b/a\n", paths: ["../outside"] } },
84
- },
85
- {
86
- jsonrpc: "2.0",
87
- id: 2,
88
- method: "tools/call",
89
- params: { name: "fix", arguments: { diff: "diff --git a/a b/a\n", apply: true } },
90
- },
91
- {
92
- jsonrpc: "2.0",
93
- id: 3,
94
- method: "tools/call",
95
- params: { name: "test_fix", arguments: { diff: "diff --git a/a b/a\n" } },
96
- },
97
- {
98
- jsonrpc: "2.0",
99
- id: 4,
100
- method: "tools/call",
101
- params: { name: "sast", arguments: { paths: ["app.js"], update_baseline: true } },
102
- },
103
- {
104
- jsonrpc: "2.0",
105
- id: 5,
106
- method: "tools/call",
107
- params: { name: "mutate", arguments: { max_mutants: 1 } },
108
- },
109
- {
110
- jsonrpc: "2.0",
111
- id: 6,
112
- method: "tools/call",
113
- params: { name: "deps", arguments: { fix: true } },
114
- },
115
- {
116
- jsonrpc: "2.0",
117
- id: 7,
118
- method: "tools/call",
119
- params: { name: "test_gen", arguments: { apply: true } },
120
- },
121
- {
122
- jsonrpc: "2.0",
123
- id: 8,
124
- method: "tools/call",
125
- params: { name: "battle", arguments: { task: "x", apply: true } },
126
- },
127
- {
128
- jsonrpc: "2.0",
129
- id: 9,
130
- method: "tools/call",
131
- params: { name: "cleanup", arguments: { apply: true } },
132
- },
133
- {
134
- jsonrpc: "2.0",
135
- id: 10,
136
- method: "tools/call",
137
- params: { name: "echo", arguments: { submit: true, endpoint: "https://example.com/echo" } },
138
- },
139
- ], []);
140
- assert.equal(status, 0, stderr);
141
- const byId = new Map(responses.map((response) => [response.id, response]));
142
- const pathResult = byId.get(1)?.result;
143
- assert.equal(pathResult?.isError, true);
144
- assert.match(pathResult?.content?.[0]?.text ?? "", /inside the project/);
145
- const fixResult = byId.get(2)?.result;
146
- assert.equal(fixResult?.isError, true);
147
- assert.match(fixResult?.content?.[0]?.text ?? "", /read-only/);
148
- const testResult = byId.get(3)?.result;
149
- assert.equal(testResult?.isError, true);
150
- assert.match(testResult?.content?.[0]?.text ?? "", /read-only/);
151
- const baselineResult = byId.get(4)?.result;
152
- assert.equal(baselineResult?.isError, true);
153
- assert.match(baselineResult?.content?.[0]?.text ?? "", /read-only/);
154
- const mutateResult = byId.get(5)?.result;
155
- assert.equal(mutateResult?.isError, true);
156
- assert.match(mutateResult?.content?.[0]?.text ?? "", /read-only/);
157
- const depsResult = byId.get(6)?.result;
158
- assert.equal(depsResult?.isError, true);
159
- assert.match(depsResult?.content?.[0]?.text ?? "", /read-only/);
160
- const testGenResult = byId.get(7)?.result;
161
- assert.equal(testGenResult?.isError, true);
162
- assert.match(testGenResult?.content?.[0]?.text ?? "", /read-only/);
163
- const battleResult = byId.get(8)?.result;
164
- assert.equal(battleResult?.isError, true);
165
- assert.match(battleResult?.content?.[0]?.text ?? "", /read-only/);
166
- const cleanupResult = byId.get(9)?.result;
167
- assert.equal(cleanupResult?.isError, true);
168
- assert.match(cleanupResult?.content?.[0]?.text ?? "", /read-only/);
169
- const echoResult = byId.get(10)?.result;
170
- assert.equal(echoResult?.isError, true);
171
- assert.match(echoResult?.content?.[0]?.text ?? "", /read-only/);
172
- }
173
- finally {
174
- rmSync(dir, { recursive: true, force: true });
175
- }
176
- });
177
- test("MCP rejects malformed JSON without crashing", () => {
178
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-"));
179
- try {
180
- const result = spawnSync(process.execPath, [MCP, "--cwd", dir], {
181
- input: "{not json\n",
182
- encoding: "utf8",
183
- timeout: 30_000,
184
- });
185
- assert.equal(result.status, 0, result.stderr);
186
- const response = JSON.parse(result.stdout.trim());
187
- assert.equal(response.error?.code, -32700);
188
- }
189
- finally {
190
- rmSync(dir, { recursive: true, force: true });
191
- }
192
- });
193
- test("MCP exposes resources and resource templates", () => {
194
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-res-"));
195
- try {
196
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
197
- git(["init"]);
198
- git(["config", "user.email", "test@example.com"]);
199
- git(["config", "user.name", "Test"]);
200
- git(["config", "core.autocrlf", "false"]);
201
- writeFileSync(join(dir, "a.txt"), "v1\n");
202
- writeFileSync(join(dir, "sample.txt"), `const key = "${AWS_KEY}"\n`);
203
- git(["add", "."]);
204
- git(["commit", "-m", "init"]);
205
- writeFileSync(join(dir, "a.txt"), `v2\nconst key = "${AWS_KEY}"\n`);
206
- git(["add", "a.txt"]);
207
- const { status, responses, stderr } = runServer(dir, [
208
- {
209
- jsonrpc: "2.0",
210
- id: 1,
211
- method: "initialize",
212
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
213
- },
214
- { jsonrpc: "2.0", id: 2, method: "resources/list" },
215
- { jsonrpc: "2.0", id: 3, method: "resources/templates/list" },
216
- { jsonrpc: "2.0", id: 4, method: "resources/read", params: { uri: "oc-pilot://config" } },
217
- { jsonrpc: "2.0", id: 5, method: "resources/read", params: { uri: "oc-pilot://prompt/en" } },
218
- { jsonrpc: "2.0", id: 6, method: "resources/read", params: { uri: "oc-pilot://diff/staged" } },
219
- { jsonrpc: "2.0", id: 7, method: "resources/read", params: { uri: "oc-pilot://scan/staged" } },
220
- { jsonrpc: "2.0", id: 8, method: "resources/read", params: { uri: "oc-pilot://file/sample.txt" } },
221
- { jsonrpc: "2.0", id: 9, method: "resources/read", params: { uri: "oc-pilot://file/..%2Fescape.txt" } },
222
- { jsonrpc: "2.0", id: 10, method: "resources/read", params: { uri: "oc-pilot://unknown" } },
223
- ]);
224
- assert.equal(status, 0, stderr);
225
- const byId = new Map(responses.map((response) => [response.id, response]));
226
- const init = byId.get(1)?.result;
227
- assert.ok(init?.capabilities?.resources, "resources capability missing");
228
- assert.ok(init?.capabilities?.resourceTemplates, "resourceTemplates capability missing");
229
- const list = byId.get(2)?.result;
230
- const uris = new Set(list?.resources?.map((resource) => resource.uri));
231
- for (const uri of ["oc-pilot://config", "oc-pilot://rules", "oc-pilot://version", "oc-pilot://prompt/en", "oc-pilot://prompt/ru"]) {
232
- assert.ok(uris.has(uri), uri);
233
- }
234
- const templates = byId.get(3)?.result;
235
- const templateIds = new Set(templates?.resourceTemplates?.map((template) => template.uriTemplate));
236
- for (const template of ["oc-pilot://diff/{mode}", "oc-pilot://scan/{mode}", "oc-pilot://file/{+path}"]) {
237
- assert.ok(templateIds.has(template), template);
238
- }
239
- const config = byId.get(4)?.result;
240
- const configJson = JSON.parse(config?.contents?.[0]?.text ?? "{}");
241
- assert.equal(configJson.config?.engine, "opencode");
242
- const prompt = byId.get(5)?.result;
243
- assert.match(prompt?.contents?.[0]?.text ?? "", /ROLE AND GOAL/);
244
- const diff = byId.get(6)?.result;
245
- const diffText = diff?.contents?.[0]?.text ?? "";
246
- assert.match(diffText, /\+v2/);
247
- assert.ok(!diffText.includes(AWS_KEY), "diff resource must redact secrets");
248
- const scan = byId.get(7)?.result;
249
- const scanText = scan?.contents?.[0]?.text ?? "";
250
- assert.match(scanText, /AWS Access Key ID/);
251
- assert.ok(!scanText.includes(AWS_KEY), "scan resource must not leak the raw secret");
252
- const file = byId.get(8)?.result;
253
- const fileText = file?.contents?.[0]?.text ?? "";
254
- assert.match(fileText, /REDACTED/);
255
- assert.ok(!fileText.includes(AWS_KEY), "file resource must redact secrets");
256
- assert.equal(byId.get(9)?.error?.code, -32002);
257
- assert.match(byId.get(9)?.error?.message ?? "", /inside the project/);
258
- assert.equal(byId.get(10)?.error?.code, -32002);
259
- }
260
- finally {
261
- rmSync(dir, { recursive: true, force: true });
262
- }
263
- });
264
- test("MCP advertises slop and result caps in tools/list", () => {
265
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-tools-"));
266
- try {
267
- const { responses } = runServer(dir, [
268
- {
269
- jsonrpc: "2.0",
270
- id: 1,
271
- method: "initialize",
272
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
273
- },
274
- { jsonrpc: "2.0", id: 2, method: "tools/list" },
275
- ]);
276
- const tools = responses.find((response) => response.id === 2)?.result?.tools ?? [];
277
- const slop = tools.find((tool) => tool.name === "slop");
278
- assert.ok(slop, "slop tool missing");
279
- assert.ok(slop.inputSchema.properties.max_findings, "max_findings missing on slop");
280
- assert.ok(slop.inputSchema.properties.verbosity, "verbosity missing on slop");
281
- const review = tools.find((tool) => tool.name === "review");
282
- assert.ok(review?.inputSchema.properties.max_findings, "max_findings missing on review");
283
- const preflight = tools.find((tool) => tool.name === "preflight");
284
- assert.ok(preflight, "preflight tool missing");
285
- assert.ok(preflight.inputSchema.properties.max_delta, "max_delta missing on preflight");
286
- assert.ok(preflight.inputSchema.properties.fail_on_issue, "fail_on_issue missing on preflight");
287
- assert.ok(preflight.inputSchema.properties.no_sast, "no_sast missing on preflight");
288
- assert.ok(preflight.inputSchema.properties.no_authz, "no_authz missing on preflight");
289
- const honeypot = tools.find((tool) => tool.name === "honeypot");
290
- assert.ok(honeypot, "honeypot tool missing");
291
- assert.ok(honeypot.inputSchema.properties.action, "action missing on honeypot");
292
- assert.ok(honeypot.inputSchema.properties.force, "force missing on honeypot");
293
- const alienDna = tools.find((tool) => tool.name === "alien_dna");
294
- assert.ok(alienDna, "alien_dna tool missing");
295
- assert.ok(alienDna.inputSchema.properties.diff, "diff missing on alien_dna");
296
- assert.ok(alienDna.inputSchema.properties.base, "base missing on alien_dna");
297
- const hyperChamber = tools.find((tool) => tool.name === "hyper_chamber");
298
- assert.ok(hyperChamber, "hyper_chamber tool missing");
299
- assert.ok(hyperChamber.inputSchema.properties.file, "file missing on hyper_chamber");
300
- assert.ok(hyperChamber.inputSchema.properties.days, "days missing on hyper_chamber");
301
- assert.ok(hyperChamber.inputSchema.properties.budget_ms, "budget_ms missing on hyper_chamber");
302
- assert.ok(hyperChamber.inputSchema.properties.memory_mb, "memory_mb missing on hyper_chamber");
303
- const butterfly = tools.find((tool) => tool.name === "butterfly");
304
- assert.ok(butterfly, "butterfly tool missing");
305
- assert.ok(butterfly.inputSchema.properties.command, "command missing on butterfly");
306
- assert.ok(butterfly.inputSchema.properties.seed, "seed missing on butterfly");
307
- assert.ok(butterfly.inputSchema.properties.fail_rate, "fail_rate missing on butterfly");
308
- assert.ok(butterfly.inputSchema.properties.latency_rate, "latency_rate missing on butterfly");
309
- assert.ok(butterfly.inputSchema.properties.latency_ms, "latency_ms missing on butterfly");
310
- assert.ok(butterfly.inputSchema.properties.broken_json_rate, "broken_json_rate missing on butterfly");
311
- assert.ok(butterfly.inputSchema.properties.fs_fail_rate, "fs_fail_rate missing on butterfly");
312
- assert.ok(butterfly.inputSchema.properties.timeout_ms, "timeout_ms missing on butterfly");
313
- assert.ok(butterfly.inputSchema.properties.scope, "scope missing on butterfly");
314
- const blindfold = tools.find((tool) => tool.name === "blindfold");
315
- assert.ok(blindfold, "blindfold tool missing");
316
- assert.ok(blindfold.inputSchema.properties.file, "file missing on blindfold");
317
- assert.ok(blindfold.inputSchema.properties.diff, "diff missing on blindfold");
318
- assert.ok(blindfold.inputSchema.properties.min_confidence, "min_confidence missing on blindfold");
319
- assert.ok(blindfold.inputSchema.properties.dry_run, "dry_run missing on blindfold");
320
- const skeptic = tools.find((tool) => tool.name === "skeptic");
321
- assert.ok(skeptic, "skeptic tool missing");
322
- assert.ok(skeptic.inputSchema.properties.diff, "diff missing on skeptic");
323
- assert.ok(skeptic.inputSchema.properties.command, "command missing on skeptic");
324
- assert.ok(skeptic.inputSchema.properties.timeout_ms, "timeout_ms missing on skeptic");
325
- const antibody = tools.find((tool) => tool.name === "antibody");
326
- assert.ok(antibody, "antibody tool missing");
327
- assert.ok(antibody.inputSchema.properties.action, "action missing on antibody");
328
- assert.ok(antibody.inputSchema.properties.id, "id missing on antibody");
329
- assert.ok(antibody.inputSchema.properties.force, "force missing on antibody");
330
- assert.ok(antibody.inputSchema.properties.diff, "diff missing on antibody");
331
- const polygraph = tools.find((tool) => tool.name === "polygraph");
332
- assert.ok(polygraph, "polygraph tool missing");
333
- assert.ok(polygraph.inputSchema.properties.commit, "commit missing on polygraph");
334
- assert.ok(polygraph.inputSchema.properties.message, "message missing on polygraph");
335
- assert.ok(polygraph.inputSchema.properties.claims, "claims missing on polygraph");
336
- assert.ok(polygraph.inputSchema.properties.fail_on, "fail_on missing on polygraph");
337
- const passport = tools.find((tool) => tool.name === "passport");
338
- assert.ok(passport, "passport tool missing");
339
- assert.ok(passport.inputSchema.properties.action, "action missing on passport");
340
- assert.ok(passport.inputSchema.properties.commit, "commit missing on passport");
341
- assert.ok(passport.inputSchema.properties.checks, "checks missing on passport");
342
- assert.ok(passport.inputSchema.properties.force, "force missing on passport");
343
- const oracle = tools.find((tool) => tool.name === "oracle");
344
- assert.ok(oracle, "oracle tool missing");
345
- assert.ok(oracle.inputSchema.properties.command, "command missing on oracle");
346
- assert.ok(oracle.inputSchema.properties.cases, "cases missing on oracle");
347
- assert.ok(oracle.inputSchema.properties.case_timeout_ms, "case_timeout_ms missing on oracle");
348
- const vaccine = tools.find((tool) => tool.name === "vaccine");
349
- assert.ok(vaccine, "vaccine tool missing");
350
- assert.ok(vaccine.inputSchema.properties.action, "action missing on vaccine");
351
- assert.ok(vaccine.inputSchema.properties.fix, "fix missing on vaccine");
352
- assert.ok(vaccine.inputSchema.properties.bug, "bug missing on vaccine");
353
- assert.ok(vaccine.inputSchema.properties.test_timeout_ms, "test_timeout_ms missing on vaccine");
354
- const mitosis = tools.find((tool) => tool.name === "mitosis");
355
- assert.ok(mitosis, "mitosis tool missing");
356
- assert.ok(mitosis.inputSchema.properties.action, "action missing on mitosis");
357
- assert.ok(mitosis.inputSchema.properties.strategy, "strategy missing on mitosis");
358
- assert.ok(mitosis.inputSchema.properties.branch, "branch missing on mitosis");
359
- assert.ok(mitosis.inputSchema.properties.test_command, "test_command missing on mitosis");
360
- const intent = tools.find((tool) => tool.name === "intent");
361
- assert.ok(intent, "intent tool missing");
362
- assert.ok(intent.inputSchema.properties.action, "action missing on intent");
363
- assert.ok(intent.inputSchema.properties.criteria, "criteria missing on intent");
364
- assert.ok(intent.inputSchema.properties.request, "request missing on intent");
365
- assert.ok(intent.inputSchema.properties.strict, "strict missing on intent");
366
- const scalpel = tools.find((tool) => tool.name === "scalpel");
367
- assert.ok(scalpel, "scalpel tool missing");
368
- assert.ok(scalpel.inputSchema.properties.log, "log missing on scalpel");
369
- assert.ok(scalpel.inputSchema.properties.command, "command missing on scalpel");
370
- assert.ok(scalpel.inputSchema.properties.apply, "apply missing on scalpel");
371
- assert.ok(scalpel.inputSchema.properties.test_command, "test_command missing on scalpel");
372
- const mayday = tools.find((tool) => tool.name === "mayday");
373
- assert.ok(mayday, "mayday tool missing");
374
- assert.ok(mayday.inputSchema.properties.action, "action missing on mayday");
375
- assert.ok(mayday.inputSchema.properties.good, "good missing on mayday");
376
- assert.ok(mayday.inputSchema.properties.to, "to missing on mayday");
377
- assert.ok(mayday.inputSchema.properties.command, "command missing on mayday");
378
- const clairvoyant = tools.find((tool) => tool.name === "clairvoyant");
379
- assert.ok(clairvoyant, "clairvoyant tool missing");
380
- assert.ok(clairvoyant.inputSchema.properties.diff, "diff missing on clairvoyant");
381
- assert.ok(clairvoyant.inputSchema.properties.fail_on_empty, "fail_on_empty missing on clairvoyant");
382
- const hemorrhage = tools.find((tool) => tool.name === "hemorrhage");
383
- assert.ok(hemorrhage, "hemorrhage tool missing");
384
- assert.ok(hemorrhage.inputSchema.properties.command, "command missing on hemorrhage");
385
- assert.ok(hemorrhage.inputSchema.properties.metric, "metric missing on hemorrhage");
386
- assert.ok(hemorrhage.inputSchema.properties.runs, "runs missing on hemorrhage");
387
- assert.ok(hemorrhage.inputSchema.properties.threshold, "threshold missing on hemorrhage");
388
- const cuckoo = tools.find((tool) => tool.name === "cuckoo");
389
- assert.ok(cuckoo, "cuckoo tool missing");
390
- assert.ok(cuckoo.inputSchema.properties.file, "file missing on cuckoo");
391
- assert.ok(cuckoo.inputSchema.properties.script_timeout_ms, "script_timeout_ms missing on cuckoo");
392
- assert.ok(cuckoo.inputSchema.properties.allow, "allow missing on cuckoo");
393
- const chronos = tools.find((tool) => tool.name === "chronos");
394
- assert.ok(chronos, "chronos tool missing");
395
- assert.ok(chronos.inputSchema.properties.file, "file missing on chronos");
396
- assert.ok(chronos.inputSchema.properties.limit, "limit missing on chronos");
397
- assert.ok(chronos.inputSchema.properties.since, "since missing on chronos");
398
- for (const name of [
399
- "flight_start",
400
- "flight_exec",
401
- "flight_note",
402
- "flight_checkpoint",
403
- "flight_status",
404
- "flight_grep",
405
- "flight_list",
406
- "flight_show",
407
- "flight_verify",
408
- "flight_end",
409
- "flight_replay",
410
- "flight_bisect",
411
- "flight_prove",
412
- "flight_diff",
413
- "flight_compare",
414
- "flight_html",
415
- "flight_summary",
416
- "flight_stats",
417
- "flight_delete",
418
- "flight_prune",
419
- "flight_restore",
420
- "flight_export",
421
- "flight_verify_bundle",
422
- ]) {
423
- assert.ok(tools.some((tool) => tool.name === name), `${name} tool missing`);
424
- }
425
- const flightExec = tools.find((tool) => tool.name === "flight_exec");
426
- assert.ok(flightExec, "flight_exec tool missing");
427
- assert.ok(flightExec.inputSchema.properties.command, "command missing on flight_exec");
428
- assert.ok(flightExec.inputSchema.properties.timeout, "timeout missing on flight_exec");
429
- const flightBisect = tools.find((tool) => tool.name === "flight_bisect");
430
- assert.ok(flightBisect, "flight_bisect tool missing");
431
- assert.ok(flightBisect.inputSchema.properties.command, "command missing on flight_bisect");
432
- assert.ok(flightBisect.inputSchema.properties.timeout, "timeout missing on flight_bisect");
433
- const flightProve = tools.find((tool) => tool.name === "flight_prove");
434
- assert.ok(flightProve, "flight_prove tool missing");
435
- assert.ok(flightProve.inputSchema.properties.claim, "claim missing on flight_prove");
436
- assert.ok(flightProve.inputSchema.properties.command, "command missing on flight_prove");
437
- const flightCompare = tools.find((tool) => tool.name === "flight_compare");
438
- assert.ok(flightCompare, "flight_compare tool missing");
439
- assert.ok(flightCompare.inputSchema.properties.id, "id missing on flight_compare");
440
- assert.ok(flightCompare.inputSchema.properties.with, "with missing on flight_compare");
441
- assert.ok(flightCompare.inputSchema.properties.bundles, "bundles missing on flight_compare");
442
- const flightNote = tools.find((tool) => tool.name === "flight_note");
443
- assert.ok(flightNote, "flight_note tool missing");
444
- assert.ok(flightNote.inputSchema.properties.text, "text missing on flight_note");
445
- const flightHtml = tools.find((tool) => tool.name === "flight_html");
446
- assert.ok(flightHtml, "flight_html tool missing");
447
- assert.ok(flightHtml.inputSchema.properties.id, "id missing on flight_html");
448
- const flightSummary = tools.find((tool) => tool.name === "flight_summary");
449
- assert.ok(flightSummary, "flight_summary tool missing");
450
- assert.ok(flightSummary.inputSchema.properties.id, "id missing on flight_summary");
451
- assert.ok(flightSummary.inputSchema.properties.bundle, "bundle missing on flight_summary");
452
- assert.ok(flightHtml.inputSchema.properties.bundle, "bundle missing on flight_html");
453
- const flightShow = tools.find((tool) => tool.name === "flight_show");
454
- assert.ok(flightShow, "flight_show tool missing");
455
- assert.ok(flightShow.inputSchema.properties.bundle, "bundle missing on flight_show");
456
- assert.ok(flightShow.inputSchema.properties.kind, "kind missing on flight_show");
457
- assert.ok(flightShow.inputSchema.properties.last, "last missing on flight_show");
458
- const flightDelete = tools.find((tool) => tool.name === "flight_delete");
459
- assert.ok(flightDelete, "flight_delete tool missing");
460
- assert.ok(flightDelete.inputSchema.properties.id, "id missing on flight_delete");
461
- assert.ok(flightDelete.inputSchema.properties.dry_run, "dry_run missing on flight_delete");
462
- const flightDiff = tools.find((tool) => tool.name === "flight_diff");
463
- assert.ok(flightDiff, "flight_diff tool missing");
464
- assert.ok(flightDiff.inputSchema.properties.bundle, "bundle missing on flight_diff");
465
- const flightPrune = tools.find((tool) => tool.name === "flight_prune");
466
- assert.ok(flightPrune, "flight_prune tool missing");
467
- assert.ok(flightPrune.inputSchema.properties.keep, "keep missing on flight_prune");
468
- assert.ok(flightPrune.inputSchema.properties.older_than_days, "older_than_days missing on flight_prune");
469
- const flightList = tools.find((tool) => tool.name === "flight_list");
470
- assert.ok(flightList, "flight_list tool missing");
471
- assert.ok(flightList.inputSchema.properties.limit, "limit missing on flight_list");
472
- const flightGrep = tools.find((tool) => tool.name === "flight_grep");
473
- assert.ok(flightGrep, "flight_grep tool missing");
474
- assert.ok(flightGrep.inputSchema.properties.text, "text missing on flight_grep");
475
- assert.ok(flightGrep.inputSchema.properties.limit, "limit missing on flight_grep");
476
- assert.ok(flightGrep.inputSchema.properties.kind, "kind missing on flight_grep");
477
- assert.ok(flightGrep.inputSchema.properties.bundle, "bundle missing on flight_grep");
478
- const flightExport = tools.find((tool) => tool.name === "flight_export");
479
- assert.ok(flightExport, "flight_export tool missing");
480
- assert.ok(flightExport.inputSchema.properties.key, "key missing on flight_export");
481
- assert.ok(flightExport.inputSchema.properties.bundle, "bundle missing on flight_export");
482
- const flightRestore = tools.find((tool) => tool.name === "flight_restore");
483
- assert.ok(flightRestore, "flight_restore tool missing");
484
- assert.ok(flightRestore.inputSchema.properties.ref, "ref missing on flight_restore");
485
- assert.ok(flightRestore.inputSchema.properties.id, "id missing on flight_restore");
486
- assert.ok(flightRestore.inputSchema.properties.force, "force missing on flight_restore");
487
- assert.ok(flightRestore.inputSchema.properties.dry_run, "dry_run missing on flight_restore");
488
- const flightVerifyBundle = tools.find((tool) => tool.name === "flight_verify_bundle");
489
- assert.ok(flightVerifyBundle, "flight_verify_bundle tool missing");
490
- assert.ok(flightVerifyBundle.inputSchema.properties.file, "file missing on flight_verify_bundle");
491
- assert.ok(flightVerifyBundle.inputSchema.properties.key, "key missing on flight_verify_bundle");
492
- const flightVerify = tools.find((tool) => tool.name === "flight_verify");
493
- assert.ok(flightVerify, "flight_verify tool missing");
494
- assert.ok(flightVerify.inputSchema.properties.all, "all missing on flight_verify");
495
- const beacon = tools.find((tool) => tool.name === "beacon");
496
- assert.ok(beacon, "beacon tool missing");
497
- assert.ok(beacon.inputSchema.properties.action, "action missing on beacon");
498
- assert.ok(beacon.inputSchema.properties.checks, "checks missing on beacon");
499
- assert.ok(beacon.inputSchema.properties.key, "key missing on beacon");
500
- assert.ok(beacon.inputSchema.properties.identity, "identity missing on beacon");
501
- const quarantine = tools.find((tool) => tool.name === "quarantine");
502
- assert.ok(quarantine, "quarantine tool missing");
503
- assert.ok(quarantine.inputSchema.properties.action, "action missing on quarantine");
504
- assert.ok(quarantine.inputSchema.properties.test, "test missing on quarantine");
505
- assert.ok(quarantine.inputSchema.properties.owner, "owner missing on quarantine");
506
- assert.ok(quarantine.inputSchema.properties.days, "days missing on quarantine");
507
- const mirage = tools.find((tool) => tool.name === "mirage");
508
- assert.ok(mirage, "mirage tool missing");
509
- assert.ok(mirage.inputSchema.properties.action, "action missing on mirage");
510
- assert.ok(mirage.inputSchema.properties.command, "command missing on mirage");
511
- assert.ok(mirage.inputSchema.properties.cassette, "cassette missing on mirage");
512
- const warden = tools.find((tool) => tool.name === "warden");
513
- assert.ok(warden, "warden tool missing");
514
- assert.ok(warden.inputSchema.properties.action, "action missing on warden");
515
- assert.ok(warden.inputSchema.properties.force, "force missing on warden");
516
- assert.ok(warden.inputSchema.properties.diff, "diff missing on warden");
517
- const tribunal = tools.find((tool) => tool.name === "tribunal");
518
- assert.ok(tribunal, "tribunal tool missing");
519
- assert.ok(tribunal.inputSchema.properties.lenses, "lenses missing on tribunal");
520
- assert.ok(tribunal.inputSchema.properties.min_consensus, "min_consensus missing on tribunal");
521
- assert.ok(tribunal.inputSchema.properties.fail_on, "fail_on missing on tribunal");
522
- const apoptosis = tools.find((tool) => tool.name === "apoptosis");
523
- assert.ok(apoptosis, "apoptosis tool missing");
524
- assert.ok(apoptosis.inputSchema.properties.action, "action missing on apoptosis");
525
- assert.ok(apoptosis.inputSchema.properties.command, "command missing on apoptosis");
526
- assert.ok(apoptosis.inputSchema.properties.confirm, "confirm missing on apoptosis");
527
- const scanInjection = tools.find((tool) => tool.name === "scan_injection");
528
- assert.ok(scanInjection, "scan_injection tool missing");
529
- assert.ok(scanInjection.inputSchema.properties.fix, "fix missing on scan_injection");
530
- assert.ok(scanInjection.inputSchema.properties.fail_on, "fail_on missing on scan_injection");
531
- const mutate = tools.find((tool) => tool.name === "mutate");
532
- assert.ok(mutate, "mutate tool missing");
533
- assert.ok(mutate.inputSchema.properties.max_mutants, "max_mutants missing on mutate");
534
- assert.ok(mutate.inputSchema.properties.min_score, "min_score missing on mutate");
535
- const fuzz = tools.find((tool) => tool.name === "fuzz");
536
- assert.ok(fuzz, "fuzz tool missing");
537
- assert.ok(fuzz.inputSchema.properties.duration_ms, "duration_ms missing on fuzz");
538
- assert.ok(fuzz.inputSchema.properties.memory_mb, "memory_mb missing on fuzz");
539
- assert.ok(fuzz.inputSchema.properties.fail_on_crash, "fail_on_crash missing on fuzz");
540
- const flaky = tools.find((tool) => tool.name === "flaky");
541
- assert.ok(flaky, "flaky tool missing");
542
- assert.ok(flaky.inputSchema.properties.runs, "runs missing on flaky");
543
- assert.ok(flaky.inputSchema.properties.fail_on_flaky, "fail_on_flaky missing on flaky");
544
- assert.ok(flaky.inputSchema.properties.shuffle, "shuffle missing on flaky");
545
- assert.ok(flaky.inputSchema.properties.seed, "seed missing on flaky");
546
- const impact = tools.find((tool) => tool.name === "impact");
547
- assert.ok(impact, "impact tool missing");
548
- assert.ok(impact.inputSchema.properties.base, "base missing on impact");
549
- assert.ok(impact.inputSchema.properties.staged, "staged missing on impact");
550
- assert.ok(impact.inputSchema.properties.paths, "paths missing on impact");
551
- const deps = tools.find((tool) => tool.name === "deps");
552
- assert.ok(deps, "deps tool missing");
553
- assert.ok(deps.inputSchema.properties.fail_on_issue, "fail_on_issue missing on deps");
554
- assert.ok(deps.inputSchema.properties.fix, "fix missing on deps");
555
- assert.ok(deps.inputSchema.properties.sbom, "sbom missing on deps");
556
- const coverage = tools.find((tool) => tool.name === "coverage");
557
- assert.ok(coverage, "coverage tool missing");
558
- assert.ok(coverage.inputSchema.properties.coverage_file, "coverage_file missing on coverage");
559
- assert.ok(coverage.inputSchema.properties.fail_under, "fail_under missing on coverage");
560
- assert.ok(coverage.inputSchema.properties.max_uncovered, "max_uncovered missing on coverage");
561
- const testGen = tools.find((tool) => tool.name === "test_gen");
562
- assert.ok(testGen, "test_gen tool missing");
563
- assert.ok(testGen.inputSchema.properties.apply, "apply missing on test_gen");
564
- assert.ok(testGen.inputSchema.properties.no_run, "no_run missing on test_gen");
565
- assert.ok(testGen.inputSchema.properties.coverage, "coverage missing on test_gen");
566
- assert.ok(testGen.inputSchema.properties.from_slop, "from_slop missing on test_gen");
567
- assert.ok(testGen.inputSchema.properties.rounds, "rounds missing on test_gen");
568
- const reviewers = tools.find((tool) => tool.name === "reviewers");
569
- assert.ok(reviewers, "reviewers tool missing");
570
- assert.ok(reviewers.inputSchema.properties.limit, "limit missing on reviewers");
571
- assert.ok(reviewers.inputSchema.properties.depth, "depth missing on reviewers");
572
- assert.ok(reviewers.inputSchema.properties.exclude, "exclude missing on reviewers");
573
- const testGuard = tools.find((tool) => tool.name === "test_guard");
574
- assert.ok(testGuard, "test_guard tool missing");
575
- assert.ok(testGuard.inputSchema.properties.fail_on_weakening, "fail_on_weakening missing on test_guard");
576
- assert.ok(testGuard.inputSchema.properties.staged, "staged missing on test_guard");
577
- const envSync = tools.find((tool) => tool.name === "env_sync");
578
- assert.ok(envSync, "env_sync tool missing");
579
- assert.ok(envSync.inputSchema.properties.fail_on_missing, "fail_on_missing missing on env_sync");
580
- assert.ok(envSync.inputSchema.properties.staged, "staged missing on env_sync");
581
- const mockLeak = tools.find((tool) => tool.name === "mock_leak");
582
- assert.ok(mockLeak, "mock_leak tool missing");
583
- assert.ok(mockLeak.inputSchema.properties.fail_on_leak, "fail_on_leak missing on mock_leak");
584
- assert.ok(mockLeak.inputSchema.properties.staged, "staged missing on mock_leak");
585
- const ecosystem = tools.find((tool) => tool.name === "ecosystem_verify");
586
- assert.ok(ecosystem, "ecosystem_verify tool missing");
587
- assert.ok(ecosystem.inputSchema.properties.online, "online missing on ecosystem_verify");
588
- assert.ok(ecosystem.inputSchema.properties.min_age_days, "min_age_days missing on ecosystem_verify");
589
- assert.ok(ecosystem.inputSchema.properties.fail_on_issue, "fail_on_issue missing on ecosystem_verify");
590
- const pack = tools.find((tool) => tool.name === "pack");
591
- assert.ok(pack, "pack tool missing");
592
- assert.ok(pack.inputSchema.properties.task, "task missing on pack");
593
- assert.ok(pack.inputSchema.properties.budget, "budget missing on pack");
594
- assert.ok(pack.inputSchema.properties.test_log, "test_log missing on pack");
595
- assert.ok(pack.inputSchema.properties.rules, "rules missing on pack");
596
- const packHologram = tools.find((tool) => tool.name === "pack_hologram");
597
- assert.ok(packHologram, "pack_hologram tool missing");
598
- assert.ok(packHologram.inputSchema.properties.max_tokens, "max_tokens missing on pack_hologram");
599
- const zoomSymbol = tools.find((tool) => tool.name === "zoom_symbol");
600
- assert.ok(zoomSymbol, "zoom_symbol tool missing");
601
- assert.ok(zoomSymbol.inputSchema.properties.file, "file missing on zoom_symbol");
602
- assert.ok(zoomSymbol.inputSchema.properties.symbol, "symbol missing on zoom_symbol");
603
- const invariants = tools.find((tool) => tool.name === "invariants");
604
- assert.ok(invariants, "invariants tool missing");
605
- assert.ok(invariants.inputSchema.properties.strict, "strict missing on invariants");
606
- assert.ok(invariants.inputSchema.properties.fail_on, "fail_on missing on invariants");
607
- assert.ok(invariants.inputSchema.properties.no_cache, "no_cache missing on invariants");
608
- const contractDrift = tools.find((tool) => tool.name === "contract_drift");
609
- assert.ok(contractDrift, "contract_drift tool missing");
610
- assert.ok(contractDrift.inputSchema.properties.fail_on_drift, "fail_on_drift missing on contract_drift");
611
- assert.ok(contractDrift.inputSchema.properties.staged, "staged missing on contract_drift");
612
- const bankruptcy = tools.find((tool) => tool.name === "bankruptcy");
613
- assert.ok(bankruptcy, "bankruptcy tool missing");
614
- assert.ok(bankruptcy.inputSchema.properties.history_days, "history_days missing on bankruptcy");
615
- assert.ok(bankruptcy.inputSchema.properties.explain, "explain missing on bankruptcy");
616
- const queryAst = tools.find((tool) => tool.name === "query_ast");
617
- assert.ok(queryAst, "query_ast tool missing");
618
- assert.ok(queryAst.inputSchema.properties.query, "query missing on query_ast");
619
- assert.ok(queryAst.inputSchema.properties.limit, "limit missing on query_ast");
620
- const sandbox = tools.find((tool) => tool.name === "sandbox");
621
- assert.ok(sandbox, "sandbox tool missing");
622
- assert.ok(sandbox.inputSchema.properties.file, "file missing on sandbox");
623
- assert.ok(sandbox.inputSchema.properties.timeout_ms, "timeout_ms missing on sandbox");
624
- const hivemind = tools.find((tool) => tool.name === "hivemind_status");
625
- assert.ok(hivemind, "hivemind_status tool missing");
626
- const antiRegression = tools.find((tool) => tool.name === "anti_regression");
627
- assert.ok(antiRegression, "anti_regression tool missing");
628
- assert.ok(antiRegression.inputSchema.properties.max_commits, "max_commits missing on anti_regression");
629
- assert.ok(antiRegression.inputSchema.properties.since, "since missing on anti_regression");
630
- assert.ok(antiRegression.inputSchema.properties.fail_on_regression, "fail_on_regression missing on anti_regression");
631
- const boundaries = tools.find((tool) => tool.name === "boundaries");
632
- assert.ok(boundaries, "boundaries tool missing");
633
- assert.ok(boundaries.inputSchema.properties.config, "config missing on boundaries");
634
- assert.ok(boundaries.inputSchema.properties.fail_on_violation, "fail_on_violation missing on boundaries");
635
- const testPlan = tools.find((tool) => tool.name === "test_plan");
636
- assert.ok(testPlan, "test_plan tool missing");
637
- assert.ok(testPlan.inputSchema.properties.strategy, "strategy missing on test_plan");
638
- assert.ok(testPlan.inputSchema.properties.max_tests, "max_tests missing on test_plan");
639
- assert.ok(testPlan.inputSchema.properties.fail_on_uncovered, "fail_on_uncovered missing on test_plan");
640
- const complianceVerify = tools.find((tool) => tool.name === "compliance_verify");
641
- assert.ok(complianceVerify, "compliance_verify tool missing");
642
- assert.ok(complianceVerify.inputSchema.properties.manifest, "manifest missing on compliance_verify");
643
- assert.ok(complianceVerify.inputSchema.properties.public_key, "public_key missing on compliance_verify");
644
- const brag = tools.find((tool) => tool.name === "brag");
645
- assert.ok(brag, "brag tool missing");
646
- assert.ok(brag.inputSchema.properties.since_days, "since_days missing on brag");
647
- assert.ok(brag.inputSchema.properties.no_paths, "no_paths missing on brag");
648
- assert.ok(brag.inputSchema.properties.svg, "svg missing on brag");
649
- const battle = tools.find((tool) => tool.name === "battle");
650
- assert.ok(battle, "battle tool missing");
651
- assert.ok(battle.inputSchema.properties.task, "task missing on battle");
652
- assert.ok(battle.inputSchema.properties.rounds, "rounds missing on battle");
653
- assert.ok(battle.inputSchema.properties.shadow, "shadow missing on battle");
654
- const cleanup = tools.find((tool) => tool.name === "cleanup");
655
- assert.ok(cleanup, "cleanup tool missing");
656
- assert.ok(cleanup.inputSchema.properties.apply, "apply missing on cleanup");
657
- assert.ok(cleanup.inputSchema.properties.fail_on_task, "fail_on_task missing on cleanup");
658
- const archDiff = tools.find((tool) => tool.name === "arch_diff");
659
- assert.ok(archDiff, "arch_diff tool missing");
660
- assert.ok(archDiff.inputSchema.properties.max_edges, "max_edges missing on arch_diff");
661
- assert.ok(archDiff.inputSchema.properties.fail_on_removed, "fail_on_removed missing on arch_diff");
662
- const roast = tools.find((tool) => tool.name === "roast");
663
- assert.ok(roast, "roast tool missing");
664
- assert.ok(roast.inputSchema.properties.persona, "persona missing on roast");
665
- assert.ok(roast.inputSchema.properties.context, "context missing on roast");
666
- const cinema = tools.find((tool) => tool.name === "cinema");
667
- assert.ok(cinema, "cinema tool missing");
668
- assert.ok(cinema.inputSchema.properties.since_days, "since_days missing on cinema");
669
- assert.ok(cinema.inputSchema.properties.max_frames, "max_frames missing on cinema");
670
- assert.ok(cinema.inputSchema.properties.cast, "cast missing on cinema");
671
- const bounty = tools.find((tool) => tool.name === "bounty");
672
- assert.ok(bounty, "bounty tool missing");
673
- assert.ok(bounty.inputSchema.properties.limit, "limit missing on bounty");
674
- assert.ok(bounty.inputSchema.properties.since_days, "since_days missing on bounty");
675
- const autopsy = tools.find((tool) => tool.name === "autopsy");
676
- assert.ok(autopsy, "autopsy tool missing");
677
- assert.ok(autopsy.inputSchema.properties.commit, "commit missing on autopsy");
678
- assert.ok(autopsy.inputSchema.properties.depth, "depth missing on autopsy");
679
- assert.ok(autopsy.inputSchema.properties.fail_on_risk, "fail_on_risk missing on autopsy");
680
- const echo = tools.find((tool) => tool.name === "echo");
681
- assert.ok(echo, "echo tool missing");
682
- assert.ok(echo.inputSchema.properties.name, "name missing on echo");
683
- assert.ok(echo.inputSchema.properties.submit, "submit missing on echo");
684
- assert.ok(echo.inputSchema.properties.endpoint, "endpoint missing on echo");
685
- assert.ok(echo.inputSchema.properties.svg, "svg missing on echo");
686
- const sast = tools.find((tool) => tool.name === "sast");
687
- assert.ok(sast, "sast tool missing");
688
- assert.ok(sast.inputSchema.properties.fail_on_issue, "fail_on_issue missing on sast");
689
- assert.ok(sast.inputSchema.properties.ignore, "ignore missing on sast");
690
- assert.ok(sast.inputSchema.properties.baseline, "baseline missing on sast");
691
- assert.ok(sast.inputSchema.properties.update_baseline, "update_baseline missing on sast");
692
- const authz = tools.find((tool) => tool.name === "authz");
693
- assert.ok(authz, "authz tool missing");
694
- assert.ok(authz.inputSchema.properties.public, "public missing on authz");
695
- assert.ok(authz.inputSchema.properties.fail_on_issue, "fail_on_issue missing on authz");
696
- assert.ok(authz.inputSchema.properties.baseline, "baseline missing on authz");
697
- assert.ok(authz.inputSchema.properties.update_baseline, "update_baseline missing on authz");
698
- const fix = tools.find((tool) => tool.name === "fix");
699
- assert.ok(fix, "fix tool missing");
700
- assert.ok(fix.inputSchema.properties.from_sast, "from_sast missing on fix");
701
- assert.ok(fix.inputSchema.properties.from_authz, "from_authz missing on fix");
702
- assert.ok(fix.inputSchema.properties.shadow, "shadow missing on fix");
703
- const ready = tools.find((tool) => tool.name === "ready");
704
- assert.ok(ready, "ready tool missing");
705
- assert.ok(ready.inputSchema.properties.fail_under, "fail_under missing on ready");
706
- const receiptVerify = tools.find((tool) => tool.name === "receipt_verify");
707
- assert.ok(receiptVerify, "receipt_verify tool missing");
708
- assert.ok(receiptVerify.inputSchema.properties.receipt, "receipt missing on receipt_verify");
709
- assert.ok(receiptVerify.inputSchema.properties.public_key, "public_key missing on receipt_verify");
710
- }
711
- finally {
712
- rmSync(dir, { recursive: true, force: true });
713
- }
714
- });
715
- test("MCP slop tool returns the Slop Index offline", () => {
716
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-slop-"));
717
- try {
718
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
719
- git(["init"]);
720
- git(["config", "user.email", "test@example.com"]);
721
- git(["config", "user.name", "Test"]);
722
- git(["config", "core.autocrlf", "false"]);
723
- writeFileSync(join(dir, "wallet.go"), "package main\n\nfunc main() {}\n", "utf8");
724
- git(["add", "."]);
725
- git(["commit", "-m", "init"]);
726
- const { responses, stderr } = runServer(dir, [
727
- {
728
- jsonrpc: "2.0",
729
- id: 1,
730
- method: "initialize",
731
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
732
- },
733
- {
734
- jsonrpc: "2.0",
735
- id: 2,
736
- method: "tools/call",
737
- params: { name: "slop", arguments: { verbosity: "compact", no_blame: true } },
738
- },
739
- ]);
740
- const result = responses.find((response) => response.id === 2)?.result;
741
- assert.notEqual(result?.isError, true, stderr);
742
- assert.match(result?.content?.[0]?.text ?? "", /Slop Index/);
743
- assert.equal(typeof result?.structuredContent?.index, "number");
744
- }
745
- finally {
746
- rmSync(dir, { recursive: true, force: true });
747
- }
748
- });
749
- test("MCP preflight returns a failing verdict without a tool error", () => {
750
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-preflight-"));
751
- try {
752
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
753
- git(["init"]);
754
- git(["config", "user.email", "test@example.com"]);
755
- git(["config", "user.name", "Test"]);
756
- git(["config", "core.autocrlf", "false"]);
757
- writeFileSync(join(dir, "wallet.go"), "package main\n\nfunc main() {}\n", "utf8");
758
- git(["add", "."]);
759
- git(["commit", "-m", "init"]);
760
- const diff = [
761
- "diff --git a/src/app.ts b/src/app.ts",
762
- "new file mode 100644",
763
- "--- /dev/null",
764
- "+++ b/src/app.ts",
765
- "@@ -0,0 +1 @@",
766
- '+const key = "AKIAIOSFODNN7EXAMPLE";',
767
- "",
768
- ].join("\n");
769
- const { responses, stderr } = runServer(dir, [
770
- {
771
- jsonrpc: "2.0",
772
- id: 1,
773
- method: "initialize",
774
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
775
- },
776
- {
777
- jsonrpc: "2.0",
778
- id: 2,
779
- method: "tools/call",
780
- params: { name: "preflight", arguments: { diff, no_slop: true } },
781
- },
782
- ]);
783
- const result = responses.find((response) => response.id === 2)?.result;
784
- assert.notEqual(result?.isError, true, stderr);
785
- assert.equal(result?._meta?.exitCode, 1);
786
- assert.equal(result?.structuredContent?.status, "fail");
787
- const secrets = result?.structuredContent?.checks?.find((check) => check.id === "secrets");
788
- assert.equal(secrets?.status, "fail");
789
- assert.match(result?.content?.[0]?.text ?? "", /"status": "fail"/);
790
- }
791
- finally {
792
- rmSync(dir, { recursive: true, force: true });
793
- }
794
- });
795
- test("MCP ready returns the readiness score without a tool error", () => {
796
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-ready-"));
797
- try {
798
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
799
- git(["init"]);
800
- git(["config", "user.email", "test@example.com"]);
801
- git(["config", "user.name", "Test"]);
802
- git(["config", "core.autocrlf", "false"]);
803
- writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "demo", private: true, scripts: { test: 'node -e "process.exit(0)"' } }), "utf8");
804
- writeFileSync(join(dir, "package-lock.json"), JSON.stringify({ name: "demo", lockfileVersion: 3, packages: { "": { name: "demo" } } }), "utf8");
805
- writeFileSync(join(dir, "app.ts"), "export const value = 1;\n", "utf8");
806
- git(["add", "."]);
807
- git(["commit", "-m", "init"]);
808
- const { responses, stderr } = runServer(dir, [
809
- {
810
- jsonrpc: "2.0",
811
- id: 1,
812
- method: "initialize",
813
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
814
- },
815
- {
816
- jsonrpc: "2.0",
817
- id: 2,
818
- method: "tools/call",
819
- params: { name: "ready", arguments: { fail_under: 85 } },
820
- },
821
- ]);
822
- const result = responses.find((response) => response.id === 2)?.result;
823
- assert.notEqual(result?.isError, true, stderr);
824
- assert.equal(result?._meta?.exitCode, 1);
825
- assert.equal(typeof result?.structuredContent?.score, "number");
826
- assert.equal(result?.structuredContent?.checks?.find((check) => check.id === "tests")?.status, "pass");
827
- assert.match(result?.content?.[0]?.text ?? "", /"grade"/);
828
- }
829
- finally {
830
- rmSync(dir, { recursive: true, force: true });
831
- }
832
- });
833
- test("MCP receipt_verify rejects a missing and a tampered receipt", () => {
834
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-receipt-"));
835
- try {
836
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
837
- git(["init"]);
838
- git(["config", "user.email", "test@example.com"]);
839
- git(["config", "user.name", "Test"]);
840
- git(["config", "core.autocrlf", "false"]);
841
- writeFileSync(join(dir, "app.ts"), "export const value = 1;\n", "utf8");
842
- git(["add", "."]);
843
- git(["commit", "-m", "init"]);
844
- const call = () => {
845
- const { responses, stderr } = runServer(dir, [
846
- {
847
- jsonrpc: "2.0",
848
- id: 1,
849
- method: "initialize",
850
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
851
- },
852
- {
853
- jsonrpc: "2.0",
854
- id: 2,
855
- method: "tools/call",
856
- params: { name: "receipt_verify", arguments: {} },
857
- },
858
- ]);
859
- const result = responses.find((response) => response.id === 2)?.result;
860
- return { result, stderr };
861
- };
862
- const missing = call();
863
- assert.notEqual(missing.result?.isError, true, missing.stderr);
864
- assert.equal(missing.result?._meta?.exitCode, 1);
865
- assert.equal(missing.result?.structuredContent?.ok, false);
866
- const created = spawnSync(process.execPath, [CLI, "receipt", "--cwd", dir, "--no-run", "--json"], {
867
- cwd: dir,
868
- encoding: "utf8",
869
- timeout: 60_000,
870
- });
871
- assert.equal(created.status, 0, created.stderr);
872
- const valid = call();
873
- assert.notEqual(valid.result?.isError, true, valid.stderr);
874
- assert.equal(valid.result?._meta?.exitCode, 0);
875
- assert.equal(valid.result?.structuredContent?.ok, true);
876
- assert.equal(valid.result?.structuredContent?.hashOk, true);
877
- assert.equal(valid.result?.structuredContent?.stale, false);
878
- const path = join(dir, ".git", "oc-pilot", "receipt.json");
879
- const receipt = JSON.parse(readFileSync(path, "utf8"));
880
- receipt.createdAt = "2020-01-01T00:00:00.000Z";
881
- writeFileSync(path, JSON.stringify(receipt, null, 2), "utf8");
882
- const tampered = call();
883
- assert.equal(tampered.result?._meta?.exitCode, 1);
884
- assert.equal(tampered.result?.structuredContent?.ok, false);
885
- assert.equal(tampered.result?.structuredContent?.hashOk, false);
886
- }
887
- finally {
888
- rmSync(dir, { recursive: true, force: true });
889
- }
890
- });
891
- test("MCP sast returns findings without a tool error", () => {
892
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-sast-"));
893
- try {
894
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
895
- git(["init"]);
896
- git(["config", "user.email", "test@example.com"]);
897
- git(["config", "user.name", "Test"]);
898
- writeFileSync(join(dir, "base.txt"), "x\n", "utf8");
899
- git(["add", "."]);
900
- git(["commit", "-m", "init"]);
901
- writeFileSync(join(dir, "app.js"), 'const { exec } = require("child_process");\nexec(`rm -rf ${req.query.dir}`);\n', "utf8");
902
- const { responses, stderr } = runServer(dir, [
903
- {
904
- jsonrpc: "2.0",
905
- id: 1,
906
- method: "initialize",
907
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
908
- },
909
- {
910
- jsonrpc: "2.0",
911
- id: 2,
912
- method: "tools/call",
913
- params: { name: "sast", arguments: { paths: ["app.js"], fail_on_issue: "high" } },
914
- },
915
- ]);
916
- const result = responses.find((response) => response.id === 2)?.result;
917
- assert.notEqual(result?.isError, true, stderr);
918
- assert.equal(result?._meta?.exitCode, 1);
919
- assert.equal(result?.structuredContent?.findings?.[0]?.rule, "command-injection");
920
- assert.equal(result?.structuredContent?.findings?.[0]?.severity, "high");
921
- }
922
- finally {
923
- rmSync(dir, { recursive: true, force: true });
924
- }
925
- });
926
- test("MCP authz returns route findings without a tool error", () => {
927
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-authz-"));
928
- try {
929
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
930
- git(["init"]);
931
- git(["config", "user.email", "test@example.com"]);
932
- git(["config", "user.name", "Test"]);
933
- writeFileSync(join(dir, "base.txt"), "x\n", "utf8");
934
- git(["add", "."]);
935
- git(["commit", "-m", "init"]);
936
- writeFileSync(join(dir, "app.js"), 'router.get("/users/:id", async (req, res) => { const user = await db.user.findUnique({ where: { id: req.params.id } }); res.json(user); });\n', "utf8");
937
- const { responses, stderr } = runServer(dir, [
938
- {
939
- jsonrpc: "2.0",
940
- id: 1,
941
- method: "initialize",
942
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
943
- },
944
- {
945
- jsonrpc: "2.0",
946
- id: 2,
947
- method: "tools/call",
948
- params: { name: "authz", arguments: { paths: ["app.js"], fail_on_issue: "high" } },
949
- },
950
- ]);
951
- const result = responses.find((response) => response.id === 2)?.result;
952
- assert.notEqual(result?.isError, true, stderr);
953
- assert.equal(result?._meta?.exitCode, 1);
954
- assert.equal(result?.structuredContent?.routes?.length, 1);
955
- const rules = (result?.structuredContent?.findings ?? []).map((finding) => finding.rule);
956
- assert.ok(rules.includes("route-no-auth"), `rules: ${rules.join(",")}`);
957
- assert.ok(rules.includes("idor"), `rules: ${rules.join(",")}`);
958
- }
959
- finally {
960
- rmSync(dir, { recursive: true, force: true });
961
- }
962
- });
963
- test("MCP mutate reports surviving mutants and restores the source", () => {
964
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-mutate-"));
965
- try {
966
- const source = "export function same(a, b) {\n return a === b;\n}\n";
967
- writeFileSync(join(dir, "app.js"), source, "utf8");
968
- const diff = [
969
- "diff --git a/app.js b/app.js",
970
- "new file mode 100644",
971
- "--- /dev/null",
972
- "+++ b/app.js",
973
- "@@ -0,0 +1,3 @@",
974
- "+export function same(a, b) {",
975
- "+ return a === b;",
976
- "+}",
977
- "",
978
- ].join("\n");
979
- const { responses, stderr } = runServer(dir, [
980
- {
981
- jsonrpc: "2.0",
982
- id: 1,
983
- method: "initialize",
984
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
985
- },
986
- {
987
- jsonrpc: "2.0",
988
- id: 2,
989
- method: "tools/call",
990
- params: {
991
- name: "mutate",
992
- arguments: {
993
- diff,
994
- command: 'node -e "process.exit(0)"',
995
- max_mutants: 2,
996
- min_score: 100,
997
- verbosity: "compact",
998
- },
999
- },
1000
- },
1001
- ], ["--allow-write"]);
1002
- const result = responses.find((response) => response.id === 2)?.result;
1003
- assert.notEqual(result?.isError, true, stderr);
1004
- assert.equal(result?._meta?.exitCode, 1);
1005
- assert.equal(result?.structuredContent?.survived, 1);
1006
- assert.equal(result?.structuredContent?.score, 0);
1007
- assert.equal(result?.structuredContent?.mutants?.length, 1);
1008
- assert.match(result?.content?.[0]?.text ?? "", /mutation score 0\/100, 1 survived/);
1009
- assert.equal(readFileSync(join(dir, "app.js"), "utf8"), source);
1010
- }
1011
- finally {
1012
- rmSync(dir, { recursive: true, force: true });
1013
- }
1014
- });
1015
- test("MCP deps --why explains the lockfile chain", () => {
1016
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-deps-"));
1017
- try {
1018
- spawnSync("git", ["init", "-q"], { cwd: dir });
1019
- writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "demo", dependencies: { express: "^4.18.0" } }, null, 2), "utf8");
1020
- writeFileSync(join(dir, "package-lock.json"), JSON.stringify({
1021
- name: "demo",
1022
- version: "1.0.0",
1023
- lockfileVersion: 3,
1024
- requires: true,
1025
- packages: {
1026
- "": { name: "demo", version: "1.0.0", dependencies: { express: "^4.18.0" } },
1027
- "node_modules/express": { version: "4.18.2", dependencies: { "body-parser": "1.20.1" } },
1028
- "node_modules/body-parser": { version: "1.20.1", dependencies: { qs: "6.11.0" } },
1029
- "node_modules/qs": { version: "6.11.0" },
1030
- },
1031
- }, null, 2), "utf8");
1032
- writeFileSync(join(dir, "app.ts"), 'import express from "express";\n\nexport const app = express();\n', "utf8");
1033
- const { responses, stderr } = runServer(dir, [
1034
- {
1035
- jsonrpc: "2.0",
1036
- id: 1,
1037
- method: "initialize",
1038
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1039
- },
1040
- {
1041
- jsonrpc: "2.0",
1042
- id: 2,
1043
- method: "tools/call",
1044
- params: { name: "deps", arguments: { why: "qs" } },
1045
- },
1046
- ]);
1047
- const result = responses.find((response) => response.id === 2)?.result;
1048
- assert.notEqual(result?.isError, true, stderr);
1049
- assert.equal(result?._meta?.exitCode, 0);
1050
- assert.equal(result?.structuredContent?.name, "qs");
1051
- assert.deepEqual(result?.structuredContent?.versions, ["6.11.0"]);
1052
- assert.deepEqual(result?.structuredContent?.dependents, ["body-parser"]);
1053
- assert.deepEqual(result?.structuredContent?.chains, [["express", "body-parser", "qs"]]);
1054
- }
1055
- finally {
1056
- rmSync(dir, { recursive: true, force: true });
1057
- }
1058
- });
1059
- test("MCP coverage gates uncovered changed lines", () => {
1060
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-coverage-"));
1061
- try {
1062
- mkdirSync(join(dir, "coverage"), { recursive: true });
1063
- writeFileSync(join(dir, "coverage", "lcov.info"), ["SF:src/app.ts", "DA:1,1", "DA:2,0", "end_of_record", ""].join("\n"), "utf8");
1064
- const diff = [
1065
- "diff --git a/src/app.ts b/src/app.ts",
1066
- "new file mode 100644",
1067
- "--- /dev/null",
1068
- "+++ b/src/app.ts",
1069
- "@@ -0,0 +1,3 @@",
1070
- "+export function add(a: number, b: number) {",
1071
- "+ return a + b;",
1072
- "+}",
1073
- "",
1074
- ].join("\n");
1075
- const { responses, stderr } = runServer(dir, [
1076
- {
1077
- jsonrpc: "2.0",
1078
- id: 1,
1079
- method: "initialize",
1080
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1081
- },
1082
- {
1083
- jsonrpc: "2.0",
1084
- id: 2,
1085
- method: "tools/call",
1086
- params: {
1087
- name: "coverage",
1088
- arguments: {
1089
- diff,
1090
- coverage_file: "coverage/lcov.info",
1091
- fail_under: 80,
1092
- verbosity: "compact",
1093
- },
1094
- },
1095
- },
1096
- ]);
1097
- const result = responses.find((response) => response.id === 2)?.result;
1098
- assert.notEqual(result?.isError, true, stderr);
1099
- assert.equal(result?._meta?.exitCode, 1);
1100
- assert.equal(result?.structuredContent?.coveragePercent, 50);
1101
- assert.equal(result?.structuredContent?.uncoveredLines, 1);
1102
- assert.deepEqual(result?.structuredContent?.gaps, [{ file: "src/app.ts", uncovered: [2] }]);
1103
- assert.equal(result?.structuredContent?.gate?.passed, false);
1104
- assert.match(result?.content?.[0]?.text ?? "", /1 uncovered changed line in 1 file \(50%\)/);
1105
- }
1106
- finally {
1107
- rmSync(dir, { recursive: true, force: true });
1108
- }
1109
- });
1110
- test("MCP reviewers ranks authors from git history", () => {
1111
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-reviewers-"));
1112
- try {
1113
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
1114
- git(["init", "-q"]);
1115
- git(["config", "user.email", "alice@example.com"]);
1116
- git(["config", "user.name", "Alice"]);
1117
- mkdirSync(join(dir, "src"), { recursive: true });
1118
- writeFileSync(join(dir, "src", "app.ts"), "export function a() {}\n", "utf8");
1119
- git(["add", "."]);
1120
- git(["commit", "-m", "init"]);
1121
- const diff = [
1122
- "diff --git a/src/app.ts b/src/app.ts",
1123
- "--- a/src/app.ts",
1124
- "+++ b/src/app.ts",
1125
- "@@ -1 +1,2 @@",
1126
- " export function a() {}",
1127
- "+export function b() {}",
1128
- "",
1129
- ].join("\n");
1130
- const { responses, stderr } = runServer(dir, [
1131
- {
1132
- jsonrpc: "2.0",
1133
- id: 1,
1134
- method: "initialize",
1135
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1136
- },
1137
- {
1138
- jsonrpc: "2.0",
1139
- id: 2,
1140
- method: "tools/call",
1141
- params: { name: "reviewers", arguments: { diff, verbosity: "compact" } },
1142
- },
1143
- ]);
1144
- const result = responses.find((response) => response.id === 2)?.result;
1145
- assert.notEqual(result?.isError, true, stderr);
1146
- assert.equal(result?._meta?.exitCode, 0);
1147
- assert.deepEqual(result?.structuredContent?.files, ["src/app.ts"]);
1148
- assert.equal(result?.structuredContent?.candidates?.length, 1);
1149
- assert.equal(result?.structuredContent?.candidates?.[0]?.name, "Alice");
1150
- assert.equal(result?.structuredContent?.candidates?.[0]?.files, 1);
1151
- assert.equal(result?.structuredContent?.candidates?.[0]?.commits, 1);
1152
- assert.match(result?.content?.[0]?.text ?? "", /1 reviewer candidate, 0 CODEOWNERS owners for 1 file/);
1153
- }
1154
- finally {
1155
- rmSync(dir, { recursive: true, force: true });
1156
- }
1157
- });
1158
- test("MCP test_guard flags a weakened matcher", () => {
1159
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-guard-"));
1160
- try {
1161
- const diff = [
1162
- "diff --git a/src/app.test.ts b/src/app.test.ts",
1163
- "--- a/src/app.test.ts",
1164
- "+++ b/src/app.test.ts",
1165
- "@@ -1,3 +1,3 @@",
1166
- ' test("adds", () => {',
1167
- "- expect(add(1, 2)).toBe(3);",
1168
- "+ expect(add(1, 2)).toBeDefined();",
1169
- " });",
1170
- "",
1171
- ].join("\n");
1172
- const { responses, stderr } = runServer(dir, [
1173
- {
1174
- jsonrpc: "2.0",
1175
- id: 1,
1176
- method: "initialize",
1177
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1178
- },
1179
- {
1180
- jsonrpc: "2.0",
1181
- id: 2,
1182
- method: "tools/call",
1183
- params: {
1184
- name: "test_guard",
1185
- arguments: { diff, fail_on_weakening: true, verbosity: "compact" },
1186
- },
1187
- },
1188
- ]);
1189
- const result = responses.find((response) => response.id === 2)?.result;
1190
- assert.notEqual(result?.isError, true, stderr);
1191
- assert.equal(result?._meta?.exitCode, 1);
1192
- assert.equal(result?.structuredContent?.status, "fail");
1193
- assert.equal(result?.structuredContent?.counts?.total, 1);
1194
- assert.equal(result?.structuredContent?.findings?.[0]?.kind, "weakened-matcher");
1195
- assert.equal(result?.structuredContent?.findings?.[0]?.file, "src/app.test.ts");
1196
- assert.match(result?.content?.[0]?.text ?? "", /1 test weakening finding, status fail/);
1197
- }
1198
- finally {
1199
- rmSync(dir, { recursive: true, force: true });
1200
- }
1201
- });
1202
- test("MCP env_sync reports a missing environment variable", () => {
1203
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-env-"));
1204
- try {
1205
- writeFileSync(join(dir, ".env"), "EXISTING_KEY=value\n", "utf8");
1206
- writeFileSync(join(dir, ".env.example"), "EXISTING_KEY=\n", "utf8");
1207
- const diff = [
1208
- "diff --git a/src/config.ts b/src/config.ts",
1209
- "--- a/src/config.ts",
1210
- "+++ b/src/config.ts",
1211
- "@@ -1,2 +1,3 @@",
1212
- " const existing = process.env.EXISTING_KEY;",
1213
- "+const missing = process.env.MISSING_KEY;",
1214
- " export { existing, missing };",
1215
- "",
1216
- ].join("\n");
1217
- const { responses, stderr } = runServer(dir, [
1218
- {
1219
- jsonrpc: "2.0",
1220
- id: 1,
1221
- method: "initialize",
1222
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1223
- },
1224
- {
1225
- jsonrpc: "2.0",
1226
- id: 2,
1227
- method: "tools/call",
1228
- params: {
1229
- name: "env_sync",
1230
- arguments: { diff, fail_on_missing: true, verbosity: "compact" },
1231
- },
1232
- },
1233
- ]);
1234
- const result = responses.find((response) => response.id === 2)?.result;
1235
- assert.notEqual(result?.isError, true, stderr);
1236
- assert.equal(result?._meta?.exitCode, 1);
1237
- assert.equal(result?.structuredContent?.status, "fail");
1238
- assert.deepEqual(result?.structuredContent?.missing, ["MISSING_KEY"]);
1239
- assert.deepEqual(result?.structuredContent?.undocumented, []);
1240
- assert.equal(result?.structuredContent?.references?.length, 1);
1241
- assert.equal(result?.structuredContent?.references?.[0]?.name, "MISSING_KEY");
1242
- assert.equal(result?.structuredContent?.references?.[0]?.line, 2);
1243
- assert.match(result?.content?.[0]?.text ?? "", /1 env reference, 1 missing, 0 undocumented/);
1244
- }
1245
- finally {
1246
- rmSync(dir, { recursive: true, force: true });
1247
- }
1248
- });
1249
- test("MCP mock_leak finds hardcoded paths and always-true branches", () => {
1250
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-mock-"));
1251
- try {
1252
- const diff = [
1253
- "diff --git a/src/app.ts b/src/app.ts",
1254
- "--- a/src/app.ts",
1255
- "+++ b/src/app.ts",
1256
- "@@ -1,1 +1,4 @@",
1257
- '+const home = "C:\\\\Users\\\\aleyn\\\\project";',
1258
- "+if (true) {",
1259
- "+ load(home);",
1260
- "+}",
1261
- "",
1262
- ].join("\n");
1263
- const { responses, stderr } = runServer(dir, [
1264
- {
1265
- jsonrpc: "2.0",
1266
- id: 1,
1267
- method: "initialize",
1268
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1269
- },
1270
- {
1271
- jsonrpc: "2.0",
1272
- id: 2,
1273
- method: "tools/call",
1274
- params: {
1275
- name: "mock_leak",
1276
- arguments: { diff, fail_on_leak: "high", verbosity: "compact" },
1277
- },
1278
- },
1279
- ]);
1280
- const result = responses.find((response) => response.id === 2)?.result;
1281
- assert.notEqual(result?.isError, true, stderr);
1282
- assert.equal(result?._meta?.exitCode, 1);
1283
- assert.equal(result?.structuredContent?.status, "fail");
1284
- assert.equal(result?.structuredContent?.counts?.total, 2);
1285
- assert.equal(result?.structuredContent?.counts?.high, 2);
1286
- const kinds = (result?.structuredContent?.findings ?? []).map((finding) => finding.kind);
1287
- assert.ok(kinds.includes("local-path"), `kinds: ${kinds.join(", ")}`);
1288
- assert.ok(kinds.includes("always-true"), `kinds: ${kinds.join(", ")}`);
1289
- assert.match(result?.content?.[0]?.text ?? "", /2 mock leaks, 2 high, 0 medium/);
1290
- }
1291
- finally {
1292
- rmSync(dir, { recursive: true, force: true });
1293
- }
1294
- });
1295
- test("MCP pack returns a compact context bundle", () => {
1296
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-pack-"));
1297
- try {
1298
- mkdirSync(join(dir, "src"), { recursive: true });
1299
- writeFileSync(join(dir, "src", "wallet.ts"), "export function chargeCard(amount: number) {\n return amount;\n}\n", "utf8");
1300
- const diff = [
1301
- "diff --git a/src/wallet.ts b/src/wallet.ts",
1302
- "new file mode 100644",
1303
- "--- /dev/null",
1304
- "+++ b/src/wallet.ts",
1305
- "@@ -0,0 +1,3 @@",
1306
- "+export function chargeCard(amount: number) {",
1307
- "+ return amount;",
1308
- "+}",
1309
- "",
1310
- ].join("\n");
1311
- const { responses, stderr } = runServer(dir, [
1312
- {
1313
- jsonrpc: "2.0",
1314
- id: 1,
1315
- method: "initialize",
1316
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1317
- },
1318
- {
1319
- jsonrpc: "2.0",
1320
- id: 2,
1321
- method: "tools/call",
1322
- params: {
1323
- name: "pack",
1324
- arguments: { task: "fix login", diff, budget: 4000, verbosity: "compact" },
1325
- },
1326
- },
1327
- ]);
1328
- const result = responses.find((response) => response.id === 2)?.result;
1329
- assert.notEqual(result?.isError, true, stderr);
1330
- assert.equal(result?._meta?.exitCode, 0);
1331
- assert.equal(result?.structuredContent?.task, "fix login");
1332
- assert.ok((result?.structuredContent?.files?.length ?? 0) >= 1, "pack files missing");
1333
- assert.ok((result?.structuredContent?.chars ?? 0) <= 4000, "pack exceeded the budget");
1334
- assert.equal(result?.structuredContent?.truncated, false);
1335
- assert.match(result?.structuredContent?.content ?? "", /fix login/);
1336
- assert.match(result?.structuredContent?.content ?? "", /chargeCard/);
1337
- assert.match(result?.content?.[0]?.text ?? "", /1 file, \d+ chars \(within budget\)/);
1338
- }
1339
- finally {
1340
- rmSync(dir, { recursive: true, force: true });
1341
- }
1342
- });
1343
- test("MCP contract_drift flags a removed field still used by a consumer", () => {
1344
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-contract-"));
1345
- try {
1346
- spawnSync("git", ["init", "-q"], { cwd: dir });
1347
- mkdirSync(join(dir, "src"), { recursive: true });
1348
- writeFileSync(join(dir, "src", "types.ts"), "export interface Account {\n id: string;\n role: string;\n}\n", "utf8");
1349
- writeFileSync(join(dir, "src", "billing.ts"), "export function bill(account: Account) {\n return account.billingEmail;\n}\n", "utf8");
1350
- const diff = [
1351
- "diff --git a/src/types.ts b/src/types.ts",
1352
- "--- a/src/types.ts",
1353
- "+++ b/src/types.ts",
1354
- "@@ -1,4 +1,3 @@",
1355
- " export interface Account {",
1356
- " id: string;",
1357
- "- billingEmail: string;",
1358
- " role: string;",
1359
- " }",
1360
- "",
1361
- ].join("\n");
1362
- const { responses, stderr } = runServer(dir, [
1363
- {
1364
- jsonrpc: "2.0",
1365
- id: 1,
1366
- method: "initialize",
1367
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1368
- },
1369
- {
1370
- jsonrpc: "2.0",
1371
- id: 2,
1372
- method: "tools/call",
1373
- params: {
1374
- name: "contract_drift",
1375
- arguments: { diff, fail_on_drift: "high", verbosity: "compact" },
1376
- },
1377
- },
1378
- ]);
1379
- const result = responses.find((response) => response.id === 2)?.result;
1380
- assert.notEqual(result?.isError, true, stderr);
1381
- assert.equal(result?._meta?.exitCode, 1);
1382
- assert.equal(result?.structuredContent?.status, "fail");
1383
- assert.equal(result?.structuredContent?.counts?.total, 1);
1384
- const finding = result?.structuredContent?.findings?.[0];
1385
- assert.equal(finding?.kind, "removed-field");
1386
- assert.equal(finding?.field, "billingEmail");
1387
- assert.equal(finding?.severity, "high");
1388
- assert.equal(finding?.references?.[0]?.file, "src/billing.ts");
1389
- assert.match(result?.content?.[0]?.text ?? "", /1 contract drift, 1 high, 0 medium/);
1390
- }
1391
- finally {
1392
- rmSync(dir, { recursive: true, force: true });
1393
- }
1394
- });
1395
- test("MCP test_plan selects tests from the import graph", () => {
1396
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-test-plan-"));
1397
- try {
1398
- spawnSync("git", ["init", "-q"], { cwd: dir });
1399
- mkdirSync(join(dir, "src"), { recursive: true });
1400
- writeFileSync(join(dir, "src", "wallet.ts"), "export function charge(amount: number) {\n return amount;\n}\n", "utf8");
1401
- writeFileSync(join(dir, "src", "checkout.ts"), 'import { charge } from "./wallet";\n\nexport function pay() {\n return charge(10);\n}\n', "utf8");
1402
- writeFileSync(join(dir, "src", "wallet.test.ts"), 'import { charge } from "./wallet";\n', "utf8");
1403
- writeFileSync(join(dir, "src", "checkout.test.ts"), 'import { pay } from "./checkout";\n', "utf8");
1404
- const diff = [
1405
- "diff --git a/src/wallet.ts b/src/wallet.ts",
1406
- "--- a/src/wallet.ts",
1407
- "+++ b/src/wallet.ts",
1408
- "@@ -1,3 +1,3 @@",
1409
- "-export function charge(amount: number) {",
1410
- "+export function chargeCard(amount: number) {",
1411
- " return amount;",
1412
- " }",
1413
- "",
1414
- ].join("\n");
1415
- const { responses, stderr } = runServer(dir, [
1416
- {
1417
- jsonrpc: "2.0",
1418
- id: 1,
1419
- method: "initialize",
1420
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1421
- },
1422
- {
1423
- jsonrpc: "2.0",
1424
- id: 2,
1425
- method: "tools/call",
1426
- params: {
1427
- name: "test_plan",
1428
- arguments: { diff, strategy: "affected", fail_on_uncovered: true, verbosity: "compact" },
1429
- },
1430
- },
1431
- ]);
1432
- const result = responses.find((response) => response.id === 2)?.result;
1433
- assert.notEqual(result?.isError, true, stderr);
1434
- assert.equal(result?._meta?.exitCode, 0);
1435
- assert.deepEqual(result?.structuredContent?.uncovered, []);
1436
- const files = (result?.structuredContent?.tests ?? []).map((test) => test.file);
1437
- assert.ok(files.includes("src/wallet.test.ts"), `tests: ${files.join(", ")}`);
1438
- assert.ok(files.includes("src/checkout.test.ts"), `tests: ${files.join(", ")}`);
1439
- assert.match(result?.content?.[0]?.text ?? "", /2 test files selected, 0 uncovered changed files/);
1440
- }
1441
- finally {
1442
- rmSync(dir, { recursive: true, force: true });
1443
- }
1444
- });
1445
- test("MCP pack_hologram layers files and zoom_symbol returns the body", () => {
1446
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-hologram-"));
1447
- try {
1448
- spawnSync("git", ["init", "-q"], { cwd: dir });
1449
- spawnSync("git", ["config", "user.email", "test@example.com"], { cwd: dir });
1450
- spawnSync("git", ["config", "user.name", "Test"], { cwd: dir });
1451
- mkdirSync(join(dir, "src"), { recursive: true });
1452
- writeFileSync(join(dir, "src", "a.ts"), 'import { helper } from "./b";\n\nexport const run = 1;\n', "utf8");
1453
- writeFileSync(join(dir, "src", "b.ts"), "export function helper(): number {\n return 1;\n}\n", "utf8");
1454
- writeFileSync(join(dir, "src", "c.ts"), "export const far = 2;\n", "utf8");
1455
- spawnSync("git", ["add", "."], { cwd: dir });
1456
- spawnSync("git", ["commit", "-m", "init"], { cwd: dir });
1457
- const diff = [
1458
- "diff --git a/src/a.ts b/src/a.ts",
1459
- "--- a/src/a.ts",
1460
- "+++ b/src/a.ts",
1461
- "@@ -1,1 +1,3 @@",
1462
- '+import { helper } from "./b";',
1463
- " ",
1464
- " export const run = 1;",
1465
- "",
1466
- ].join("\n");
1467
- const { responses, stderr } = runServer(dir, [
1468
- {
1469
- jsonrpc: "2.0",
1470
- id: 1,
1471
- method: "initialize",
1472
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1473
- },
1474
- {
1475
- jsonrpc: "2.0",
1476
- id: 2,
1477
- method: "tools/call",
1478
- params: {
1479
- name: "pack_hologram",
1480
- arguments: { diff, max_tokens: 30000, verbosity: "compact" },
1481
- },
1482
- },
1483
- {
1484
- jsonrpc: "2.0",
1485
- id: 3,
1486
- method: "tools/call",
1487
- params: {
1488
- name: "zoom_symbol",
1489
- arguments: { file: "src/b.ts", symbol: "helper", verbosity: "compact" },
1490
- },
1491
- },
1492
- ]);
1493
- const hologram = responses.find((response) => response.id === 2)?.result;
1494
- assert.notEqual(hologram?.isError, true, stderr);
1495
- assert.equal(hologram?.structuredContent?.files?.find((file) => file.file === "src/a.ts")?.lod, 0);
1496
- assert.equal(hologram?.structuredContent?.files?.find((file) => file.file === "src/b.ts")?.lod, 1);
1497
- assert.ok((hologram?.structuredContent?.estimatedTokens ?? 0) > 0);
1498
- assert.match(hologram?.structuredContent?.content ?? "", /body hidden \(LOD 1\)/);
1499
- assert.match(hologram?.content?.[0]?.text ?? "", /hologram \d+ file\(s\)/);
1500
- const zoom = responses.find((response) => response.id === 3)?.result;
1501
- assert.notEqual(zoom?.isError, true, stderr);
1502
- assert.equal(zoom?.structuredContent?.symbol, "helper");
1503
- assert.equal(zoom?.structuredContent?.line, 1);
1504
- assert.match(zoom?.structuredContent?.body ?? "", /return 1/);
1505
- assert.match(zoom?.content?.[0]?.text ?? "", /symbol src\/b\.ts#helper/);
1506
- }
1507
- finally {
1508
- rmSync(dir, { recursive: true, force: true });
1509
- }
1510
- });
1511
- test("MCP bounty posts a WANTED poster for the worst file", () => {
1512
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-bounty-"));
1513
- try {
1514
- spawnSync("git", ["init", "-q"], { cwd: dir });
1515
- spawnSync("git", ["config", "user.email", "test@example.com"], { cwd: dir });
1516
- spawnSync("git", ["config", "user.name", "Test"], { cwd: dir });
1517
- writeFileSync(join(dir, "app.js"), 'const { exec } = require("child_process");\n// TODO: remove the debug command\nexec(req.query.cmd);\n', "utf8");
1518
- spawnSync("git", ["add", "."], { cwd: dir });
1519
- spawnSync("git", ["commit", "-m", "init"], { cwd: dir });
1520
- const { responses, stderr } = runServer(dir, [
1521
- {
1522
- jsonrpc: "2.0",
1523
- id: 1,
1524
- method: "initialize",
1525
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1526
- },
1527
- {
1528
- jsonrpc: "2.0",
1529
- id: 2,
1530
- method: "tools/call",
1531
- params: {
1532
- name: "bounty",
1533
- arguments: { limit: 5, since_days: 30, verbosity: "compact" },
1534
- },
1535
- },
1536
- ]);
1537
- const result = responses.find((response) => response.id === 2)?.result;
1538
- assert.notEqual(result?.isError, true, stderr);
1539
- assert.equal(result?._meta?.exitCode, 0);
1540
- assert.equal(result?.structuredContent?.file, "app.js");
1541
- assert.ok((result?.structuredContent?.score ?? 0) > 0);
1542
- assert.match(result?.structuredContent?.poster ?? "", /W\s*A\s*N\s*T\s*E\s*D/);
1543
- assert.match(result?.content?.[0]?.text ?? "", /worst file app\.js/);
1544
- }
1545
- finally {
1546
- rmSync(dir, { recursive: true, force: true });
1547
- }
1548
- });
1549
- test("MCP autopsy finds a dangerous commit", () => {
1550
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-autopsy-"));
1551
- try {
1552
- spawnSync("git", ["init", "-q"], { cwd: dir });
1553
- spawnSync("git", ["config", "user.email", "test@example.com"], { cwd: dir });
1554
- spawnSync("git", ["config", "user.name", "Test"], { cwd: dir });
1555
- writeFileSync(join(dir, "app.js"), 'const { exec } = require("child_process");\nexec(req.query.cmd);\n', "utf8");
1556
- spawnSync("git", ["add", "."], { cwd: dir });
1557
- spawnSync("git", ["commit", "-m", "add the debug command"], { cwd: dir });
1558
- const { responses, stderr } = runServer(dir, [
1559
- {
1560
- jsonrpc: "2.0",
1561
- id: 1,
1562
- method: "initialize",
1563
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1564
- },
1565
- {
1566
- jsonrpc: "2.0",
1567
- id: 2,
1568
- method: "tools/call",
1569
- params: {
1570
- name: "autopsy",
1571
- arguments: { commit: "HEAD", depth: 5, fail_on_risk: true, verbosity: "compact" },
1572
- },
1573
- },
1574
- ]);
1575
- const result = responses.find((response) => response.id === 2)?.result;
1576
- assert.notEqual(result?.isError, true, stderr);
1577
- assert.equal(result?._meta?.exitCode, 1);
1578
- assert.equal(result?.structuredContent?.verdict, "dangerous");
1579
- assert.ok((result?.structuredContent?.signals?.length ?? 0) >= 1);
1580
- assert.match(result?.content?.[0]?.text ?? "", /autopsy dangerous for/);
1581
- }
1582
- finally {
1583
- rmSync(dir, { recursive: true, force: true });
1584
- }
1585
- });
1586
- test("MCP echo builds badges without submitting", () => {
1587
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-echo-"));
1588
- try {
1589
- spawnSync("git", ["init", "-q"], { cwd: dir });
1590
- spawnSync("git", ["config", "user.email", "test@example.com"], { cwd: dir });
1591
- spawnSync("git", ["config", "user.name", "Test"], { cwd: dir });
1592
- writeFileSync(join(dir, "app.ts"), "export const value = 1;\n", "utf8");
1593
- spawnSync("git", ["add", "."], { cwd: dir });
1594
- spawnSync("git", ["commit", "-m", "init"], { cwd: dir });
1595
- const { responses, stderr } = runServer(dir, [
1596
- {
1597
- jsonrpc: "2.0",
1598
- id: 1,
1599
- method: "initialize",
1600
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1601
- },
1602
- {
1603
- jsonrpc: "2.0",
1604
- id: 2,
1605
- method: "tools/call",
1606
- params: { name: "echo", arguments: { name: "tester", since_days: 30, verbosity: "compact" } },
1607
- },
1608
- ]);
1609
- const result = responses.find((response) => response.id === 2)?.result;
1610
- assert.notEqual(result?.isError, true, stderr);
1611
- assert.equal(result?._meta?.exitCode, 0);
1612
- assert.equal(result?.structuredContent?.name, "tester");
1613
- assert.equal(result?.structuredContent?.badges?.length, 6);
1614
- assert.equal(result?.structuredContent?.stats?.commits, 1);
1615
- assert.equal(result?.structuredContent?.submitted, false);
1616
- assert.match(result?.structuredContent?.content ?? "", /<svg/);
1617
- assert.match(result?.content?.[0]?.text ?? "", /6 badge\(s\) for tester, 1 commits, 0 runs/);
1618
- }
1619
- finally {
1620
- rmSync(dir, { recursive: true, force: true });
1621
- }
1622
- });
1623
- test("MCP brag returns a self-contained session report", () => {
1624
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-brag-"));
1625
- try {
1626
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
1627
- git(["init", "-q"]);
1628
- git(["config", "user.email", "test@example.com"]);
1629
- git(["config", "user.name", "Test"]);
1630
- writeFileSync(join(dir, "app.ts"), "export const answer = 42;\n", "utf8");
1631
- git(["add", "."]);
1632
- git(["commit", "-m", "init"]);
1633
- const { responses, stderr } = runServer(dir, [
1634
- {
1635
- jsonrpc: "2.0",
1636
- id: 1,
1637
- method: "initialize",
1638
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1639
- },
1640
- {
1641
- jsonrpc: "2.0",
1642
- id: 2,
1643
- method: "tools/call",
1644
- params: { name: "brag", arguments: { title: "demo", since_days: 30, verbosity: "compact" } },
1645
- },
1646
- ]);
1647
- const result = responses.find((response) => response.id === 2)?.result;
1648
- assert.notEqual(result?.isError, true, stderr);
1649
- assert.equal(result?._meta?.exitCode, 0);
1650
- assert.match(result?.structuredContent?.content ?? "", /<html/i);
1651
- assert.equal(result?.structuredContent?.stats?.commits, 1);
1652
- assert.match(result?.content?.[0]?.text ?? "", /1 commits, 0 runs, 0 findings \(HTML\)/);
1653
- }
1654
- finally {
1655
- rmSync(dir, { recursive: true, force: true });
1656
- }
1657
- });
1658
- test("MCP compliance_verify accepts a manifest for HEAD", () => {
1659
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-compliance-"));
1660
- try {
1661
- spawnSync("git", ["init", "-q"], { cwd: dir });
1662
- spawnSync("git", ["config", "user.email", "test@example.com"], { cwd: dir });
1663
- spawnSync("git", ["config", "user.name", "Test"], { cwd: dir });
1664
- writeFileSync(join(dir, "app.ts"), "export const value = 1;\n", "utf8");
1665
- spawnSync("git", ["add", "."], { cwd: dir });
1666
- spawnSync("git", ["commit", "-m", "init"], { cwd: dir });
1667
- const created = spawnSync(process.execPath, [CLI, "compliance", "--json"], { cwd: dir, encoding: "utf8" });
1668
- assert.equal(created.status, 0, created.stderr);
1669
- const { responses, stderr } = runServer(dir, [
1670
- {
1671
- jsonrpc: "2.0",
1672
- id: 1,
1673
- method: "initialize",
1674
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1675
- },
1676
- {
1677
- jsonrpc: "2.0",
1678
- id: 2,
1679
- method: "tools/call",
1680
- params: { name: "compliance_verify", arguments: { verbosity: "compact" } },
1681
- },
1682
- ]);
1683
- const result = responses.find((response) => response.id === 2)?.result;
1684
- assert.notEqual(result?.isError, true, stderr);
1685
- assert.equal(result?._meta?.exitCode, 0);
1686
- assert.equal(result?.structuredContent?.verification?.ok, true);
1687
- assert.equal(result?.structuredContent?.verification?.hashOk, true);
1688
- assert.equal(result?.structuredContent?.verification?.chainOk, true);
1689
- assert.match(result?.content?.[0]?.text ?? "", /compliance ok for/);
1690
- }
1691
- finally {
1692
- rmSync(dir, { recursive: true, force: true });
1693
- }
1694
- });
1695
- test("MCP boundaries flags an import that crosses a layer rule", () => {
1696
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-boundaries-"));
1697
- try {
1698
- mkdirSync(join(dir, ".oc-pilot"), { recursive: true });
1699
- writeFileSync(join(dir, ".oc-pilot", "architecture.json"), JSON.stringify({
1700
- rules: [{ from: "src/ui/**", deny: ["src/db/**"], reason: "UI не ходит в БД" }],
1701
- }), "utf8");
1702
- const diff = [
1703
- "diff --git a/src/ui/app.ts b/src/ui/app.ts",
1704
- "new file mode 100644",
1705
- "--- /dev/null",
1706
- "+++ b/src/ui/app.ts",
1707
- "@@ -0,0 +1,2 @@",
1708
- '+import { db } from "../db/user";',
1709
- "+export const app = db;",
1710
- "",
1711
- ].join("\n");
1712
- const { responses, stderr } = runServer(dir, [
1713
- {
1714
- jsonrpc: "2.0",
1715
- id: 1,
1716
- method: "initialize",
1717
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1718
- },
1719
- {
1720
- jsonrpc: "2.0",
1721
- id: 2,
1722
- method: "tools/call",
1723
- params: {
1724
- name: "boundaries",
1725
- arguments: { diff, fail_on_violation: true, verbosity: "compact" },
1726
- },
1727
- },
1728
- ]);
1729
- const result = responses.find((response) => response.id === 2)?.result;
1730
- assert.notEqual(result?.isError, true, stderr);
1731
- assert.equal(result?._meta?.exitCode, 1);
1732
- assert.equal(result?.structuredContent?.status, "fail");
1733
- assert.equal(result?.structuredContent?.violations?.length, 1);
1734
- assert.equal(result?.structuredContent?.violations?.[0]?.file, "src/ui/app.ts");
1735
- assert.equal(result?.structuredContent?.violations?.[0]?.line, 1);
1736
- assert.equal(result?.structuredContent?.violations?.[0]?.imported, "../db/user");
1737
- assert.match(result?.structuredContent?.violations?.[0]?.rule?.reason ?? "", /UI не ходит в БД/);
1738
- assert.match(result?.content?.[0]?.text ?? "", /1 boundary violation in 1 file/);
1739
- }
1740
- finally {
1741
- rmSync(dir, { recursive: true, force: true });
1742
- }
1743
- });
1744
- test("MCP anti_regression cites the commit that deleted a re-added line", () => {
1745
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-regression-"));
1746
- try {
1747
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
1748
- git(["init", "-q"]);
1749
- git(["config", "user.email", "test@example.com"]);
1750
- git(["config", "user.name", "Test"]);
1751
- mkdirSync(join(dir, "src"), { recursive: true });
1752
- const file = join(dir, "src", "wallet.ts");
1753
- writeFileSync(file, "export function charge(amount: number) {\n return amount * 2;\n}\n", "utf8");
1754
- git(["add", "."]);
1755
- git(["commit", "-m", "add doubling"]);
1756
- writeFileSync(file, "export function charge(amount: number) {\n return amount;\n}\n", "utf8");
1757
- git(["add", "."]);
1758
- git(["commit", "-m", "stop doubling"]);
1759
- const diff = [
1760
- "diff --git a/src/wallet.ts b/src/wallet.ts",
1761
- "--- a/src/wallet.ts",
1762
- "+++ b/src/wallet.ts",
1763
- "@@ -1,3 +1,3 @@",
1764
- " export function charge(amount: number) {",
1765
- "- return amount;",
1766
- "+ return amount * 2;",
1767
- " }",
1768
- "",
1769
- ].join("\n");
1770
- const { responses, stderr } = runServer(dir, [
1771
- {
1772
- jsonrpc: "2.0",
1773
- id: 1,
1774
- method: "initialize",
1775
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1776
- },
1777
- {
1778
- jsonrpc: "2.0",
1779
- id: 2,
1780
- method: "tools/call",
1781
- params: {
1782
- name: "anti_regression",
1783
- arguments: { diff, fail_on_regression: true, verbosity: "compact" },
1784
- },
1785
- },
1786
- ]);
1787
- const result = responses.find((response) => response.id === 2)?.result;
1788
- assert.notEqual(result?.isError, true, stderr);
1789
- assert.equal(result?._meta?.exitCode, 1);
1790
- assert.equal(result?.structuredContent?.status, "fail");
1791
- const finding = result?.structuredContent?.findings?.[0];
1792
- assert.equal(finding?.kind, "readded-line");
1793
- assert.equal(finding?.file, "src/wallet.ts");
1794
- assert.equal(finding?.line, 2);
1795
- assert.match(finding?.commit?.subject ?? "", /stop doubling/);
1796
- assert.match(result?.content?.[0]?.text ?? "", /1 re-added line, 1 commit/);
1797
- }
1798
- finally {
1799
- rmSync(dir, { recursive: true, force: true });
1800
- }
1801
- });
1802
- test("MCP ecosystem_verify flags an invented export", () => {
1803
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-ecosystem-"));
1804
- try {
1805
- mkdirSync(join(dir, "src"), { recursive: true });
1806
- mkdirSync(join(dir, "node_modules", "left-pad"), { recursive: true });
1807
- writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "demo", dependencies: { "left-pad": "^1.3.0" } }), "utf8");
1808
- writeFileSync(join(dir, "node_modules", "left-pad", "package.json"), JSON.stringify({ name: "left-pad", version: "1.3.0", types: "index.d.ts" }), "utf8");
1809
- writeFileSync(join(dir, "node_modules", "left-pad", "index.d.ts"), "export function leftPad(text: string, width: number): string;\n", "utf8");
1810
- writeFileSync(join(dir, "src", "app.ts"), 'import { leftPad, invented } from "left-pad";\n\nleftPad("x", 3);\ninvented();\n', "utf8");
1811
- const diff = [
1812
- "diff --git a/src/app.ts b/src/app.ts",
1813
- "--- a/src/app.ts",
1814
- "+++ b/src/app.ts",
1815
- "@@ -1,1 +1,4 @@",
1816
- '+import { leftPad, invented } from "left-pad";',
1817
- "+",
1818
- '+leftPad("x", 3);',
1819
- "+invented();",
1820
- "",
1821
- ].join("\n");
1822
- const { responses, stderr } = runServer(dir, [
1823
- {
1824
- jsonrpc: "2.0",
1825
- id: 1,
1826
- method: "initialize",
1827
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1828
- },
1829
- {
1830
- jsonrpc: "2.0",
1831
- id: 2,
1832
- method: "tools/call",
1833
- params: {
1834
- name: "ecosystem_verify",
1835
- arguments: { diff, fail_on_issue: "high", verbosity: "compact" },
1836
- },
1837
- },
1838
- ]);
1839
- const result = responses.find((response) => response.id === 2)?.result;
1840
- assert.notEqual(result?.isError, true, stderr);
1841
- assert.equal(result?._meta?.exitCode, 1);
1842
- assert.equal(result?.structuredContent?.status, "fail");
1843
- assert.equal(result?.structuredContent?.counts?.total, 1);
1844
- assert.equal(result?.structuredContent?.counts?.high, 1);
1845
- assert.equal(result?.structuredContent?.packages?.[0]?.name, "left-pad");
1846
- assert.deepEqual(result?.structuredContent?.packages?.[0]?.missingExports, ["invented"]);
1847
- assert.equal(result?.structuredContent?.issues?.[0]?.kind, "missing-export");
1848
- assert.match(result?.content?.[0]?.text ?? "", /1 ecosystem issue, 1 high, 0 medium/);
1849
- }
1850
- finally {
1851
- rmSync(dir, { recursive: true, force: true });
1852
- }
1853
- });
1854
- test("MCP arch_diff renders added and removed internal imports", () => {
1855
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-arch-"));
1856
- try {
1857
- spawnSync("git", ["init", "-q"], { cwd: dir });
1858
- mkdirSync(join(dir, "src"), { recursive: true });
1859
- writeFileSync(join(dir, "src", "a.ts"), 'import { c } from "./c";\n\nexport const a = c;\n', "utf8");
1860
- writeFileSync(join(dir, "src", "b.ts"), "export const b = 1;\n", "utf8");
1861
- writeFileSync(join(dir, "src", "c.ts"), "export const c = 1;\n", "utf8");
1862
- const diff = [
1863
- "diff --git a/src/a.ts b/src/a.ts",
1864
- "--- a/src/a.ts",
1865
- "+++ b/src/a.ts",
1866
- "@@ -1,3 +1,3 @@",
1867
- '-import { c } from "./c";',
1868
- '+import { b } from "./b";',
1869
- " ",
1870
- " export const a = c;",
1871
- "",
1872
- ].join("\n");
1873
- const { responses, stderr } = runServer(dir, [
1874
- {
1875
- jsonrpc: "2.0",
1876
- id: 1,
1877
- method: "initialize",
1878
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1879
- },
1880
- {
1881
- jsonrpc: "2.0",
1882
- id: 2,
1883
- method: "tools/call",
1884
- params: {
1885
- name: "arch_diff",
1886
- arguments: { diff, fail_on_removed: true, verbosity: "compact" },
1887
- },
1888
- },
1889
- ]);
1890
- const result = responses.find((response) => response.id === 2)?.result;
1891
- assert.notEqual(result?.isError, true, stderr);
1892
- assert.equal(result?._meta?.exitCode, 1);
1893
- assert.equal(result?.structuredContent?.added?.[0]?.to, "src/b.ts");
1894
- assert.equal(result?.structuredContent?.removed?.[0]?.to, "src/c.ts");
1895
- assert.match(result?.structuredContent?.diagram ?? "", /flowchart LR/);
1896
- assert.match(result?.content?.[0]?.text ?? "", /1 added edge, 1 removed edge/);
1897
- }
1898
- finally {
1899
- rmSync(dir, { recursive: true, force: true });
1900
- }
1901
- });
1902
- test("MCP impact finds references to changed symbols", () => {
1903
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-impact-"));
1904
- try {
1905
- spawnSync("git", ["init", "-q"], { cwd: dir });
1906
- mkdirSync(join(dir, "src"), { recursive: true });
1907
- writeFileSync(join(dir, "src", "checkout.ts"), 'import { charge } from "./wallet";\n\nexport function pay() {\n return charge(10);\n}\n', "utf8");
1908
- const diff = [
1909
- "diff --git a/src/wallet.ts b/src/wallet.ts",
1910
- "--- a/src/wallet.ts",
1911
- "+++ b/src/wallet.ts",
1912
- "@@ -1,3 +1,3 @@",
1913
- "-export function charge(amount: number) {",
1914
- "+export function chargeCard(amount: number) {",
1915
- " return amount;",
1916
- " }",
1917
- "",
1918
- ].join("\n");
1919
- const { responses, stderr } = runServer(dir, [
1920
- {
1921
- jsonrpc: "2.0",
1922
- id: 1,
1923
- method: "initialize",
1924
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1925
- },
1926
- {
1927
- jsonrpc: "2.0",
1928
- id: 2,
1929
- method: "tools/call",
1930
- params: {
1931
- name: "impact",
1932
- arguments: { diff, verbosity: "compact" },
1933
- },
1934
- },
1935
- ]);
1936
- const result = responses.find((response) => response.id === 2)?.result;
1937
- assert.notEqual(result?.isError, true, stderr);
1938
- const names = result?.structuredContent?.symbols?.map((symbol) => symbol.name) ?? [];
1939
- assert.ok(names.includes("charge"), `symbols: ${names.join(", ")}`);
1940
- assert.ok(names.includes("chargeCard"), `symbols: ${names.join(", ")}`);
1941
- const reference = result?.structuredContent?.references?.find((item) => item.symbol === "charge");
1942
- assert.ok(reference, "charge reference missing");
1943
- assert.equal(reference.file, "src/checkout.ts");
1944
- assert.match(result?.content?.[0]?.text ?? "", /2 changed symbols, \d+ references? in \d+ scanned files?/);
1945
- }
1946
- finally {
1947
- rmSync(dir, { recursive: true, force: true });
1948
- }
1949
- });
1950
- test("MCP flaky reports a test that passes and fails across runs", () => {
1951
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-flaky-"));
1952
- try {
1953
- writeFileSync(join(dir, "flaky.cjs"), [
1954
- 'const { existsSync, readFileSync, writeFileSync } = require("node:fs");',
1955
- 'const count = existsSync("runs.txt") ? Number(readFileSync("runs.txt", "utf8")) : 0;',
1956
- 'writeFileSync("runs.txt", String(count + 1));',
1957
- "if (count === 0) {",
1958
- ' console.log("✔ alpha");',
1959
- "} else {",
1960
- ' console.log("✖ alpha");',
1961
- " process.exit(1);",
1962
- "}",
1963
- "",
1964
- ].join("\n"), "utf8");
1965
- const { responses, stderr } = runServer(dir, [
1966
- {
1967
- jsonrpc: "2.0",
1968
- id: 1,
1969
- method: "initialize",
1970
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
1971
- },
1972
- {
1973
- jsonrpc: "2.0",
1974
- id: 2,
1975
- method: "tools/call",
1976
- params: {
1977
- name: "flaky",
1978
- arguments: { runs: 2, command: "node flaky.cjs", verbosity: "compact" },
1979
- },
1980
- },
1981
- ]);
1982
- const result = responses.find((response) => response.id === 2)?.result;
1983
- assert.notEqual(result?.isError, true, stderr);
1984
- assert.equal(result?._meta?.exitCode, 0);
1985
- assert.equal(result?.structuredContent?.runs, 2);
1986
- assert.equal(result?.structuredContent?.parsed, true);
1987
- assert.equal(result?.structuredContent?.flaky?.length, 1);
1988
- assert.equal(result?.structuredContent?.flaky?.[0]?.name, "alpha");
1989
- assert.equal(result?.structuredContent?.flaky?.[0]?.passes, 1);
1990
- assert.equal(result?.structuredContent?.flaky?.[0]?.failures, 1);
1991
- assert.match(result?.content?.[0]?.text ?? "", /1 flaky, 0 failing across 2 runs/);
1992
- }
1993
- finally {
1994
- rmSync(dir, { recursive: true, force: true });
1995
- }
1996
- });
1997
- test("applyResultOptions caps findings and summarizes compactly", () => {
1998
- const findings = [1, 2, 3, 4, 5].map((n) => ({
1999
- severity: n === 1 ? "critical" : "warning",
2000
- location: `src/a.ts:${n}`,
2001
- text: `issue ${n}`,
2002
- }));
2003
- const base = {
2004
- content: [{ type: "text", text: "payload" }],
2005
- structuredContent: { findings },
2006
- };
2007
- const capped = applyResultOptions(base, { max_findings: 2 });
2008
- const payload = capped.structuredContent;
2009
- assert.equal(payload.findings.length, 2);
2010
- assert.equal(payload.truncated, true);
2011
- assert.equal(payload.totalFindings, 5);
2012
- assert.match(capped.content[0].text, /totalFindings/);
2013
- const compact = applyResultOptions(base, { verbosity: "compact" });
2014
- assert.match(compact.content[0].text, /5 findings/);
2015
- assert.equal(compact.structuredContent.findings.length, 5);
2016
- });
2017
- test("MCP handles logging/setLevel and advertises the capability", () => {
2018
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-logging-"));
2019
- try {
2020
- const { responses } = runServer(dir, [
2021
- {
2022
- jsonrpc: "2.0",
2023
- id: 1,
2024
- method: "initialize",
2025
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
2026
- },
2027
- { jsonrpc: "2.0", id: 2, method: "logging/setLevel", params: { level: "info" } },
2028
- ]);
2029
- const init = responses.find((response) => response.id === 1)?.result;
2030
- assert.deepEqual(init?.capabilities?.logging, {});
2031
- assert.deepEqual(responses.find((response) => response.id === 2)?.result, {});
2032
- }
2033
- finally {
2034
- rmSync(dir, { recursive: true, force: true });
2035
- }
2036
- });
2037
- test("MCP stops model-backed tools after the call budget", () => {
2038
- const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mcp-budget-"));
2039
- try {
2040
- const git = (args) => spawnSync("git", args, { cwd: dir, encoding: "utf8" });
2041
- git(["init"]);
2042
- git(["config", "user.email", "test@example.com"]);
2043
- git(["config", "user.name", "Test"]);
2044
- git(["config", "core.autocrlf", "false"]);
2045
- writeFileSync(join(dir, ".oc-pilot.json"), JSON.stringify({ engine: "openai", baseUrl: "http://127.0.0.1:9/v1", model: "test-model" }), "utf8");
2046
- writeFileSync(join(dir, "wallet.go"), "package main\n\nfunc main() {}\n", "utf8");
2047
- git(["add", "."]);
2048
- git(["commit", "-m", "init"]);
2049
- const { responses } = runServer(dir, [
2050
- {
2051
- jsonrpc: "2.0",
2052
- id: 1,
2053
- method: "initialize",
2054
- params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "test", version: "1" } },
2055
- },
2056
- { jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: "review", arguments: {} } },
2057
- { jsonrpc: "2.0", id: 3, method: "tools/call", params: { name: "review", arguments: {} } },
2058
- { jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "stats", arguments: {} } },
2059
- ], ["--max-calls", "1"]);
2060
- const blocked = responses.find((response) => response.id === 3)?.result;
2061
- assert.equal(blocked?.isError, true);
2062
- assert.match(blocked?.content?.[0]?.text ?? "", /budget/i);
2063
- const offline = responses.find((response) => response.id === 4)?.result;
2064
- assert.doesNotMatch(offline?.content?.[0]?.text ?? "", /budget/i);
2065
- }
2066
- finally {
2067
- rmSync(dir, { recursive: true, force: true });
2068
- }
2069
- });
2070
- test("patchSummary describes a patch and applyResultOptions caps its size", () => {
2071
- const patch = [
2072
- "diff --git a/src/a.ts b/src/a.ts",
2073
- "--- a/src/a.ts",
2074
- "+++ b/src/a.ts",
2075
- "@@ -1,3 +1,4 @@",
2076
- " const a = 1;",
2077
- "-const b = 2;",
2078
- "+const b = 3;",
2079
- "+const c = 4;",
2080
- "diff --git a/src/b.ts b/src/b.ts",
2081
- "--- a/src/b.ts",
2082
- "+++ b/src/b.ts",
2083
- "@@ -1 +1 @@",
2084
- "-old",
2085
- "+new",
2086
- "",
2087
- ].join("\n");
2088
- const summary = patchSummary(patch);
2089
- assert.equal(summary.files.length, 2);
2090
- assert.equal(summary.additions, 3);
2091
- assert.equal(summary.deletions, 2);
2092
- assert.equal(summary.hunks, 2);
2093
- assert.equal(summary.bytes, patch.length);
2094
- const result = applyResultOptions({ content: [], structuredContent: { applied: false, patch } }, { verbosity: "compact" });
2095
- const structured = result.structuredContent;
2096
- assert.equal(structured.files.length, 2);
2097
- assert.equal(structured.patchStats.additions, 3);
2098
- const text = result.content[0]?.text ?? "";
2099
- assert.match(text, /fix 2 files/);
2100
- assert.match(text, /not applied/);
2101
- const huge = "x".repeat(200_001);
2102
- const capped = applyResultOptions({ content: [], structuredContent: { applied: true, patch: huge } }, {});
2103
- const payload = capped.structuredContent;
2104
- assert.equal(payload.patchTruncated, true);
2105
- assert.equal(payload.patchBytes, 200_001);
2106
- assert.equal(payload.patch.length, 200_000);
2107
- });
2108
- //# sourceMappingURL=mcp.test.js.map