reasonweave 0.0.0-stage → 1.3.2

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 (228) hide show
  1. package/AGENTS.md +101 -0
  2. package/INSTALL.md +258 -0
  3. package/README.md +280 -2
  4. package/bin/lab.mjs +888 -0
  5. package/constitution.md +55 -0
  6. package/docs/CONSUMER-PROMPTS.md +474 -0
  7. package/docs/backlogs/01-forward-wait-self-detach.md +18 -0
  8. package/docs/backlogs/02-decouple-wait-and-daemon-for-agent-hosts.md +35 -0
  9. package/docs/backlogs/03-baton-wait-multi-id-lightweight-pubsub.md +34 -0
  10. package/docs/backlogs/04-adr-cross-repo-automated-dispatch-boundary.md +19 -0
  11. package/docs/backlogs/05-feat-units-worktree-isolation-engine.md +23 -0
  12. package/docs/backlogs/06-feat-blind-audit-automated-clean-runner.md +22 -0
  13. package/docs/backlogs/07-feat-attention-throttle-silent-pipe.md +23 -0
  14. package/docs/backlogs/08-future-units-shadow-ledger.md +22 -0
  15. package/docs/backlogs/09-feat-agent-baton-core-convergence-and-resilience.md +42 -0
  16. package/docs/backlogs/10-feat-anti-orphan-deterministic-wiring-governance.md +35 -0
  17. package/docs/backlogs/11-perf-orphan-index-fs-read.md +16 -0
  18. package/docs/backlogs/12-feat-vibe-security-anti-suppression-and-orphan-deps.md +43 -0
  19. package/docs/backlogs/13-feat-sdd-reppit-tiered-guardrails.md +40 -0
  20. package/docs/backlogs/14-feat-universal-cli-contract-and-hermetic-test-fixtures.md +48 -0
  21. package/docs/backlogs/15-feat-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +44 -0
  22. package/docs/backlogs/16-feat-micro-engineering-skills-and-sdd-baton-fusion.md +52 -0
  23. package/docs/codegraph-readiness-check.md +49 -0
  24. package/group/architecture/adr/0001-handoff-async-wait-and-reactive-wakeup.md +87 -0
  25. package/group/architecture/adr/0002-de-ritualize-handoff-prompt-for-intra-repo.md +53 -0
  26. package/group/architecture/adr/0003-attention-throttle-and-workspace-driver.md +65 -0
  27. package/group/architecture/adr/0004-spec-guard-and-drift-prevention.md +90 -0
  28. package/group/architecture/adr/0005-global-orphan-scavenger-and-read-only-invariants.md +94 -0
  29. package/group/architecture/adr/0006-triad-engineering-defense-and-mutation-sensitivity.md +68 -0
  30. package/group/architecture/adr/0007-agent-baton-state-machine-defense-and-workspace-jail-spec.md +86 -0
  31. package/group/architecture/adr/0008-agent-baton-core-convergence-and-heterogeneous-session-resilience.md +133 -0
  32. package/group/architecture/adr/0009-anti-orphan-deterministic-wiring-governance-and-federated-guardrails.md +108 -0
  33. package/group/architecture/adr/0010-agent-baton-identity-security-cryptographic-credentials-and-prompt-anti-confusion.md +119 -0
  34. package/group/architecture/adr/0011-vibe-security-anti-suppression-and-dependency-reachability.md +161 -0
  35. package/group/architecture/adr/0012-spec-driven-development-reppit-and-tiered-guardrails.md +130 -0
  36. package/group/architecture/adr/0013-universal-cli-contract-hermetic-testing-and-defensive-probes.md +110 -0
  37. package/group/architecture/adr/0014-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +108 -0
  38. package/group/architecture/adr/0015-micro-engineering-skills-and-dual-core-gate-invariant.md +127 -0
  39. package/group/architecture/adr/INDEX.md +29 -0
  40. package/group/architecture/adr/templates/adr-template.md +33 -0
  41. package/group/architecture/dependency-graph.md +60 -0
  42. package/group/contracts/npm-packaging.md +69 -0
  43. package/group/product/intent.md +24 -0
  44. package/package.json +93 -4
  45. package/scripts/sync-all-consumers.mjs +174 -0
  46. package/specs/RFC-20261110-SPEC-GUARD-UNIT.md +353 -0
  47. package/specs/templates/01-research.md.template +23 -0
  48. package/specs/templates/02-proposals.md.template +22 -0
  49. package/specs/templates/03-spec.md.template +33 -0
  50. package/specs/templates/04-tasks.md.template +29 -0
  51. package/specs/templates/05-evidence.md.template +29 -0
  52. package/specs/templates/README.md +26 -0
  53. package/units/adr/AGENTS.md +85 -0
  54. package/units/adr/CHANGELOG.md +20 -0
  55. package/units/adr/README.md +88 -0
  56. package/units/adr/VERSION.md +10 -0
  57. package/units/adr/docs/existing-project-prompt.md +24 -0
  58. package/units/adr/docs/new-project-prompt.md +36 -0
  59. package/units/adr/scripts/adr-init.sh +101 -0
  60. package/units/adr/templates/INDEX.md +19 -0
  61. package/units/adr/templates/adr-frozen.md +33 -0
  62. package/units/adr/templates/adr-light.md +56 -0
  63. package/units/adr/templates/adr-standard.md +61 -0
  64. package/units/backlog/AGENTS.md +53 -0
  65. package/units/backlog/AUTONOMOUS-GOVERNANCE.md +98 -0
  66. package/units/backlog/CHANGELOG.md +37 -0
  67. package/units/backlog/README.md +124 -0
  68. package/units/backlog/VERSION.md +11 -0
  69. package/units/backlog/docs/existing-project-ironrules-prompt.md +31 -0
  70. package/units/backlog/docs/existing-project-prompt.md +24 -0
  71. package/units/backlog/docs/new-project-prompt.md +19 -0
  72. package/units/backlog/templates/entry.md +39 -0
  73. package/units/backlog/templates/project-ironrules.md +36 -0
  74. package/units/handoffs/AGENT-GUIDE.md +118 -0
  75. package/units/handoffs/AGENTS.md +28 -0
  76. package/units/handoffs/CHANGELOG.md +498 -0
  77. package/units/handoffs/CLAUDE.md +28 -0
  78. package/units/handoffs/COMMANDS.md +187 -0
  79. package/units/handoffs/DESIGN.md +74 -0
  80. package/units/handoffs/README.md +456 -0
  81. package/units/handoffs/RESPONSE-TEMPLATE.md +138 -0
  82. package/units/handoffs/VERSION.md +1 -0
  83. package/units/handoffs/handoff-status.mjs +1017 -0
  84. package/units/handoffs/handoff.mjs +5675 -0
  85. package/units/orphan/CHANGELOG.md +118 -0
  86. package/units/orphan/DESIGN.md +484 -0
  87. package/units/orphan/README.md +143 -0
  88. package/units/orphan/VERSION.md +1 -0
  89. package/units/orphan/adapters/android/index.mjs +140 -0
  90. package/units/orphan/adapters/python/index.mjs +232 -0
  91. package/units/orphan/adapters/web/index.mjs +280 -0
  92. package/units/orphan/bin/lab-orphan.mjs +298 -0
  93. package/units/orphan/core/blob-reader.mjs +142 -0
  94. package/units/orphan/core/classifier.mjs +261 -0
  95. package/units/orphan/core/cleaner.mjs +166 -0
  96. package/units/orphan/core/diff-checker.mjs +341 -0
  97. package/units/orphan/core/inverted-index.mjs +124 -0
  98. package/units/orphan/core/orphan-deps.mjs +192 -0
  99. package/units/orphan/core/protocol-s1-s3.mjs +194 -0
  100. package/units/orphan/core/solver.mjs +217 -0
  101. package/units/orphan/index.mjs +105 -0
  102. package/units/orphan/templates/ci/orphan-guard.yml +36 -0
  103. package/units/orphan/templates/pre-commit.d/30-orphan-guard +34 -0
  104. package/units/orphan/templates/wiring/README.md +51 -0
  105. package/units/orphan/templates/wiring/miniprogram-route-guard.js.template +80 -0
  106. package/units/orphan/templates/wiring/pre-commit-node.sh.template +73 -0
  107. package/units/orphan/templates/wiring/project-agents-gemini-templates.md +60 -0
  108. package/units/orphan/templates/wiring/python-parity-test.py.template +100 -0
  109. package/units/orphan/templates/wiring/rust-exhaustive-match.md +65 -0
  110. package/units/orphan/templates/wiring/swift-periphery.md +56 -0
  111. package/units/orphan/tests/adapters.test.mjs +243 -0
  112. package/units/orphan/tests/orphan-deps.test.mjs +131 -0
  113. package/units/orphan/tests/phase3-gates.test.mjs +135 -0
  114. package/units/playbook/README.md +106 -0
  115. package/units/playbook/ZSPEC-AGENT-GUIDE.md +99 -0
  116. package/units/playbook/docs/01-architecture.md +99 -0
  117. package/units/playbook/docs/02-bootstrap.md +126 -0
  118. package/units/playbook/docs/03-units.md +91 -0
  119. package/units/playbook/docs/04-constitution.md +113 -0
  120. package/units/playbook/docs/05-adr.md +33 -0
  121. package/units/playbook/docs/06-spec-kit.md +76 -0
  122. package/units/playbook/docs/07-backlog.md +30 -0
  123. package/units/playbook/docs/08-codegraph.md +79 -0
  124. package/units/playbook/docs/09-skills.md +101 -0
  125. package/units/playbook/docs/10-handoff.md +72 -0
  126. package/units/playbook/docs/11-evidence.md +163 -0
  127. package/units/playbook/docs/12-gates.md +124 -0
  128. package/units/playbook/docs/13-parallel.md +115 -0
  129. package/units/playbook/docs/14-dependency-graph.md +86 -0
  130. package/units/playbook/docs/15-memory.md +153 -0
  131. package/units/playbook/docs/16-change-control.md +121 -0
  132. package/units/playbook/docs/17-prompts.md +121 -0
  133. package/units/playbook/docs/18-shift-left.md +97 -0
  134. package/units/playbook/docs/19-anti-orphan-vertical-slicing.md +102 -0
  135. package/units/playbook/docs/20-vibe-security-and-anti-suppression.md +88 -0
  136. package/units/playbook/docs/21-spec-driven-reppit-closed-loop.md +88 -0
  137. package/units/playbook/examples/owisel.md +80 -0
  138. package/units/playbook/references/Agent-Engineering-Framework-AEF-v1.0.md +2033 -0
  139. package/units/playbook/references/links.md +103 -0
  140. package/units/playbook/templates/AGENTS.root.md +44 -0
  141. package/units/playbook/templates/AGENTS.unit.md +52 -0
  142. package/units/playbook/templates/adr/INDEX.md +17 -0
  143. package/units/playbook/templates/adr/NNNN-template.md +56 -0
  144. package/units/playbook/templates/backlogs/entry.md +30 -0
  145. package/units/playbook/templates/constitution.md +93 -0
  146. package/units/playbook/templates/evidence/README.md +36 -0
  147. package/units/playbook/templates/group/architecture/dependency-graph.md +48 -0
  148. package/units/playbook/templates/group/architecture/system.md +59 -0
  149. package/units/playbook/templates/group/contracts/api.md +67 -0
  150. package/units/playbook/templates/group/product/intent.md +30 -0
  151. package/units/playbook/templates/group/product/requirements.md +48 -0
  152. package/units/playbook/templates/unit-skeleton/README.md +35 -0
  153. package/units/preflight/AGENTS.md +45 -0
  154. package/units/preflight/CHANGELOG.md +55 -0
  155. package/units/preflight/INSTALL.md +65 -0
  156. package/units/preflight/README.md +104 -0
  157. package/units/preflight/VERSION.md +3 -0
  158. package/units/preflight/docs/audit-requirements.md +114 -0
  159. package/units/preflight/docs/existing-project-prompt.md +25 -0
  160. package/units/preflight/docs/new-project-prompt.md +25 -0
  161. package/units/preflight/docs/transfers/CONSUMER-INSTALL.md +40 -0
  162. package/units/preflight/docs/transfers/CONSUMER-SELFCHECK.md +51 -0
  163. package/units/preflight/docs/transfers/README.md +39 -0
  164. package/units/preflight/docs/transfers/prospero.md +26 -0
  165. package/units/preflight/templates/check.sh +43 -0
  166. package/units/preflight/templates/pre-commit +55 -0
  167. package/units/preflight/templates/pre-commit.d/20-preflight +15 -0
  168. package/units/preflight/templates/preflight.conf.example +21 -0
  169. package/units/preflight/templates/preflight.sh +189 -0
  170. package/units/preflight/templates/wrap-up.md +9 -0
  171. package/units/review-gate/AGENTS.md +42 -0
  172. package/units/review-gate/CHANGELOG.md +58 -0
  173. package/units/review-gate/README.md +118 -0
  174. package/units/review-gate/VERSION.md +3 -0
  175. package/units/review-gate/clean-runner.mjs +350 -0
  176. package/units/review-gate/docs/existing-project-prompt.md +28 -0
  177. package/units/review-gate/docs/new-project-prompt.md +38 -0
  178. package/units/review-gate/docs/transfers/iggle.md +34 -0
  179. package/units/review-gate/docs/transfers/prospero.md +35 -0
  180. package/units/review-gate/docs/transfers/swoop.md +36 -0
  181. package/units/review-gate/docs/transfers/yiqiyihuihua.md +35 -0
  182. package/units/review-gate/templates/.semgrepignore +37 -0
  183. package/units/review-gate/templates/pre-commit +130 -0
  184. package/units/review-gate/templates/scan.sh +158 -0
  185. package/units/skills/AGENTS.md +17 -0
  186. package/units/skills/CHANGELOG.md +18 -0
  187. package/units/skills/README.md +63 -0
  188. package/units/skills/VERSION.md +1 -0
  189. package/units/skills/bin/review-package.mjs +99 -0
  190. package/units/skills/bin/task-brief.mjs +102 -0
  191. package/units/skills/catalog/brainstorming/SKILL.md +75 -0
  192. package/units/skills/catalog/brainstorming/references/design-doc-template.md +28 -0
  193. package/units/skills/catalog/systematic-debugging/SKILL.md +101 -0
  194. package/units/skills/catalog/systematic-debugging/references/root-cause-tracing.md +23 -0
  195. package/units/skills/catalog/test-driven-development/SKILL.md +88 -0
  196. package/units/skills/catalog/test-driven-development/references/writing-good-tests.md +13 -0
  197. package/units/skills/catalog/verification-before-completion/SKILL.md +73 -0
  198. package/units/skills/skills.mjs +181 -0
  199. package/units/skills/tests/pipeline.test.mjs +131 -0
  200. package/units/skills/tests/skill-contract.test.mjs +67 -0
  201. package/units/skills/tests/skills-cli.test.mjs +107 -0
  202. package/units/spec-guard/AGENTS.md +43 -0
  203. package/units/spec-guard/CHANGELOG.md +88 -0
  204. package/units/spec-guard/README.md +148 -0
  205. package/units/spec-guard/VERSION.md +1 -0
  206. package/units/spec-guard/bin/spec-guard.mjs +431 -0
  207. package/units/spec-guard/core/adr-parser.mjs +540 -0
  208. package/units/spec-guard/core/matrix-checker.mjs +587 -0
  209. package/units/spec-guard/core/mutation-runner.mjs +267 -0
  210. package/units/spec-guard/core/scanner.mjs +333 -0
  211. package/units/spec-guard/core/telemetry_authenticator.mjs +484 -0
  212. package/units/spec-guard/core/wiring_tracer.mjs +306 -0
  213. package/units/spec-guard/templates/annotations/ContractOnly.kt +19 -0
  214. package/units/spec-guard/templates/annotations/Invariant.kt +16 -0
  215. package/units/spec-guard/templates/annotations/invariant.go +19 -0
  216. package/units/spec-guard/templates/annotations/invariant.py +38 -0
  217. package/units/spec-guard/templates/annotations/invariant.ts +39 -0
  218. package/units/spec-guard/templates/ci/spec-guard-audit.yml +23 -0
  219. package/units/spec-guard/templates/pre-commit.d/15-spec-guard +72 -0
  220. package/units/spec-guard/templates/spec-matrix.overlay.yml +70 -0
  221. package/units/spec-guard/tests/spec-guard.test.mjs +716 -0
  222. package/units/spec-guard/tests/telemetry_authenticator.test.mjs +633 -0
  223. package/units/worktree/AGENTS.md +22 -0
  224. package/units/worktree/CHANGELOG.md +14 -0
  225. package/units/worktree/README.md +65 -0
  226. package/units/worktree/VERSION.md +1 -0
  227. package/units/worktree/worktree.mjs +352 -0
  228. package//344/275/277/347/224/250/350/257/264/346/230/216.md +322 -0
