@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,67 +0,0 @@
1
- /**
2
- * @test REQ-2 xp-gate doctor
3
- * @intent Prove that the path constants follow process.env.HOME even when
4
- * another module loaded shared-paths.js first (the doctor.test.js bug:
5
- * detect-deps.js is loaded in beforeAll, before any HOME is set, which
6
- * pinned CONFIG_FILE to the REAL home for the rest of the suite).
7
- * @covers AC-05, AC-08, AC-10
8
- */
9
- const fs = require('fs');
10
- const path = require('path');
11
- const os = require('os');
12
-
13
- describe('shared-paths resolves the home directory lazily', () => {
14
- let originalHome;
15
- let tmpA;
16
- let tmpB;
17
-
18
- beforeEach(() => {
19
- originalHome = process.env.HOME;
20
- tmpA = fs.mkdtempSync(path.join(os.tmpdir(), 'sp-a-'));
21
- tmpB = fs.mkdtempSync(path.join(os.tmpdir(), 'sp-b-'));
22
- vi.resetModules();
23
- });
24
-
25
- afterEach(() => {
26
- process.env.HOME = originalHome;
27
- for (const d of [tmpA, tmpB]) {
28
- if (d && fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
29
- }
30
- vi.resetModules();
31
- });
32
-
33
- function freshSharedPaths() {
34
- const p = require.resolve('../shared-paths');
35
- delete require.cache[p];
36
- return require('../shared-paths');
37
- }
38
-
39
- it('CONFIG_FILE follows a HOME change made after the module was first loaded', () => {
40
- process.env.HOME = tmpA;
41
- const first = freshSharedPaths();
42
- expect(first.CONFIG_FILE).toBe(path.join(tmpA, '.config', 'xp-gate', 'xp-gate.json'));
43
-
44
- // A second "test" changes HOME — the same module object must now reflect it.
45
- process.env.HOME = tmpB;
46
- expect(first.CONFIG_FILE).toBe(
47
- path.join(tmpB, '.config', 'xp-gate', 'xp-gate.json'),
48
- 'CONFIG_FILE still points at the HOME value captured at require() time'
49
- );
50
- });
51
-
52
- it('HOME_DIR follows a HOME change made after the module was first loaded', () => {
53
- process.env.HOME = tmpA;
54
- const sp = freshSharedPaths();
55
- expect(sp.HOME_DIR).toBe(tmpA);
56
- process.env.HOME = tmpB;
57
- expect(sp.HOME_DIR).toBe(tmpB, 'HOME_DIR is frozen at require() time');
58
- });
59
-
60
- it('a fresh require after a HOME change also reflects it (regression guard)', () => {
61
- process.env.HOME = tmpA;
62
- freshSharedPaths();
63
- process.env.HOME = tmpB;
64
- const sp = freshSharedPaths();
65
- expect(sp.CONFIG_FILE).toBe(path.join(tmpB, '.config', 'xp-gate', 'xp-gate.json'));
66
- });
67
- });
@@ -1,130 +0,0 @@
1
- /**
2
- * @test shared-paths
3
- * @intent Verify platform-aware template directory resolution
4
- * @covers Issue #188 — templateDir pointing to OpenCode residue path
5
- */
6
- const path = require('path');
7
- const fs = require('fs');
8
- const os = require('os');
9
-
10
- describe('shared-paths', () => {
11
- let tmpHome;
12
- let originalHome;
13
-
14
- beforeEach(() => {
15
- originalHome = process.env.HOME;
16
- tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-sp-'));
17
- process.env.HOME = tmpHome;
18
- vi.resetModules();
19
- delete require.cache[require.resolve('../shared-paths')];
20
- });
21
-
22
- afterEach(() => {
23
- process.env.HOME = originalHome;
24
- if (tmpHome && fs.existsSync(tmpHome)) {
25
- fs.rmSync(tmpHome, { recursive: true, force: true });
26
- }
27
- });
28
-
29
- function createPlatformMarker(platform) {
30
- const dirs = {
31
- opencode: path.join(tmpHome, '.config', 'opencode', 'skills'),
32
- 'claude-code': path.join(tmpHome, '.claude', 'skills'),
33
- qoder: path.join(tmpHome, '.qoder', 'skills'),
34
- };
35
- const dir = dirs[platform];
36
- if (dir) {
37
- fs.mkdirSync(dir, { recursive: true });
38
- }
39
- }
40
-
41
- it('returns opencode template dir when no platform marker exists (default)', () => {
42
- const { TEMPLATE_DIR } = require('../shared-paths');
43
- expect(TEMPLATE_DIR).toBe(path.join(tmpHome, '.config', 'opencode', 'git-hooks-template'));
44
- });
45
-
46
- it('returns opencode template dir when opencode platform marker exists', () => {
47
- createPlatformMarker('opencode');
48
- const { TEMPLATE_DIR } = require('../shared-paths');
49
- expect(TEMPLATE_DIR).toBe(path.join(tmpHome, '.config', 'opencode', 'git-hooks-template'));
50
- });
51
-
52
- it('returns claude-code template dir when claude-code platform marker exists', () => {
53
- createPlatformMarker('claude-code');
54
- const { TEMPLATE_DIR } = require('../shared-paths');
55
- expect(TEMPLATE_DIR).toBe(path.join(tmpHome, '.claude', 'git-hooks-template'));
56
- });
57
-
58
- it('returns qoder template dir when qoder platform marker exists', () => {
59
- createPlatformMarker('qoder');
60
- const { TEMPLATE_DIR } = require('../shared-paths');
61
- expect(TEMPLATE_DIR).toBe(path.join(tmpHome, '.qoder', 'git-hooks-template'));
62
- });
63
-
64
- it('qoder marker takes priority over opencode when both exist', () => {
65
- createPlatformMarker('opencode');
66
- createPlatformMarker('qoder');
67
- const { TEMPLATE_DIR } = require('../shared-paths');
68
- // Qoder should take priority (checked first)
69
- expect(TEMPLATE_DIR).toBe(path.join(tmpHome, '.qoder', 'git-hooks-template'));
70
- });
71
-
72
- it('detectPlatform returns opencode when no marker exists', () => {
73
- const { detectPlatform } = require('../shared-paths');
74
- expect(detectPlatform()).toBe('opencode');
75
- });
76
-
77
- it('detectPlatform returns qoder when qoder marker exists', () => {
78
- createPlatformMarker('qoder');
79
- const { detectPlatform } = require('../shared-paths');
80
- expect(detectPlatform()).toBe('qoder');
81
- });
82
-
83
- it('detectPlatform returns claude-code when claude-code marker exists', () => {
84
- createPlatformMarker('claude-code');
85
- const { detectPlatform } = require('../shared-paths');
86
- expect(detectPlatform()).toBe('claude-code');
87
- });
88
-
89
- // ── #424: brand-new Qoder installs have no skills/ subdirectory yet ──
90
-
91
- it('detectPlatform returns qoder when only ~/.qoder exists (brand-new install, no skills dir)', () => {
92
- fs.mkdirSync(path.join(tmpHome, '.qoder'), { recursive: true });
93
- const { detectPlatform } = require('../shared-paths');
94
- expect(detectPlatform()).toBe('qoder');
95
- });
96
-
97
- it('detectPlatform returns qoder when only ~/.qoder/agents exists (no skills dir)', () => {
98
- fs.mkdirSync(path.join(tmpHome, '.qoder', 'agents'), { recursive: true });
99
- const { detectPlatform } = require('../shared-paths');
100
- expect(detectPlatform()).toBe('qoder');
101
- });
102
-
103
- it('detect-deps re-exports the SAME detectPlatform as shared-paths (no divergent copies)', () => {
104
- const fromShared = require('../shared-paths').detectPlatform;
105
- const fromDetectDeps = require('../detect-deps').detectPlatform;
106
- expect(fromDetectDeps).toBe(fromShared);
107
- });
108
-
109
- it('getTemplateDir returns correct path for each platform', () => {
110
- const { getTemplateDir } = require('../shared-paths');
111
-
112
- // No marker → opencode
113
- expect(getTemplateDir()).toBe(path.join(tmpHome, '.config', 'opencode', 'git-hooks-template'));
114
-
115
- // Qoder marker
116
- createPlatformMarker('qoder');
117
- // Need fresh module to re-evaluate
118
- delete require.cache[require.resolve('../shared-paths')];
119
- const { getTemplateDir: getTpl2 } = require('../shared-paths');
120
- expect(getTpl2()).toBe(path.join(tmpHome, '.qoder', 'git-hooks-template'));
121
- });
122
-
123
- it('CONFIG_DIR and GLOBAL_HOOKS_DIR remain under xp-gate regardless of platform', () => {
124
- createPlatformMarker('qoder');
125
- const { CONFIG_DIR, GLOBAL_HOOKS_DIR, GLOBAL_ADAPTERS_DIR } = require('../shared-paths');
126
- expect(CONFIG_DIR).toBe(path.join(tmpHome, '.config', 'xp-gate'));
127
- expect(GLOBAL_HOOKS_DIR).toBe(path.join(tmpHome, '.config', 'xp-gate', 'hooks'));
128
- expect(GLOBAL_ADAPTERS_DIR).toBe(path.join(tmpHome, '.config', 'xp-gate', 'adapters'));
129
- });
130
- });
@@ -1,69 +0,0 @@
1
- /**
2
- * @test REQ-DEPLOY-001 copyHooks 消费方接线(AC-DEPLOY-08/09)
3
- * @intent 验证 shared-utils.copyHooks 与 update-hooks.copyHooks 的 hook 文件列表
4
- * 来自 deploy-manifest.js 的单一事实源(HOOK_FILES),而非各自手写的字面量
5
- * 清单。update-hooks 原先只拷 3 个 hook(pre-commit/pre-push/post-merge),
6
- * 缺 post-commit 与 hook-module-resolution.sh——后者缺失会让 pre-commit 在
7
- * 任何 tier 决策前 fail-closed FATAL,即 AC-DEPLOY-09 记录的活 bug。
8
- * 接线后两者都从 HOOK_FILES 取,update-hooks 自动补齐 5 个。
9
- * @covers AC-DEPLOY-08, AC-DEPLOY-09
10
- */
11
- const fs = require('node:fs');
12
- const os = require('node:os');
13
- const path = require('node:path');
14
-
15
- const manifest = require('../deploy-manifest.js');
16
- const updateHooks = require('../update-hooks.js');
17
-
18
- const LIB_DIR = path.resolve(__dirname, '..');
19
- const SHARED_UTILS = path.join(LIB_DIR, 'shared-utils.js');
20
- const UPDATE_HOOKS = path.join(LIB_DIR, 'update-hooks.js');
21
- const PKG_ROOT = path.resolve(LIB_DIR, '..');
22
-
23
- describe('copyHooks consumers wire to deploy-manifest (REQ-DEPLOY-001)', () => {
24
- describe('AC-DEPLOY-08: 数据源统一,无私有清单', () => {
25
- it('shared-utils.js 从 deploy-manifest 取 hook 列表', () => {
26
- const src = fs.readFileSync(SHARED_UTILS, 'utf8');
27
- expect(src).toMatch(/require\(['"]\.\/deploy-manifest\.js['"]\)/);
28
- // 反空缺:硬编码字面量必须消失,否则"消费清单"只是注释里的一句话。
29
- expect(src).not.toMatch(/\['pre-commit'\s*,\s*'pre-push'/);
30
- });
31
-
32
- it('update-hooks.js 从 deploy-manifest 取 hook 列表', () => {
33
- const src = fs.readFileSync(UPDATE_HOOKS, 'utf8');
34
- expect(src).toMatch(/require\(['"]\.\/deploy-manifest\.js['"]\)/);
35
- expect(src).not.toMatch(/\['pre-commit'\s*,\s*'pre-push'\s*,\s*'post-merge'\]/);
36
- });
37
-
38
- it('init.js 已经由 shared-utils.copyHooks 间接消费(无需自持清单)', () => {
39
- const src = fs.readFileSync(path.join(LIB_DIR, 'init.js'), 'utf8');
40
- expect(src).toMatch(/require\(['"]\.\/shared-utils\.js['"]\)/);
41
- expect(src).toMatch(/copyHooks/);
42
- });
43
- });
44
-
45
- describe('AC-DEPLOY-09: update-hooks 装出 HOOK_FILES 全集', () => {
46
- it('update-hooks.copyHooks 拷出 5 个 hook 与 lib/', () => {
47
- const destDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-gate-ac09-'));
48
- try {
49
- updateHooks.copyHooks(PKG_ROOT, destDir, false, false);
50
-
51
- for (const hook of manifest.HOOK_FILES) {
52
- expect(
53
- fs.existsSync(path.join(destDir, hook)),
54
- `update-hooks 未部署 ${hook}——缺 hook-module-resolution.sh 会让 pre-commit FATAL`,
55
- ).toBe(true);
56
- }
57
- // 反空缺:hook 集必须恰好是 HOOK_FILES 的规模,不是"至少 3 个"。
58
- const shipped = fs
59
- .readdirSync(destDir, { withFileTypes: true })
60
- .filter(e => e.isFile() && manifest.HOOK_FILES.includes(e.name))
61
- .map(e => e.name);
62
- expect(shipped.sort()).toEqual([...manifest.HOOK_FILES].sort());
63
- expect(fs.existsSync(path.join(destDir, 'lib'))).toBe(true);
64
- } finally {
65
- fs.rmSync(destDir, { recursive: true, force: true });
66
- }
67
- });
68
- });
69
- });
@@ -1,180 +0,0 @@
1
- /**
2
- * @test shared-utils
3
- * @intent Verify copyAdapters deploys shipped gate scripts (gate-*.sh, sprint-gate.sh) from the package root so npm-installed init/setup-global produce working gates
4
- * @covers gate-script deployment into ADAPTER_DIR / PROJECT_GITHOOKS for init and setup-global
5
- */
6
- const fs = require('node:fs');
7
- const path = require('node:path');
8
- const os = require('node:os');
9
-
10
- describe('shared-utils', () => {
11
- let tmpRoot;
12
-
13
- beforeEach(() => {
14
- tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'xpgate-shared-utils-'));
15
- vi.resetModules();
16
- });
17
-
18
- afterEach(() => {
19
- fs.rmSync(tmpRoot, { recursive: true, force: true });
20
- vi.restoreAllMocks();
21
- });
22
-
23
- describe('copyAdapters', () => {
24
- it('copies gate-*.sh and sprint-gate.sh from the package root (npm install layout)', () => {
25
- // npm install layout: the package root carries the shipped copies of
26
- // gate-*.sh + sprint-gate.sh (placed by sync-package-content.js) and the
27
- // repo-level githooks/ directory does not exist.
28
- const pkgRoot = path.join(tmpRoot, 'node_modules', '@boyingliu01', 'xp-gate');
29
- fs.mkdirSync(pkgRoot, { recursive: true });
30
- fs.writeFileSync(path.join(pkgRoot, 'adapter-common.sh'), '# adapter-common');
31
- fs.writeFileSync(path.join(pkgRoot, 'gate-3.sh'), '# gate-3');
32
- fs.writeFileSync(path.join(pkgRoot, 'gate-12-file-hygiene.sh'), '# gate-12');
33
- fs.writeFileSync(path.join(pkgRoot, 'sprint-gate.sh'), '# sprint-gate');
34
- fs.mkdirSync(path.join(pkgRoot, 'adapters'), { recursive: true });
35
- fs.writeFileSync(path.join(pkgRoot, 'adapters', 'typescript.sh'), '# ts');
36
-
37
- const destDir = path.join(tmpRoot, 'project-githooks');
38
- fs.mkdirSync(destDir, { recursive: true });
39
-
40
- const { copyAdapters } = require('../shared-utils');
41
- copyAdapters(pkgRoot, destDir);
42
-
43
- expect(fs.existsSync(path.join(destDir, 'adapter-common.sh'))).toBe(true);
44
- expect(fs.existsSync(path.join(destDir, 'typescript.sh'))).toBe(true);
45
- expect(fs.existsSync(path.join(destDir, 'gate-3.sh'))).toBe(true);
46
- expect(fs.existsSync(path.join(destDir, 'gate-12-file-hygiene.sh'))).toBe(true);
47
- expect(fs.existsSync(path.join(destDir, 'sprint-gate.sh'))).toBe(true);
48
- });
49
-
50
- it('copies only gate-*.sh and sprint-gate.sh from the package root (filters other files)', () => {
51
- const pkgRoot = path.join(tmpRoot, 'pkg');
52
- fs.mkdirSync(path.join(pkgRoot, 'adapters'), { recursive: true });
53
- fs.writeFileSync(path.join(pkgRoot, 'adapter-common.sh'), '# adapter-common');
54
- fs.writeFileSync(path.join(pkgRoot, 'gate-3.sh'), '# gate-3');
55
- fs.writeFileSync(path.join(pkgRoot, 'verify.sh'), '# verify');
56
- fs.writeFileSync(path.join(pkgRoot, 'VERSION'), '1.0.0.0');
57
-
58
- const destDir = path.join(tmpRoot, 'dest');
59
- fs.mkdirSync(destDir, { recursive: true });
60
-
61
- const { copyAdapters } = require('../shared-utils');
62
- copyAdapters(pkgRoot, destDir);
63
-
64
- expect(fs.existsSync(path.join(destDir, 'gate-3.sh'))).toBe(true);
65
- expect(fs.existsSync(path.join(destDir, 'verify.sh'))).toBe(false);
66
- expect(fs.existsSync(path.join(destDir, 'VERSION'))).toBe(false);
67
- });
68
- it('copies hooks/lib so gate-3 can source the complexity ratchet library', () => {
69
- // gate-3.sh resolves $GATE_DIR/lib/ccn-ratchet.sh, and GATE_DIR is this same
70
- // adapters directory (init.js: copyAdapters(srcDir, GLOBAL_ADAPTERS_DIR)). The
71
- // installer used to skip hooks/lib entirely, so the source failed with "No such
72
- // file or directory", evaluate_ccn_ratchet stayed undefined and the ratchet
73
- // graded every CCN regression as PASS.
74
- const pkgRoot = path.join(tmpRoot, 'pkg');
75
- fs.mkdirSync(path.join(pkgRoot, 'hooks', 'lib'), { recursive: true });
76
- fs.writeFileSync(path.join(pkgRoot, 'gate-3.sh'), '# gate-3');
77
- fs.writeFileSync(path.join(pkgRoot, 'hooks', 'lib', 'ccn-ratchet.sh'), '# ratchet');
78
- fs.writeFileSync(path.join(pkgRoot, 'hooks', 'lib', 'now-ms.sh'), '# now-ms');
79
-
80
- const destDir = path.join(tmpRoot, 'adapters');
81
- fs.mkdirSync(destDir, { recursive: true });
82
-
83
- const { copyAdapters } = require('../shared-utils');
84
- copyAdapters(pkgRoot, destDir);
85
-
86
- expect(fs.existsSync(path.join(destDir, 'lib', 'ccn-ratchet.sh'))).toBe(true);
87
- expect(fs.existsSync(path.join(destDir, 'lib', 'now-ms.sh'))).toBe(true);
88
- });
89
- });
90
- describe('copyHooks ships post-commit (audit flush + bypass detection)', () => {
91
- it('@covers gate-script deployment: copyHooks installs post-commit, not just pre-commit/pre-push/post-merge', () => {
92
- // Regression: post-commit was absent from both the ship list and copyHooks,
93
- // so the audit-attribution flush and --no-verify bypass detection that live
94
- // in post-commit never executed for any installed user.
95
- const pkgRoot = path.join(tmpRoot, 'node_modules', '@boyingliu01', 'xp-gate');
96
- const hooksSrc = path.join(pkgRoot, 'hooks');
97
- fs.mkdirSync(hooksSrc, { recursive: true });
98
- for (const h of ['pre-commit', 'pre-push', 'post-commit', 'post-merge']) {
99
- fs.writeFileSync(path.join(hooksSrc, h), `# ${h}`);
100
- }
101
- const destDir = path.join(tmpRoot, 'dest-hooks');
102
- fs.mkdirSync(destDir, { recursive: true });
103
-
104
- const { copyHooks } = require('../shared-utils');
105
- copyHooks(pkgRoot, destDir);
106
-
107
- expect(fs.existsSync(path.join(destDir, 'post-commit'))).toBe(true);
108
- expect(fs.existsSync(path.join(destDir, 'pre-commit'))).toBe(true);
109
- });
110
- });
111
-
112
- describe('copyHooks ships hook-module-resolution.sh (#655/#631)', () => {
113
- it('@covers gate-script deployment: copyHooks installs hook-module-resolution.sh so pre-commit does not FATAL', () => {
114
- // pre-commit loads hook-module-resolution.sh before any tier decision and
115
- // fails closed. It was absent from copyHooks, so every fresh `init` /
116
- // `setup-global` produced hooks that FATAL'd on every commit.
117
- const pkgRoot = path.join(tmpRoot, 'node_modules', '@boyingliu01', 'xp-gate');
118
- const hooksSrc = path.join(pkgRoot, 'hooks');
119
- fs.mkdirSync(hooksSrc, { recursive: true });
120
- for (const h of ['pre-commit', 'pre-push', 'post-commit', 'post-merge', 'hook-module-resolution.sh']) {
121
- fs.writeFileSync(path.join(hooksSrc, h), `# ${h}`);
122
- }
123
- const destDir = path.join(tmpRoot, 'dest-hooks');
124
- fs.mkdirSync(destDir, { recursive: true });
125
-
126
- const { copyHooks } = require('../shared-utils');
127
- copyHooks(pkgRoot, destDir);
128
-
129
- expect(fs.existsSync(path.join(destDir, 'hook-module-resolution.sh'))).toBe(true);
130
- });
131
- });
132
-
133
- describe('copyDirRecursive (#640 concurrency)', () => {
134
- // The mirrored trees this walks are rewritten in place by
135
- // scripts/sync-package-content.js. A concurrent init enumerates the
136
- // directory, then finds an entry gone -- ENOENT on a file that reappears
137
- // microseconds later. That must not abort the install.
138
- it('skips a file that disappears between enumeration and copy', () => {
139
- const src = path.join(tmpRoot, 'src');
140
- const dest = path.join(tmpRoot, 'dest');
141
- fs.mkdirSync(src, { recursive: true });
142
- fs.writeFileSync(path.join(src, 'stable.sh'), 'stable');
143
- fs.writeFileSync(path.join(src, 'vanishing.sh'), 'vanishing');
144
-
145
- const realReadFileSync = fs.readFileSync;
146
- vi.spyOn(fs, 'readFileSync').mockImplementation((p, ...rest) => {
147
- if (String(p).endsWith('vanishing.sh')) {
148
- const err = new Error('ENOENT: no such file or directory');
149
- err.code = 'ENOENT';
150
- throw err;
151
- }
152
- return realReadFileSync(p, ...rest);
153
- });
154
-
155
- const { copyDirRecursive } = require('../shared-utils');
156
- expect(() => copyDirRecursive(src, dest)).not.toThrow();
157
- expect(fs.existsSync(path.join(dest, 'stable.sh'))).toBe(true);
158
- expect(fs.existsSync(path.join(dest, 'vanishing.sh'))).toBe(false);
159
- });
160
-
161
- it('still surfaces a real read error instead of silently skipping', () => {
162
- // Only ENOENT means "being replaced". A permission or disk error is a real
163
- // failure, and swallowing it would ship a half-installed hook set.
164
- const src = path.join(tmpRoot, 'src2');
165
- const dest = path.join(tmpRoot, 'dest2');
166
- fs.mkdirSync(src, { recursive: true });
167
- fs.writeFileSync(path.join(src, 'locked.sh'), 'locked');
168
-
169
- vi.spyOn(fs, 'readFileSync').mockImplementation(() => {
170
- const err = new Error('EACCES: permission denied');
171
- err.code = 'EACCES';
172
- throw err;
173
- });
174
-
175
- const { copyDirRecursive } = require('../shared-utils');
176
- expect(() => copyDirRecursive(src, dest)).toThrow(/EACCES/);
177
- });
178
- });
179
-
180
- });
@@ -1,48 +0,0 @@
1
- /**
2
- * @test REQ-416
3
- * @intent install-skill 的用法字符串删掉了 --offline,但 parseOptions 对认不出的 flag
4
- * 照旧静默忽略 —— 这正是 #488 给 doctor 修掉的同一类缺陷:用户执行了已不存在的
5
- * flag,得到 exit 0 与「安装成功」,而 flag 从未生效(Round 1 架构席位 MA-02)
6
- * @covers AC-416-06
7
- */
8
- const { parseSkillFlags } = require('../shared-utils');
9
-
10
- describe('parseSkillFlags (#416)', () => {
11
- it('parses the flags the skill commands implement', () => {
12
- const { options, unknown } = parseSkillFlags(['--verbose', '--force'], 'install-skill');
13
-
14
- expect(options).toMatchObject({ verbose: true, force: true, all: false, check: false });
15
- expect(unknown).toEqual([]);
16
- });
17
-
18
- it('names a flag it does not implement instead of swallowing it', () => {
19
- const { unknown } = parseSkillFlags(['--offline', '--verbose'], 'install-skill');
20
-
21
- expect(unknown).toEqual(['--offline']);
22
- });
23
-
24
- it('treats a value argument as unknown rather than silently dropping it', () => {
25
- expect(parseSkillFlags(['main'], 'install-skill').unknown).toEqual(['main']);
26
- });
27
-
28
- it('reports no unknown flag for an empty argument list', () => {
29
- expect(parseSkillFlags([], 'install-skill')).toEqual({
30
- options: { verbose: false, force: false, all: false, check: false },
31
- unknown: [],
32
- });
33
- });
34
-
35
- // Round 2 architecture MI-04: one global table meant `install-skill x --all`
36
- // parsed clean and then dropped options.all on the floor -- parsed-but-not-
37
- // consumed is the same silent no-op this branch exists to remove.
38
- it('accepts a flag only for the command that consumes it', () => {
39
- expect(parseSkillFlags(['--all'], 'install-skill').unknown).toEqual(['--all']);
40
- expect(parseSkillFlags(['--check'], 'uninstall-skill').unknown).toEqual(['--check']);
41
- expect(parseSkillFlags(['--verbose'], 'uninstall-skill').unknown).toEqual(['--verbose']);
42
-
43
- const update = parseSkillFlags(['--all', '--check', '--verbose'], 'update-skill');
44
- expect(update.unknown).toEqual([]);
45
- expect(update.options).toMatchObject({ all: true, check: true, verbose: true });
46
- expect(parseSkillFlags(['--force'], 'uninstall-skill').unknown).toEqual([]);
47
- });
48
- });
@@ -1,89 +0,0 @@
1
- /**
2
- * @test REQ-609 SLO 三态判定:PASS / MISS / UNKNOWN 必须互不可替代
3
- * @intent 六项 SLO 的价值不在数字本身,而在"能不能行动"。
4
- *
5
- * 这里断言的是**状态机**,不是阈值算术:
6
- *
7
- * - 没数据 -> UNKNOWN,既不报通过也不报失败
8
- * - 有数据但越界 -> MISS(唯一需要行动的状态)
9
- * - 文件丢失目标为 0 时,"没跑过守卫" 不得算成 PASS
10
- *
11
- * 最后一条是本模块最容易被写错的地方:`0 <= 0` 恒真,所以任何按
12
- * 数值比较的实现都会在没有观测时报告"零文件丢失"——那是对**没有发生
13
- * 观测**和**观测到零**的混淆,与 #554 门禁没跑却报通过同源。
14
- * @covers AC-609-01, AC-609-02, AC-609-03
15
- */
16
- 'use strict';
17
-
18
- const { evaluateSlo, evaluateAll, summariseStates, SLO_DEFINITIONS, STATES } = require('../slo');
19
-
20
- describe('SLO 三态判定 (#609)', () => {
21
- it('AC-609-01: 无数据返回 UNKNOWN 而不是 PASS 或 MISS', () => {
22
- for (const id of ['first_build_pass', 'flaky_rate', 'file_loss']) {
23
- const r = evaluateSlo(id, null);
24
- expect(r.state).toBe(STATES.UNKNOWN);
25
- expect(r.value).toBeNull();
26
- expect(r.reason.length).toBeGreaterThan(0);
27
- }
28
- });
29
-
30
- it('AC-609-01: 有价值的 0 与无数据必须可区分', () => {
31
- // flaky_rate = 0 is a real, excellent measurement; null is not a measurement.
32
- const zero = evaluateSlo('flaky_rate', 0);
33
- const absent = evaluateSlo('flaky_rate', null);
34
- expect(zero.state).toBe(STATES.PASS);
35
- expect(absent.state).toBe(STATES.UNKNOWN);
36
- expect(zero.state).not.toBe(absent.state);
37
- });
38
-
39
- it('AC-609-02: min 方向越界是 MISS,达标是 PASS', () => {
40
- expect(evaluateSlo('first_build_pass', 90).state).toBe(STATES.PASS);
41
- expect(evaluateSlo('first_build_pass', 89.9).state).toBe(STATES.MISS);
42
- });
43
-
44
- it('AC-609-02: max 方向越界是 MISS,零违规是 PASS', () => {
45
- expect(evaluateSlo('ci_wasted_trigger', 20).state).toBe(STATES.PASS);
46
- expect(evaluateSlo('ci_wasted_trigger', 20.1).state).toBe(STATES.MISS);
47
- });
48
-
49
- it('AC-609-03: file_loss 目标为 0 时,没有样本不算 PASS', () => {
50
- // `0 <= 0` passes a naive comparison. Without an observation, the honest
51
- // answer is UNKNOWN -- same defect class as a gate that reports success
52
- // without running.
53
- const noSamples = evaluateSlo('file_loss', 0);
54
- expect(noSamples.state).toBe(STATES.UNKNOWN);
55
- });
56
-
57
- it('AC-609-03: file_loss 有样本且为 0 才算 PASS', () => {
58
- const observed = evaluateSlo('file_loss', 0, { samples: 12 });
59
- expect(observed.state).toBe(STATES.PASS);
60
- expect(observed.sampleCount).toBe(12);
61
- });
62
-
63
- it('AC-609-03: file_loss 有样本且非 0 是 MISS', () => {
64
- expect(evaluateSlo('file_loss', 3, { samples: 12 }).state).toBe(STATES.MISS);
65
- });
66
-
67
- it('AC-609-01: 每项 SLO 都声明了数据来源', () => {
68
- // A metric whose provenance is unstated cannot be verified, so it cannot be
69
- // trusted -- and an untrusted SLO panel is worse than no panel.
70
- for (const def of SLO_DEFINITIONS) {
71
- expect(def.source).toBeTruthy();
72
- expect(def.describe).toBeTruthy();
73
- }
74
- });
75
-
76
- it('AC-609-01: evaluateAll 覆盖全部六项且计数自洽', () => {
77
- const rows = evaluateAll({ first_build_pass: 95, flaky_rate: null });
78
- expect(rows).toHaveLength(SLO_DEFINITIONS.length);
79
- const counts = summariseStates(rows);
80
- expect(counts.total).toBe(SLO_DEFINITIONS.length);
81
- expect(counts.PASS + counts.MISS + counts.UNKNOWN).toBe(counts.total);
82
- expect(counts.PASS).toBe(1);
83
- expect(counts.UNKNOWN).toBe(SLO_DEFINITIONS.length - 1);
84
- });
85
-
86
- it('AC-609-02: 未知 SLO id 抛错而不是静默返回', () => {
87
- expect(() => evaluateSlo('no_such_slo', 1)).toThrow(/unknown SLO id/);
88
- });
89
- });