@dommaker/harness 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cli/commands/check.js +3 -3
  3. package/dist/cli/commands/check.js.map +1 -1
  4. package/dist/core/app-constraints-loader.d.ts +5 -3
  5. package/dist/core/app-constraints-loader.d.ts.map +1 -1
  6. package/dist/core/app-constraints-loader.js +20 -7
  7. package/dist/core/app-constraints-loader.js.map +1 -1
  8. package/dist/core/constraints/checker.d.ts +5 -3
  9. package/dist/core/constraints/checker.d.ts.map +1 -1
  10. package/dist/core/constraints/checker.js +31 -10
  11. package/dist/core/constraints/checker.js.map +1 -1
  12. package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
  13. package/dist/core/constraints/checkers/capability-sync.js +21 -8
  14. package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
  15. package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
  16. package/dist/core/constraints/checkers/context-doc-sync.js +7 -1
  17. package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
  18. package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
  19. package/dist/core/constraints/checkers/docs-freshness.js +41 -26
  20. package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
  21. package/dist/core/constraints/checkers/governance-presence.d.ts +3 -0
  22. package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
  23. package/dist/core/constraints/checkers/governance-presence.js +7 -10
  24. package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
  25. package/dist/core/constraints/checkers/index.d.ts +6 -6
  26. package/dist/core/constraints/checkers/index.d.ts.map +1 -1
  27. package/dist/core/constraints/checkers/index.js +14 -9
  28. package/dist/core/constraints/checkers/index.js.map +1 -1
  29. package/dist/core/constraints/checkers/iron-flags.js +1 -1
  30. package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
  31. package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +11 -4
  32. package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -1
  33. package/dist/core/constraints/checkers/no-hardcoded-credentials.js +117 -30
  34. package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -1
  35. package/dist/core/constraints/checkers/no-test-simplification.d.ts +16 -2
  36. package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -1
  37. package/dist/core/constraints/checkers/no-test-simplification.js +115 -15
  38. package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
  39. package/dist/core/constraints/checkers/templated/exec.d.ts +19 -0
  40. package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -0
  41. package/dist/core/constraints/checkers/templated/exec.js +124 -0
  42. package/dist/core/constraints/checkers/templated/exec.js.map +1 -0
  43. package/dist/core/constraints/checkers/templated/index.d.ts +1 -0
  44. package/dist/core/constraints/checkers/templated/index.d.ts.map +1 -1
  45. package/dist/core/constraints/checkers/templated/index.js +3 -1
  46. package/dist/core/constraints/checkers/templated/index.js.map +1 -1
  47. package/dist/core/constraints/checkers/templates-registry.d.ts +2 -1
  48. package/dist/core/constraints/checkers/templates-registry.d.ts.map +1 -1
  49. package/dist/core/constraints/checkers/templates-registry.js +3 -1
  50. package/dist/core/constraints/checkers/templates-registry.js.map +1 -1
  51. package/dist/core/constraints/checkers/types.d.ts +67 -6
  52. package/dist/core/constraints/checkers/types.d.ts.map +1 -1
  53. package/dist/core/constraints/checkers/types.js +51 -6
  54. package/dist/core/constraints/checkers/types.js.map +1 -1
  55. package/dist/core/constraints/definitions/guidelines.d.ts +1 -0
  56. package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
  57. package/dist/core/constraints/definitions/guidelines.js +4 -0
  58. package/dist/core/constraints/definitions/guidelines.js.map +1 -1
  59. package/dist/core/constraints/definitions/iron-laws.d.ts +1 -0
  60. package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
  61. package/dist/core/constraints/definitions/iron-laws.js +6 -1
  62. package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
  63. package/dist/core/constraints/definitions.d.ts +7 -0
  64. package/dist/core/constraints/definitions.d.ts.map +1 -1
  65. package/dist/core/constraints/definitions.js +10 -0
  66. package/dist/core/constraints/definitions.js.map +1 -1
  67. package/dist/core/constraints/git-evidence.d.ts +10 -0
  68. package/dist/core/constraints/git-evidence.d.ts.map +1 -1
  69. package/dist/core/constraints/git-evidence.js +2 -0
  70. package/dist/core/constraints/git-evidence.js.map +1 -1
  71. package/dist/core/constraints/index.d.ts +3 -1
  72. package/dist/core/constraints/index.d.ts.map +1 -1
  73. package/dist/core/constraints/index.js +8 -1
  74. package/dist/core/constraints/index.js.map +1 -1
  75. package/dist/core/index.d.ts +2 -2
  76. package/dist/core/index.d.ts.map +1 -1
  77. package/dist/core/index.js +6 -1
  78. package/dist/core/index.js.map +1 -1
  79. package/dist/gates/checker-gate.d.ts +5 -1
  80. package/dist/gates/checker-gate.d.ts.map +1 -1
  81. package/dist/gates/checker-gate.js +10 -3
  82. package/dist/gates/checker-gate.js.map +1 -1
  83. package/dist/index.d.ts +3 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +14 -3
  86. package/dist/index.js.map +1 -1
  87. package/dist/types/constraint.d.ts +32 -3
  88. package/dist/types/constraint.d.ts.map +1 -1
  89. package/dist/types/constraint.js +6 -1
  90. package/dist/types/constraint.js.map +1 -1
  91. package/dist/types/trace.d.ts +7 -0
  92. package/dist/types/trace.d.ts.map +1 -1
  93. package/package.json +1 -1
  94. package/src/CONTEXT.md +1 -1
  95. package/src/__tests__/app-constraints-loader.test.ts +86 -3
  96. package/src/__tests__/checker-extra.test.ts +80 -4
  97. package/src/__tests__/checker-primitives-sdk.test.ts +70 -0
  98. package/src/__tests__/exec-checker-full-chain.test.ts +118 -0
  99. package/src/__tests__/public-exports.test.ts +5 -0
  100. package/src/__tests__/public-type-surface.test.ts +22 -0
  101. package/src/__tests__/public-value-surface.test.ts +5 -0
  102. package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -4
  103. package/src/cli/commands/__tests__/check.test.ts +2 -0
  104. package/src/cli/commands/check.ts +3 -3
  105. package/src/core/CONTEXT.md +6 -6
  106. package/src/core/app-constraints-loader.ts +23 -8
  107. package/src/core/constraints/__tests__/git-evidence.test.ts +20 -0
  108. package/src/core/constraints/__tests__/run-env.test.ts +2 -0
  109. package/src/core/constraints/checker.ts +35 -12
  110. package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +21 -3
  111. package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +20 -12
  112. package/src/core/constraints/checkers/__tests__/docs-freshness-degraded.test.ts +89 -0
  113. package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +4 -2
  114. package/src/core/constraints/checkers/__tests__/exec-checker.test.ts +99 -0
  115. package/src/core/constraints/checkers/__tests__/fixtures/public-repo-sanitization.mjs +40 -0
  116. package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +23 -2
  117. package/src/core/constraints/checkers/__tests__/input-contract.test.ts +135 -0
  118. package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +15 -2
  119. package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +110 -5
  120. package/src/core/constraints/checkers/__tests__/no-test-simplification.test.ts +144 -21
  121. package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +6 -2
  122. package/src/core/constraints/checkers/capability-sync.ts +24 -10
  123. package/src/core/constraints/checkers/context-doc-sync.ts +8 -1
  124. package/src/core/constraints/checkers/docs-freshness.ts +44 -26
  125. package/src/core/constraints/checkers/governance-presence.ts +7 -8
  126. package/src/core/constraints/checkers/index.ts +22 -10
  127. package/src/core/constraints/checkers/iron-flags.ts +1 -1
  128. package/src/core/constraints/checkers/no-hardcoded-credentials.ts +135 -29
  129. package/src/core/constraints/checkers/no-test-simplification.ts +128 -17
  130. package/src/core/constraints/checkers/templated/exec.ts +138 -0
  131. package/src/core/constraints/checkers/templated/index.ts +1 -0
  132. package/src/core/constraints/checkers/templates-registry.ts +4 -2
  133. package/src/core/constraints/checkers/types.ts +106 -9
  134. package/src/core/constraints/definitions/guidelines.ts +4 -0
  135. package/src/core/constraints/definitions/iron-laws.ts +6 -1
  136. package/src/core/constraints/definitions.ts +10 -0
  137. package/src/core/constraints/git-evidence.ts +13 -0
  138. package/src/core/constraints/index.ts +22 -0
  139. package/src/core/index.ts +16 -0
  140. package/src/gates/CONTEXT.md +1 -1
  141. package/src/gates/__tests__/checker-gate.test.ts +19 -2
  142. package/src/gates/checker-gate.ts +11 -4
  143. package/src/index.ts +26 -0
  144. package/src/types/constraint.ts +35 -3
  145. package/src/types/trace.ts +8 -0