@@ -0,0 +1,716 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import os from 'node:os';
6
+ import { execSync } from 'node:child_process';
7
+
8
+ import {
9
+ makeStrictBoundaryRegex,
10
+ containsStrictInvariant,
11
+ parseAdrContent,
12
+ findAdrFiles,
13
+ loadOverlayConfig,
14
+ parseSimpleYamlOverlay,
15
+ } from '../core/adr-parser.mjs';
16
+
17
+ import {
18
+ extractTelemetryMetrics,
19
+ verifyAdrTelemetry,
20
+ verifyAllAdrsTelemetry,
21
+ } from '../core/telemetry_authenticator.mjs';
22
+
23
+ import {
24
+ isTestPath,
25
+ scanFileContent,
26
+ analyzeSymbolWiring,
27
+ } from '../core/scanner.mjs';
28
+
29
+ import {
30
+ buildAndCheckMatrix,
31
+ buildFullTriadMatrix,
32
+ generateAdrAuditReport,
33
+ } from '../core/matrix-checker.mjs';
34
+
35
+ import {
36
+ runMutationTest,
37
+ generateMutants,
38
+ } from '../core/mutation-runner.mjs';
39
+
40
+ import {
41
+ Classifier,
42
+ CallerKind,
43
+ countProductionCallers,
44
+ } from '../../orphan/index.mjs';
45
+
46
+ describe('spec-guard: 严格词界与边界防伪测试 (Constraint 2)', () => {
47
+ it('应正确匹配严格词界的 Invariant ID', () => {
48
+ assert.equal(containsStrictInvariant('这是一个 ADR-060:H-1 测试', 'ADR-060:H-1'), true);
49
+ assert.equal(containsStrictInvariant('@Invariant("ADR-060:H-1")', 'ADR-060:H-1'), true);
50
+ assert.equal(containsStrictInvariant('// [INVARIANT: ADR-060:H-1]', 'ADR-060:H-1'), true);
51
+ assert.equal(containsStrictInvariant('H-1', 'H-1'), true);
52
+ assert.equal(containsStrictInvariant('- **H-1**: 零唤醒要求', 'H-1'), true);
53
+ });
54
+
55
+ it('严格词界严禁误伤 H-10 或 H-1-OBSOLETE 或前缀扩展', () => {
56
+ // 严格测试:H-1 绝不能匹配 H-10
57
+ assert.equal(containsStrictInvariant('@Invariant("ADR-060:H-10")', 'ADR-060:H-1'), false);
58
+ assert.equal(containsStrictInvariant('这是 H-10 描述', 'H-1'), false);
59
+
60
+ // H-1 绝不能匹配 H-1-OBSOLETE
61
+ assert.equal(containsStrictInvariant('@Invariant("H-1-OBSOLETE")', 'H-1'), false);
62
+
63
+ // H-1 绝不能匹配 MY_H-1
64
+ assert.equal(containsStrictInvariant('MY_H-1', 'H-1'), false);
65
+
66
+ // 正则边界对象测试
67
+ const regex = makeStrictBoundaryRegex('H-1');
68
+ assert.equal(regex.test('H-1'), true);
69
+ assert.equal(regex.test('H-10'), false);
70
+ assert.equal(regex.test('H-1-DEPRECATED'), false);
71
+ });
72
+ });
73
+
74
+ describe('spec-guard: ADR 规约解析器', () => {
75
+ // [INVARIANT: ADR-0004:INV-1]
76
+ // [INVARIANT: ADR-0004:INV-3]
77
+ it('应准确提取 🔒Frozen 状态、Implementation Status 与 Invariants', () => {
78
+ const sampleAdr = `
79
+ # ADR-060: OTA 升级规约
80
+
81
+ - **状态(Status)**:🔒 Frozen
82
+ - **日期**:2026-11-07
83
+
84
+ ## 1. Context
85
+ 背景内容说明。
86
+
87
+ ## 2. Decision
88
+ 决策内容说明。
89
+
90
+ ## 3. Implementation Status
91
+ | 项 | 状态 | 说明 |
92
+ |---|---|---|
93
+ | T1 节律定时 | ✅ 已实现 | 30s tick 已接入 |
94
+ | T2 空闲判定 | ❌ 未实现 | 依赖跨端 IPC |
95
+
96
+ ## 5. Consequences / Invariants
97
+ - **H-1**: 零唤醒/零网络负担约束
98
+ - **H-2**: 业务排他互斥约束
99
+ - **Gate1**: 温控熔断门禁
100
+ `;
101
+
102
+ const res = parseAdrContent(sampleAdr, 'group/architecture/adr/ADR-060-ota.md');
103
+ assert.equal(res.adrId, 'ADR-060');
104
+ assert.equal(res.isFrozen, true);
105
+ assert.equal(res.hasImplementationStatus, true);
106
+ assert.equal(res.implementationItems.length, 2);
107
+ assert.equal(res.implementationItems[0].status, 'verified');
108
+ assert.equal(res.implementationItems[1].status, 'unwired');
109
+
110
+ assert.equal(res.hasInvariantsSection, true);
111
+ assert.equal(res.invariants.length, 3);
112
+ assert.equal(res.invariants[0].localId, 'H-1');
113
+ assert.equal(res.invariants[0].canonicalId, 'ADR-060:H-1');
114
+ assert.equal(res.invariants[1].localId, 'H-2');
115
+ assert.equal(res.invariants[2].localId, 'Gate1');
116
+ });
117
+ });
118
+
119
+ describe('spec-guard: 多语言扫描与防伪铁律 (No-Cheat Rule)', () => {
120
+ it('应准确识别测试文件路径', () => {
121
+ assert.equal(isTestPath('android/app/src/test/java/AppTest.kt'), true);
122
+ assert.equal(isTestPath('src/main/java/App.kt'), false);
123
+ assert.equal(isTestPath('tests/unit/test_watchdog.py'), true);
124
+ assert.equal(isTestPath('app/watchdog.py'), false);
125
+ assert.equal(isTestPath('pkg/server_test.go'), true);
126
+ assert.equal(isTestPath('pkg/server.go'), false);
127
+ assert.equal(isTestPath('client.test.ts'), true);
128
+ assert.equal(isTestPath('client.ts'), false);
129
+ });
130
+
131
+ it('多语言断言提取器测试', () => {
132
+ const kotlinCode = `
133
+ package com.tappy.test
134
+ import lab.specguard.annotations.Invariant
135
+ import lab.specguard.annotations.ContractOnly
136
+
137
+ @ContractOnly(adr = "ADR-060", expire = "2026-12-01", reason = "等待空闲服务")
138
+ class PrototypeAlgorithm { }
139
+
140
+ class AppUpdateManagerTest {
141
+ @Test
142
+ @Invariant("ADR-060:H-1")
143
+ fun testNightlyWindow() { }
144
+ }
145
+ `;
146
+
147
+ const res = scanFileContent(kotlinCode, 'src/test/java/AppUpdateManagerTest.kt');
148
+ assert.equal(res.isTest, true);
149
+ assert.equal(res.invariants.length, 1);
150
+ assert.equal(res.invariants[0].id, 'ADR-060:H-1');
151
+ assert.equal(res.contracts.length, 1);
152
+ assert.equal(res.contracts[0].adr, 'ADR-060');
153
+ assert.equal(res.contracts[0].expire, '2026-12-01');
154
+
155
+ // 测试 TypeScript / JSDoc 注释提取
156
+ const tsCode = `
157
+ // @invariant ADR-060:H-3
158
+ it('should verify TS comment invariant', () => {});
159
+ // @invariant: ADR-060:H-4
160
+ it('should verify TS comment colon variant', () => {});
161
+ `;
162
+ const tsRes = scanFileContent(tsCode, 'client.test.ts');
163
+ assert.equal(tsRes.invariants.length, 2);
164
+ assert.equal(tsRes.invariants[0].id, 'ADR-060:H-3');
165
+ assert.equal(tsRes.invariants[1].id, 'ADR-060:H-4');
166
+ });
167
+
168
+ // [INVARIANT: ADR-0004:INV-2]
169
+ it('No-Cheat 规则:测试中的调用不得计入生产接线证明,生产带变量赋值调用正常计数', () => {
170
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-nocheat-'));
171
+ try {
172
+ const prodDir = path.join(tmpDir, 'src', 'main');
173
+ const testDir = path.join(tmpDir, 'src', 'test');
174
+ fs.mkdirSync(prodDir, { recursive: true });
175
+ fs.mkdirSync(testDir, { recursive: true });
176
+
177
+ // 生产中定义函数并在另一个生产文件中通过 val 赋值调用
178
+ fs.writeFileSync(
179
+ path.join(prodDir, 'AppUpdateManager.kt'),
180
+ `package com.tappy
181
+ class AppUpdateManager {
182
+ fun shouldTriggerScheduledCheck(): Boolean = true
183
+ }`
184
+ );
185
+
186
+ fs.writeFileSync(
187
+ path.join(prodDir, 'ServiceWatchdog.kt'),
188
+ `package com.tappy
189
+ class ServiceWatchdog {
190
+ fun tick() {
191
+ val isSafe = AppUpdateManager().shouldTriggerScheduledCheck()
192
+ }
193
+ }`
194
+ );
195
+
196
+ // 测试中也调用该函数
197
+ fs.writeFileSync(
198
+ path.join(testDir, 'AppUpdateManagerTest.kt'),
199
+ `package com.tappy
200
+ class AppUpdateManagerTest {
201
+ fun test() {
202
+ val mgr = AppUpdateManager()
203
+ mgr.shouldTriggerScheduledCheck()
204
+ }
205
+ }`
206
+ );
207
+
208
+ // 分析符号接线:生产中有真实调用 (val isSafe = ...),测试中也有调用
209
+ const wiringRes = analyzeSymbolWiring('shouldTriggerScheduledCheck', tmpDir);
210
+ assert.equal(wiringRes.testCallers.length, 1);
211
+ assert.equal(wiringRes.prodCallers.length, 1);
212
+ assert.equal(wiringRes.wiringStatus, 'wired');
213
+ } finally {
214
+ fs.rmSync(tmpDir, { recursive: true, force: true });
215
+ }
216
+ });
217
+ });
218
+
219
+ describe('spec-guard: 动态对账矩阵与漂移告警 (Code-as-Spec-Matrix)', () => {
220
+ it('完整工作流:扫描 ADR 与源码,精准识别 Verified 与 Drift', () => {
221
+ const tmpRepo = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-matrix-'));
222
+ try {
223
+ const adrDir = path.join(tmpRepo, 'group', 'architecture', 'adr');
224
+ const testDir = path.join(tmpRepo, 'tests');
225
+ fs.mkdirSync(adrDir, { recursive: true });
226
+ fs.mkdirSync(testDir, { recursive: true });
227
+
228
+ // 创建一个包含两个不变量的 Frozen ADR
229
+ fs.writeFileSync(
230
+ path.join(adrDir, 'ADR-060-ota.md'),
231
+ `# ADR-060: OTA 升级规约
232
+ - **状态(Status)**:🔒 Frozen
233
+
234
+ ## 3. Implementation Status
235
+ | 项 | 状态 | 说明 |
236
+ |---|---|---|
237
+ | H-1 | ✅ 已实现 | 已接线 |
238
+
239
+ ## 5. Consequences / Invariants
240
+ - **H-1**: 零网络负担
241
+ - **H-2**: 业务排他互斥
242
+ `
243
+ );
244
+
245
+ // 仅为 H-1 编写机器断言,漏掉 H-2
246
+ fs.writeFileSync(
247
+ path.join(testDir, 'test_ota.py'),
248
+ `import pytest
249
+ # [INVARIANT: ADR-060:H-1]
250
+ def test_zero_network():
251
+ assert True
252
+ `
253
+ );
254
+
255
+ const matrix = buildAndCheckMatrix(tmpRepo);
256
+ assert.equal(matrix.totalInvariantsCount, 2);
257
+ assert.equal(matrix.verifiedCount, 1); // H-1 有断言
258
+ assert.equal(matrix.driftCount, 1); // H-2 处于 Frozen 但零断言,触发漂移告警!
259
+ assert.equal(matrix.isHealthy, false);
260
+
261
+ // 生成 Markdown 审计报告
262
+ const auditReport = generateAdrAuditReport(matrix, 'ADR-060');
263
+ assert.match(auditReport, /ADR-060/);
264
+ assert.match(auditReport, /零网络负担/);
265
+ assert.match(auditReport, /漂移脱节/);
266
+ assert.match(auditReport, /阻断判定/);
267
+ } finally {
268
+ fs.rmSync(tmpRepo, { recursive: true, force: true });
269
+ }
270
+ });
271
+
272
+ // [INVARIANT: ADR-0004:INV-3]
273
+ // [INVARIANT: ADR-0006:INV-1]
274
+ it('孤儿接线机检拦截实测:构造一个有单测打 @invariant 但生产调用数为 0 的样本,lab spec-guard check --check-callers 必须精准 Exit 1 阻断;在生产分发器接入后复测通过', () => {
275
+ const tmpRepo = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-orphan-wiring-'));
276
+ try {
277
+ const adrDir = path.join(tmpRepo, 'group', 'architecture', 'adr');
278
+ const prodDir = path.join(tmpRepo, 'src', 'device');
279
+ const testDir = path.join(tmpRepo, 'tests');
280
+ fs.mkdirSync(adrDir, { recursive: true });
281
+ fs.mkdirSync(prodDir, { recursive: true });
282
+ fs.mkdirSync(testDir, { recursive: true });
283
+
284
+ // 1. 创建 Frozen ADR-060
285
+ fs.writeFileSync(
286
+ path.join(adrDir, 'ADR-060-ota.md'),
287
+ `# ADR-060: 设备互锁规约
288
+ - **状态(Status)**:🔒 Frozen
289
+
290
+ ## 3. Implementation Status
291
+ | 项 | 状态 | 说明 |
292
+ |---|---|---|
293
+ | Gate1 | ✅ 已实现 | 跨端互锁守护 |
294
+
295
+ ## 5. Consequences / Invariants
296
+ - **Gate1**: 跨端设备排他互斥门禁
297
+ `
298
+ );
299
+
300
+ // 2. 生产代码定义了核心函数 acquire_device_probe_guard,但生产无任何调用
301
+ const prodFile = path.join(prodDir, 'device_lock.py');
302
+ fs.writeFileSync(
303
+ prodFile,
304
+ `# [INVARIANT: ADR-060:Gate1]
305
+ def acquire_device_probe_guard():
306
+ """生产核心不变量互锁函数"""
307
+ return True
308
+ `
309
+ );
310
+
311
+ // 3. 测试文件单测打 @invariant 并且调用了该函数
312
+ const testFile = path.join(testDir, 'test_device_lock.py');
313
+ fs.writeFileSync(
314
+ testFile,
315
+ `import pytest
316
+ # [INVARIANT: ADR-060:Gate1]
317
+ def test_interlock():
318
+ from src.device.device_lock import acquire_device_probe_guard
319
+ assert acquire_device_probe_guard() is True
320
+ `
321
+ );
322
+
323
+ // 4. 运行 matrix check 开启 --check-callers
324
+ const matrix = buildAndCheckMatrix(tmpRepo, { checkCallers: true });
325
+ assert.equal(matrix.unwiredInvariants.length, 1);
326
+ assert.equal(matrix.unwiredInvariants[0].symbolName, 'acquire_device_probe_guard');
327
+ assert.equal(matrix.isHealthy, false);
328
+
329
+ // 5. 校验 CLI (lab spec-guard check --check-callers) 必须 Exit 1 阻断
330
+ const labBin = path.resolve(process.cwd(), 'bin/lab.mjs');
331
+ let exitCode = 0;
332
+ let out = '';
333
+ try {
334
+ out = execSync(`node ${labBin} spec-guard check --check-callers`, {
335
+ cwd: tmpRepo,
336
+ stdio: 'pipe',
337
+ encoding: 'utf8',
338
+ });
339
+ } catch (err) {
340
+ exitCode = err.status || 1;
341
+ out = (err.stdout ? err.stdout.toString() : '') + (err.stderr ? err.stderr.toString() : '');
342
+ }
343
+ assert.equal(exitCode, 1, '生产调用数为 0 时必须精准 Exit 1 阻断');
344
+ assert.match(out, /Zero Production Callers/);
345
+
346
+ // 6. 在生产分发器 (Dispatcher) 接入调用
347
+ const dispatcherFile = path.join(prodDir, 'dispatcher.py');
348
+ fs.writeFileSync(
349
+ dispatcherFile,
350
+ `from src.device.device_lock import acquire_device_probe_guard
351
+
352
+ def dispatch_task():
353
+ # 生产关键链路接入排他锁守卫
354
+ if acquire_device_probe_guard():
355
+ return "DISPATCHED"
356
+ return "BLOCKED"
357
+ `
358
+ );
359
+
360
+ // 7. 复测:构建矩阵与 CLI 再次执行
361
+ const reMatrix = buildAndCheckMatrix(tmpRepo, { checkCallers: true });
362
+ assert.equal(reMatrix.unwiredInvariants.length, 0);
363
+ assert.equal(reMatrix.isHealthy, true);
364
+
365
+ let reExitCode = 0;
366
+ let reOut = '';
367
+ try {
368
+ reOut = execSync(`node ${labBin} spec-guard check --check-callers`, {
369
+ cwd: tmpRepo,
370
+ stdio: 'pipe',
371
+ encoding: 'utf8',
372
+ });
373
+ } catch (err) {
374
+ reExitCode = err.status || 1;
375
+ }
376
+ assert.equal(reExitCode, 0, '生产分发器接入后复测必须通过 Exit 0');
377
+ assert.match(reOut, /生产接线: 1 处/);
378
+ } finally {
379
+ fs.rmSync(tmpRepo, { recursive: true, force: true });
380
+ }
381
+ });
382
+
383
+ // [INVARIANT: ADR-0006:INV-2]
384
+ // [INVARIANT: ADR-0006:INV-3]
385
+ it('变异测试反向拦截实测:构造一个断言为恒真的假测试,变异引擎注入后测试未红则判定为无效测试并阻断', () => {
386
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-mutation-fake-'));
387
+ try {
388
+ fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({ type: 'module' }));
389
+ const srcFile = path.join(tmpDir, 'service.mjs');
390
+ const testFile = path.join(tmpDir, 'service.test.mjs');
391
+
392
+ // 被测生产代码:包含关键接口端点 /api/v1/device/interlock
393
+ fs.writeFileSync(
394
+ srcFile,
395
+ `export function getEndpoint() {
396
+ return "/api/v1/device/interlock";
397
+ }
398
+ `
399
+ );
400
+
401
+ // 假测试(回音壁假测试):不论 endpoint 变成什么,单测恒真 assert(true)
402
+ fs.writeFileSync(
403
+ testFile,
404
+ `import assert from 'node:assert/strict';
405
+ import { getEndpoint } from './service.mjs';
406
+
407
+ const ep = getEndpoint();
408
+ // 假测试:没有深度断言 ep 的实际值,恒真断言
409
+ assert.equal(true, true);
410
+ `
411
+ );
412
+
413
+ const fakeCmd = `node ${testFile}`;
414
+
415
+ // 变异引擎执行:注入变异后测试依然绿,判定为假测试阻断!
416
+ const fakeResult = runMutationTest({
417
+ repoRoot: tmpDir,
418
+ targetFile: srcFile,
419
+ testCmd: fakeCmd,
420
+ mutator: 'endpoint',
421
+ });
422
+
423
+ assert.equal(fakeResult.status, 'MUTATION_SURVIVED', '变异注入后假测试未红,变异体存活!');
424
+ assert.equal(fakeResult.exitCode, 1);
425
+ assert.match(fakeResult.message, /回音壁假测试/);
426
+
427
+ // CLI 方式执行验证:退出码必须为 1
428
+ const labBin = path.resolve(process.cwd(), 'bin/lab.mjs');
429
+ let cliExitCode = 0;
430
+ try {
431
+ execSync(`node ${labBin} spec-guard mutate --file ${srcFile} --cmd "${fakeCmd}"`, {
432
+ cwd: tmpDir,
433
+ stdio: 'pipe',
434
+ encoding: 'utf8',
435
+ });
436
+ } catch (err) {
437
+ cliExitCode = err.status || 1;
438
+ }
439
+ assert.equal(cliExitCode, 1, 'CLI 变异拦截假测试必须精准 Exit 1');
440
+
441
+ // 编写真实敏感测试(对端点有严格断言)
442
+ fs.writeFileSync(
443
+ testFile,
444
+ `import assert from 'node:assert/strict';
445
+ import { getEndpoint } from './service.mjs';
446
+
447
+ const ep = getEndpoint();
448
+ // 严格断言端点,一旦变异为 /MUTATION_BOGUS_ENDPOINT_MUTANT 测试必爆红
449
+ assert.equal(ep, "/api/v1/device/interlock");
450
+ `
451
+ );
452
+
453
+ const realResult = runMutationTest({
454
+ repoRoot: tmpDir,
455
+ targetFile: srcFile,
456
+ testCmd: fakeCmd,
457
+ mutator: 'endpoint',
458
+ });
459
+
460
+ assert.equal(realResult.status, 'MUTATION_KILLED', '变异注入后真实测试爆红,变异体被消灭!');
461
+ assert.equal(realResult.exitCode, 0);
462
+ assert.match(realResult.message, /变异敏感性自检通过/);
463
+
464
+ // CLI 方式执行真实测试验证:退出码必须为 0
465
+ let realCliExitCode = 0;
466
+ try {
467
+ execSync(`node ${labBin} spec-guard mutate --file ${srcFile} --cmd "${fakeCmd}"`, {
468
+ cwd: tmpDir,
469
+ stdio: 'pipe',
470
+ encoding: 'utf8',
471
+ });
472
+ } catch (err) {
473
+ realCliExitCode = err.status || 1;
474
+ }
475
+ assert.equal(realCliExitCode, 0, '真实敏感测试在变异自检中必须 Exit 0');
476
+ } finally {
477
+ fs.rmSync(tmpDir, { recursive: true, force: true });
478
+ }
479
+ });
480
+
481
+ it('orphan 单元联动测试:符号引用分类与倒排生产调用者检索', () => {
482
+ assert.equal(Classifier.isTestPath('src/test/java/Test.kt'), true);
483
+ assert.equal(Classifier.isTestPath('src/main/java/Main.kt'), false);
484
+
485
+ const refProd = { path: 'src/main/Dispatcher.kt', lineNo: 10, lineText: 'mgr.lock()' };
486
+ const refTest = { path: 'src/test/Test.kt', lineNo: 20, lineText: 'mgr.lock()' };
487
+ const refDoc = { path: 'docs/README.md', lineNo: 5, lineText: 'mgr.lock()' };
488
+
489
+ assert.equal(Classifier.classifyCaller(refProd), CallerKind.PRODUCTION_CALLER);
490
+ assert.equal(Classifier.classifyCaller(refTest), CallerKind.TEST_CALLER);
491
+ assert.equal(Classifier.classifyCaller(refDoc), CallerKind.DOC_CALLER);
492
+
493
+ const callersEval = Classifier.evaluateCallers([refProd, refTest, refDoc]);
494
+ assert.equal(callersEval.productionCallerCount, 1);
495
+ assert.equal(callersEval.testCallerCount, 1);
496
+ assert.equal(callersEval.docReferenceCount, 1);
497
+ assert.equal(callersEval.wiringStatus, 'wired');
498
+ });
499
+ });
500
+
501
+ describe('spec-guard v2.1: ADR 发现规则可配置化与零覆盖防护 (LAB-20261114-01-feature)', () => {
502
+ it('findAdrFiles 支持配置 adr_dirs 与 adr_id_pattern,未配置时缺省回退四目录零回归', () => {
503
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-find-'));
504
+ try {
505
+ // 1. 缺省目录
506
+ const defDir = path.join(tmp, 'docs', 'adr');
507
+ fs.mkdirSync(defDir, { recursive: true });
508
+ fs.writeFileSync(path.join(defDir, 'ADR-001-init.md'), '# ADR-001');
509
+ fs.writeFileSync(path.join(defDir, '0002-legacy.md'), '# 0002');
510
+ fs.writeFileSync(path.join(defDir, 'README.md'), '# Readme');
511
+
512
+ const defFound = findAdrFiles(tmp);
513
+ assert.equal(defFound.length, 2);
514
+
515
+ // 2. 自定义目录与正则
516
+ const customDir = path.join(tmp, 'docs', 'decisions');
517
+ fs.mkdirSync(customDir, { recursive: true });
518
+ fs.writeFileSync(path.join(customDir, 'DECISION-0001-test.md'), '# DECISION-0001');
519
+ fs.writeFileSync(path.join(customDir, 'DECISION-0002-test.md'), '# DECISION-0002');
520
+ fs.writeFileSync(path.join(customDir, 'GUIDE.md'), '# Guide');
521
+
522
+ const customFound = findAdrFiles(tmp, {
523
+ adr_dirs: ['docs/decisions'],
524
+ adr_id_pattern: 'DECISION-\\d+',
525
+ });
526
+ assert.equal(customFound.length, 2);
527
+ assert.ok(customFound.every((f) => f.includes('DECISION-')));
528
+ } finally {
529
+ fs.rmSync(tmp, { recursive: true, force: true });
530
+ }
531
+ });
532
+
533
+ it('parseAdrContent 支持 frontmatter id 与 status 映射(active 不误判 Frozen)', () => {
534
+ const doc = `---
535
+ id: DECISION-0007
536
+ status: active
537
+ scope:
538
+ - src/core.ts
539
+ ---
540
+ # DECISION-0007 · coreml 自愈定位架构不变量
541
+
542
+ ## 背景
543
+ 一些背景。
544
+
545
+ ## 决定
546
+ 采用 \`elementFromPoint\` 与 \`grounding_repair\` 进行定位。
547
+
548
+ ## 验证
549
+ 实测基准通过。
550
+ `;
551
+ const parsed = parseAdrContent(doc, 'docs/decisions/DECISION-0007-grounding.md', {
552
+ adr_id_pattern: 'DECISION-\\d+',
553
+ section_aliases: {
554
+ decision: ['决定'],
555
+ implementation: ['验证'],
556
+ },
557
+ });
558
+
559
+ assert.equal(parsed.adrId, 'DECISION-0007');
560
+ assert.equal(parsed.status, 'active');
561
+ assert.equal(parsed.isFrozen, false, 'active 状态不得误判为 Frozen');
562
+ assert.equal(parsed.hasImplementationStatus, true, '## 验证 应被识别为 implementation 节');
563
+ });
564
+
565
+ it('totalAdrs === 0 时必须报告 ZERO_COVERAGE,覆盖率严禁为 100%,strict 模式下 exit 1 阻断', () => {
566
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-zero-check-'));
567
+ try {
568
+ const matrix = buildAndCheckMatrix(tmp);
569
+ assert.equal(matrix.adrsCount, 0);
570
+ assert.equal(matrix.coveragePercent, 0, '零 ADR 时覆盖率必须为 0%,禁止输出 100%');
571
+ assert.equal(matrix.zeroCoverage, true);
572
+ assert.equal(matrix.isHealthy, false);
573
+
574
+ const triad = buildFullTriadMatrix(tmp);
575
+ assert.equal(triad.totalAdrs, 0);
576
+ assert.equal(triad.coveragePercent, 0);
577
+ assert.equal(triad.zeroCoverage, true);
578
+ assert.equal(triad.isHealthy, false);
579
+
580
+ let threw = false;
581
+ try {
582
+ execSync(`node units/spec-guard/bin/spec-guard.mjs check --strict --repo "${tmp}"`, {
583
+ encoding: 'utf8',
584
+ stdio: 'pipe',
585
+ });
586
+ } catch (err) {
587
+ threw = true;
588
+ assert.equal(err.status, 1);
589
+ const out = (err.stdout || '') + (err.stderr || '');
590
+ assert.ok(out.includes('ZERO_COVERAGE'));
591
+ }
592
+ assert.ok(threw, 'check --strict 在零覆盖时必须 Exit 1 阻断');
593
+ } finally {
594
+ fs.rmSync(tmp, { recursive: true, force: true });
595
+ }
596
+ });
597
+
598
+ it('门禁片 15-spec-guard 改为 check --full --strict,反向漂移夹具必须 Exit 1 阻断', () => {
599
+ const hookContent = fs.readFileSync('units/spec-guard/templates/pre-commit.d/15-spec-guard', 'utf8');
600
+ assert.ok(hookContent.includes('check --full --strict'), '门禁脚本必须调用 check --full --strict');
601
+ assert.ok(!hookContent.includes('check --incremental'), '门禁脚本禁止残留未实现的 check --incremental');
602
+ });
603
+ });
604
+
605
+ describe('spec-guard v2.2: 性能实测自述与约定阈值解耦 (Telemetry Decoupling & Exemption)', () => {
606
+ it('parseSimpleYamlOverlay 正确解析 telemetry_ignore_patterns 与 telemetry_exempt_adrs(支持顶层与嵌套)', () => {
607
+ const yaml = `
608
+ version: "1.0"
609
+ telemetry:
610
+ ignore_patterns:
611
+ - "≤1s"
612
+ - "/\\\\b\\\\d+\\\\s*s\\\\s*轮询/"
613
+ exempt_adrs:
614
+ - "ADR-0006"
615
+ telemetry_ignore_patterns:
616
+ - "周期 <= 500ms"
617
+ telemetry_exempt_adrs:
618
+ - "ADR-0008"
619
+ `;
620
+ const cfg = parseSimpleYamlOverlay(yaml);
621
+ assert.ok(cfg.telemetry_ignore_patterns.includes('≤1s'));
622
+ assert.ok(cfg.telemetry_ignore_patterns.includes('/\\b\\d+\\s*s\\s*轮询/'));
623
+ assert.ok(cfg.telemetry_ignore_patterns.includes('周期 <= 500ms'));
624
+ assert.ok(cfg.telemetry_exempt_adrs.includes('ADR-0006'));
625
+ assert.ok(cfg.telemetry_exempt_adrs.includes('ADR-0008'));
626
+ });
627
+
628
+ it('extractTelemetryMetrics 支持配置 ignorePatterns(字符串与正则):约定阈值被忽略,实测数据正常保留', () => {
629
+ const content = `
630
+ ## 验证
631
+ - 约定阈值:checkAuth 这类 ≤1s 轮询属于高频,不作为基准
632
+ - 实测基准:PP-OCRv5 推理均值 39.42ms,P95 44.37ms
633
+ `;
634
+ // 无 ignorePatterns 时:提取 1s, 39.42ms, P95, 44.37ms
635
+ const allMetrics = extractTelemetryMetrics(content);
636
+ assert.ok(allMetrics.some((m) => m.metric === '1s'));
637
+ assert.ok(allMetrics.some((m) => m.metric === '39.42ms'));
638
+
639
+ // 配置 ignorePatterns: ["≤1s"]
640
+ const filteredMetrics = extractTelemetryMetrics(content, {
641
+ ignorePatterns: ['≤1s'],
642
+ });
643
+ assert.equal(filteredMetrics.some((m) => m.metric === '1s'), false, '≤1s 应被 ignorePatterns 过滤');
644
+ assert.ok(filteredMetrics.some((m) => m.metric === '39.42ms'), '实测 39.42ms 必须正常保留');
645
+ });
646
+
647
+ it('extractTelemetryMetrics 支持行级内联标记 <!-- telemetry: ignore --> 过滤约定阈值', () => {
648
+ const content = `
649
+ ## 验证
650
+ - checkAuth 轮询周期 ≤1s <!-- telemetry: ignore -->
651
+ - 软拷贝实测均值 207ms,P95 264.92ms
652
+ `;
653
+ const metrics = extractTelemetryMetrics(content);
654
+ assert.equal(metrics.some((m) => m.metric === '1s'), false, '标记 telemetry: ignore 的行不得提取指标');
655
+ assert.ok(metrics.some((m) => m.metric === '207ms'), '未标记的实测行正常提取指标');
656
+ });
657
+
658
+ it('extractTelemetryMetrics 支持块级标记 <!-- telemetry: ignore-start --> / ignore-end 范围过滤', () => {
659
+ const content = `
660
+ ## 验证
661
+ <!-- telemetry: ignore-start -->
662
+ - 超时门限 ≤ 120s
663
+ - 重试窗口 500ms
664
+ <!-- telemetry: ignore-end -->
665
+ - 实测冷启耗时 460ms
666
+ `;
667
+ const metrics = extractTelemetryMetrics(content);
668
+ assert.equal(metrics.some((m) => m.metric === '120s'), false);
669
+ assert.equal(metrics.some((m) => m.metric === '500ms'), false);
670
+ assert.ok(metrics.some((m) => m.metric === '460ms'), '块外实测指标必须被提取');
671
+ });
672
+
673
+ it('verifyAdrTelemetry 支持 ADR frontmatter 声明 telemetry: exempt 整体豁免', () => {
674
+ const adrData = {
675
+ adrId: 'ADR-0006',
676
+ filePath: 'adr/0006.md',
677
+ content: `---
678
+ id: ADR-0006
679
+ status: active
680
+ telemetry: exempt
681
+ ---
682
+ # ADR-0006
683
+ ## 验证
684
+ - 实测均值 39.42ms
685
+ `,
686
+ telemetryExempt: true,
687
+ };
688
+ const res = verifyAdrTelemetry(adrData, '/tmp');
689
+ assert.equal(res.status, 'SKIPPED');
690
+ assert.equal(res.isCompliant, true);
691
+ assert.ok(res.reason.includes('telemetry: exempt'));
692
+ });
693
+
694
+ it('verifyAdrTelemetry 支持 overlay 配置 telemetry_exempt_adrs 整体豁免', () => {
695
+ const adrData = {
696
+ adrId: 'ADR-0006',
697
+ filePath: 'adr/0006.md',
698
+ content: `
699
+ # ADR-0006
700
+ ## 验证
701
+ - 实测均值 39.42ms(无凭证)
702
+ `,
703
+ };
704
+ // 未豁免时应 FAIL
705
+ const unexempted = verifyAdrTelemetry(adrData, '/tmp');
706
+ assert.equal(unexempted.status, 'FAIL');
707
+
708
+ // 配置 telemetry_exempt_adrs: ["ADR-0006"]
709
+ const exempted = verifyAdrTelemetry(adrData, '/tmp', {
710
+ telemetry_exempt_adrs: ['ADR-0006'],
711
+ });
712
+ assert.equal(exempted.status, 'SKIPPED');
713
+ assert.equal(exempted.isCompliant, true);
714
+ assert.ok(exempted.reason.includes('telemetry_exempt_adrs'));
715
+ });
716
+ });