@boyingliu01/xp-gate 0.38.126 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) 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/sprint-flow/AGENTS.md +1 -1
  65. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  66. package/plugins/dsh/package.json +1 -1
  67. package/plugins/dsh/scripts/prepack.cjs +43 -18
  68. package/plugins/dsh/scripts/verify-skill-provider.mjs +39 -14
  69. package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +6 -11
  70. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  71. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  72. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  73. package/plugins/opencode/index.ts +337 -123
  74. package/plugins/opencode/package.json +1 -1
  75. package/plugins/opencode/scripts/prepack.cjs +41 -16
  76. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +6 -11
  77. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  78. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  79. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  80. package/plugins/qoder/bin/sprint-flow-guard.sh +12 -60
  81. package/plugins/qoder/plugin.json +1 -1
  82. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +6 -11
  83. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  84. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  85. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  86. package/plugins/shared/README.md +3 -0
  87. package/plugins/shared/bin/delphi-review-guard.sh +68 -0
  88. package/principles/adapters/control-nesting.ts +481 -168
  89. package/principles/adapters/cpp.ts +61 -22
  90. package/principles/adapters/csharp.ts +183 -66
  91. package/principles/adapters/dart.ts +11 -1
  92. package/principles/adapters/duplication.ts +49 -16
  93. package/principles/adapters/import-clause.ts +62 -15
  94. package/principles/adapters/java.ts +199 -70
  95. package/principles/adapters/line-comment.ts +18 -0
  96. package/principles/adapters/member-scan.ts +50 -8
  97. package/principles/adapters/php.ts +232 -103
  98. package/principles/adapters/python.ts +25 -18
  99. package/principles/adapters/quote-state.ts +21 -8
  100. package/principles/adapters/typescript-mask.ts +276 -0
  101. package/principles/adapters/typescript.ts +206 -200
  102. package/principles/analyzer.ts +16 -6
  103. package/principles/baseline-prune.ts +18 -8
  104. package/principles/baseline.ts +28 -11
  105. package/principles/boy-scout-usage.ts +26 -0
  106. package/principles/boy-scout.ts +261 -180
  107. package/principles/config.ts +183 -57
  108. package/principles/direct-execution.ts +24 -12
  109. package/principles/lint-baseline.ts +235 -122
  110. package/principles/rules/arch/dependency.ts +34 -25
  111. package/principles/rules/arch/shared.ts +24 -20
  112. package/principles/rules/clean-code/deep-nesting.ts +23 -13
  113. package/principles/rules/clean-code/god-class.ts +67 -41
  114. package/principles/rules/clean-code/large-file.ts +30 -23
  115. package/principles/rules/clean-code/long-function.ts +51 -37
  116. package/principles/rules/clean-code/magic-numbers.ts +51 -36
  117. package/principles/rules/clean-code/many-exports.ts +46 -29
  118. package/principles/rules/clean-code/missing-error-handling.ts +38 -20
  119. package/principles/rules/clean-code/too-many-params.ts +41 -22
  120. package/principles/rules/function-source.ts +62 -0
  121. package/principles/rules/solid/dip.ts +10 -6
  122. package/principles/rules/solid/isp.ts +64 -24
  123. package/principles/rules/solid/lsp.ts +66 -18
  124. package/principles/rules/solid/ocp.ts +29 -13
  125. package/principles/rules/solid/srp.ts +34 -18
  126. package/principles/warnings-count.ts +43 -0
  127. package/scripts/__tests__/prepush-source-classification.test.js +129 -0
  128. package/scripts/delphi-config-read.cjs +245 -0
  129. package/scripts/delphi-external-review.cjs +410 -585
  130. package/scripts/delphi-json-extract.cjs +108 -0
  131. package/scripts/delphi-model-validation.cjs +297 -0
  132. package/scripts/delphi-prompts.cjs +55 -0
  133. package/scripts/delphi-repo-tools.cjs +273 -0
  134. package/scripts/delphi-seat-calibration.cjs +204 -0
  135. package/scripts/run-bats-ci.cjs +240 -97
  136. package/scripts/sync-package-content.js +18 -2
  137. package/skills/delphi-review/.delphi-config.json.example +6 -11
  138. package/skills/delphi-review/AGENTS.md +1 -1
  139. package/skills/sprint-flow/AGENTS.md +1 -1
  140. package/skills/test-specification-alignment/AGENTS.md +1 -1
  141. package/lib/__tests__/agent-runtime-journal.test.js +0 -326
  142. package/lib/__tests__/arch-config-template.test.js +0 -190
  143. package/lib/__tests__/arch.test.js +0 -430
  144. package/lib/__tests__/assertion-debt.test.js +0 -99
  145. package/lib/__tests__/audit-cli-contract.test.ts +0 -117
  146. package/lib/__tests__/audit-log.test.ts +0 -107
  147. package/lib/__tests__/audit-skip-reasons.test.ts +0 -143
  148. package/lib/__tests__/baseline-completeness.test.js +0 -264
  149. package/lib/__tests__/baseline-shell-scope.test.js +0 -60
  150. package/lib/__tests__/baseline-unevaluated.test.js +0 -142
  151. package/lib/__tests__/baseline.test.js +0 -212
  152. package/lib/__tests__/bootstrap.test.js +0 -60
  153. package/lib/__tests__/check-alignment-cli.test.mjs +0 -94
  154. package/lib/__tests__/check-alignment-reasons.test.mjs +0 -101
  155. package/lib/__tests__/check-all-skip-accounting.test.js +0 -171
  156. package/lib/__tests__/check-changed-brief.test.js +0 -63
  157. package/lib/__tests__/check-normalize-exit.test.js +0 -24
  158. package/lib/__tests__/check-single-file.test.js +0 -114
  159. package/lib/__tests__/check-tools-list.test.js +0 -155
  160. package/lib/__tests__/check-version.test.js +0 -463
  161. package/lib/__tests__/coverage-scope.test.js +0 -140
  162. package/lib/__tests__/coverage-threshold.test.js +0 -80
  163. package/lib/__tests__/crap-cli.test.js +0 -87
  164. package/lib/__tests__/crap.test.js +0 -494
  165. package/lib/__tests__/debt-classify.test.js +0 -78
  166. package/lib/__tests__/delphi-channel-doctor.test.js +0 -116
  167. package/lib/__tests__/delphi-channel-uninstall.test.js +0 -128
  168. package/lib/__tests__/delphi-channel.test.js +0 -109
  169. package/lib/__tests__/delphi-setup.test.js +0 -203
  170. package/lib/__tests__/deploy-manifest-check-wired.test.js +0 -138
  171. package/lib/__tests__/deploy-manifest-completeness.test.js +0 -151
  172. package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +0 -40
  173. package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +0 -74
  174. package/lib/__tests__/deploy-manifest-projection.test.js +0 -66
  175. package/lib/__tests__/deploy-manifest-shell-parity.test.js +0 -108
  176. package/lib/__tests__/deploy-manifest.test.js +0 -97
  177. package/lib/__tests__/detect-deps-dsh-profile.test.js +0 -323
  178. package/lib/__tests__/detect-deps-gate-identity.test.js +0 -135
  179. package/lib/__tests__/detect-deps.test.js +0 -655
  180. package/lib/__tests__/doctor-469-hook-env.test.js +0 -211
  181. package/lib/__tests__/doctor-arch-tools.test.js +0 -169
  182. package/lib/__tests__/doctor-audit-ledger.test.js +0 -61
  183. package/lib/__tests__/doctor-brief.test.js +0 -59
  184. package/lib/__tests__/doctor-delphi.test.js +0 -628
  185. package/lib/__tests__/doctor-drift-direction.test.js +0 -104
  186. package/lib/__tests__/doctor-drift-round2.test.js +0 -215
  187. package/lib/__tests__/doctor-exec-retry.test.js +0 -162
  188. package/lib/__tests__/doctor-executed-surface.test.js +0 -230
  189. package/lib/__tests__/doctor-helpers.test.js +0 -139
  190. package/lib/__tests__/doctor-hook-drift.test.js +0 -329
  191. package/lib/__tests__/doctor-hook-signatures.test.js +0 -65
  192. package/lib/__tests__/doctor-machine-mutation.test.js +0 -116
  193. package/lib/__tests__/doctor-module-drift.test.js +0 -212
  194. package/lib/__tests__/doctor-module-resolution-parity.test.js +0 -463
  195. package/lib/__tests__/doctor-path-equivalence.test.js +0 -70
  196. package/lib/__tests__/doctor-repair-boundary.test.js +0 -52
  197. package/lib/__tests__/doctor-signature-stability.test.js +0 -55
  198. package/lib/__tests__/doctor-spawn-capability.test.js +0 -116
  199. package/lib/__tests__/doctor-timeout-partial.test.js +0 -79
  200. package/lib/__tests__/doctor-tool-delegation.test.js +0 -156
  201. package/lib/__tests__/doctor-tui-skill-freshness.test.js +0 -385
  202. package/lib/__tests__/doctor.test.js +0 -1320
  203. package/lib/__tests__/find-bash-wsl.test.js +0 -121
  204. package/lib/__tests__/flaky.test.js +0 -128
  205. package/lib/__tests__/foreign-hooks-global.test.js +0 -125
  206. package/lib/__tests__/gate-audit-skip.test.ts +0 -81
  207. package/lib/__tests__/gate-audit.test.ts +0 -440
  208. package/lib/__tests__/gate-coverage-hook-floor.test.js +0 -94
  209. package/lib/__tests__/gate-coverage.test.js +0 -204
  210. package/lib/__tests__/gate-entry-provenance.test.js +0 -71
  211. package/lib/__tests__/gate-numbering.test.js +0 -79
  212. package/lib/__tests__/gate-rules.test.js +0 -58
  213. package/lib/__tests__/gate-runner-tsx-invocation.test.js +0 -149
  214. package/lib/__tests__/gate-runner-verdict.test.js +0 -105
  215. package/lib/__tests__/gate-runner.test.js +0 -371
  216. package/lib/__tests__/gate2-verdict.test.js +0 -183
  217. package/lib/__tests__/helpers/lib-sandbox.cjs +0 -55
  218. package/lib/__tests__/hook-health-path.test.js +0 -109
  219. package/lib/__tests__/hook-health.test.js +0 -85
  220. package/lib/__tests__/init-gitignore.test.js +0 -204
  221. package/lib/__tests__/init-gitleaks-notice.test.js +0 -57
  222. package/lib/__tests__/init.test.js +0 -530
  223. package/lib/__tests__/install-cmd.test.js +0 -6
  224. package/lib/__tests__/install-sh-deploy-manifest.test.js +0 -80
  225. package/lib/__tests__/install-skill-full-dir.test.js +0 -194
  226. package/lib/__tests__/install-skill.test.js +0 -416
  227. package/lib/__tests__/install-tools-repair.test.js +0 -263
  228. package/lib/__tests__/issue-519-phase-transition-guard.test.js +0 -233
  229. package/lib/__tests__/issue-566-sync-hooks-backup.test.js +0 -228
  230. package/lib/__tests__/issue-583-hook-deploy-log.test.js +0 -121
  231. package/lib/__tests__/issue-586-principles-cmdline.test.js +0 -218
  232. package/lib/__tests__/issue-589-check-all-gate3.test.js +0 -190
  233. package/lib/__tests__/issue-590-archlint-vacuous-pass.test.js +0 -138
  234. package/lib/__tests__/issue-618-gate-not-run.test.js +0 -100
  235. package/lib/__tests__/jscpd-entry-resolution.test.js +0 -143
  236. package/lib/__tests__/language-capability.test.js +0 -318
  237. package/lib/__tests__/language-tools-build-file-install.test.js +0 -82
  238. package/lib/__tests__/language-tools-detect.test.js +0 -301
  239. package/lib/__tests__/migrate.test.js +0 -232
  240. package/lib/__tests__/mirror-manifest.test.js +0 -64
  241. package/lib/__tests__/mirror-sync.test.js +0 -803
  242. package/lib/__tests__/next-sprint.test.js +0 -231
  243. package/lib/__tests__/npm-package.test.js +0 -140
  244. package/lib/__tests__/phase-transition.test.js +0 -1136
  245. package/lib/__tests__/principles-csharp-coverage.test.js +0 -227
  246. package/lib/__tests__/principles-directory.test.js +0 -87
  247. package/lib/__tests__/qoder-delphi-agents.test.js +0 -316
  248. package/lib/__tests__/retro-gate-m.test.js +0 -144
  249. package/lib/__tests__/retro.test.js +0 -131
  250. package/lib/__tests__/rework.test.js +0 -127
  251. package/lib/__tests__/rollback.test.js +0 -183
  252. package/lib/__tests__/runtime-journal.test.js +0 -164
  253. package/lib/__tests__/sastd-client.test.js +0 -514
  254. package/lib/__tests__/shared-paths-lazy-home.test.js +0 -67
  255. package/lib/__tests__/shared-paths.test.js +0 -130
  256. package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +0 -69
  257. package/lib/__tests__/shared-utils.test.js +0 -180
  258. package/lib/__tests__/skill-flags.test.js +0 -48
  259. package/lib/__tests__/slo.test.js +0 -89
  260. package/lib/__tests__/sprint-audit.test.js +0 -207
  261. package/lib/__tests__/sprint-discovery.test.ts +0 -366
  262. package/lib/__tests__/sprint-state-manager.test.js +0 -310
  263. package/lib/__tests__/sprint-status-rework-704.test.js +0 -149
  264. package/lib/__tests__/sprint-status-rework.test.js +0 -329
  265. package/lib/__tests__/sprint-status.test.js +0 -193
  266. package/lib/__tests__/sprint-status.test.ts +0 -213
  267. package/lib/__tests__/test-alignment-java-702.test.ts +0 -177
  268. package/lib/__tests__/test-alignment-range-guard.test.ts +0 -82
  269. package/lib/__tests__/test-alignment.test.ts +0 -853
  270. package/lib/__tests__/tool-audit-collect.test.js +0 -184
  271. package/lib/__tests__/tool-audit-fixtures.js +0 -87
  272. package/lib/__tests__/tool-audit-latest.test.js +0 -84
  273. package/lib/__tests__/tool-audit.test.js +0 -428
  274. package/lib/__tests__/tsconfig.json +0 -8
  275. package/lib/__tests__/tsx-resolution.test.js +0 -89
  276. package/lib/__tests__/ui-detector.test.ts +0 -459
  277. package/lib/__tests__/ui-review.test.ts +0 -132
  278. package/lib/__tests__/uninstall-global-residue.test.js +0 -545
  279. package/lib/__tests__/uninstall-skill.test.js +0 -189
  280. package/lib/__tests__/uninstall.test.js +0 -717
  281. package/lib/__tests__/update-hooks.test.js +0 -737
  282. package/lib/__tests__/update-skill-flags.test.js +0 -78
  283. package/lib/__tests__/update-skill.test.js +0 -644
  284. package/lib/__tests__/upgrade-exec.test.js +0 -273
  285. package/lib/__tests__/upgrade-skill-sync.test.js +0 -65
  286. package/lib/__tests__/upgrade.test.js +0 -78
  287. package/lib/__tests__/windows-bash-probe.test.js +0 -123
  288. package/lib/check-alignment-runner.cjs +0 -97
  289. package/lib/coverage-total.sh +0 -92
  290. package/lib/layer-baseline.cjs +0 -94
  291. package/lib/mattpocock-license-verdict.json +0 -7