@@ -4,11 +4,14 @@
4
4
  * 测试面 = ConstraintCheck.evaluate(env):判定只吃 stagedDiff 文本,
5
5
  * 证据经 providers 注入(旧 facade 测用真实非 git 目录触发 IO 失败,
6
6
  * 旁测直接让 provider 抛错表达同一语义)。自 checker-extra.test.ts 迁入。
7
+ *
8
+ * harness#185 启发式修正:判定限定测试文件(.test./.spec./__tests__),
9
+ * 配对新增豁免(净删除才判),新增 .skip/.only/xit/xdescribe 判违规。
7
10
  */
8
11
 
9
12
  import { describe, it, expect } from '@jest/globals';
10
13
  import { noTestSimplification } from '../no-test-simplification';
11
- import { buildCheckEnv } from '../types';
14
+ import { buildCheckEnv, type CheckDetail } from '../types';
12
15
  import type { ConstraintContext } from '../../../../types/constraint';
13
16
 
14
17
  function evaluate(diff: string | (() => Promise<string>)) {
@@ -23,36 +26,156 @@ function evaluate(diff: string | (() => Promise<string>)) {
23
26
  );
24
27
  }
25
28
 
29
+ /** 构造单文件 unified diff */
30
+ function diffFor(path: string, body: string): string {
31
+ return `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1,5 +1,5 @@\n${body}`;
32
+ }
33
+
34
+ /** fail 结果必须是带证据的 CheckDetail,且证据指到文件 */
35
+ async function expectFailWithEvidence(diff: string, fileHint: string) {
36
+ const outcome = await evaluate(diff);
37
+ expect(typeof outcome).toBe('object');
38
+ const detail = outcome as CheckDetail;
39
+ expect(detail.pass).toBe(false);
40
+ expect(detail.evidence?.some(e => e.includes(fileHint))).toBe(true);
41
+ }
42
+
26
43
  describe('no_test_simplification', () => {
27
- it('删除 test/it/describe → fail', async () => {
28
- expect(await evaluate('--- a/x.test.ts\n+++ b/x.test.ts\n@@\n- test("gone", () => {});\n')).toBe(false);
29
- expect(await evaluate('- it("gone", () => {});')).toBe(false);
30
- expect(await evaluate('-describe("suite", () => {});')).toBe(false);
44
+ describe('净删除判定(限测试文件)', () => {
45
+ it('净删除 test/it/describe → fail', async () => {
46
+ await expectFailWithEvidence(
47
+ diffFor('src/x.test.ts', '- test("gone", () => {});\n'),
48
+ 'src/x.test.ts'
49
+ );
50
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '- it("gone", () => {});\n'), 'src/x.test.ts');
51
+ await expectFailWithEvidence(
52
+ diffFor('src/x.test.ts', '-describe("suite", () => {});\n'),
53
+ 'src/x.test.ts'
54
+ );
55
+ });
56
+
57
+ it('净删除 expect → fail', async () => {
58
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '- expect(x).toBe(y);\n'), 'src/x.test.ts');
59
+ });
60
+
61
+ it('删除注释掉的 test → fail', async () => {
62
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '- // test pending case\n'), 'src/x.test.ts');
63
+ });
64
+
65
+ it('删多增少(净删除)→ fail', async () => {
66
+ const body =
67
+ '- it("a", () => {});\n- it("b", () => {});\n- it("c", () => {});\n+ it("renamed", () => {});\n';
68
+ await expectFailWithEvidence(diffFor('src/x.test.ts', body), 'src/x.test.ts');
69
+ });
70
+
71
+ it('.spec. 文件净删除 → fail', async () => {
72
+ await expectFailWithEvidence(diffFor('src/x.spec.ts', '- it("gone", () => {});\n'), 'src/x.spec.ts');
73
+ });
74
+
75
+ it('__tests__ 路径净删除 → fail', async () => {
76
+ await expectFailWithEvidence(
77
+ diffFor('src/__tests__/x.ts', '- it("gone", () => {});\n'),
78
+ 'src/__tests__/x.ts'
79
+ );
80
+ });
81
+
82
+ it('整文件删除(+++ /dev/null)的测试文件 → fail', async () => {
83
+ const diff =
84
+ 'diff --git a/src/x.test.ts b/src/x.test.ts\ndeleted file mode 100644\n--- a/src/x.test.ts\n+++ /dev/null\n@@ -1,2 +0,0 @@\n- it("a", () => {});\n- expect(1).toBe(1);\n';
85
+ await expectFailWithEvidence(diff, 'src/x.test.ts');
86
+ });
31
87
  });
