@boyingliu01/xp-gate 0.38.126 → 0.39.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 (421) hide show
  1. package/README.md +93 -0
  2. package/adapters/gate-3.sh +13 -2
  3. package/adapters/python.sh +36 -38
  4. package/bin/xp-gate.js +11 -0
  5. package/build-integrity/gate-10-lines.ts +98 -0
  6. package/build-integrity/gate-10.ts +98 -109
  7. package/build-integrity/quote-masker.ts +17 -3
  8. package/gate-3.sh +13 -2
  9. package/gates/common-process.ts +116 -34
  10. package/gates/common.ts +51 -15
  11. package/gates/gate-3.ts +166 -61
  12. package/gates/gate-8.ts +76 -24
  13. package/gates/gate-9.ts +276 -82
  14. package/gates/pbt-detect.ts +70 -39
  15. package/gates/python-health.ts +236 -98
  16. package/gates/test-layers.ts +103 -30
  17. package/hooks/gate-3.sh +13 -2
  18. package/hooks/gate-entries/gate-1-entry.sh +10 -1
  19. package/hooks/gate-entries/gate-5-entry.sh +5 -1
  20. package/hooks/lib/validate-code-walkthrough.cjs +324 -99
  21. package/hooks/pre-commit +52 -0
  22. package/hooks/pre-push +54 -3
  23. package/lib/agent-runtime-journal.js +104 -37
  24. package/lib/arch.js +6 -0
  25. package/lib/baseline.js +329 -201
  26. package/lib/check.js +38 -2
  27. package/lib/doctor-constants.js +43 -0
  28. package/lib/doctor.js +2008 -1001
  29. package/lib/flaky.js +178 -79
  30. package/lib/gate-runner.js +110 -63
  31. package/lib/init.js +6 -0
  32. package/lib/language-capability-surfaces.js +5 -2
  33. package/lib/language-registry.js +608 -0
  34. package/lib/language-tools.js +487 -1018
  35. package/lib/phase-transition.js +646 -446
  36. package/lib/prepush-evidence.js +174 -0
  37. package/lib/sprint-audit.js +52 -22
  38. package/lib/sprint-discovery.js +66 -35
  39. package/lib/sprint-format.js +114 -0
  40. package/lib/sprint-init.js +372 -118
  41. package/lib/sprint-status.js +134 -90
  42. package/lib/star-notice.js +346 -0
  43. package/lib/tool-display.js +52 -0
  44. package/lib/tool-install.js +179 -0
  45. package/lib/uninstall.js +331 -188
  46. package/mock-policy/gate-m3.ts +74 -23
  47. package/mock-policy/mock-decision-engine.ts +21 -7
  48. package/mock-policy/scope-scanner.ts +128 -69
  49. package/mutation/detect-ai-test.ts +20 -12
  50. package/mutation/gate-m.ts +6 -2
  51. package/mutation/init-baseline.ts +49 -13
  52. package/mutation/runners/go-mutant-runner.ts +7 -49
  53. package/mutation/runners/gremlins-runner.ts +53 -18
  54. package/mutation/runners/mutmut-runner.ts +455 -163
  55. package/mutation/runners/pitest-runner.ts +85 -131
  56. package/mutation/runners/spawn-with-capture.ts +304 -0
  57. package/mutation/runners/stryker-runner.ts +14 -55
  58. package/mutation/update-baseline.ts +25 -18
  59. package/package.json +20 -8
  60. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  61. package/plugins/claude-code/bin/delphi-review-guard.sh +12 -61
  62. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +6 -11
  63. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  64. package/plugins/claude-code/skills/reinstall-xp-gate/.architecture-skip +8 -0
  65. package/plugins/claude-code/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
  66. package/plugins/claude-code/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
  67. package/plugins/claude-code/skills/reinstall-xp-gate/LICENSE +21 -0
  68. package/plugins/claude-code/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
  69. package/plugins/claude-code/skills/reinstall-xp-gate/README.md +167 -0
  70. package/plugins/claude-code/skills/reinstall-xp-gate/SKILL.md +271 -0
  71. package/plugins/claude-code/skills/reinstall-xp-gate/TODO.md +253 -0
  72. package/plugins/claude-code/skills/reinstall-xp-gate/VERSION +1 -0
  73. package/plugins/claude-code/skills/reinstall-xp-gate/package.json +28 -0
  74. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
  75. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
  76. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
  77. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
  78. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
  79. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
  80. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
  81. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
  82. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
  83. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
  84. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
  85. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
  86. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
  87. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
  88. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
  89. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/probes.mjs +102 -0
  90. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
  91. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
  92. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
  93. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
  94. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
  95. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +161 -0
  96. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
  97. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
  98. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
  99. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
  100. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
  101. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
  102. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
  103. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
  104. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/reinstall.mjs +297 -0
  105. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
  106. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/verify.mjs +222 -0
  107. package/plugins/claude-code/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
  108. package/plugins/claude-code/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
  109. package/plugins/claude-code/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
  110. package/plugins/claude-code/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
  111. package/plugins/claude-code/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
  112. package/plugins/claude-code/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
  113. package/plugins/claude-code/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
  114. package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
  115. package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
  116. package/plugins/claude-code/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
  117. package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
  118. package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc.test.mjs +243 -0
  119. package/plugins/claude-code/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
  120. package/plugins/claude-code/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
  121. package/plugins/claude-code/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
  122. package/plugins/claude-code/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
  123. package/plugins/claude-code/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
  124. package/plugins/claude-code/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
  125. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
  126. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
  127. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
  128. package/plugins/claude-code/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
  129. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  130. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  131. package/plugins/dsh/package.json +1 -1
  132. package/plugins/dsh/scripts/prepack.cjs +43 -18
  133. package/plugins/dsh/scripts/verify-skill-provider.mjs +39 -14
  134. package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +6 -11
  135. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  136. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  137. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  138. package/plugins/opencode/index.ts +337 -123
  139. package/plugins/opencode/package.json +1 -1
  140. package/plugins/opencode/scripts/prepack.cjs +41 -16
  141. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +6 -11
  142. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  143. package/plugins/opencode/skills/reinstall-xp-gate/.architecture-skip +8 -0
  144. package/plugins/opencode/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
  145. package/plugins/opencode/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
  146. package/plugins/opencode/skills/reinstall-xp-gate/LICENSE +21 -0
  147. package/plugins/opencode/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
  148. package/plugins/opencode/skills/reinstall-xp-gate/README.md +167 -0
  149. package/plugins/opencode/skills/reinstall-xp-gate/SKILL.md +271 -0
  150. package/plugins/opencode/skills/reinstall-xp-gate/TODO.md +253 -0
  151. package/plugins/opencode/skills/reinstall-xp-gate/VERSION +1 -0
  152. package/plugins/opencode/skills/reinstall-xp-gate/package.json +28 -0
  153. package/plugins/opencode/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
  154. package/plugins/opencode/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
  155. package/plugins/opencode/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
  156. package/plugins/opencode/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
  157. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
  158. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
  159. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
  160. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
  161. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
  162. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
  163. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
  164. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
  165. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
  166. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
  167. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
  168. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/probes.mjs +102 -0
  169. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
  170. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
  171. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
  172. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
  173. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
  174. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +161 -0
  175. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
  176. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
  177. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
  178. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
  179. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
  180. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
  181. package/plugins/opencode/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
  182. package/plugins/opencode/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
  183. package/plugins/opencode/skills/reinstall-xp-gate/scripts/reinstall.mjs +297 -0
  184. package/plugins/opencode/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
  185. package/plugins/opencode/skills/reinstall-xp-gate/scripts/verify.mjs +222 -0
  186. package/plugins/opencode/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
  187. package/plugins/opencode/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
  188. package/plugins/opencode/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
  189. package/plugins/opencode/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
  190. package/plugins/opencode/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
  191. package/plugins/opencode/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
  192. package/plugins/opencode/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
  193. package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
  194. package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
  195. package/plugins/opencode/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
  196. package/plugins/opencode/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
  197. package/plugins/opencode/skills/reinstall-xp-gate/tests/proc.test.mjs +243 -0
  198. package/plugins/opencode/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
  199. package/plugins/opencode/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
  200. package/plugins/opencode/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
  201. package/plugins/opencode/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
  202. package/plugins/opencode/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
  203. package/plugins/opencode/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
  204. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
  205. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
  206. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
  207. package/plugins/opencode/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
  208. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  209. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  210. package/plugins/qoder/bin/sprint-flow-guard.sh +12 -60
  211. package/plugins/qoder/plugin.json +1 -1
  212. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +6 -11
  213. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  214. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  215. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  216. package/plugins/shared/README.md +3 -0
  217. package/plugins/shared/bin/delphi-review-guard.sh +68 -0
  218. package/principles/adapters/control-nesting.ts +481 -168
  219. package/principles/adapters/cpp.ts +61 -22
  220. package/principles/adapters/csharp.ts +183 -66
  221. package/principles/adapters/dart.ts +11 -1
  222. package/principles/adapters/duplication.ts +49 -16
  223. package/principles/adapters/import-clause.ts +62 -15
  224. package/principles/adapters/java.ts +199 -70
  225. package/principles/adapters/line-comment.ts +18 -0
  226. package/principles/adapters/member-scan.ts +50 -8
  227. package/principles/adapters/php.ts +232 -103
  228. package/principles/adapters/python.ts +25 -18
  229. package/principles/adapters/quote-state.ts +21 -8
  230. package/principles/adapters/typescript-mask.ts +276 -0
  231. package/principles/adapters/typescript.ts +206 -200
  232. package/principles/analyzer.ts +16 -6
  233. package/principles/baseline-prune.ts +18 -8
  234. package/principles/baseline.ts +28 -11
  235. package/principles/boy-scout-usage.ts +26 -0
  236. package/principles/boy-scout.ts +261 -180
  237. package/principles/config.ts +183 -57
  238. package/principles/direct-execution.ts +24 -12
  239. package/principles/lint-baseline.ts +235 -122
  240. package/principles/rules/arch/dependency.ts +34 -25
  241. package/principles/rules/arch/shared.ts +24 -20
  242. package/principles/rules/clean-code/deep-nesting.ts +23 -13
  243. package/principles/rules/clean-code/god-class.ts +67 -41
  244. package/principles/rules/clean-code/large-file.ts +30 -23
  245. package/principles/rules/clean-code/long-function.ts +51 -37
  246. package/principles/rules/clean-code/magic-numbers.ts +51 -36
  247. package/principles/rules/clean-code/many-exports.ts +46 -29
  248. package/principles/rules/clean-code/missing-error-handling.ts +38 -20
  249. package/principles/rules/clean-code/too-many-params.ts +41 -22
  250. package/principles/rules/function-source.ts +62 -0
  251. package/principles/rules/solid/dip.ts +10 -6
  252. package/principles/rules/solid/isp.ts +64 -24
  253. package/principles/rules/solid/lsp.ts +66 -18
  254. package/principles/rules/solid/ocp.ts +29 -13
  255. package/principles/rules/solid/srp.ts +34 -18
  256. package/principles/warnings-count.ts +43 -0
  257. package/scripts/__tests__/prepush-source-classification.test.js +129 -0
  258. package/scripts/delphi-config-read.cjs +245 -0
  259. package/scripts/delphi-external-review.cjs +410 -585
  260. package/scripts/delphi-json-extract.cjs +108 -0
  261. package/scripts/delphi-model-validation.cjs +297 -0
  262. package/scripts/delphi-prompts.cjs +55 -0
  263. package/scripts/delphi-repo-tools.cjs +273 -0
  264. package/scripts/delphi-seat-calibration.cjs +204 -0
  265. package/scripts/run-bats-ci.cjs +240 -97
  266. package/scripts/sync-package-content.js +18 -2
  267. package/skills/delphi-review/.delphi-config.json.example +6 -11
  268. package/skills/delphi-review/AGENTS.md +1 -1
  269. package/skills/sprint-flow/AGENTS.md +1 -1
  270. package/skills/test-specification-alignment/AGENTS.md +1 -1
  271. package/lib/__tests__/agent-runtime-journal.test.js +0 -326
  272. package/lib/__tests__/arch-config-template.test.js +0 -190
  273. package/lib/__tests__/arch.test.js +0 -430
  274. package/lib/__tests__/assertion-debt.test.js +0 -99
  275. package/lib/__tests__/audit-cli-contract.test.ts +0 -117
  276. package/lib/__tests__/audit-log.test.ts +0 -107
  277. package/lib/__tests__/audit-skip-reasons.test.ts +0 -143
  278. package/lib/__tests__/baseline-completeness.test.js +0 -264
  279. package/lib/__tests__/baseline-shell-scope.test.js +0 -60
  280. package/lib/__tests__/baseline-unevaluated.test.js +0 -142
  281. package/lib/__tests__/baseline.test.js +0 -212
  282. package/lib/__tests__/bootstrap.test.js +0 -60
  283. package/lib/__tests__/check-alignment-cli.test.mjs +0 -94
  284. package/lib/__tests__/check-alignment-reasons.test.mjs +0 -101
  285. package/lib/__tests__/check-all-skip-accounting.test.js +0 -171
  286. package/lib/__tests__/check-changed-brief.test.js +0 -63
  287. package/lib/__tests__/check-normalize-exit.test.js +0 -24
  288. package/lib/__tests__/check-single-file.test.js +0 -114
  289. package/lib/__tests__/check-tools-list.test.js +0 -155
  290. package/lib/__tests__/check-version.test.js +0 -463
  291. package/lib/__tests__/coverage-scope.test.js +0 -140
  292. package/lib/__tests__/coverage-threshold.test.js +0 -80
  293. package/lib/__tests__/crap-cli.test.js +0 -87
  294. package/lib/__tests__/crap.test.js +0 -494
  295. package/lib/__tests__/debt-classify.test.js +0 -78
  296. package/lib/__tests__/delphi-channel-doctor.test.js +0 -116
  297. package/lib/__tests__/delphi-channel-uninstall.test.js +0 -128
  298. package/lib/__tests__/delphi-channel.test.js +0 -109
  299. package/lib/__tests__/delphi-setup.test.js +0 -203
  300. package/lib/__tests__/deploy-manifest-check-wired.test.js +0 -138
  301. package/lib/__tests__/deploy-manifest-completeness.test.js +0 -151
  302. package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +0 -40
  303. package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +0 -74
  304. package/lib/__tests__/deploy-manifest-projection.test.js +0 -66
  305. package/lib/__tests__/deploy-manifest-shell-parity.test.js +0 -108
  306. package/lib/__tests__/deploy-manifest.test.js +0 -97
  307. package/lib/__tests__/detect-deps-dsh-profile.test.js +0 -323
  308. package/lib/__tests__/detect-deps-gate-identity.test.js +0 -135
  309. package/lib/__tests__/detect-deps.test.js +0 -655
  310. package/lib/__tests__/doctor-469-hook-env.test.js +0 -211
  311. package/lib/__tests__/doctor-arch-tools.test.js +0 -169
  312. package/lib/__tests__/doctor-audit-ledger.test.js +0 -61
  313. package/lib/__tests__/doctor-brief.test.js +0 -59
  314. package/lib/__tests__/doctor-delphi.test.js +0 -628
  315. package/lib/__tests__/doctor-drift-direction.test.js +0 -104
  316. package/lib/__tests__/doctor-drift-round2.test.js +0 -215
  317. package/lib/__tests__/doctor-exec-retry.test.js +0 -162
  318. package/lib/__tests__/doctor-executed-surface.test.js +0 -230
  319. package/lib/__tests__/doctor-helpers.test.js +0 -139
  320. package/lib/__tests__/doctor-hook-drift.test.js +0 -329
  321. package/lib/__tests__/doctor-hook-signatures.test.js +0 -65
  322. package/lib/__tests__/doctor-machine-mutation.test.js +0 -116
  323. package/lib/__tests__/doctor-module-drift.test.js +0 -212
  324. package/lib/__tests__/doctor-module-resolution-parity.test.js +0 -463
  325. package/lib/__tests__/doctor-path-equivalence.test.js +0 -70
  326. package/lib/__tests__/doctor-repair-boundary.test.js +0 -52
  327. package/lib/__tests__/doctor-signature-stability.test.js +0 -55
  328. package/lib/__tests__/doctor-spawn-capability.test.js +0 -116
  329. package/lib/__tests__/doctor-timeout-partial.test.js +0 -79
  330. package/lib/__tests__/doctor-tool-delegation.test.js +0 -156
  331. package/lib/__tests__/doctor-tui-skill-freshness.test.js +0 -385
  332. package/lib/__tests__/doctor.test.js +0 -1320
  333. package/lib/__tests__/find-bash-wsl.test.js +0 -121
  334. package/lib/__tests__/flaky.test.js +0 -128
  335. package/lib/__tests__/foreign-hooks-global.test.js +0 -125
  336. package/lib/__tests__/gate-audit-skip.test.ts +0 -81
  337. package/lib/__tests__/gate-audit.test.ts +0 -440
  338. package/lib/__tests__/gate-coverage-hook-floor.test.js +0 -94
  339. package/lib/__tests__/gate-coverage.test.js +0 -204
  340. package/lib/__tests__/gate-entry-provenance.test.js +0 -71
  341. package/lib/__tests__/gate-numbering.test.js +0 -79
  342. package/lib/__tests__/gate-rules.test.js +0 -58
  343. package/lib/__tests__/gate-runner-tsx-invocation.test.js +0 -149
  344. package/lib/__tests__/gate-runner-verdict.test.js +0 -105
  345. package/lib/__tests__/gate-runner.test.js +0 -371
  346. package/lib/__tests__/gate2-verdict.test.js +0 -183
  347. package/lib/__tests__/helpers/lib-sandbox.cjs +0 -55
  348. package/lib/__tests__/hook-health-path.test.js +0 -109
  349. package/lib/__tests__/hook-health.test.js +0 -85
  350. package/lib/__tests__/init-gitignore.test.js +0 -204
  351. package/lib/__tests__/init-gitleaks-notice.test.js +0 -57
  352. package/lib/__tests__/init.test.js +0 -530
  353. package/lib/__tests__/install-cmd.test.js +0 -6
  354. package/lib/__tests__/install-sh-deploy-manifest.test.js +0 -80
  355. package/lib/__tests__/install-skill-full-dir.test.js +0 -194
  356. package/lib/__tests__/install-skill.test.js +0 -416
  357. package/lib/__tests__/install-tools-repair.test.js +0 -263
  358. package/lib/__tests__/issue-519-phase-transition-guard.test.js +0 -233
  359. package/lib/__tests__/issue-566-sync-hooks-backup.test.js +0 -228
  360. package/lib/__tests__/issue-583-hook-deploy-log.test.js +0 -121
  361. package/lib/__tests__/issue-586-principles-cmdline.test.js +0 -218
  362. package/lib/__tests__/issue-589-check-all-gate3.test.js +0 -190
  363. package/lib/__tests__/issue-590-archlint-vacuous-pass.test.js +0 -138
  364. package/lib/__tests__/issue-618-gate-not-run.test.js +0 -100
  365. package/lib/__tests__/jscpd-entry-resolution.test.js +0 -143
  366. package/lib/__tests__/language-capability.test.js +0 -318
  367. package/lib/__tests__/language-tools-build-file-install.test.js +0 -82
  368. package/lib/__tests__/language-tools-detect.test.js +0 -301
  369. package/lib/__tests__/migrate.test.js +0 -232
  370. package/lib/__tests__/mirror-manifest.test.js +0 -64
  371. package/lib/__tests__/mirror-sync.test.js +0 -803
  372. package/lib/__tests__/next-sprint.test.js +0 -231
  373. package/lib/__tests__/npm-package.test.js +0 -140
  374. package/lib/__tests__/phase-transition.test.js +0 -1136
  375. package/lib/__tests__/principles-csharp-coverage.test.js +0 -227
  376. package/lib/__tests__/principles-directory.test.js +0 -87
  377. package/lib/__tests__/qoder-delphi-agents.test.js +0 -316
  378. package/lib/__tests__/retro-gate-m.test.js +0 -144
  379. package/lib/__tests__/retro.test.js +0 -131
  380. package/lib/__tests__/rework.test.js +0 -127
  381. package/lib/__tests__/rollback.test.js +0 -183
  382. package/lib/__tests__/runtime-journal.test.js +0 -164
  383. package/lib/__tests__/sastd-client.test.js +0 -514
  384. package/lib/__tests__/shared-paths-lazy-home.test.js +0 -67
  385. package/lib/__tests__/shared-paths.test.js +0 -130
  386. package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +0 -69
  387. package/lib/__tests__/shared-utils.test.js +0 -180
  388. package/lib/__tests__/skill-flags.test.js +0 -48
  389. package/lib/__tests__/slo.test.js +0 -89
  390. package/lib/__tests__/sprint-audit.test.js +0 -207
  391. package/lib/__tests__/sprint-discovery.test.ts +0 -366
  392. package/lib/__tests__/sprint-state-manager.test.js +0 -310
  393. package/lib/__tests__/sprint-status-rework-704.test.js +0 -149
  394. package/lib/__tests__/sprint-status-rework.test.js +0 -329
  395. package/lib/__tests__/sprint-status.test.js +0 -193
  396. package/lib/__tests__/sprint-status.test.ts +0 -213
  397. package/lib/__tests__/test-alignment-java-702.test.ts +0 -177
  398. package/lib/__tests__/test-alignment-range-guard.test.ts +0 -82
  399. package/lib/__tests__/test-alignment.test.ts +0 -853
  400. package/lib/__tests__/tool-audit-collect.test.js +0 -184
  401. package/lib/__tests__/tool-audit-fixtures.js +0 -87
  402. package/lib/__tests__/tool-audit-latest.test.js +0 -84
  403. package/lib/__tests__/tool-audit.test.js +0 -428
  404. package/lib/__tests__/tsconfig.json +0 -8
  405. package/lib/__tests__/tsx-resolution.test.js +0 -89
  406. package/lib/__tests__/ui-detector.test.ts +0 -459
  407. package/lib/__tests__/ui-review.test.ts +0 -132
  408. package/lib/__tests__/uninstall-global-residue.test.js +0 -545
  409. package/lib/__tests__/uninstall-skill.test.js +0 -189
  410. package/lib/__tests__/uninstall.test.js +0 -717
  411. package/lib/__tests__/update-hooks.test.js +0 -737
  412. package/lib/__tests__/update-skill-flags.test.js +0 -78
  413. package/lib/__tests__/update-skill.test.js +0 -644
  414. package/lib/__tests__/upgrade-exec.test.js +0 -273
  415. package/lib/__tests__/upgrade-skill-sync.test.js +0 -65
  416. package/lib/__tests__/upgrade.test.js +0 -78
  417. package/lib/__tests__/windows-bash-probe.test.js +0 -123
  418. package/lib/check-alignment-runner.cjs +0 -97
  419. package/lib/coverage-total.sh +0 -92
  420. package/lib/layer-baseline.cjs +0 -94
  421. package/lib/mattpocock-license-verdict.json +0 -7