@@ -1,204 +0,0 @@
1
- /**
2
- * @test REQ-636 One command that shows compliance against EVERY gate
3
- * @intent Today the answer to "how healthy is this project against xp-gate's
4
- * gates" takes six commands and mental arithmetic:
5
- *
6
- * xp-gate gate-list && xp-gate check . --all && xp-gate doctor
7
- * node scripts/ccn-report.cjs --check
8
- * node -e "...sum .warnings-baseline.json..."
9
- * gh run list
10
- *
11
- * Every existing command answers "did THIS gate pass". None answers
12
- * "where is the debt and what should I fix first".
13
- *
14
- * The single most important property is that the view has FOUR states,
15
- * not three. `passed / skipped / failed` merges "did not run" into
16
- * "ran and was fine", and that is exactly where technical debt hides.
17
- * A gate that never executed renders identically to a gate that passed
18
- * clean -- a false green, which is the most dangerous output this
19
- * tooling can produce.
20
- *
21
- * Two data hazards drive the rest of the design:
22
- *
23
- * - The artifact emits `gate9_build_integrity` and `gate10_sast`. An
24
- * earlier version of this comment claimed the CLI numbered those the
25
- * other way round and that the two were SWAPPED. That was false: the
26
- * registry, gate-runner.js and the artifact all say 9=Build Integrity,
27
- * 10=SAST. gate-coverage alone disagreed, via a swap table written for
28
- * an inversion that never existed (#738). The table is deleted; the
29
- * table and report keys are now DERIVED from githooks/gate-registry.sh
30
- * so a fresh copy of the mapping cannot reappear here.
31
- *
32
- * - `quality-status/<branch>.json` records the commit it was generated
33
- * from. Rendering it for a different HEAD silently presents stale
34
- * results as current. This repo has had that artifact sit at an old
35
- * commit for days, so staleness must be explicit, not inferred away.
36
- * @covers AC-636-01, AC-636-02, AC-636-03, AC-636-04, AC-636-05, AC-636-06
37
- */
38
- 'use strict';
39
-
40
- const { renderGateCoverage, buildCoverageRows, STATUS } = require('../gate-coverage');
41
-
42
- /** A `quality-status` artifact shaped like the real producer's output. */
43
- function artifact(overrides) {
44
- return {
45
- reportVersion: '2.0',
46
- generatedAt: '2026-10-27T03:06:05Z',
47
- commit: 'a0bceb9c0000000000000000000000000000000',
48
- branch: 'main',
49
- language: 'typescript iac',
50
- overall: {
51
- gatesPassed: 6,
52
- gatesTotal: 12,
53
- gatesSkipped: 6,
54
- gatesWarned: 0,
55
- gatesFailed: 0,
56
- gatesEffective: 6,
57
- effectivePassRate: 100,
58
- scoreAllGates: 5,
59
- score: 10,
60
- verdict: 'PARTIAL',
61
- ...(overrides && overrides.overall ? overrides.overall : {}),
62
- },
63
- gates: {
64
- gate1_static_analysis: { name: 'Static Analysis', status: 'PASS', tool: 'eslint' },
65
- gate9_build_integrity: { name: 'Build Integrity', status: 'PASS', tool: 'tsc' },
66
- gate10_sast: { name: 'SAST Security', status: 'PASS', tool: 'semgrep' },
67
- ...(overrides && overrides.gates ? overrides.gates : {}),
68
- },
69
- };
70
- }
71
-
72
- describe('gate coverage — four states, never a false green (#636)', () => {
73
- it('AC-636-01: a gate that never ran is SKIP with a reason, never folded into PASS', () => {
74
- const rows = buildCoverageRows(artifact(), { headCommit: 'a0bceb9c0000000000000000000000000000000' });
75
- // Gates 0/1/5/11 are hook-only: they exist but the CLI cannot run them.
76
- const version = rows.find((r) => r.gate === 0);
77
- expect(version, 'Gate 0 must appear even though it never ran').toBeDefined();
78
- expect(version.status).toBe(STATUS.SKIP);
79
- // A bare SKIP is the false green. The reason is mandatory.
80
- expect(version.reason).toBeTruthy();
81
- // The reason must say WHY it did not run -- "hook only" and "not run here"
82
- // are both honest; a bare SKIP is not.
83
- expect(version.reason).toMatch(/hook|git commit|not run/i);
84
- });
85
-
86
- it('AC-636-02: gate 9 is Build Integrity and gate 10 is SAST, matching the artifact keys', () => {
87
- // This assertion replaces an earlier one that pinned 9=SAST / 10=Build
88
- // Integrity and called it "the CLI's numbering, not the artifact's". That
89
- // claim was false: githooks/pre-commit emits `gate9_build_integrity` and
90
- // `gate10_sast`, exactly like gate-registry.sh and gate-runner.js. Only
91
- // gate-coverage disagreed, via a swap table asserting the producer numbered
92
- // them "the other way round" (#738).
93
- //
94
- // The old assertion is DELETED rather than inverted in place: an inverted
95
- // assertion would still be a hand-written number->name mapping — a second
96
- // copy of the fact, which is the defect class itself. The expectation now
97
- // comes from the registry through the derived table, and
98
- // scripts/__tests__/gate-identity-cross-surface.test.cjs compares every
99
- // surface so a fresh copy fails a test instead of misleading a reader.
100
- const rows = buildCoverageRows(artifact(), { headCommit: 'a0bceb9c0000000000000000000000000000000' });
101
- const build = rows.find((r) => r.name === 'Build Integrity');
102
- const sast = rows.find((r) => r.name === 'SAST Security');
103
- expect(build, 'Build Integrity row must exist').toBeDefined();
104
- expect(sast, 'SAST row must exist').toBeDefined();
105
- // Evidence: the real artifact keys (hooked at pre-commit:6158/6163).
106
- expect(build.gate).toBe(9);
107
- expect(sast.gate).toBe(10);
108
- });
109
-
110
- it('AC-636-03: a stale artifact is marked STALE instead of presented as current', () => {
111
- const rows = buildCoverageRows(artifact(), { headCommit: 'ffffffffffffffffffffffffffffffffffffffff' });
112
- const rendered = renderGateCoverage(rows, { stale: true, headCommit: 'ffffffffffffffffffffffffffffffffffffffff' });
113
- expect(rendered).toMatch(/STALE/i);
114
- });
115
-
116
- it('AC-636-04: DEBT is observable and quantified, not rendered as a clean PASS', () => {
117
- // Gate 6 holds no warnings of its own; the debt lives in the Boy Scout
118
- // baseline. A view that only reads gate statuses reports "PASS" and hides it.
119
- const rows = buildCoverageRows(artifact(), {
120
- headCommit: 'a0bceb9c0000000000000000000000000000000',
121
- boyScout: { files: 14, warnings: 129 },
122
- });
123
- const boyScout = rows.find((r) => /boy scout/i.test(r.name));
124
- expect(boyScout).toBeDefined();
125
- expect(boyScout.status).toBe(STATUS.DEBT);
126
- expect(String(boyScout.debt)).toMatch(/129/);
127
- expect(boyScout.evidence).toMatch(/warnings-baseline/);
128
- });
129
-
130
- it('AC-636-05: default exit does not fail on DEBT, but --strict does', () => {
131
- const debtRows = [{ gate: 6, name: 'Boy Scout', status: STATUS.DEBT, debt: '1 warning' }];
132
- expect(buildCoverageRows).toBeDefined();
133
- const { exitCodeFor } = require('../gate-coverage');
134
- // Debt is budgeted and known: failing on it by default makes the command
135
- // unusable as a CI dashboard.
136
- expect(exitCodeFor(debtRows, {})).toBe(0);
137
- expect(exitCodeFor(debtRows, { strict: true })).toBe(1);
138
- // A real failure always fails.
139
- expect(exitCodeFor([{ gate: 7, name: 'x', status: STATUS.FAIL }], {})).toBe(1);
140
- });
141
-
142
- it('AC-636-06: every row carries evidence pointing at the artifact that decided it', () => {
143
- const rows = buildCoverageRows(artifact(), { headCommit: 'a0bceb9c0000000000000000000000000000000' });
144
- // Without Evidence the user can only trust a one-line claim; with it they
145
- // can go check. Same reason `doctor` prints paths.
146
- for (const row of rows) {
147
- expect(row.evidence, `Gate ${row.gate} (${row.name}) has no evidence pointer`).toBeTruthy();
148
- }
149
- });
150
- });
151
-
152
- describe('REQ-GATEID-007 — artifact selection is deterministic or fails', () => {
153
- const fs = require('node:fs');
154
- const os = require('node:os');
155
- const pathMod = require('node:path');
156
- const { readQualityStatus } = require('../gate-coverage.js');
157
-
158
- function makeRepo(artifacts) {
159
- const root = fs.mkdtempSync(pathMod.join(os.tmpdir(), 'xp-gate-coverage-'));
160
- const dir = pathMod.join(root, '.xp-gate', 'quality-status');
161
- fs.mkdirSync(dir, { recursive: true });
162
- for (const [name, body] of Object.entries(artifacts)) {
163
- fs.writeFileSync(pathMod.join(dir, `${name}.json`), JSON.stringify(body));
164
- }
165
- return root;
166
- }
167
-
168
- it('AC-GATEID-007-01/04: several artifacts refuse to pick by directory order', () => {
169
- // This is the second cause of the wrong output this sprint fixes: bare
170
- // `xp-gate gate-coverage` used to read whichever file readdirSync returned
171
- // first -- here `land-pr438.json` (commit 33672f6d) rather than the branch's
172
- // own `main.json`. Reading the wrong object beats reading a stale one for
173
- // danger, and the `stale: true` notice masked it.
174
- const root = makeRepo({ 'cam-a': { commit: 'aaa' }, 'cam-b': { commit: 'bbb' } });
175
- const status = readQualityStatus(root);
176
- expect(status.artifact).toBeNull();
177
- expect(status.error).toBeTruthy();
178
- // The migration path must be discoverable from the message itself.
179
- expect(status.error).toMatch(/--branch/);
180
- expect(status.candidates.sort()).toEqual(['cam-a', 'cam-b']);
181
- // Every candidate must be named, not merely "there are several".
182
- expect(status.error).toMatch(/cam-a/);
183
- expect(status.error).toMatch(/cam-b/);
184
- });
185
-
186
- it('AC-GATEID-007-02: a single artifact still works', () => {
187
- const root = makeRepo({ only: { commit: 'ccc', gates: {} } });
188
- const status = readQualityStatus(root);
189
- expect(status.error).toBeUndefined();
190
- expect(status.artifact.commit).toBe('ccc');
191
- });
192
-
193
- it('AC-GATEID-007-03: an explicit --branch that does not exist errors instead of falling back', () => {
194
- const root = makeRepo({ other: { commit: 'ddd', gates: {} } });
195
- const status = readQualityStatus(root, 'missing');
196
- expect(status.artifact).toBeNull();
197
- expect(status.error).toMatch(/missing/);
198
- });
199
-
200
- it('AC-GATEID-007-03: an explicit --branch reads exactly that artifact', () => {
201
- const root = makeRepo({ 'cam-a': { commit: 'aaa' }, 'cam-b': { commit: 'bbb' } });
202
- expect(readQualityStatus(root, 'cam-b').artifact.commit).toBe('bbb');
203
- });
204
- });
@@ -1,71 +0,0 @@
1
- /**
2
- * @test REQ-672
3
- * @intent 门禁的 TypeScript 实现必须**随包走**,不能随被检项目的 cwd 走。
4
- *
5
- * `findTsGateEntry` 曾把 `process.cwd()/src/gates/<gate>.ts` 也列进候选。
6
- * 在开发者布局里这条永远轮不到(前三个候选先命中),所以在本仓跑任何
7
- * 断言都是绿的——**这正是这个缺陷能活下来的原因**。必须在 npm 安装布局
8
- * 下测:前三个候选都不存在,第四条的 cwd 候选才会浮上来。
9
- *
10
- * 后果不是"用错了文件",是**被检方决定门禁怎么判**:那个文件可以是
11
- * `process.exit(0)`,于是任何一个自带该路径的项目都能让自己通过任何门禁。
12
- * 一个能被被检对象改写的门禁不是门禁。
13
- *
14
- * 夹具把 `lib/` 复制到临时目录并**故意不放** `gates/` 兄弟目录,以此复现
15
- * npm 包的布局;被检项目则种下一个 `src/gates/gate-9.ts`。
16
- * @covers AC-672-01
17
- */
18
- 'use strict';
19
-
20
- const { spawnSync } = require('node:child_process');
21
- const fs = require('node:fs');
22
- const os = require('node:os');
23
- const path = require('node:path');
24
-
25
- const LIB_DIR = path.resolve(__dirname, '..');
26
-
27
- /**
28
- * Build an npm-install-shaped fixture and ask it to resolve gate-9.
29
- *
30
- * @returns {{ resolved: string, consumer: string, planted: string }} paths for assertions
31
- */
32
- function resolveInNpmLayout() {
33
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'xpg-provenance-'));
34
- // npm package layout: `lib/` exists, and there is NO `src/gates/` sibling three
35
- // levels up (that is the developer layout, which always wins when it is present).
36
- const pkg = path.join(root, 'node_modules', 'xp-gate');
37
- fs.mkdirSync(path.join(pkg, 'lib'), { recursive: true });
38
- fs.cpSync(LIB_DIR, path.join(pkg, 'lib'), { recursive: true });
39
-
40
- // The party being checked: it plants its own gate implementation.
41
- const consumer = path.join(root, 'consumer');
42
- const planted = path.join(consumer, 'src', 'gates', 'gate-9.ts');
43
- fs.mkdirSync(path.dirname(planted), { recursive: true });
44
- fs.writeFileSync(planted, 'process.exit(0)\n');
45
-
46
- const runner = path.join(pkg, 'lib', 'gate-runner.js');
47
- const script = [
48
- `const { findTsGateEntry } = require(${JSON.stringify(runner)});`,
49
- 'process.stdout.write(String(findTsGateEntry("gate-9")));',
50
- ].join('\n');
51
- const result = spawnSync(process.execPath, ['-e', script], {
52
- cwd: consumer,
53
- encoding: 'utf8',
54
- timeout: 30000,
55
- });
56
- return { resolved: (result.stdout || '').trim(), consumer, planted, root };
57
- }
58
-
59
- describe('findTsGateEntry 不从消费项目解析实现 (#672)', () => {
60
- it('AC-672-01: a project that plants src/gates/gate-9.ts cannot own the gate implementation', () => {
61
- const { resolved, consumer, root } = resolveInNpmLayout();
62
- try {
63
- // Whatever it resolves to (an installed package normally has no gates/ dir at
64
- // all, so `null` is fine), it must never be a file under the checked project:
65
- // that file is data supplied by the party being checked.
66
- expect(resolved.startsWith(consumer)).toBe(false);
67
- } finally {
68
- fs.rmSync(root, { recursive: true, force: true });
69
- }
70
- });
71
- });
@@ -1,79 +0,0 @@
1
- /**
2
- * @test REQ-686
3
- * @intent 验证 CLI 的门禁编号与钩子一致——钩子把 9 号门叫 Build integrity、
4
- * 10 号门叫 SAST,而 CLI 注册表把两者对调了;用户按报错提示单跑对应门
5
- * 会跑到另一道门上去(#677)
6
- * @covers AC-686-01, AC-686-02, AC-686-03
7
- *
8
- * 为什么必须直接断言注册表:这个错误的表现是「跑起来了、报告绿了」。
9
- * `xp-gate check --gates 9` 在编号错位时不会报错,它跑的是 semgrep 并如实报告
10
- * semgrep 的结果——只有拿它和钩子里的门名对照才能看出跑错了门。
11
- */
12
- 'use strict';
13
-
14
- const fs = require('fs');
15
- const path = require('path');
16
- const { GATE_REGISTRY, resolveAlias } = require('../gate-runner');
17
-
18
- const REPO_ROOT = path.join(__dirname, '../../../..');
19
-
20
- /**
21
- * Concatenate every file that participates in the pre-commit gate chain: the
22
- * entry point, the ordered driver, and one body per gate.
23
- *
24
- * #798 moved each gate's banner and logic out of pre-commit into
25
- * gate-entries/. Assertions about gate NAMES must therefore read the whole
26
- * chain, or they pass while the names moved to a file nothing sources.
27
- * @returns {string} the chain's source text, newline-joined
28
- */
29
- function readGateChain() {
30
- const parts = [fs.readFileSync(path.join(REPO_ROOT, 'githooks/pre-commit'), 'utf8')];
31
- const driver = path.join(REPO_ROOT, 'githooks/gate-driver.sh');
32
- if (fs.existsSync(driver)) parts.push(fs.readFileSync(driver, 'utf8'));
33
- const entriesDir = path.join(REPO_ROOT, 'githooks/gate-entries');
34
- if (fs.existsSync(entriesDir)) {
35
- for (const f of fs.readdirSync(entriesDir).sort()) {
36
- if (f.endsWith('.sh')) parts.push(fs.readFileSync(path.join(entriesDir, f), 'utf8'));
37
- }
38
- }
39
- return parts.join('\n');
40
- }
41
-
42
- describe('gate numbering matches the hook (#677)', () => {
43
- it('AC-686-01: gate 9 is Build Integrity and gate 10 is SAST Security', () => {
44
- expect(GATE_REGISTRY['9'].name).toBe('Build Integrity');
45
- expect(GATE_REGISTRY['10'].name).toBe('SAST Security');
46
- });
47
-
48
- it('AC-686-02: the hook agrees — its own output names 9 as Build integrity', () => {
49
- // Reads the hook rather than restating the constant: if the hook ever
50
- // renumbers again, this fails and points at which side moved.
51
- //
52
- // #798 moved each gate's banner into its own gate-entries/ file, so the
53
- // assertion reads the whole chain. It deliberately does NOT assert on
54
- // pre-commit alone: that would pass while every banner sat in a file no
55
- // hook sources -- the exact failure #677 was filed about.
56
- const hook = readGateChain();
57
- expect(hook).toMatch(/→ Gate 9: Build integrity/);
58
- expect(hook).toMatch(/GATE 10: Semgrep SAST/);
59
- });
60
-
61
- it('AC-686-03: aliases resolve to the gate the user meant', () => {
62
- expect(resolveAlias('sast')).toBe('10');
63
- expect(resolveAlias('semgrep')).toBe('10');
64
- expect(resolveAlias('build')).toBe('9');
65
- });
66
-
67
- it('AC-686-03: gates 12 and 13 are registered instead of "Unknown gate(s)"', () => {
68
- // Both block commits in the hook. Answering "Unknown gate" for a gate that just
69
- // blocked the user is the same category of wrong as running the wrong one.
70
- expect(GATE_REGISTRY['12'].name).toBe('File Hygiene');
71
- expect(GATE_REGISTRY['13'].name).toBe('Compiler Strictness');
72
- // They are registered as hook-only, with a stated reason -- not as runnable
73
- // stubs that would answer PASS without doing the work.
74
- expect(GATE_REGISTRY['12'].preCommitOnly).toBe(true);
75
- expect(GATE_REGISTRY['13'].preCommitOnly).toBe(true);
76
- expect(GATE_REGISTRY['12'].reason).toBeTruthy();
77
- expect(GATE_REGISTRY['13'].reason).toBeTruthy();
78
- });
79
- });
@@ -1,58 +0,0 @@
1
- /**
2
- * @test REQ-652 BUILD 阶段的门禁清单必须从真相源生成,而非手抄
3
- * @intent #652 的实证是:BUILD 阶段生成代码时,模型对 Boy Scout / CCN / jscpd /
4
- * archlint 完全不可知——不是"知道却不遵守",是**根本不知道规则存在**。
5
- * 后果是 27% 的门禁失败属于静态规则违规,即唯一 100% 可在生成前规避的类别。
6
- *
7
- * 补一页手写的阈值表能解决今天的问题,但会制造明天的问题:`.principlesrc`
8
- * 里 `long-function` 是 50、`deep-nesting` 是 4,一旦有人调成 60/5,那一页
9
- * 手抄的表就开始说谎。**一个说谎的自检清单比没有清单更糟**——它会让人按错的
10
- * 规则写代码,然后在提交时被告知另一套。
11
- *
12
- * 所以这个清单必须从配置文件生成。真相源有几个就在几个里读,不复制。
13
- * @covers AC-652-01, AC-652-02, AC-652-03
14
- */
15
- 'use strict';
16
-
17
- const fs = require('node:fs');
18
- const path = require('node:path');
19
- const { collectGateRules } = require('../gate-rules');
20
-
21
- const REPO = path.join(__dirname, '..', '..', '..', '..');
22
-
23
- describe('BUILD 阶段门禁清单 (#652)', () => {
24
- it('AC-652-01: 从 .principlesrc 读出真实阈值,不是写死的数字', () => {
25
- const rules = collectGateRules({ cwd: REPO });
26
- const longFn = rules.find((r) => r.id === 'clean-code.long-function');
27
- const nesting = rules.find((r) => r.id === 'clean-code.deep-nesting');
28
- expect(longFn).toBeDefined();
29
- expect(nesting).toBeDefined();
30
- // The value must come from the config file. Reading .principlesrc here keeps the
31
- // test honest: if the config changes and the generator does not follow, this fails.
32
- const cfg = JSON.parse(fs.readFileSync(path.join(REPO, '.principlesrc'), 'utf8'));
33
- expect(longFn.threshold).toBe(cfg.rules['clean-code']['long-function'].threshold);
34
- expect(nesting.threshold).toBe(cfg.rules['clean-code']['deep-nesting'].threshold);
35
- });
36
-
37
- it('AC-652-02: 覆盖会阻断提交的每一类规则,而不只是 principles', () => {
38
- const rules = collectGateRules({ cwd: REPO });
39
- const sources = new Set(rules.map((r) => r.source));
40
- // #652 named exactly these four as absent from BUILD docs.
41
- for (const required of ['principles', 'ccn', 'jscpd', 'boy-scout']) {
42
- expect(sources).toContain(required);
43
- }
44
- });
45
-
46
- it('AC-652-03: 生成结果可渲染成一份自检清单,含阈值与出处', () => {
47
- const rules = collectGateRules({ cwd: REPO });
48
- for (const rule of rules) {
49
- expect(typeof rule.id).toBe('string');
50
- expect(typeof rule.source).toBe('string');
51
- // Without the evidence pointer, "the threshold is 50" cannot be checked or
52
- // argued with -- it is indistinguishable from a guess.
53
- expect(typeof rule.evidence).toBe('string');
54
- expect(rule.evidence).not.toBe('');
55
- expect(['block', 'warn', 'info']).toContain(rule.severity);
56
- }
57
- });
58
- });
@@ -1,149 +0,0 @@
1
- /**
2
- * @test REQ-ts-gate-startup tsx 直调(#779)
3
- * @intent 证明 TypeScript 门禁不再经 `npx -y tsx` 启动,而是用当前 node.exe 直接
4
- * 运行 tsx 的 cli.mjs。`npx -y` 每次都要重新解析包位置,实测 4.5-5.8s,而
5
- * node 直调 0.79-0.82s —— 每道 TS 门禁白付约 4 秒。
6
- * @covers AC-TS-GATE-STARTUP-01, AC-TS-GATE-STARTUP-02, AC-TS-GATE-STARTUP-03, AC-TS-GATE-STARTUP-04
7
- */
8
- const fs = require('node:fs');
9
- const path = require('node:path');
10
- const os = require('node:os');
11
- const { resolveTsxInvocation } = require('../gate-runner');
12
-
13
- let tmpDir;
14
-
15
- beforeEach(() => {
16
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-tsx-'));
17
- });
18
-
19
- afterEach(() => {
20
- if (tmpDir && fs.existsSync(tmpDir)) {
21
- fs.rmSync(tmpDir, { recursive: true, force: true });
22
- }
23
- });
24
-
25
- /**
26
- * Lay down a fake <root>/node_modules/tsx/dist/cli.mjs that exists and is readable.
27
- *
28
- * Failing here means the FIXTURE broke, not the resolver, so the error names the
29
- * fixture. Swallowing it would let a setup defect surface later as "the resolver
30
- * returned the npx fallback", which is a misleading diagnosis.
31
- */
32
- function plantLocalTsx(root) {
33
- const cli = path.join(root, 'node_modules', 'tsx', 'dist', 'cli.mjs');
34
- try {
35
- fs.mkdirSync(path.dirname(cli), { recursive: true });
36
- fs.writeFileSync(cli, '// fake tsx cli' + String.fromCharCode(10));
37
- } catch (err) {
38
- throw new Error(`fixture: could not plant tsx cli at ${cli}: ${err.message}`);
39
- }
40
- return cli;
41
- }
42
-
43
- describe('resolveTsxInvocation — AC-TS-GATE-STARTUP-01', () => {
44
- it('uses node.exe + tsx/cli.mjs when a local tsx is installed', () => {
45
- const cli = plantLocalTsx(tmpDir);
46
- const { command, args } = resolveTsxInvocation(['gate.ts', '--run'], { cwd: tmpDir });
47
-
48
- expect(command).toBe(process.execPath);
49
- expect(args[0]).toBe(cli);
50
- expect(args.slice(1)).toEqual(['gate.ts', '--run']);
51
- });
52
-
53
- it('never puts `-y` in the argv — that is the npx network-retry flag', () => {
54
- plantLocalTsx(tmpDir);
55
- const { args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
56
- expect(args).not.toContain('-y');
57
- expect(args).not.toContain('tsx');
58
- });
59
- });
60
-
61
- describe('resolveTsxInvocation — AC-TS-GATE-STARTUP-02', () => {
62
- it('walks up parent directories to find a hoisted node_modules/tsx', () => {
63
- const nested = path.join(tmpDir, 'a', 'b', 'c');
64
- fs.mkdirSync(nested, { recursive: true });
65
- const cli = plantLocalTsx(tmpDir);
66
-
67
- const { args } = resolveTsxInvocation(['gate.ts'], { cwd: nested });
68
- expect(args[0]).toBe(cli);
69
- });
70
-
71
- it('falls back to npm npx-cli.js (still no shell) when no tsx is installed', () => {
72
- const { command, args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
73
-
74
- // The fallback keeps the pre-existing no-shell guarantee: node.exe runs npx's
75
- // own JS entry. What must NOT happen is a bare `npx` (unresolvable without a
76
- // shell on Windows) or `shell: true` (cmd.exe's 8191-char ceiling, #586).
77
- expect(command).toBe(process.execPath);
78
- expect(args.some((a) => String(a).includes('npx-cli.js'))).toBe(true);
79
- expect(args).toContain('-y');
80
- });
81
- });
82
-
83
- describe('resolveTsxInvocation — AC-TS-GATE-STARTUP-03', () => {
84
- it('ignores a tsx dir that exists but has no cli.mjs (partial install)', () => {
85
- fs.mkdirSync(path.join(tmpDir, 'node_modules', 'tsx', 'dist'), { recursive: true });
86
- const { args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
87
- expect(args.some((a) => String(a).includes('npx-cli.js'))).toBe(true);
88
- });
89
-
90
- it('produces a spawnable argv: an existing file for args[0] when local', () => {
91
- plantLocalTsx(tmpDir);
92
- const { command, args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
93
- expect(command).toBe(process.execPath);
94
- expect(fs.existsSync(args[0])).toBe(true);
95
- });
96
- });
97
-
98
- describe('resolveTsxInvocation — AC-TS-GATE-STARTUP-04 (npm layout varies by install)', () => {
99
- /**
100
- * Restore `process.execPath` after the probe. Kept as a helper because the
101
- * override is only sound if it is undone even when an assertion throws, and an
102
- * unrestored execPath would corrupt every later test in this process.
103
- */
104
- function withExecPath(fakeNode, fn) {
105
- const real = process.execPath;
106
- Object.defineProperty(process, 'execPath', { value: fakeNode, configurable: true });
107
- try {
108
- return fn();
109
- } finally {
110
- Object.defineProperty(process, 'execPath', { value: real, configurable: true });
111
- delete require.cache[require.resolve('../gate-runner')];
112
- }
113
- }
114
-
115
- it('finds npm under lib/node_modules — the layout actions/setup-node produces on Linux', () => {
116
- // This is the shape CI actually runs on: /opt/hostedtoolcache/node/<v>/x64/bin/node
117
- // with npm's library at <...>/lib/node_modules/npm, not alongside the binary.
118
- // Probe order matters only because the plain layout is tried first; what this
119
- // asserts is that the `lib/` layout is tried at all.
120
- const root = path.join(tmpDir, 'node-install');
121
- const fakeNode = path.join(root, 'x64', 'bin', 'node');
122
- const libNpm = path.join(root, 'x64', 'lib', 'node_modules', 'npm', 'bin', 'npx-cli.js');
123
- fs.mkdirSync(path.dirname(libNpm), { recursive: true });
124
- fs.writeFileSync(libNpm, '');
125
-
126
- withExecPath(fakeNode, () => {
127
- const { command, args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
128
- // A bare `npx` here is the defect: unresolvable without a shell on Windows,
129
- // and a PATH hop that silently runs whatever npx happens to be first.
130
- expect(command).toBe(fakeNode);
131
- expect(args.some((a) => String(a).includes('npx-cli.js'))).toBe(true);
132
- expect(fs.existsSync(args[0])).toBe(true);
133
- });
134
- });
135
-
136
- it('finds npm alongside the binary — the Windows MSI / official tarball layout', () => {
137
- const root = path.join(tmpDir, 'win-install');
138
- const fakeNode = path.join(root, 'node.exe');
139
- const plainNpm = path.join(root, 'node_modules', 'npm', 'bin', 'npx-cli.js');
140
- fs.mkdirSync(path.dirname(plainNpm), { recursive: true });
141
- fs.writeFileSync(plainNpm, '');
142
-
143
- withExecPath(fakeNode, () => {
144
- const { command, args } = resolveTsxInvocation(['gate.ts'], { cwd: tmpDir });
145
- expect(command).toBe(fakeNode);
146
- expect(args.some((a) => String(a).includes('npx-cli.js'))).toBe(true);
147
- });
148
- });
149
- });
@@ -1,105 +0,0 @@
1
- /**
2
- * @test REQ-563 runGate must not discard a synchronous gate verdict
3
- * @intent `runGate()` reports "passed" for every gate whose `run()` returns a
4
- * number instead of a Promise. Four registry entries — gates 3, 7, 8
5
- * and 9 — reach `runTsGate()`, which returns `result.status` as a plain
6
- * number, and the runner's own code path was:
7
- *
8
- * const result = gate.run(targetPath);
9
- * if (result && typeof result.then === 'function') return await result;
10
- * return 0; // <-- the number is dropped here
11
- *
12
- * So a gate that exits 1 in its child process is reported as 0 by
13
- * `xp-gate check`. `checkAllGates()` counts `code !== 0` as a failure, so
14
- * it faithfully counts whatever `runGate` hands back — which is always
15
- * 0 for those four gates. The fail-open is in exactly one place and it
16
- * is silent: nothing in the output says the verdict was manufactured.
17
- *
18
- * Gates 4 and 6 escaped this by returning `Promise.resolve(...)`, and
19
- * gate 2 escaped it because `execFileSync` throws on a non-zero exit and
20
- * the `catch` converts that to 1. Both of those are accidents of how
21
- * each handler was written, not a contract — which is why the fix has to
22
- * be in the runner, not in each handler.
23
- * @covers AC-563-01, AC-563-02, AC-563-03
24
- */
25
- const gateRunner = require('../gate-runner.js');
26
- const { runGate, GATE_REGISTRY } = gateRunner;
27
-
28
- const STUB_GATE_ID = '__stub_gate__';
29
-
30
- /**
31
- * Install a throwaway registry entry and return a cleanup function.
32
- * @param {object} handler - the `run` implementation to install
33
- * @returns {Function} cleanup
34
- */
35
- function withStubGate(handler) {
36
- GATE_REGISTRY[STUB_GATE_ID] = {
37
- name: 'Stub Gate',
38
- description: 'test double',
39
- aliases: [],
40
- run: handler,
41
- };
42
- return () => {
43
- delete GATE_REGISTRY[STUB_GATE_ID];
44
- };
45
- }
46
-
47
- let cleanup = null;
48
-
49
- beforeEach(() => {
50
- // Keep the console quiet: runGate prints a banner for every invocation.
51
- if (!global.__xpGateStubLog) {
52
- global.__xpGateStubLog = console.log;
53
- }
54
- console.log = () => {};
55
- });
56
-
57
- afterEach(() => {
58
- if (cleanup) {
59
- cleanup();
60
- cleanup = null;
61
- }
62
- console.log = global.__xpGateStubLog;
63
- });
64
-
65
- describe('runGate verdict propagation', () => {
66
- test('AC-563-01: a synchronous non-zero verdict is returned, not swallowed', async () => {
67
- // This is the exact shape `runTsGate` has: a plain number, no Promise.
68
- cleanup = withStubGate(() => 1);
69
-
70
- const code = await runGate(STUB_GATE_ID, '.');
71
-
72
- expect(
73
- code,
74
- 'runGate returned a manufactured 0 for a gate whose synchronous handler ' +
75
- 'said 1 — the caller (checkAllGates) cannot distinguish pass from fail'
76
- ).toBe(1);
77
- });
78
-
79
- test('AC-563-02: a synchronous zero verdict still reads as pass', async () => {
80
- // The guard against "fix it by always failing": a genuine 0 must stay 0.
81
- cleanup = withStubGate(() => 0);
82
-
83
- const code = await runGate(STUB_GATE_ID, '.');
84
-
85
- expect(code).toBe(0);
86
- });
87
-
88
- test('AC-563-03: async and throwing handlers keep their existing verdicts', async () => {
89
- // Promise-returning handlers already worked; the fix must not regress them.
90
- cleanup = withStubGate(() => Promise.resolve(2));
91
- expect(await runGate(STUB_GATE_ID, '.')).toBe(2);
92
- cleanup();
93
-
94
- cleanup = withStubGate(() => {
95
- throw new Error('boom');
96
- });
97
- expect(await runGate(STUB_GATE_ID, '.')).toBe(1);
98
- cleanup();
99
-
100
- // An async handler that REJECTS must also fail closed, not propagate an
101
- // unhandled rejection out of runGate.
102
- cleanup = withStubGate(() => Promise.reject(new Error('async boom')));
103
- expect(await runGate(STUB_GATE_ID, '.')).toBe(1);
104
- });
105
- });