32
88
 
33
- it('删除 expect → fail', async () => {
34
- expect(await evaluate('- expect(x).toBe(y);')).toBe(false);
89
+ describe('配对新增豁免(重命名/改写不误报)', () => {
90
+ it('重命名测试(-it 配 +it)→ pass', async () => {
91
+ const body = '- it("旧名", () => {});\n+ it("新名", () => {});\n';
92
+ expect(await evaluate(diffFor('src/x.test.ts', body))).toBe(true);
93
+ });
94
+
95
+ it('修改断言(-expect 配 +expect)→ pass', async () => {
96
+ const body = '- expect(x).toBe(oldValue);\n+ expect(x).toBe(newValue);\n';
97
+ expect(await evaluate(diffFor('src/x.test.ts', body))).toBe(true);
98
+ });
99
+
100
+ it('重构 helper:测试块删增等量 → pass', async () => {
101
+ const body =
102
+ '-describe("old suite", () => {});\n-it("a", () => {});\n+describe("new suite", () => {});\n+it("a", () => {});\n';
103
+ expect(await evaluate(diffFor('src/x.test.ts', body))).toBe(true);
104
+ });
35
105
  });
36
106
 
37
- it('删除注释掉的 test → fail', async () => {
38
- expect(await evaluate('- // test pending case')).toBe(false);
107
+ describe('跳过/独占形态检测', () => {
108
+ it('新增 .skip( → fail', async () => {
109
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '+ it.skip("flaky", () => {});\n'), 'src/x.test.ts');
110
+ await expectFailWithEvidence(
111
+ diffFor('src/x.test.ts', '+ describe.skip("suite", () => {});\n'),
112
+ 'src/x.test.ts'
113
+ );
114
+ await expectFailWithEvidence(
115
+ diffFor('src/x.test.ts', '+ test.skip("flaky", () => {});\n'),
116
+ 'src/x.test.ts'
117
+ );
118
+ });
119
+
120
+ it('新增 .only( → fail', async () => {
121
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '+ test.only("focus", () => {});\n'), 'src/x.test.ts');
122
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '+ it.only("focus", () => {});\n'), 'src/x.test.ts');
123
+ });
124
+
125
+ it('新增 xit(/xdescribe( → fail', async () => {
126
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '+ xit("gone", () => {});\n'), 'src/x.test.ts');
127
+ await expectFailWithEvidence(diffFor('src/x.test.ts', '+ xdescribe("s", () => {});\n'), 'src/x.test.ts');
128
+ });
129
+
130
+ it('把 it( 改成 it.skip((删旧增新)仍 → fail', async () => {
131
+ const body = '- it("flaky", () => {});\n+ it.skip("flaky", () => {});\n';
132
+ await expectFailWithEvidence(diffFor('src/x.test.ts', body), 'src/x.test.ts');
133
+ });
134
+
135
+ it('非测试文件新增 .skip( → pass', async () => {
136
+ expect(await evaluate(diffFor('src/list.ts', '+ node.skip();\n'))).toBe(true);
137
+ });
138
+
139
+ it('删除 .skip((恢复测试)→ pass', async () => {
140
+ const body = '- it.skip("flaky", () => {});\n+ it("flaky", () => {});\n';
141
+ expect(await evaluate(diffFor('src/x.test.ts', body))).toBe(true);
142
+ });
39
143
  });