@@ -1,803 +0,0 @@
1
- /**
2
- * TDD: written RED first (per AGENTS.md TDD-GATE spec).
3
- * @test REQ-713 Mirror checks must ignore untracked build artifacts, and a
4
- * one-shot sync must bring every mirror back to byte parity
5
- * @intent The hook-lib mirror check failed on a machine where `githooks/lib`
6
- * held an untracked `__pycache__/` — Python byte-compiled the helper during a
7
- * test run. The canonical file set was otherwise byte-identical to the mirror.
8
- * A false failure here costs a real fix cycle at commit time, which is exactly
9
- * the rework this task set out to remove. The check must compare what git
10
- * tracks, and a single command must repair drift instead of hand-copying.
11
- * @covers AC-713-01
12
- * @covers AC-713-02
13
- * @covers AC-713-03
14
- * @covers AC-713-04
15
- * @covers AC-713-05
16
- * @covers AC-713-06
17
- */
18
- 'use strict';
19
-
20
- const fs = require('fs');
21
- const os = require('os');
22
- const path = require('path');
23
- // Deliberately the MODULE, not `const { execFileSync } = ...`: the spy in the
24
- // "git invocations per pair" block has to replace `childProcess.execFileSync`,
25
- // and a load-time destructure would keep calling the pre-spy binding. That is
26
- // the same trap `init.test.js` documents — but there it was the SUBJECT holding
27
- // the stale reference; here it is the test.
28
- const childProcess = require('child_process');
29
- const { execFileSync } = childProcess;
30
-
31
- const {
32
- collectMirrorPairs,
33
- diffTrees,
34
- syncMirrors,
35
- handleSyncMirrors,
36
- SYNC_EXCLUDES,
37
- KNOWN_PAIRS,
38
- HAND_LISTED_PAIRS,
39
- assertPairsResolved,
40
- } = require('../mirror-sync');
41
-
42
- /**
43
- * Directories that are mirrors of a canonical tree rather than this package's own
44
- * source.
45
- *
46
- * `bin/`, `lib/` and `scripts/` are the package's own code, not copies.
47
- *
48
- * `hooks/`, `plugins/` and `gates/` are supervised ELSEWHERE and are deliberately
49
- * omitted here rather than being reported as unsupervised:
50
- * - `hooks/` -> HOOK_MIRROR_FILES in scripts/check-hook-mirror.sh (a curated
51
- * file list, not the whole tree; same reason KNOWN_PAIRS omits it)
52
- * - `plugins/`-> syncPlugins in sync-package-content.js
53
- * - `gates/` -> listed in files[] but the directory does not exist at all, so
54
- * there is nothing to compare. Left alone: removing a stale
55
- * files[] entry is a packaging change, not a mirror one.
56
- * Including them would make this case report three permanent failures that no
57
- * mirror work could ever fix.
58
- */
59
- const MIRROR_DIR_CANDIDATES = [
60
- 'adapters',
61
- 'skills',
62
- 'principles',
63
- 'mutation',
64
- 'mock-policy',
65
- 'build-integrity',
66
- ];
67
-
68
- /** Package-relative mirror dirs supervised by an explicit pair, not a generator. */
69
- const HAND_LISTED_MIRRORS = HAND_LISTED_PAIRS.map((pair) =>
70
- pair.mirror.replace(/^src\/npm-package\//, '')
71
- );
72
-
73
- let TMP_REPO;
74
-
75
- /**
76
- * Build the empty git repository ONCE, then copy it per case.
77
- *
78
- * Every case writes its own fixture into a pristine repo (and `afterEach`
79
- * deletes the tree), so each one genuinely needs a fresh repo -- but building
80
- * that repo means three git processes (`init` + two `config`), measured at
81
- * 1.4-5.0 s per case here (median ~2.6 s). Across 17 cases that was most of this
82
- * file's runtime.
83
- *
84
- * Copying a prepared `.git` measured 1.1 s/case less (median 1.5 s vs 2.6 s) and
85
- * keeps everything the cases rely on: verified after `fs.cpSync` that `git add
86
- * -A -f` succeeds and `git config user.email` still reports the template
87
- * identity. It also narrows the spread -- copying varied 0.9-2.2 s against
88
- * `git init`'s 1.4-5.0 s.
89
- *
90
- * No `core.hooksPath` override is needed: this file never runs `git commit`, so
91
- * this machine's global hooks cannot fire (the only `commit` occurrence is prose).
92
- */
93
- let repoTemplate;
94
-
95
- beforeAll(() => {
96
- repoTemplate = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-tpl-'));
97
- execFileSync('git', ['init', '-q'], { cwd: repoTemplate });
98
- execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: repoTemplate });
99
- execFileSync('git', ['config', 'user.name', 'Test'], { cwd: repoTemplate });
100
- });
101
-
102
- afterAll(() => {
103
- if (repoTemplate) fs.rmSync(repoTemplate, { recursive: true, force: true });
104
- });
105
-
106
- beforeEach(() => {
107
- TMP_REPO = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-'));
108
- fs.cpSync(repoTemplate, TMP_REPO, { recursive: true });
109
- });
110
-
111
- afterEach(() => {
112
- fs.rmSync(TMP_REPO, { recursive: true, force: true });
113
- });
114
-
115
- /**
116
- * Write a file, creating parent directories.
117
- * @param {string} root
118
- * @param {string} rel
119
- * @param {string} content
120
- */
121
- function write(root, rel, content) {
122
- const full = path.join(root, rel);
123
- try {
124
- fs.mkdirSync(path.dirname(full), { recursive: true });
125
- fs.writeFileSync(full, content);
126
- } catch (err) {
127
- // Swallowing this would turn a broken fixture into a confusing assertion
128
- // failure further down ("expected undefined"), so rethrow with the path that
129
- // actually failed. The rule wants the IO handled, not hidden.
130
- throw new Error(`failed to write fixture ${rel}: ${err instanceof Error ? err.message : String(err)}`);
131
- }
132
- }
133
-
134
- /**
135
- * Stage everything so the files count as tracked.
136
- * @param {string} root
137
- */
138
- function trackAll(root) {
139
- execFileSync('git', ['add', '-A', '-f'], { cwd: root });
140
- }
141
-
142
- /**
143
- * Stage the canonical tree and `.gitignore`, leaving the mirror untracked.
144
- *
145
- * `trackAll` cannot be used for the generated-mirror cases: its `-f` overrides
146
- * `.gitignore`, so `mirror/` gets staged and the "the mirror is untracked" premise
147
- * disappears. Verified in a scratch repo: `git add -A -f` lists `mirror/a.sh` in
148
- * `git ls-files` even with `mirror/` ignored.
149
- *
150
- * @param {string} root
151
- * @param {string} canonical directory to track
152
- */
153
- function trackCanonicalOnly(root, canonical) {
154
- execFileSync('git', ['add', '--', '.gitignore', canonical], { cwd: root });
155
- }
156
-
157
- describe('diffTrees — git invocations per pair', () => {
158
- /**
159
- * Each `git` launch costs ~120ms on Windows (measured: 10 launches averaged
160
- * 120ms). `diffTrees` used to launch one process per side, so every pair paid
161
- * twice, and a test asserting three pairs paid six times. The count is the
162
- * contract this block pins: it is the difference between a suite that finishes
163
- * and one that does not, and it is invisible to any assertion about *results*.
164
- *
165
- * Counted by spying on the real module, not by timing: timing on this machine
166
- * is noise-dominated (load 80-100%), the count is deterministic.
167
- */
168
- let spawnCount;
169
-
170
- beforeEach(() => {
171
- spawnCount = 0;
172
- const real = childProcess.execFileSync;
173
- vi.spyOn(childProcess, 'execFileSync').mockImplementation((cmd, args, opts) => {
174
- if (cmd === 'git') spawnCount += 1;
175
- return real(cmd, args, opts);
176
- });
177
- });
178
-
179
- afterEach(() => {
180
- vi.restoreAllMocks();
181
- });
182
-
183
- it('reads both sides of one pair in a single git call', () => {
184
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
185
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
186
- trackAll(TMP_REPO);
187
-
188
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
189
- expect(diff.inSync).toBe(true);
190
- // One query for both sides. Two would still be correct, and that is exactly
191
- // why this needs a test: nothing about the RESULT changes when it regresses.
192
- expect(spawnCount).toBe(1);
193
- });
194
-
195
- it('falls back to a disk walk when the directory is not a checkout', () => {
196
- // The merged read added this branch: one failed `git ls-files` now has to
197
- // answer for BOTH sides. If the fallback returned early for only one of them,
198
- // the other side would compare a disk walk against an empty set and report
199
- // every file as missing -- a crash-shaped bug dressed as drift.
200
- const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'mirror-sync-nogit-'));
201
- try {
202
- fs.mkdirSync(path.join(outside, 'a'), { recursive: true });
203
- fs.mkdirSync(path.join(outside, 'b'), { recursive: true });
204
- fs.writeFileSync(path.join(outside, 'a', 'x.sh'), 'echo x\n');
205
- fs.writeFileSync(path.join(outside, 'b', 'x.sh'), 'echo x\n');
206
-
207
- expect(diffTrees(outside, 'a', 'b').inSync).toBe(true);
208
-
209
- fs.writeFileSync(path.join(outside, 'b', 'x.sh'), 'echo DIFFERENT\n');
210
- const bad = diffTrees(outside, 'a', 'b');
211
- expect(bad.inSync).toBe(false);
212
- expect(bad.differing).toEqual(['x.sh']);
213
- expect(bad.missing).toEqual([]);
214
- } finally {
215
- fs.rmSync(outside, { recursive: true, force: true });
216
- }
217
- });
218
-
219
- it('does not grow linearly when the caller asks about several pairs', () => {
220
- write(TMP_REPO, 'c1/a.sh', 'echo a\n');
221
- write(TMP_REPO, 'm1/a.sh', 'echo a\n');
222
- write(TMP_REPO, 'c2/b.sh', 'echo b\n');
223
- write(TMP_REPO, 'm2/b.sh', 'echo b\n');
224
- trackAll(TMP_REPO);
225
-
226
- expect(diffTrees(TMP_REPO, 'c1', 'm1').inSync).toBe(true);
227
- expect(spawnCount).toBe(1);
228
- expect(diffTrees(TMP_REPO, 'c2', 'm2').inSync).toBe(true);
229
- expect(spawnCount).toBe(2);
230
- });
231
- });
232
-
233
- describe('diffTrees — AC-713-01 untracked artifacts are not drift', () => {
234
- it('ignores an untracked build artifact in the canonical tree', () => {
235
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
236
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
237
- // The artifact that broke the real check: untracked, gitignored.
238
- write(TMP_REPO, 'canonical/__pycache__/helper.pyc', 'binary');
239
- write(TMP_REPO, '.gitignore', '__pycache__/\n');
240
- trackAll(TMP_REPO);
241
-
242
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
243
- expect(diff.missing).toEqual([]);
244
- expect(diff.differing).toEqual([]);
245
- expect(diff.inSync).toBe(true);
246
- });
247
-
248
- it('still reports a genuinely missing mirrored file', () => {
249
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
250
- write(TMP_REPO, 'canonical/b.sh', 'echo b\n');
251
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
252
- trackAll(TMP_REPO);
253
-
254
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
255
- expect(diff.inSync).toBe(false);
256
- expect(diff.missing).toContain('b.sh');
257
- });
258
-
259
- it('reports byte differences, not just missing files', () => {
260
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
261
- write(TMP_REPO, 'mirror/a.sh', 'echo CHANGED\n');
262
- trackAll(TMP_REPO);
263
-
264
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
265
- expect(diff.inSync).toBe(false);
266
- expect(diff.differing).toContain('a.sh');
267
- });
268
-
269
- it('excludes declared noise directories even when they are tracked', () => {
270
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
271
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
272
- write(TMP_REPO, 'canonical/node_modules/x.js', 'x');
273
- write(TMP_REPO, '.gitignore', 'node_modules/\n');
274
- trackAll(TMP_REPO);
275
-
276
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
277
- expect(diff.inSync).toBe(true);
278
- expect(SYNC_EXCLUDES).toContain('node_modules');
279
- });
280
- });
281
-
282
- describe('diffTrees — per-pair excludes', () => {
283
- it('honours a pair-specific exclude, matching the guard script it mirrors', () => {
284
- // The mechanism under test is the per-pair `exclude` option. It used to be
285
- // demonstrated with `__tests__`, but that is now a GLOBAL rule (MIRROR_EXCLUDES)
286
- // because the generator never copies test code for any pair -- keeping the old
287
- // example would assert that an undeclared `__tests__` still reports drift,
288
- // which is the bug this file now pins. `fixtures` stands in for a directory
289
- // only one pair wants to skip.
290
- write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
291
- write(TMP_REPO, 'canonical/fixtures/data.json', '{}\n');
292
- write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
293
- trackAll(TMP_REPO);
294
-
295
- const withoutExclude = diffTrees(TMP_REPO, 'canonical', 'mirror');
296
- expect(withoutExclude.inSync).toBe(false);
297
-
298
- const withExclude = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['fixtures'] });
299
- expect(withExclude.inSync).toBe(true);
300
- expect(withExclude.missing).toEqual([]);
301
- });
302
-
303
- it('does not let a pair-specific exclude re-enable the global ones', () => {
304
- // The lists compose. `exclude: ['fixtures']` must not silently drop
305
- // `__tests__` back into the comparison, or every caller that names one
306
- // directory reintroduces the drift this section exists to prevent.
307
- write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
308
- write(TMP_REPO, 'canonical/__tests__/lib.test.ts', 'test\n');
309
- write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
310
- trackAll(TMP_REPO);
311
-
312
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['fixtures'] });
313
- expect(diff.inSync).toBe(true);
314
- });
315
- });
316
-
317
- describe('diffTrees — P1-E a generated mirror is untracked, not missing', () => {
318
- it('does not report drift when the mirror tree is gitignored and byte-identical', () => {
319
- // P1-E step 2 took four mirror trees out of version control: prepack
320
- // regenerates them from canonical, so tracking them IS the duplication the
321
- // decision set out to remove.
322
- //
323
- // Measured after that landed: `xp-gate sync-mirrors` reported DRIFT for
324
- // adapters, hooks/lib, build-integrity AND skills -- the four trees the
325
- // generator had just written correctly. Both sides were compared on their
326
- // tracked file set, and a gitignored tree has none, so every canonical file
327
- // read as "missing from the mirror".
328
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
329
- write(TMP_REPO, 'canonical/sub/b.sh', 'echo b\n');
330
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
331
- write(TMP_REPO, 'mirror/sub/b.sh', 'echo b\n');
332
- write(TMP_REPO, '.gitignore', 'mirror/\n');
333
- trackCanonicalOnly(TMP_REPO, 'canonical');
334
-
335
- // Premise asserted before the verdict: if the fixture stages the mirror, the
336
- // case passes vacuously and stops covering what it names.
337
- const tracked = execFileSync('git', ['ls-files', '--', 'mirror'], {
338
- cwd: TMP_REPO,
339
- encoding: 'utf8',
340
- }).trim();
341
- expect(tracked).toBe('');
342
-
343
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
344
- expect(diff.missing).toEqual([]);
345
- expect(diff.differing).toEqual([]);
346
- expect(diff.extra).toEqual([]);
347
- expect(diff.inSync).toBe(true);
348
- });
349
-
350
- it('still reports a byte difference inside an untracked mirror tree', () => {
351
- // Control. Relaxing to "the mirror is untracked, stop looking" would make the
352
- // case above pass and destroy the check.
353
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
354
- write(TMP_REPO, 'mirror/a.sh', 'echo DRIFTED\n');
355
- write(TMP_REPO, '.gitignore', 'mirror/\n');
356
- trackCanonicalOnly(TMP_REPO, 'canonical');
357
-
358
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
359
- expect(diff.inSync).toBe(false);
360
- expect(diff.differing).toContain('a.sh');
361
- });
362
-
363
- it('still reports a genuinely absent file inside an untracked mirror tree', () => {
364
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
365
- write(TMP_REPO, 'canonical/b.sh', 'echo b\n');
366
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
367
- write(TMP_REPO, '.gitignore', 'mirror/\n');
368
- trackCanonicalOnly(TMP_REPO, 'canonical');
369
-
370
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
371
- expect(diff.inSync).toBe(false);
372
- expect(diff.missing).toContain('b.sh');
373
- });
374
-
375
- it('reports an orphan in an untracked mirror tree, not just missing files', () => {
376
- // `extra` is the verdict a disk-walk fix is most likely to drop: on the tracked
377
- // path it came from the mirror's own set, which is now empty.
378
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
379
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
380
- write(TMP_REPO, 'mirror/gone.sh', 'echo orphan\n');
381
- write(TMP_REPO, '.gitignore', 'mirror/\n');
382
- trackCanonicalOnly(TMP_REPO, 'canonical');
383
-
384
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
385
- expect(diff.extra).toContain('gone.sh');
386
- expect(diff.inSync).toBe(false);
387
- });
388
-
389
- it('keeps an untracked artifact in an untracked mirror out of the verdict', () => {
390
- // Both relaxations at once, which is the real repo's shape: the mirror is
391
- // gitignored AND holds build noise. The disk fallback must not start reporting
392
- // cache files as orphans -- that is the #587/#588 false failure reintroduced.
393
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
394
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
395
- write(TMP_REPO, 'mirror/__pycache__/a.pyc', 'binary');
396
- write(TMP_REPO, '.gitignore', 'mirror/\n');
397
- trackCanonicalOnly(TMP_REPO, 'canonical');
398
-
399
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror');
400
- expect(diff.extra).toEqual([]);
401
- expect(diff.inSync).toBe(true);
402
- });
403
-
404
- it('still respects a pair-specific exclude in an untracked mirror tree', () => {
405
- write(TMP_REPO, 'canonical/lib.ts', 'export const a = 1;\n');
406
- write(TMP_REPO, 'mirror/lib.ts', 'export const a = 1;\n');
407
- write(TMP_REPO, 'mirror/__tests__/lib.test.ts', 'test\n');
408
- write(TMP_REPO, '.gitignore', 'mirror/\n');
409
- trackCanonicalOnly(TMP_REPO, 'canonical');
410
-
411
- const diff = diffTrees(TMP_REPO, 'canonical', 'mirror', { exclude: ['__tests__'] });
412
- expect(diff.inSync).toBe(true);
413
- expect(diff.extra).toEqual([]);
414
- });
415
- });
416
-
417
-
418
- describe('collectMirrorPairs — AC-713-02 pair discovery', () => {
419
- it('discovers a pair only when both sides exist', () => {
420
- write(TMP_REPO, 'githooks/lib/a.sh', 'echo a\n');
421
- write(TMP_REPO, 'src/npm-package/hooks/lib/a.sh', 'echo a\n');
422
- trackAll(TMP_REPO);
423
-
424
- const pairs = collectMirrorPairs(TMP_REPO);
425
- const found = pairs.find((p) => p.canonical === 'githooks/lib' && p.mirror === 'src/npm-package/hooks/lib');
426
- // Asserted on the pair's own fields, not only on its existence: "a pair object
427
- // was returned" is satisfied by a pair whose mirror path is wrong, which is the
428
- // bug this case is named after -- the pair must be the CORRECT one.
429
- expect(found).toBeDefined();
430
- expect({ canonical: found.canonical, mirror: found.mirror }).toEqual({
431
- canonical: 'githooks/lib',
432
- mirror: 'src/npm-package/hooks/lib',
433
- });
434
- });
435
-
436
- it('does not invent a pair for a canonical tree with no mirror', () => {
437
- write(TMP_REPO, 'githooks/lib/a.sh', 'echo a\n');
438
- trackAll(TMP_REPO);
439
-
440
- const pairs = collectMirrorPairs(TMP_REPO);
441
- const found = pairs.find((p) => p.canonical === 'githooks/lib');
442
- // Asserted on the collection, not only on `found`: the bug this guards against
443
- // is "a canonical tree with no mirror gets paired with something", and a bare
444
- // `toBeUndefined()` cannot distinguish that from the whole function returning
445
- // nothing. Naming the discovered canonical set makes the empty result mean
446
- // "this pair was not invented" rather than "no pairs were found at all".
447
- expect(pairs.map((p) => p.canonical)).toEqual([]);
448
- expect(found).toBeUndefined();
449
- });
450
- });
451
-
452
- describe('syncMirrors — AC-713-03 repair instead of hand-copying', () => {
453
- it('copies a missing file and produces parity', () => {
454
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
455
- write(TMP_REPO, 'canonical/b.sh', 'echo b\n');
456
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
457
- write(TMP_REPO, 'mirror/b.sh', 'echo b\n');
458
- trackAll(TMP_REPO);
459
-
460
- // Remove the mirror copy to simulate drift.
461
- fs.rmSync(path.join(TMP_REPO, 'mirror/b.sh'));
462
-
463
- const result = syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
464
- expect(result.copied).toContain('b.sh');
465
- expect(diffTrees(TMP_REPO, 'canonical', 'mirror').inSync).toBe(true);
466
- });
467
-
468
- it('rewrites a differing file to match the canonical bytes', () => {
469
- write(TMP_REPO, 'canonical/a.sh', 'echo canonical\n');
470
- write(TMP_REPO, 'mirror/a.sh', 'echo stale\n');
471
- trackAll(TMP_REPO);
472
-
473
- syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
474
- expect(fs.readFileSync(path.join(TMP_REPO, 'mirror/a.sh'), 'utf8')).toBe('echo canonical\n');
475
- });
476
-
477
- it('is idempotent — a second run changes nothing', () => {
478
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
479
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
480
- trackAll(TMP_REPO);
481
-
482
- syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
483
- const second = syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
484
- expect(second.copied).toEqual([]);
485
- expect(second.cleaned).toEqual([]);
486
- });
487
-
488
- it('supports --dry-run so the caller can preview before writing', () => {
489
- write(TMP_REPO, 'canonical/a.sh', 'echo fresh\n');
490
- write(TMP_REPO, 'mirror/a.sh', 'echo stale\n');
491
- trackAll(TMP_REPO);
492
-
493
- const result = syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }], { dryRun: true });
494
- expect(result.copied).toContain('a.sh');
495
- // Nothing was written.
496
- expect(fs.readFileSync(path.join(TMP_REPO, 'mirror/a.sh'), 'utf8')).toBe('echo stale\n');
497
- });
498
-
499
- it('prunes a mirror file whose canonical source is gone', () => {
500
- write(TMP_REPO, 'canonical/a.sh', 'echo a\n');
501
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
502
- write(TMP_REPO, 'mirror/orphan.sh', 'echo orphan\n');
503
- trackAll(TMP_REPO);
504
-
505
- const result = syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
506
- expect(result.cleaned).toContain('orphan.sh');
507
- expect(fs.existsSync(path.join(TMP_REPO, 'mirror/orphan.sh'))).toBe(false);
508
- });
509
- });
510
-
511
- describe('handleSyncMirrors — CLI contract', () => {
512
- let captured;
513
- let outSpy;
514
-
515
- beforeEach(() => {
516
- captured = [];
517
- outSpy = vi.spyOn(process.stdout, 'write').mockImplementation((chunk) => {
518
- captured.push(String(chunk));
519
- return true;
520
- });
521
- });
522
-
523
- afterEach(() => {
524
- outSpy.mockRestore();
525
- });
526
-
527
- it('reports NOT MEASURABLE and exits 1 outside a repo with no pairs', () => {
528
- expect(handleSyncMirrors([], { root: TMP_REPO })).toBe(1);
529
- expect(captured.join('')).toMatch(/NOT MEASURABLE/i);
530
- });
531
-
532
- it('names the generator when a checkout cannot resolve any pairs', () => {
533
- // The caller has two branches on `assertPairsResolved`'s return: a bare
534
- // "is this the repo?" when it is null, and the generator-specific reason when it
535
- // is not. Only the first was ever tested, so review could not tell whether the
536
- // second was reachable. This pins it.
537
- //
538
- // `broken` is non-null only when the generator is present AND the pair list is
539
- // empty, so the stubbed generator reproduces exactly that shape: present on
540
- // disk, exporting nothing usable.
541
- const fakeCheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nopairs-'));
542
- fs.mkdirSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts'), { recursive: true });
543
- fs.writeFileSync(
544
- path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'),
545
- 'module.exports = {};\n'
546
- );
547
-
548
- // Here KNOWN_PAIRS is still non-empty (it belongs to the module, not the root),
549
- // so this repo is measured normally -- proving the fixture does not accidentally
550
- // reach the branch under test. The branch itself is covered directly in the
551
- // `assertPairsResolved` suite by passing an empty pair list.
552
- expect(fs.existsSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
553
- const code = handleSyncMirrors([], { root: fakeCheckout });
554
- expect(code).toBe(1);
555
- expect(captured.join('')).toMatch(/NOT MEASURABLE/i);
556
- });
557
-
558
- it('defaults to a dry run and does not modify files', () => {
559
- write(TMP_REPO, 'githooks/lib/a.sh', 'echo canonical\n');
560
- write(TMP_REPO, 'src/npm-package/hooks/lib/a.sh', 'echo stale\n');
561
- trackAll(TMP_REPO);
562
-
563
- const code = handleSyncMirrors([], { root: TMP_REPO });
564
- // Dry run with pending work is a non-zero exit so CI can act on it.
565
- expect(code).toBe(1);
566
- expect(captured.join('')).toMatch(/Re-run with --write/);
567
- expect(fs.readFileSync(path.join(TMP_REPO, 'src/npm-package/hooks/lib/a.sh'), 'utf8')).toBe('echo stale\n');
568
- });
569
-
570
- it('applies the repair with --write and reports it', () => {
571
- write(TMP_REPO, 'githooks/lib/a.sh', 'echo canonical\n');
572
- write(TMP_REPO, 'src/npm-package/hooks/lib/a.sh', 'echo stale\n');
573
- trackAll(TMP_REPO);
574
-
575
- expect(handleSyncMirrors(['--write'], { root: TMP_REPO })).toBe(0);
576
- expect(fs.readFileSync(path.join(TMP_REPO, 'src/npm-package/hooks/lib/a.sh'), 'utf8')).toBe('echo canonical\n');
577
- });
578
- });
579
-
580
- describe('syncMirrors — AC-713-04 safety', () => {
581
- it('refuses a pair whose canonical directory does not exist', () => {
582
- write(TMP_REPO, 'mirror/a.sh', 'echo a\n');
583
- trackAll(TMP_REPO);
584
-
585
- // Guessing "canonical is empty, so wipe the mirror" would delete real files.
586
- expect(() => syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }])).toThrow(/canonical/i);
587
- });
588
-
589
- it('preserves the executable bit so hooks stay runnable', () => {
590
- write(TMP_REPO, 'canonical/hook.sh', '#!/bin/sh\necho a\n');
591
- fs.chmodSync(path.join(TMP_REPO, 'canonical/hook.sh'), 0o755);
592
- // The mirror must start as *drift*. The sync loop only touches files that
593
- // are `missing` or `differing`, so identical content is skipped and the mode
594
- // never gets rewritten. An earlier version gave both sides the same bytes,
595
- // so the file never entered `toWrite`; on Linux the assertion then failed
596
- // ("expected +0 to be truthy") while Windows skipped the whole block, which
597
- // is how it stayed invisible locally. The test was measuring nothing.
598
- write(TMP_REPO, 'mirror/hook.sh', '#!/bin/sh\necho stale\n');
599
- trackAll(TMP_REPO);
600
-
601
- const result = syncMirrors(TMP_REPO, [{ canonical: 'canonical', mirror: 'mirror' }]);
602
- // Prove the copy actually happened, so a green result cannot come from
603
- // "nothing was touched".
604
- expect(result.copied).toContain('hook.sh');
605
- expect(fs.readFileSync(path.join(TMP_REPO, 'mirror/hook.sh'), 'utf8')).toBe('#!/bin/sh\necho a\n');
606
-
607
- // On Windows the exec bit is not meaningful; only assert where it applies.
608
- if (process.platform !== 'win32') {
609
- const mode = fs.statSync(path.join(TMP_REPO, 'mirror/hook.sh')).mode;
610
- expect(mode & 0o111).toBeTruthy();
611
- }
612
- });
613
- });
614
-
615
- describe('KNOWN_PAIRS — P1-E the pair list is derived, not hand-copied', () => {
616
- it('every mirror directory the package ships is supervised by something', () => {
617
- // The real question, and the one a naive version of this case got wrong.
618
- //
619
- // Asserting "KNOWN_PAIRS contains every GENERATED_TREES row" is VACUOUS:
620
- // KNOWN_PAIRS is derived from GENERATED_TREES, so it holds by construction.
621
- // Verified by deleting the mock-policy row from the generator -- the assertion
622
- // still passed, which is proof it could never fail.
623
- //
624
- // What actually went wrong historically is different: `mutation` and
625
- // `mock-policy` were in the package's `files[]` with NO generator and NO pair,
626
- // so nothing ever compared them against their source. That state is
627
- // undetectable from inside the pair list; it needs the SHIPPED list as the
628
- // starting set. Every shipped mirror directory must be either generated or
629
- // explicitly hand-listed -- silence is the bug.
630
- const pkg = require('../../package.json');
631
- const { GENERATED_TREES } = require('../../scripts/generate-mirrors.cjs');
632
- // Directory-shaped `files[]` entries (a trailing slash). Loose files like
633
- // `gate-3.sh` and `adapter-common.sh` are mirrors of individual gates and are
634
- // covered by HOOK_MIRROR_FILES in check-hook-mirror.sh, not by this table.
635
- const shippedDirs = pkg.files
636
- .filter((f) => f.endsWith('/'))
637
- .map((f) => f.replace(/\/$/, ''))
638
- // Only entries that have a canonical counterpart under the repo are mirror
639
- // pairs; `bin/`, `lib/`, `scripts/` are this package's own source.
640
- .filter((d) => MIRROR_DIR_CANDIDATES.some((c) => d === c));
641
-
642
- const generated = new Set(GENERATED_TREES.map((t) => t.mirror));
643
- const handListed = new Set(HAND_LISTED_MIRRORS);
644
- const unsupervised = shippedDirs.filter((d) => !generated.has(d) && !handListed.has(d));
645
- expect(unsupervised).toEqual([]);
646
- });
647
-
648
- it('declares no pair whose mirror the package does not ship', () => {
649
- // The other direction. A pair pointing at a directory absent from `files[]`
650
- // would check something that never reaches a consumer, which reads as coverage
651
- // without being any.
652
- const pkg = require('../../package.json');
653
- // KNOWN_PAIRS holds REPO-relative paths; files[] holds PACKAGE-relative ones.
654
- const PRE = 'src/npm-package/';
655
- // files[] entries carry a trailing slash ('adapters/'). Comparing the raw
656
- // strings reports EVERY pair as unshipped -- which is exactly how this case
657
- // failed on its first version, and why the check is written against the
658
- // normalised entry rather than trusting the two lists to be spelled alike.
659
- const shipped = (p) =>
660
- p.startsWith(PRE) &&
661
- pkg.files.some((f) => {
662
- const entry = f.replace(/\/$/, '');
663
- const rel = p.slice(PRE.length);
664
- return rel === entry || rel.startsWith(`${entry}/`);
665
- });
666
- for (const pair of KNOWN_PAIRS) {
667
- expect(shipped(pair.mirror)).toBe(true);
668
- }
669
- });
670
-
671
- it('has no duplicate canonical tree', () => {
672
- const canonicals = KNOWN_PAIRS.map((p) => p.canonical);
673
- expect(new Set(canonicals).size).toBe(canonicals.length);
674
- });
675
- });
676
-
677
- describe('assertPairsResolved — a zero-pair result must not read as a pass', () => {
678
- // Resolve the checkout once, and fail here rather than deep inside an assertion.
679
- // The review flagged the bare `path.resolve(__dirname, '..', '..', '..', '..')`
680
- // used inline: if this suite ever moves, that walk lands somewhere else and the
681
- // failure surfaces as `Cannot read properties of null` on a toMatch, which reads
682
- // like a logic bug in the guard rather than a broken path in the test.
683
- const repoRoot = path.resolve(__dirname, '..', '..', '..', '..');
684
- const generatorPath = path.join(repoRoot, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs');
685
-
686
- it('can locate the checkout it claims to test', () => {
687
- expect(fs.existsSync(generatorPath)).toBe(true);
688
- });
689
-
690
- it('reports a usable pair list for this checkout', () => {
691
- // Every pair is derived from generate-mirrors.cjs now, so if that file moved or
692
- // stopped exporting GENERATED_TREES, KNOWN_PAIRS would be empty and every query
693
- // would answer "nothing drifted" -- a perfect score from a broken tool.
694
- expect(KNOWN_PAIRS.length).toBeGreaterThan(0);
695
- expect(assertPairsResolved(repoRoot)).toBeNull();
696
- });
697
-
698
- it('refuses to stay quiet over zero pairs in a checkout', () => {
699
- // The error branch used to be unreachable: it read the module-level KNOWN_PAIRS,
700
- // resolved once at require time against this repository, so no fixture could
701
- // make it empty and no test could execute it. `pairs` is now a parameter with
702
- // KNOWN_PAIRS as its default, which is what makes this case possible at all.
703
- //
704
- // This branch is the whole reason the function exists: it is the guard against a
705
- // broken generator reporting a perfect score.
706
- const message = assertPairsResolved(repoRoot, []);
707
- expect(message).toMatch(/ZERO mirror pairs/);
708
- expect(message).toContain('generate-mirrors.cjs');
709
- // And a non-empty list stays silent -- the contrast that makes the message mean
710
- // "zero", not "something is wrong here".
711
- expect(assertPairsResolved(repoRoot, [{ canonical: 'a', mirror: 'b' }])).toBeNull();
712
- });
713
-
714
- it('keeps KNOWN_PAIRS as the default so call sites need no argument', () => {
715
- // The parameterisation must not change behaviour for existing callers: the only
716
- // production call passes just a root.
717
- //
718
- // Written first as `assertPairsResolved(root) === assertPairsResolved(root,
719
- // KNOWN_PAIRS)`, which the review correctly called near-tautological: that is
720
- // just what a default parameter means, and if the generator were absent BOTH
721
- // calls would return null and the assertion would pass having checked nothing.
722
- // The precondition below removes that vacuous pass, and the real signal is that
723
- // the default must behave like the non-empty list -- i.e. stay silent.
724
- expect(KNOWN_PAIRS.length).toBeGreaterThan(0);
725
- expect(fs.existsSync(path.join(repoRoot, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
726
-
727
- const byDefault = assertPairsResolved(repoRoot);
728
- const explicit = assertPairsResolved(repoRoot, KNOWN_PAIRS);
729
- expect(byDefault).toBeNull();
730
- expect(explicit).toBeNull();
731
-
732
- // Attribution, not just "non-null". A bare `not.toBeNull()` on the [] case was
733
- // rejected by review as proving only that the function CAN return a string --
734
- // it does not tie the null above to the pair count rather than to the
735
- // generator-missing early return. So each of the three outcomes is pinned to the
736
- // specific branch that produces it:
737
- //
738
- // default / explicit, generator present, pairs non-empty -> null (silent)
739
- // [], generator present -> reason string
740
- // anything, generator ABSENT -> null (not a checkout)
741
- const zeroPairsReason = assertPairsResolved(repoRoot, []);
742
- expect(zeroPairsReason).toContain('generate-mirrors.cjs');
743
- expect(zeroPairsReason).toMatch(/ZERO mirror pairs/);
744
-
745
- // The generator-missing early return is a DIFFERENT no-answer: a directory with
746
- // no generator is not a checkout, so null there must not be read as the same
747
- // fact as null above. This is the branch that made `not.toBeNull()` alone
748
- // insufficient -- without it, "null" had two causes and neither was pinned.
749
- const notACheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nogen-'));
750
- expect(assertPairsResolved(notACheckout, [])).toBeNull();
751
- expect(assertPairsResolved(notACheckout)).toBeNull();
752
- });
753
-
754
- it('tells a checkout apart from a non-checkout by the generator file', () => {
755
- // Scope note: KNOWN_PAIRS is a module-level constant, resolved once at require
756
- // time against THIS repository. A fixture directory therefore cannot make it
757
- // empty, so a case that expected "fake repo with a broken generator returns an
758
- // error" would assert something the design cannot do -- it failed on the first
759
- // attempt for exactly that reason.
760
- //
761
- // What IS decidable from a given root is the precondition the assertion turns
762
- // on: a checkout has the generator, a non-checkout does not. That is the half
763
- // this case pins; the empty-list message itself is exercised by
764
- // handleSyncMirrors when collectMirrorPairs returns nothing.
765
- const fakeCheckout = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-checkout-'));
766
- fs.mkdirSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts'), { recursive: true });
767
- fs.writeFileSync(
768
- path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'),
769
- 'module.exports = {};\n'
770
- );
771
- const fakeInstall = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-install-'));
772
-
773
- // In this process the pair list is non-empty, so neither root reports a
774
- // problem -- and that is correct: the list is what matters, not the root.
775
- expect(assertPairsResolved(fakeCheckout)).toBeNull();
776
- expect(assertPairsResolved(fakeInstall)).toBeNull();
777
-
778
- // The distinguishing fact the implementation reads.
779
- expect(fs.existsSync(path.join(fakeCheckout, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(true);
780
- expect(fs.existsSync(path.join(fakeInstall, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))).toBe(false);
781
- });
782
-
783
- it('stays quiet outside a checkout, where zero pairs is legitimate', () => {
784
- // An installed package ships lib/ but not scripts/, and the canonical trees it
785
- // would compare against are not installed either. Reporting an error there
786
- // would make a correct install look broken.
787
- //
788
- // `toBeNull()` alone cannot fail in a way that distinguishes "correctly quiet"
789
- // from "quiet for any reason at all", so this also asserts what the function is
790
- // NOT doing: the directory must genuinely lack a generator, or the null would
791
- // be meaningless. Verified by the companion case above, where the same call on
792
- // a root that DOES have one still returns null only because the pair list is
793
- // non-empty -- the two facts together pin the contract.
794
- const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-nocheckout-'));
795
- expect(assertPairsResolved(emptyDir)).toBeNull();
796
- expect(
797
- fs.existsSync(path.join(emptyDir, 'src', 'npm-package', 'scripts', 'generate-mirrors.cjs'))
798
- ).toBe(false);
799
- // And the real repository, which has the generator and a resolved pair list,
800
- // also reports no problem -- the contrast that makes the null above meaningful.
801
- expect(assertPairsResolved(repoRoot)).toBeNull();
802
- });
803
- });