40
144
 
41
- it('仅新增/上下文行 → pass', async () => {
42
- expect(
43
- await evaluate('--- a/x.test.ts\n+++ b/x.test.ts\n@@\n+ test("added", () => {});\n expect(1).toBe(1);\n')
44
- ).toBe(true);
145
+ describe('范围限定(非测试文件不判)', () => {
146
+ it('非测试文件删除 test( 字样 → pass', async () => {
147
+ expect(await evaluate(diffFor('src/runner.ts', '- test(benchmark);\n'))).toBe(true);
148
+ });
149
+
150
+ it('混合 diff:非测试文件删除不判,测试文件净删除照判', async () => {
151
+ const diff =
152
+ diffFor('src/runner.ts', '- test(benchmark);\n') +
153
+ diffFor('src/x.test.ts', '- it("gone", () => {});\n');
154
+ await expectFailWithEvidence(diff, 'src/x.test.ts');
155
+ });
156
+
157
+ it('仅新增/上下文行 → pass', async () => {
158
+ const body = '+ test("added", () => {});\n expect(1).toBe(1);\n';
159
+ expect(await evaluate(diffFor('src/x.test.ts', body))).toBe(true);
160
+ });
161
+
162
+ it('空 diff → pass', async () => {
163
+ expect(await evaluate('')).toBe(true);
164
+ });
165
+
166
+ it('无文件归属的裸删除行 → fail(fail-closed:无法证明不在测试文件)', async () => {
167
+ await expectFailWithEvidence('- it("gone", () => {});', '无文件归属');
168
+ });
45
169
  });
46
170
 
47
- it('空 diff → pass', async () => {
48
- expect(await evaluate('')).toBe(true);
171
+ it('声明 stagedDiff 输入契约(harness#182):git 取证失败由编排层降级,不假 pass', () => {
172
+ expect(noTestSimplification.needs).toEqual({ evidence: ['stagedDiff'] });
49
173
  });
50
174
 
51
- it('git diff 失败 → 默认通过(fail-open,自 facade 测迁入)', async () => {
52
- expect(
53
- await evaluate(async () => {
54
- throw new Error('not a git repository');
55
- })
56
- ).toBe(true);
175
+ it('git diff 失败 → 带原因的 skip(fail-open 但不假 pass,harness#182)', async () => {
176
+ const outcome = await evaluate(async () => {
177
+ throw new Error('not a git repository');
178
+ });
179
+ expect(outcome).toEqual({ skip: true, reason: 'staged diff 取证失败:not a git repository' });
57
180
  });
58
181
  });
@@ -128,7 +128,9 @@ describe('docs_freshness 评估段 skip 行为变更(工单 84:约定已立
128
128
  configYml:
129
129
  'governance:\n doc_freshness:\n checks:\n - type: changelog_version\n context_files:\n enabled: true\n',
130
130
  });
131
- expect(await evalDocsFreshness(dir)).toBe('skip');
131
+ const outcome = normalizeCheckOutcome(await evalDocsFreshness(dir));
132
+ expect(outcome.skipped).toBe(true);
133
+ expect(outcome.skipReason).toContain('required_dirs 为空');
132
134
  });
133
135
 
134
136
  it('enabled 但空 + CAPABILITIES.md 健康 → skip(原为 true)', async () => {
@@ -137,7 +139,9 @@ describe('docs_freshness 评估段 skip 行为变更(工单 84:约定已立
137
139
  files: ['src/module.ts'],
138
140
  capabilitiesBody: `${TABLE_HEAD}| module | src/module.ts | module |`,
139
141
  });
140
- expect(await evalDocsFreshness(dir)).toBe('skip');
142
+ const outcome = normalizeCheckOutcome(await evalDocsFreshness(dir));
143
+ expect(outcome.skipped).toBe(true);
144
+ expect(outcome.skipReason).toContain('required_dirs 为空');
141
145
  });
142
146
 
143
147
  it('enabled 但空 + CAPABILITIES.md 幽灵条目 → 仍 fail(Step 1 文件表判定不因 context_files 受影响)', async () => {
@@ -45,9 +45,9 @@ export const capabilitySync: ConstraintCheck = {
45
45
  id: 'capability_sync',
46
46
  async evaluate(env) {
47
47
  const projectPath = env.projectPath;
48
- // ADR-0001 存在性探测:项目未采用 CAPABILITIES.md 约定 → skip(不计 pass/fail)
48
+ // ADR-0001 存在性探测:项目未采用 CAPABILITIES.md 约定 → skip(不计 pass/fail,原因进结果面)
49
49
  if (!existsSync(join(projectPath, CAPABILITIES_FILE_REL))) {
50
- return 'skip';
50
+ return { skip: true, reason: '项目未采用 CAPABILITIES.md 约定(无 CAPABILITIES.md)' };
51
51
  }
52
52
  try {
53
53
  const capabilitiesMode = getCapabilitiesMode(env);
@@ -55,7 +55,7 @@ export const capabilitySync: ConstraintCheck = {
55
55
  const caps = env.capabilities(
56
56
  collectPopulationFiles(projectPath, env.sourceRoots(), (root) => env.srcScan(root))
57
57
  );
58
- if (!caps) return 'skip'; // 探测与取数之间文档消失:与上方同一语义
58
+ if (!caps) return { skip: true, reason: '评估期间 CAPABILITIES.md 消失(探测与取数之间被删除)' };
59
59
  const verdict = caps.verdict;
60
60
 
61
61
  // 清单格式(计数行)没有文件表可核对,计数由 sync-docs 维护,直接放行
@@ -63,14 +63,25 @@ export const capabilitySync: ConstraintCheck = {
63
63
  return true;
64
64
  }
65
65
 
66
- const diffNames = (await env.stagedDiffNames()).split('\n').filter(Boolean);
66
+ // 增量维度的输入可得性(harness#182):git 取证失败时 stagedDiffNames 归空串不抛错,
67
+ // uncoveredChanges 恒空 = Step 1 静默失效——放行路径必须带降级提示,不假「已核对」。
68
+ // 不声明 needs 改走编排层 skip:全量扫描(Step 2)不依赖 git,非 git 项目照出漂移提示
69
+ const diffNamesAvailable = env.evidenceAvailable?.('stagedDiffNames') ?? true;
70
+ const degradedNote = diffNamesAvailable
71
+ ? []
72
+ : ['增量检查降级:staged 变更清单不可得(git 取证失败),本次未核对变更文件的文档登记'];
73
+ const diffNames = diffNamesAvailable
74
+ ? (await env.stagedDiffNames()).split('\n').filter(Boolean)
75
+ : [];
67
76
  // 增量覆盖判定留在本文件:变更清单属 git 证据(#87),不在上行数据面
68
77
  const uncoveredChanges = significantCodeChanges(diffNames).filter(
69
78
  (f) => !isCoveredByEntries(verdict.coverageEntries, f)
70
79
  );
71
80
 
72
81
  // 无表格的散文文档:历史放行语义
73
- if (!verdict.hasTable) return true;
82
+ if (!verdict.hasTable) {
83
+ return degradedNote.length > 0 ? { pass: true, evidence: degradedNote } : true;
84
+ }
74
85
 
75
86
  // 文档退化门:有表格却什么都没登记(限定「源码根下确有文件」——空仓 + 空表没有可登记
76
87
  // 对象,历史行为是放行,本票不顺手扩大 fail 面)
@@ -98,14 +109,17 @@ export const capabilitySync: ConstraintCheck = {
98
109
  const kind = capabilitiesMode === 'module' ? '未登记模块目录' : '未登记源文件';
99
110
  return {
100
111
  pass: true,
101
- evidence: formatEvidence(
102
- `CAPABILITIES.md ${kind} ${gaps.length} 项(仓库级漂移,与本次变更无关;修复: harness sync-docs)`,
103
- gaps
104
- ),
112
+ evidence: [
113
+ ...formatEvidence(
114
+ `CAPABILITIES.md ${kind} ${gaps.length} 项(仓库级漂移,与本次变更无关;修复: harness sync-docs)`,
115
+ gaps
116
+ ),
117
+ ...degradedNote,
118
+ ],
105
119
  };
106
120
  }
107
121
 
108
- return true;
122
+ return degradedNote.length > 0 ? { pass: true, evidence: degradedNote } : true;
109
123
  } catch (err) {
110
124
  // fail-open 语义保留,但异常放行也要落地可见:warn 只进本地 stderr,
111
125
  // 进不了 trace——静默吞错会让解析 bug 变成「永远通过」(harness#119 同族问题)
@@ -18,7 +18,14 @@ export const contextDocSync: ConstraintCheck = {
18
18
  const projectPath = env.projectPath;
19
19
  const resolution = resolveContextFiles(env);
20
20
  if (resolution.state !== 'enabled') {
21
- return 'skip'; // 未配置或约定已立但无目标,跳过评估
21
+ // 未配置或约定已立但无目标,跳过评估(harness#182:原因进结果面)
22
+ return {
23
+ skip: true,
24
+ reason:
25
+ resolution.state === 'enabled-empty'
26
+ ? 'context_files 约定已启用但 required_dirs 为空'
27
+ : '项目未配置 governance.context_files 约定',
28
+ };
22
29
  }
23
30
 
24
31
  // 证据随判定一并返回(ADR-0016 补迁):此前只回裸 false,
@@ -36,19 +36,18 @@ function getBuiltInDocFreshnessConfig(): DocFreshnessCheck[] {
36
36
  * 判定逻辑与取数都在 run 级:文档原文、源码根、代码实况清单、对照判定一次算好,
37
37
  * 与 capability_sync 共用同一份(ADR-0023 决策 4;此前两边各读一遍、各解析一遍)。
38
38
  * 无表格(能力清单格式)时自然零幽灵。
39
+ *
40
+ * 不吞异常(harness#182):取数/解析失败由调用方统一走 fail-open 发声路径,
41
+ * 静默返回 [] 会把「检查器失效」读成「零幽灵 = 合规」。
39
42
  */
40
43
  function findDeadCapabilityEntries(env: CheckEnv): string[] {
41
- try {
42
- // 先探存在性再取数:只有 CHANGELOG 而无 CAPABILITIES.md 的项目不该为此扫一遍源码树
43
- if (!existsSync(join(env.projectPath, CAPABILITIES_FILE_REL))) return [];
44
- const population = collectPopulationFiles(env.projectPath, env.sourceRoots(), (root) =>
45
- env.srcScan(root)
46
- );
47
- const caps = env.capabilities(population);
48
- return caps ? caps.verdict.deadEntries : [];
49
- } catch {
50
- return [];
51
- }
44
+ // 先探存在性再取数:只有 CHANGELOG 而无 CAPABILITIES.md 的项目不该为此扫一遍源码树
45
+ if (!existsSync(join(env.projectPath, CAPABILITIES_FILE_REL))) return [];
46
+ const population = collectPopulationFiles(env.projectPath, env.sourceRoots(), (root) =>
47
+ env.srcScan(root)
48
+ );
49
+ const caps = env.capabilities(population);
50
+ return caps ? caps.verdict.deadEntries : [];
52
51
  }
53
52
 
54
53
  /**
@@ -82,21 +81,37 @@ export const docsFreshness: ConstraintCheck = {
82
81
  async evaluate(env) {
83
82
  const projectPath = env.projectPath;
84
83
 
85
- // ADR-0001 存在性探测:项目无任何 freshness 配置/目标 → skip(不计 pass/fail)
86
- if (!hasFreshnessTargets(env)) return 'skip';
87
-
88
- // Step 1: 文件表格式 — 登记的条目(文件+目录)是否仍存在(ADR-0009)
89
- const deadEntries = findDeadCapabilityEntries(env);
90
- if (deadEntries.length > 0) {
91
- // 证据通道点名条目(harness#119):此前是 console.error 侧信道(2026-08-08 studio
92
- // CI 4 连红时的临时办法),CLI 结构化输出与 trace 两头都拿不到,
93
- // error 级拦截时用户只看到一句通用提示,basename 碰撞下无从定位
84
+ // ADR-0001 存在性探测:项目无任何 freshness 配置/目标 → skip(不计 pass/fail,原因进结果面)
85
+ if (!hasFreshnessTargets(env)) {
94
86
  return {
95
- pass: false,
96
- evidence: formatEvidence('CAPABILITIES.md 登记的条目不存在', deadEntries),
87
+ skip: true,
88
+ reason: '项目未采用文档新鲜度约定(无 CAPABILITIES.md / CHANGELOG / freshness 配置)',
97
89
  };
98
90
  }
99
91
 
92
+ // Step 1(文件表幽灵)与 Step 2(FreshnessRunner)各自 fail-open 发声(harness#182,
93
+ // 对齐 capability_sync 姿势):任一步异常 → console.warn + 降级提示累积进 evidence,
94
+ // 不吞错、也不让一步的异常吞掉另一步的 fail 面
95
+ const degraded: string[] = [];
96
+ const reasonOf = (err: unknown) => (err instanceof Error ? err.message : String(err));
97
+
98
+ // Step 1: 文件表格式 — 登记的条目(文件+目录)是否仍存在(ADR-0009)
99
+ try {
100
+ const deadEntries = findDeadCapabilityEntries(env);
101
+ if (deadEntries.length > 0) {
102
+ // 证据通道点名条目(harness#119):此前是 console.error 侧信道(2026-08-08 studio
103
+ // CI 4 连红时的临时办法),CLI 结构化输出与 trace 两头都拿不到,
104
+ // error 级拦截时用户只看到一句通用提示,basename 碰撞下无从定位
105
+ return {
106
+ pass: false,
107
+ evidence: formatEvidence('CAPABILITIES.md 登记的条目不存在', deadEntries),
108
+ };
109
+ }
110
+ } catch (err) {
111
+ console.warn('[docs_freshness] 文件表新鲜度检查异常:', err);
112
+ degraded.push(`文件表幽灵检查异常,本次未核对: ${reasonOf(err)}(不代表登记条目均在场)`);
113
+ }
114
+
100
115
  // Step 2: 能力清单格式 + CLAUDE.md + CHANGELOG — 通过 FreshnessRunner
101
116
  try {
102
117
  const freshnessConfig = getGovernanceConfig(env)?.doc_freshness;
@@ -104,7 +119,9 @@ export const docsFreshness: ConstraintCheck = {
104
119
  // context_files 三态统一口径(工单 84):约定已立但无目标(enabled 但
105
120
  // required_dirs 缺失/空)→ skip,与 context_doc_sync 同构;不再静默放行
106
121
  const contextFiles = resolveContextFiles(env);
107
- if (contextFiles.state === 'enabled-empty') return 'skip';
122
+ if (contextFiles.state === 'enabled-empty') {
123
+ return { skip: true, reason: 'context_files 约定已启用但 required_dirs 为空' };
124
+ }
108
125
  const requiredDirs = contextFiles.state === 'enabled' ? contextFiles.dirs : undefined;
109
126
 
110
127
  const runner = new FreshnessRunner();
@@ -129,10 +146,11 @@ export const docsFreshness: ConstraintCheck = {
129
146
  ),
130
147
  };
131
148
  }
132
- } catch {
133
- // FreshnessRunner 失败不影响整体
149
+ } catch (err) {
150
+ console.warn('[docs_freshness] FreshnessRunner 检查异常,默认放行:', err);
151
+ degraded.push(`FreshnessRunner 检查异常,按 fail-open 放行: ${reasonOf(err)}(本次结果不代表文档新鲜度已验证)`);
134
152
  }
135
153
 
136
- return true;
154
+ return degraded.length > 0 ? { pass: true, evidence: degraded } : true;
137
155
  },
138
156
  };
@@ -7,12 +7,15 @@
7
7
  * 段被删除/掏空后 sync-docs 重新生成会静默丢失,此处补「在场」校验。
8
8
  *
9
9
  * ADR-0001 存在性探测:项目未采用 harness 治理(无 .harness/config.yml)→ skip。
10
+ * 探测按**文件存在**而非解析成功(harness#182):此前按 loadRawProjectConfig 解析
11
+ * 判定,config.yml YAML 损坏 → 解析抛错 → 误判「未采用」→ skip——恰在配置出问题
12
+ * 时闭嘴。文件在 = 已采用,解析坏不坏都照查治理契约在场性。
10
13
  * 向后兼容:旧模型仓(CLAUDE.md 有治理块、AGENTS.md 无 PRESERVE:governance)→ pass,
11
14
  * 不强制迁移;两处都没有才报违规。
12
15
  */
13
16
 
17
+ import { existsSync } from 'fs';
14
18
  import { join } from 'path';
15
- import { loadRawProjectConfig } from '../../project-config-loader';
16
19
  import { hasGovernanceContract, hasPreserveBlock, readIfExists } from '../injection-writer';
17
20
  import type { ConstraintCheck } from './types';
18
21
 
@@ -36,14 +39,10 @@ export const governancePresence: ConstraintCheck = {
36
39
  async evaluate(env) {
37
40
  const projectPath = env.projectPath;
38
41
 
39
- // 存在性探测:无 harness 配置 = 未采用治理约定 → skip(不计 pass/fail)
40
- let adopted = false;
41
- try {
42
- adopted = loadRawProjectConfig(env) !== undefined;
43
- } catch {
44
- adopted = false;
42
+ // 存在性探测:无 harness 配置 = 未采用治理约定 → skip(不计 pass/fail,原因进结果面)
43
+ if (!existsSync(join(projectPath, '.harness', 'config.yml'))) {
44
+ return { skip: true, reason: '项目未采用 harness 治理(无 .harness/config.yml)' };
45
45
  }
46
- if (!adopted) return 'skip';
47
46
 
48
47
  if (hasGovernancePreserveBlock(join(projectPath, 'AGENTS.md'))) return true;
49
48
  if (hasClaudeGovernance(join(projectPath, 'CLAUDE.md'))) return true;
@@ -4,9 +4,9 @@
4
4
  * checker.ts 编排层通过 getConstraintCheck() 查找实现。
5
5
  *
6
6
  * 两层注册表:
7
- * - 内置 checker(registry,按约束 id):模块加载时校验全部 kind='check' 的内置约束
8
- * 都有已注册 checker,且注册表中没有无对应 check 定义的孤儿实现;
9
- * 任一不满足即抛错(加载期失败,不许静默 pass,ADR-0001)。
7
+ * - 内置 checker(registry,按约束 id):模块加载时校验全部 channel='gate' 的内置约束
8
+ * 都有已注册 checker(ADR-0035 闭环收窄:非 gate 条目不要求 checker),且注册表中
9
+ * 没有无对应 gate 定义的孤儿实现;任一不满足即抛错(加载期失败,不许静默 pass,ADR-0001)。
10
10
  * - 模板 checker(TEMPLATES,按模板 id):填空式参数化模板,供应用层约束
11
11
  * (source='app',`.harness/constraints.yml`)按 checker + params 实例化。
12
12
  * 闭环语义扩展而非开口:应用层约束在加载期(app-constraints-loader)校验
@@ -15,7 +15,7 @@
15
15
 
16
16
  import type { Constraint } from '../../../types/constraint';
17
17
  import type { ConstraintCheck } from './types';
18
- import { getAllConstraints } from '../definitions';
18
+ import { getAllConstraints, isGateConstraint } from '../definitions';
19
19
 
20
20
  import {
21
21
  noCompletionWithoutVerification,
@@ -54,13 +54,13 @@ export { TEMPLATES } from './templates-registry';
54
54
  // 注册表闭环校验(加载期)
55
55
  // ========================================
56
56
 
57
- const checkConstraints = getAllConstraints().filter(c => c.kind === 'check');
57
+ const checkConstraints = getAllConstraints().filter(c => c.kind === 'check' && isGateConstraint(c));
58
58
 
59
59
  for (const c of checkConstraints) {
60
60
  if (!registry.has(c.id)) {
61
61
  throw new Error(
62
- `[harness] 约束注册表闭环校验失败:kind='check' 的约束 "${c.id}" 未注册 checker。` +
63
- `请在 checkers/ 中实现并注册(纯文本提示层已随 ADR-0029 关停)。`
62
+ `[harness] 约束注册表闭环校验失败:channel='gate' 的约束 "${c.id}" 未注册 checker。` +
63
+ `请在 checkers/ 中实现并注册;无 checker 的纪律/流程规则须标非 gate 通道(ADR-0035)。`
64
64
  );
65
65
  }
66
66
  }
@@ -68,7 +68,7 @@ for (const c of checkConstraints) {
68
68
  for (const id of registry.keys()) {
69
69
  if (!checkConstraints.some(c => c.id === id)) {
70
70
  throw new Error(
71
- `[harness] 约束注册表闭环校验失败:checker "${id}" 没有对应的 kind='check' 约束定义。` +
71
+ `[harness] 约束注册表闭环校验失败:checker "${id}" 没有对应的 channel='gate' 约束定义。` +
72
72
  `请在 definitions/ 中补齐定义,或从注册表移除。`
73
73
  );
74
74
  }
@@ -78,7 +78,7 @@ for (const id of registry.keys()) {
78
78
  * 查找检查实现
79
79
  *
80
80
  * - 传字符串 id 或内置约束:按 id 查内置注册表,未注册返回 undefined
81
- * (编排层对 kind='check' 未注册的情况抛错)
81
+ * (编排层对 channel='gate' 未注册的情况抛错)
82
82
  * - 传 source='app' 的约束:按 checker 模板 id + params 实例化;
83
83
  * 模板 id 未注册 → 抛错(闭环保留,不许静默 pass)
84
84
  */
@@ -107,13 +107,25 @@ export function registeredCheckCount(): number {
107
107
  return registry.size;
108
108
  }
109
109
 
110
- export { buildCheckEnv, normalizeCheckOutcome } from './types';
110
+ export {
111
+ buildCheckEnv,
112
+ normalizeCheckOutcome,
113
+ findMissingInputs,
114
+ degradeForMissingInputs,
115
+ formatEvidence,
116
+ contextFlag,
117
+ contextEvidenceFlag,
118
+ } from './types';
111
119
  export type {
112
120
  ConstraintCheck,
113
121
  TemplatedCheckerFactory,
114
122
  CheckEnv,
115
123
  CheckOutcome,
116
124
  CheckDetail,
125
+ CheckSkip,
126
+ CheckInputNeeds,
127
+ CheckEvidenceInput,
128
+ ContextEvidenceFlag,
117
129
  NormalizedOutcome,
118
130
  EvidenceProviders,
119
131
  } from './types';
@@ -13,5 +13,5 @@ import { contextEvidenceFlag } from './types';
13
13
 
14
14
  export const noCompletionWithoutVerification = contextEvidenceFlag(
15
15
  'no_completion_without_verification',
16
- ctx => ctx.hasVerificationEvidence
16
+ 'hasVerificationEvidence'
17
17
  );