@dommaker/harness 1.11.0 → 1.13.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.
- package/CHANGELOG.md +28 -0
- package/dist/cli/commands/constraints-pack-proposal.d.ts +48 -0
- package/dist/cli/commands/constraints-pack-proposal.d.ts.map +1 -0
- package/dist/cli/commands/constraints-pack-proposal.js +169 -0
- package/dist/cli/commands/constraints-pack-proposal.js.map +1 -0
- package/dist/cli/commands/constraints-reactivate.d.ts +55 -0
- package/dist/cli/commands/constraints-reactivate.d.ts.map +1 -0
- package/dist/cli/commands/constraints-reactivate.js +175 -0
- package/dist/cli/commands/constraints-reactivate.js.map +1 -0
- package/dist/cli/commands/constraints-report.d.ts +12 -1
- package/dist/cli/commands/constraints-report.d.ts.map +1 -1
- package/dist/cli/commands/constraints-report.js +35 -2
- package/dist/cli/commands/constraints-report.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts +49 -4
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +116 -34
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +31 -1
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/knowledge-view.d.ts +6 -3
- package/dist/cli/commands/knowledge-view.d.ts.map +1 -1
- package/dist/cli/commands/knowledge-view.js +8 -26
- package/dist/cli/commands/knowledge-view.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +9 -5
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/security.d.ts +19 -0
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +105 -0
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/state-io.d.ts +8 -1
- package/dist/cli/state-io.d.ts.map +1 -1
- package/dist/cli/state-io.js +2 -1
- package/dist/cli/state-io.js.map +1 -1
- package/dist/core/app-constraints-loader.d.ts +28 -0
- package/dist/core/app-constraints-loader.d.ts.map +1 -0
- package/dist/core/app-constraints-loader.js +187 -0
- package/dist/core/app-constraints-loader.js.map +1 -0
- package/dist/core/constraints/checker.js +1 -1
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +20 -9
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +40 -11
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/templated/file-exists.d.ts +16 -0
- package/dist/core/constraints/checkers/templated/file-exists.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/file-exists.js +108 -0
- package/dist/core/constraints/checkers/templated/file-exists.js.map +1 -0
- package/dist/core/constraints/checkers/templated/glob.d.ts +10 -0
- package/dist/core/constraints/checkers/templated/glob.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/glob.js +51 -0
- package/dist/core/constraints/checkers/templated/glob.js.map +1 -0
- package/dist/core/constraints/checkers/templated/index.d.ts +12 -0
- package/dist/core/constraints/checkers/templated/index.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/index.js +17 -0
- package/dist/core/constraints/checkers/templated/index.js.map +1 -0
- package/dist/core/constraints/checkers/templated/regex-scan.d.ts +15 -0
- package/dist/core/constraints/checkers/templated/regex-scan.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/regex-scan.js +129 -0
- package/dist/core/constraints/checkers/templated/regex-scan.js.map +1 -0
- package/dist/core/constraints/checkers/templates-registry.d.ts +17 -0
- package/dist/core/constraints/checkers/templates-registry.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templates-registry.js +23 -0
- package/dist/core/constraints/checkers/templates-registry.js.map +1 -0
- package/dist/core/constraints/checkers/types.d.ts +14 -0
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +0 -14
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +15 -0
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +58 -6
- package/dist/core/constraints/usage-report.d.ts.map +1 -1
- package/dist/core/constraints/usage-report.js +61 -12
- package/dist/core/constraints/usage-report.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +9 -6
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +18 -8
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/gates/command.d.ts +5 -1
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +56 -2
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +6 -1
- package/dist/gates/definitions.js.map +1 -1
- package/dist/knowledge/lifecycle.d.ts +14 -0
- package/dist/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/knowledge/lifecycle.js +50 -0
- package/dist/knowledge/lifecycle.js.map +1 -1
- package/dist/presets/standard.d.ts +1 -1
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +2 -3
- package/dist/presets/standard.js.map +1 -1
- package/dist/pretool-use-hook.d.ts +13 -4
- package/dist/pretool-use-hook.d.ts.map +1 -1
- package/dist/pretool-use-hook.js +89 -8
- package/dist/pretool-use-hook.js.map +1 -1
- package/dist/types/constraint.d.ts +24 -0
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +1 -1
- package/src/__tests__/app-constraints-loader.test.ts +220 -0
- package/src/__tests__/iron-laws.test.ts +5 -5
- package/src/__tests__/layering.test.ts +3 -1
- package/src/__tests__/pretool-use-hook.test.ts +211 -4
- package/src/cli/commands/CONTEXT.md +4 -3
- package/src/cli/commands/__tests__/check.test.ts +22 -4
- package/src/cli/commands/__tests__/constraints-pack-proposal.test.ts +142 -0
- package/src/cli/commands/__tests__/constraints-reactivate.test.ts +210 -0
- package/src/cli/commands/__tests__/constraints-report.test.ts +175 -6
- package/src/cli/commands/__tests__/constraints-retire.test.ts +135 -10
- package/src/cli/commands/__tests__/knowledge.test.ts +6 -16
- package/src/cli/commands/__tests__/report-app-constraints.test.ts +67 -0
- package/src/cli/commands/__tests__/security.test.ts +89 -1
- package/src/cli/commands/constraints-pack-proposal.ts +172 -0
- package/src/cli/commands/constraints-reactivate.ts +197 -0
- package/src/cli/commands/constraints-report.ts +44 -2
- package/src/cli/commands/constraints-retire.ts +129 -36
- package/src/cli/commands/definitions.ts +31 -1
- package/src/cli/commands/knowledge-view.ts +9 -28
- package/src/cli/commands/report.ts +9 -5
- package/src/cli/commands/security.ts +99 -0
- package/src/cli/state-io.ts +8 -1
- package/src/core/CONTEXT.md +5 -4
- package/src/core/app-constraints-loader.ts +165 -0
- package/src/core/constraints/__tests__/collect-constraints.test.ts +3 -1
- package/src/core/constraints/__tests__/usage-report.test.ts +63 -0
- package/src/core/constraints/checker.ts +1 -1
- package/src/core/constraints/checkers/__tests__/templated-checkers.test.ts +180 -0
- package/src/core/constraints/checkers/__tests__/templates-registry.test.ts +81 -0
- package/src/core/constraints/checkers/index.ts +44 -10
- package/src/core/constraints/checkers/templated/file-exists.ts +75 -0
- package/src/core/constraints/checkers/templated/glob.ts +46 -0
- package/src/core/constraints/checkers/templated/index.ts +12 -0
- package/src/core/constraints/checkers/templated/regex-scan.ts +132 -0
- package/src/core/constraints/checkers/templates-registry.ts +22 -0
- package/src/core/constraints/checkers/types.ts +15 -0
- package/src/core/constraints/definitions/guidelines.ts +0 -15
- package/src/core/constraints/definitions/iron-laws.ts +16 -0
- package/src/core/constraints/usage-report.ts +128 -13
- package/src/core/project-config-loader.ts +19 -8
- package/src/gates/CONTEXT.md +2 -2
- package/src/gates/__tests__/command.test.ts +54 -0
- package/src/gates/command.ts +57 -2
- package/src/gates/definitions.ts +6 -1
- package/src/knowledge/CONTEXT.md +3 -1
- package/src/knowledge/__tests__/lifecycle.test.ts +81 -0
- package/src/knowledge/lifecycle.ts +49 -0
- package/src/presets/__tests__/standard.test.ts +5 -4
- package/src/presets/standard.ts +2 -3
- package/src/pretool-use-hook.ts +104 -10
- package/src/types/constraint.ts +28 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用层约束加载器(ADR-0033 两层约束模型)测试
|
|
3
|
+
*
|
|
4
|
+
* 覆盖面:
|
|
5
|
+
* - loadAppConstraints 校验分支(文件不存在 / 坏 YAML / 缺必填字段 / id 无前缀 /
|
|
6
|
+
* id 与内置冲突 / 未知模板 / validateParams 失败 / trigger 形状)
|
|
7
|
+
* - 实例化缺省(source='app'、kind='check'、trigger 缺省全操作集、message 回落 rule)
|
|
8
|
+
* - memo 口径与 RunEnv.rawConfig 同形(同一观察面至多读一次;路径入参每次读当下内容)
|
|
9
|
+
* - 合并链(mergeConstraints / getEffectiveConstraints):应用层并入 +
|
|
10
|
+
* config.yml enabled:false / retired 墓碑对应用层 id 同口径生效 + 不进 unknownIds
|
|
11
|
+
*
|
|
12
|
+
* 模板注册表(TEMPLATES)本票为空表:测试用替身模板注册/注销,
|
|
13
|
+
* 真实模板(regex-scan / file-exists)随子项 2 进场。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, expect, afterEach } from '@jest/globals';
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import { loadAppConstraints } from '../core/app-constraints-loader';
|
|
20
|
+
import { getEffectiveConstraints, lintEffectiveConfig, getMergedConstraintsConfig } from '../core/effective-constraints';
|
|
21
|
+
import { CONSTRAINTS } from '../core/constraints/definitions';
|
|
22
|
+
import { createRunEnv } from '../core/constraints/run-env';
|
|
23
|
+
import { TEMPLATES, type TemplatedCheckerFactory } from '../core/constraints/checkers';
|
|
24
|
+
import { createProjectFixture } from '../test-setup/project-fixture';
|
|
25
|
+
|
|
26
|
+
const CONSTRAINTS_YML = path.join('.harness', 'constraints.yml');
|
|
27
|
+
|
|
28
|
+
const BUILTIN_TOTAL = Object.keys(CONSTRAINTS).length;
|
|
29
|
+
|
|
30
|
+
/** 替身模板:validateParams 要求 params.must 为 true(其余参数放行) */
|
|
31
|
+
const FAKE_TEMPLATE: TemplatedCheckerFactory = {
|
|
32
|
+
validateParams: (params) => (params.must === true ? [] : ['params.must 必须为 true']),
|
|
33
|
+
create: (id) => ({ id, evaluate: () => true }),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function fixture(constraintsYml?: string, configYml?: string): string {
|
|
37
|
+
return createProjectFixture({
|
|
38
|
+
name: 'app-constraints',
|
|
39
|
+
config: configYml,
|
|
40
|
+
files: constraintsYml !== undefined ? { [CONSTRAINTS_YML]: constraintsYml } : undefined,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const VALID = `
|
|
45
|
+
constraints:
|
|
46
|
+
- id: app_no_internal_url
|
|
47
|
+
rule: Web code must not contain internal URLs
|
|
48
|
+
checker: fake-template
|
|
49
|
+
params:
|
|
50
|
+
must: true
|
|
51
|
+
severity: warning
|
|
52
|
+
message: 检测到内网地址
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
// 替身模板逐用例注册、统一注销:不污染模板注册表(其他套件断言注册表构成)
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
TEMPLATES.delete('fake-template');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function registerFake(): void {
|
|
61
|
+
TEMPLATES.set('fake-template', FAKE_TEMPLATE);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('loadAppConstraints 校验分支', () => {
|
|
65
|
+
it('文件不存在 = 无应用层约束,正常返回空', () => {
|
|
66
|
+
expect(loadAppConstraints(fixture())).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('合法条目 → Constraint(source=app,kind=check,缺省 trigger=全操作集,message 回落 rule)', () => {
|
|
70
|
+
registerFake();
|
|
71
|
+
const constraints = loadAppConstraints(fixture(VALID));
|
|
72
|
+
|
|
73
|
+
expect(constraints).toHaveLength(1);
|
|
74
|
+
const c = constraints[0];
|
|
75
|
+
expect(c).toMatchObject({
|
|
76
|
+
id: 'app_no_internal_url',
|
|
77
|
+
kind: 'check',
|
|
78
|
+
rule: 'Web code must not contain internal URLs',
|
|
79
|
+
severity: 'warning',
|
|
80
|
+
message: '检测到内网地址',
|
|
81
|
+
source: 'app',
|
|
82
|
+
checker: 'fake-template',
|
|
83
|
+
params: { must: true },
|
|
84
|
+
});
|
|
85
|
+
// 缺省 trigger = 每次 check 都评估
|
|
86
|
+
expect(Array.isArray(c.trigger)).toBe(true);
|
|
87
|
+
expect(c.trigger).toContain('commit');
|
|
88
|
+
expect(c.trigger).toContain('file_modification');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('坏 YAML → 抛错(配置坏不能静默放行)', () => {
|
|
92
|
+
const root = fixture('constraints:\n - id: app_x\n bad indent: [');
|
|
93
|
+
expect(() => loadAppConstraints(root)).toThrow(/YAML 解析失败/);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('id 无 app_ 前缀 → 抛错', () => {
|
|
97
|
+
registerFake();
|
|
98
|
+
const root = fixture(`
|
|
99
|
+
constraints:
|
|
100
|
+
- id: no_prefix
|
|
101
|
+
rule: r
|
|
102
|
+
checker: fake-template
|
|
103
|
+
severity: warning
|
|
104
|
+
`);
|
|
105
|
+
expect(() => loadAppConstraints(root)).toThrow(/app_ 前缀/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('id 与内置约束冲突 → 抛错', () => {
|
|
109
|
+
registerFake();
|
|
110
|
+
const builtinId = Object.keys(CONSTRAINTS)[0];
|
|
111
|
+
const root = fixture(`
|
|
112
|
+
constraints:
|
|
113
|
+
- id: ${builtinId}
|
|
114
|
+
rule: r
|
|
115
|
+
checker: fake-template
|
|
116
|
+
severity: warning
|
|
117
|
+
`);
|
|
118
|
+
expect(() => loadAppConstraints(root)).toThrow(/与内置约束冲突/);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('checker 模板未注册 → 抛错(加载期闭环)', () => {
|
|
122
|
+
const root = fixture(`
|
|
123
|
+
constraints:
|
|
124
|
+
- id: app_unknown_template
|
|
125
|
+
rule: r
|
|
126
|
+
checker: not-a-template
|
|
127
|
+
severity: warning
|
|
128
|
+
`);
|
|
129
|
+
expect(() => loadAppConstraints(root)).toThrow(/未注册/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it.each([
|
|
133
|
+
['id', 'rule: r\nchecker: fake-template\nseverity: warning'],
|
|
134
|
+
['rule', 'id: app_x\nchecker: fake-template\nseverity: warning'],
|
|
135
|
+
['checker', 'id: app_x\nrule: r\nseverity: warning'],
|
|
136
|
+
['severity', 'id: app_x\nrule: r\nchecker: fake-template'],
|
|
137
|
+
])('缺必填字段 %s → 抛错', (_field, entryYaml) => {
|
|
138
|
+
registerFake();
|
|
139
|
+
const root = fixture(`constraints:\n - ${entryYaml.replace(/\n/g, '\n ')}\n`);
|
|
140
|
+
expect(() => loadAppConstraints(root)).toThrow(/缺必填字段/);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('severity 取值非法 → 抛错', () => {
|
|
144
|
+
registerFake();
|
|
145
|
+
const root = fixture(`
|
|
146
|
+
constraints:
|
|
147
|
+
- id: app_x
|
|
148
|
+
rule: r
|
|
149
|
+
checker: fake-template
|
|
150
|
+
severity: critical
|
|
151
|
+
`);
|
|
152
|
+
expect(() => loadAppConstraints(root)).toThrow(/severity/);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('validateParams 不通过 → 抛错(参数坏早报)', () => {
|
|
156
|
+
registerFake();
|
|
157
|
+
const root = fixture(`
|
|
158
|
+
constraints:
|
|
159
|
+
- id: app_bad_params
|
|
160
|
+
rule: r
|
|
161
|
+
checker: fake-template
|
|
162
|
+
severity: warning
|
|
163
|
+
`);
|
|
164
|
+
expect(() => loadAppConstraints(root)).toThrow(/参数校验失败/);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('constraints 段不是数组 → 抛错;顶层缺 constraints 段 = 空', () => {
|
|
168
|
+
expect(() => loadAppConstraints(fixture('constraints: notalist\n'))).toThrow(/数组/);
|
|
169
|
+
expect(loadAppConstraints(fixture('preset: standard\n'))).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('memo 与 rawConfig 同形:同一 RunEnv 至多读一次(缓存同一数组引用)', () => {
|
|
173
|
+
registerFake();
|
|
174
|
+
const root = fixture(VALID);
|
|
175
|
+
const env = createRunEnv(root);
|
|
176
|
+
const first = loadAppConstraints(env);
|
|
177
|
+
// 观察面命中 memo 后,文件改动在本 run 内不可见
|
|
178
|
+
fs.writeFileSync(path.join(root, CONSTRAINTS_YML), 'constraints: []\n');
|
|
179
|
+
expect(loadAppConstraints(env)).toBe(first);
|
|
180
|
+
// 传路径 = 一次性观察面,每次读当下内容
|
|
181
|
+
expect(loadAppConstraints(root)).toEqual([]);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('合并链并入(ADR-0033)', () => {
|
|
186
|
+
it('应用层条目并入生效集尾部(getEffectiveConstraints)', () => {
|
|
187
|
+
registerFake();
|
|
188
|
+
const root = fixture(VALID);
|
|
189
|
+
const constraints = getEffectiveConstraints(root);
|
|
190
|
+
expect(constraints).toHaveLength(BUILTIN_TOTAL + 1);
|
|
191
|
+
const app = constraints.find(c => c.id === 'app_no_internal_url');
|
|
192
|
+
expect(app?.source).toBe('app');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('config.yml enabled:false 禁用应用层条目(filterEnabledEntries 天然兼容)', () => {
|
|
196
|
+
registerFake();
|
|
197
|
+
const root = fixture(VALID, 'constraints:\n app_no_internal_url:\n enabled: false\n');
|
|
198
|
+
const merged = getMergedConstraintsConfig(root);
|
|
199
|
+
expect(merged.constraints.app_no_internal_url).toBeUndefined();
|
|
200
|
+
expect(merged.disabled).toContain('app_no_internal_url');
|
|
201
|
+
// 应用层 id 是已知 id,不进 unknownIds 诊断
|
|
202
|
+
expect(merged.unknownIds).toEqual([]);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('config.yml retired 墓碑对应用层条目同样生效(随 enabled:false)', () => {
|
|
206
|
+
registerFake();
|
|
207
|
+
const root = fixture(
|
|
208
|
+
VALID,
|
|
209
|
+
'constraints:\n app_no_internal_url:\n enabled: false\n retired:\n at: 2026-09-22\n reason: 零拦截\n'
|
|
210
|
+
);
|
|
211
|
+
const ids = getEffectiveConstraints(root).map(c => c.id);
|
|
212
|
+
expect(ids).not.toContain('app_no_internal_url');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('lintEffectiveConfig 不把应用层 id 报成未知', () => {
|
|
216
|
+
registerFake();
|
|
217
|
+
const root = fixture(VALID, 'constraints:\n app_no_internal_url:\n enabled: false\n');
|
|
218
|
+
expect(lintEffectiveConfig(root).unknownIds).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -21,11 +21,11 @@ describe('Constraint System', () => {
|
|
|
21
21
|
expect(all.every(c => c.kind === 'check')).toBe(true);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it('severity 分桶 =
|
|
24
|
+
it('severity 分桶 = 4 error + 3 warning(ADR-0032:凭证扫描升 error)', () => {
|
|
25
25
|
const errors = Object.values(CONSTRAINTS).filter(c => c.severity === 'error');
|
|
26
26
|
const warnings = Object.values(CONSTRAINTS).filter(c => c.severity === 'warning');
|
|
27
|
-
expect(errors).toHaveLength(
|
|
28
|
-
expect(warnings).toHaveLength(
|
|
27
|
+
expect(errors).toHaveLength(4);
|
|
28
|
+
expect(warnings).toHaveLength(3);
|
|
29
29
|
Object.values(CONSTRAINTS).forEach(c => {
|
|
30
30
|
expect(c.kind).toBe('check');
|
|
31
31
|
});
|
|
@@ -222,13 +222,13 @@ describe('Constraint Checker', () => {
|
|
|
222
222
|
|
|
223
223
|
describe('Constraint Severity', () => {
|
|
224
224
|
it('error 级约束 severity 均为 error', () => {
|
|
225
|
-
['no_completion_without_verification', 'no_test_simplification', 'docs_freshness'].forEach(id => {
|
|
225
|
+
['no_completion_without_verification', 'no_test_simplification', 'docs_freshness', 'no_hardcoded_credentials'].forEach(id => {
|
|
226
226
|
expect(CONSTRAINTS[id].severity).toBe('error');
|
|
227
227
|
});
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
it('warning 级约束 severity 均为 warning', () => {
|
|
231
|
-
['
|
|
231
|
+
['capability_sync', 'context_doc_sync', 'governance_presence'].forEach(id => {
|
|
232
232
|
expect(CONSTRAINTS[id].severity).toBe('warning');
|
|
233
233
|
});
|
|
234
234
|
});
|
|
@@ -84,7 +84,9 @@ const DOWNSTREAM: Record<string, string[]> = {
|
|
|
84
84
|
// ── 顶层组合面 / 测试面:可下行到任何单元 ──
|
|
85
85
|
cli: [ANY], // CLI 是唯一的上层,per-command 懒加载各命令实现
|
|
86
86
|
'index.ts': [ANY], // 包根 barrel(ADR-0003 显式清单)
|
|
87
|
-
|
|
87
|
+
// 钩子入口:PreToolUse 决策取 CommandGate;P1-7(ADR-0031)命中留痕经
|
|
88
|
+
// TraceCollector 写 traces——与 hooks 组合根 → monitoring 同方向,是下行不是债
|
|
89
|
+
'pretool-use-hook.ts': ['gates', 'monitoring', 'types', 'utils'],
|
|
88
90
|
__tests__: [ANY], // 根测试面:跨目录取生产码是本职
|
|
89
91
|
};
|
|
90
92
|
|
|
@@ -3,10 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 验收口径:block/warn/audit 行为与 studio-agent 生成版脚本一致——
|
|
5
5
|
* block 级 exit 2 阻断,warn/audit 放行,坏输入 fail-open。
|
|
6
|
+
*
|
|
7
|
+
* P1-7(ADR-0031,wayfinder 票08):命中留痕走 traces 通道——整个套件 chdir 到
|
|
8
|
+
* tmp 目录运行(TraceCollector 缺省按 cwd 解析 projectPath),断言 JSONL 行;
|
|
9
|
+
* 留痕失败不挡拦截主路径。
|
|
6
10
|
*/
|
|
7
11
|
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as os from 'os';
|
|
14
|
+
import * as path from 'path';
|
|
8
15
|
import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals';
|
|
9
16
|
import { decidePreToolUse, runPreToolUseHook, HOOK_MARKER } from '../pretool-use-hook';
|
|
17
|
+
import { CommandGate } from '../gates/command';
|
|
18
|
+
import { TraceCollector } from '../monitoring/traces';
|
|
10
19
|
|
|
11
20
|
/** 构造 provider PreToolUse stdin JSON */
|
|
12
21
|
function stdinOf(command: string): string {
|
|
@@ -14,6 +23,32 @@ function stdinOf(command: string): string {
|
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
describe('pretool-use-hook', () => {
|
|
26
|
+
const origCwd = process.cwd();
|
|
27
|
+
let workDir: string;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
// 留痕落点 = <cwd>/.harness/logs/traces.log:chdir 到每轮唯一 tmp 目录,
|
|
31
|
+
// 不污染本仓真 traces.log(回收走 mkdtemp-cleanup 劫持)
|
|
32
|
+
workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-pretool-'));
|
|
33
|
+
process.chdir(workDir);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
process.chdir(origCwd);
|
|
38
|
+
jest.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** 读本轮 tmp 目录下的 trace JSONL 行 */
|
|
42
|
+
function readTraces(): Array<Record<string, unknown>> {
|
|
43
|
+
const file = path.join(workDir, '.harness', 'logs', 'traces.log');
|
|
44
|
+
if (!fs.existsSync(file)) return [];
|
|
45
|
+
return fs
|
|
46
|
+
.readFileSync(file, 'utf-8')
|
|
47
|
+
.split('\n')
|
|
48
|
+
.filter(Boolean)
|
|
49
|
+
.map((line) => JSON.parse(line) as Record<string, unknown>);
|
|
50
|
+
}
|
|
51
|
+
|
|
17
52
|
describe('decidePreToolUse', () => {
|
|
18
53
|
it('block 级命令被拦截(rm -rf /)', () => {
|
|
19
54
|
const r = decidePreToolUse(stdinOf('rm -rf /'));
|
|
@@ -48,6 +83,12 @@ describe('pretool-use-hook', () => {
|
|
|
48
83
|
it('缺 tool_input 字段放行', () => {
|
|
49
84
|
expect(decidePreToolUse(JSON.stringify({ tool_name: 'Bash' })).allowed).toBe(true);
|
|
50
85
|
});
|
|
86
|
+
|
|
87
|
+
it('命中明细随判定带出(hits 含 rule id 与 level)', () => {
|
|
88
|
+
const r = decidePreToolUse(stdinOf('rm -rf /'));
|
|
89
|
+
expect(r.hits.map((h) => h.id)).toContain('rm-rf-root');
|
|
90
|
+
expect(r.hits.every((h) => h.level === 'block')).toBe(true);
|
|
91
|
+
});
|
|
51
92
|
});
|
|
52
93
|
|
|
53
94
|
describe('runPreToolUseHook', () => {
|
|
@@ -57,10 +98,6 @@ describe('pretool-use-hook', () => {
|
|
|
57
98
|
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
58
99
|
});
|
|
59
100
|
|
|
60
|
-
afterEach(() => {
|
|
61
|
-
errorSpy.mockRestore();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
101
|
it('block 级返回 exit 2 并写 stderr(含 marker 与原命令)', () => {
|
|
65
102
|
const code = runPreToolUseHook(stdinOf('rm -rf ~'));
|
|
66
103
|
expect(code).toBe(2);
|
|
@@ -79,4 +116,174 @@ describe('pretool-use-hook', () => {
|
|
|
79
116
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
80
117
|
});
|
|
81
118
|
});
|
|
119
|
+
|
|
120
|
+
describe('命中留痕(P1-7:traces 通道,只记账不加拦截)', () => {
|
|
121
|
+
beforeEach(() => {
|
|
122
|
+
// 阻断时 stderr 是 provider 回填面,与本组断言无关,收下不打到测试输出
|
|
123
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('block 命中写一条 error/fail 汇总 trace(规则 id + 命令首 token 进 evidence,不记完整命令)', () => {
|
|
127
|
+
expect(runPreToolUseHook(stdinOf('rm -rf /'))).toBe(2);
|
|
128
|
+
|
|
129
|
+
const traces = readTraces();
|
|
130
|
+
expect(traces).toHaveLength(1);
|
|
131
|
+
expect(traces[0]).toMatchObject({
|
|
132
|
+
constraintId: 'command-gate',
|
|
133
|
+
severity: 'error',
|
|
134
|
+
result: 'fail',
|
|
135
|
+
operation: 'pretool-use-hook',
|
|
136
|
+
});
|
|
137
|
+
const evidence = traces[0].evidence as string[];
|
|
138
|
+
expect(evidence).toContain('rule:rm-rf-root');
|
|
139
|
+
expect(evidence).toContain('cmd:rm');
|
|
140
|
+
// 脱敏:完整命令文本(可能含敏感参数)不进 evidence
|
|
141
|
+
expect(evidence.join(' ')).not.toContain('rm -rf /');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('warn 命中写 warning/pass trace,仍放行', () => {
|
|
145
|
+
expect(runPreToolUseHook(stdinOf('psql -c "DROP TABLE users"'))).toBe(0);
|
|
146
|
+
|
|
147
|
+
const traces = readTraces();
|
|
148
|
+
expect(traces).toHaveLength(1);
|
|
149
|
+
expect(traces[0]).toMatchObject({
|
|
150
|
+
constraintId: 'command-gate',
|
|
151
|
+
severity: 'warning',
|
|
152
|
+
result: 'pass',
|
|
153
|
+
operation: 'pretool-use-hook',
|
|
154
|
+
});
|
|
155
|
+
expect(traces[0].evidence).toContain('rule:drop-table');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('audit 命中写 info/pass trace,仍放行', () => {
|
|
159
|
+
expect(runPreToolUseHook(stdinOf('cat .env'))).toBe(0);
|
|
160
|
+
|
|
161
|
+
const traces = readTraces();
|
|
162
|
+
expect(traces).toHaveLength(1);
|
|
163
|
+
expect(traces[0]).toMatchObject({
|
|
164
|
+
constraintId: 'command-gate',
|
|
165
|
+
severity: 'info',
|
|
166
|
+
result: 'pass',
|
|
167
|
+
operation: 'pretool-use-hook',
|
|
168
|
+
});
|
|
169
|
+
expect(traces[0].evidence).toContain('rule:read-env');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('干净命令不写 trace', () => {
|
|
173
|
+
expect(runPreToolUseHook(stdinOf('git status'))).toBe(0);
|
|
174
|
+
expect(readTraces()).toHaveLength(0);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('留痕失败不影响拦截主路径(fail-open:block 照拦、放行照放)', () => {
|
|
178
|
+
jest.spyOn(TraceCollector.prototype, 'record').mockImplementation(() => {
|
|
179
|
+
throw new Error('disk full');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
expect(runPreToolUseHook(stdinOf('rm -rf /'))).toBe(2);
|
|
183
|
+
expect(runPreToolUseHook(stdinOf('killall node'))).toBe(0);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('非 Bash 工具事件(P1-5:只留痕不拦截,拦截归 codex 沙箱)', () => {
|
|
188
|
+
it('Edit 事件放行(exit 0)并写 tool-event trace(evidence 记工具名 + file_path,不记内容正文)', () => {
|
|
189
|
+
const stdin = JSON.stringify({
|
|
190
|
+
tool_name: 'Edit',
|
|
191
|
+
tool_input: { file_path: 'src/a.ts', old_string: 'SECRET=abc123', new_string: 'SECRET=def456' },
|
|
192
|
+
});
|
|
193
|
+
expect(runPreToolUseHook(stdin)).toBe(0);
|
|
194
|
+
|
|
195
|
+
const traces = readTraces();
|
|
196
|
+
expect(traces).toHaveLength(1);
|
|
197
|
+
expect(traces[0]).toMatchObject({
|
|
198
|
+
constraintId: 'tool-event:Edit',
|
|
199
|
+
severity: 'info',
|
|
200
|
+
result: 'pass',
|
|
201
|
+
operation: 'pretool-use-hook',
|
|
202
|
+
});
|
|
203
|
+
expect(traces[0].evidence).toEqual(['tool:Edit', 'path:src/a.ts']);
|
|
204
|
+
// 内容正文(可能含敏感值)不进 trace
|
|
205
|
+
expect(JSON.stringify(traces[0])).not.toContain('abc123');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('Write 事件放行并留痕', () => {
|
|
209
|
+
const stdin = JSON.stringify({
|
|
210
|
+
tool_name: 'Write',
|
|
211
|
+
tool_input: { file_path: 'docs/note.md', content: 'body' },
|
|
212
|
+
});
|
|
213
|
+
expect(runPreToolUseHook(stdin)).toBe(0);
|
|
214
|
+
|
|
215
|
+
const traces = readTraces();
|
|
216
|
+
expect(traces).toHaveLength(1);
|
|
217
|
+
expect(traces[0].constraintId).toBe('tool-event:Write');
|
|
218
|
+
expect(traces[0].evidence).toEqual(['tool:Write', 'path:docs/note.md']);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('apply_patch 事件(无 file_path)放行并留痕,evidence 只记工具名', () => {
|
|
222
|
+
const stdin = JSON.stringify({
|
|
223
|
+
tool_name: 'apply_patch',
|
|
224
|
+
tool_input: { patch: '*** Begin Patch' },
|
|
225
|
+
});
|
|
226
|
+
expect(runPreToolUseHook(stdin)).toBe(0);
|
|
227
|
+
|
|
228
|
+
const traces = readTraces();
|
|
229
|
+
expect(traces).toHaveLength(1);
|
|
230
|
+
expect(traces[0].constraintId).toBe('tool-event:apply_patch');
|
|
231
|
+
expect(traces[0].evidence).toEqual(['tool:apply_patch']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('MCP 工具事件放行并留痕', () => {
|
|
235
|
+
const stdin = JSON.stringify({
|
|
236
|
+
tool_name: 'mcp__local-rag__query_documents',
|
|
237
|
+
tool_input: { query: 'x' },
|
|
238
|
+
});
|
|
239
|
+
expect(runPreToolUseHook(stdin)).toBe(0);
|
|
240
|
+
|
|
241
|
+
const traces = readTraces();
|
|
242
|
+
expect(traces).toHaveLength(1);
|
|
243
|
+
expect(traces[0].constraintId).toBe('tool-event:mcp__local-rag__query_documents');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('非 Bash 事件即使 tool_input 带危险 command 字段也不拦(判定面只认 Bash)', () => {
|
|
247
|
+
const stdin = JSON.stringify({
|
|
248
|
+
tool_name: 'Edit',
|
|
249
|
+
tool_input: { file_path: 'a.ts', command: 'rm -rf /' },
|
|
250
|
+
});
|
|
251
|
+
const r = decidePreToolUse(stdin);
|
|
252
|
+
expect(r.allowed).toBe(true);
|
|
253
|
+
expect(r.toolName).toBe('Edit');
|
|
254
|
+
expect(runPreToolUseHook(stdin)).toBe(0);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('Bash 事件判定维持不变(回归:block 仍 exit 2)', () => {
|
|
258
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
259
|
+
expect(runPreToolUseHook(stdinOf('rm -rf /'))).toBe(2);
|
|
260
|
+
const traces = readTraces();
|
|
261
|
+
expect(traces).toHaveLength(1);
|
|
262
|
+
expect(traces[0].constraintId).toBe('command-gate');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('缺 tool_name 的旧事件形状按 Bash 兼容(command 照常判定)', () => {
|
|
266
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
267
|
+
expect(runPreToolUseHook(JSON.stringify({ tool_input: { command: 'rm -rf /' } }))).toBe(2);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('CommandGate.match 公共只读面(P1-7)', () => {
|
|
272
|
+
it('返回命中规则明细(id/level/message),与 isAllowed 同一谓词', () => {
|
|
273
|
+
const gate = new CommandGate();
|
|
274
|
+
const hits = gate.match('rm -rf /');
|
|
275
|
+
expect(hits.length).toBeGreaterThan(0);
|
|
276
|
+
expect(hits.some((r) => r.id === 'rm-rf-root' && r.level === 'block')).toBe(true);
|
|
277
|
+
expect(gate.isAllowed('rm -rf /')).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('干净命令命中为空', () => {
|
|
281
|
+
expect(new CommandGate().match('git status')).toEqual([]);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('类别忽略对 match 同样生效', () => {
|
|
285
|
+
const gate = new CommandGate({ ignoreCategories: ['system'] });
|
|
286
|
+
expect(gate.match('rm -rf /')).toEqual([]);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
82
289
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# cli/commands/
|
|
2
2
|
|
|
3
3
|
## 职责
|
|
4
|
-
CLI 子命令实现:20 个顶层命令 + constraints 治理子命令 report/retire,覆盖约束检查/门禁验证/文档同步/知识管理/失败诊断/发布等。
|
|
4
|
+
CLI 子命令实现:20 个顶层命令 + constraints 治理子命令 report/retire/reactivate/pack-proposal,覆盖约束检查/门禁验证/文档同步/知识管理/失败诊断/发布等。
|
|
5
5
|
|
|
6
6
|
H5(#44)起:
|
|
7
7
|
- **命令定义即注册**:`definitions.ts` 的 `COMMAND_DEFINITIONS` 是命令形状(名称/别名/位置参数/选项/子命令/实现引用)的单一来源;bin/harness.js 遍历本表注册表驱动生成,不再手写 commander 命令块,不再有 index.ts barrel 两处同步(R6)
|
|
@@ -15,10 +15,11 @@ H5(#44)起:
|
|
|
15
15
|
- 脚手架落盘面(`src/cli/commands/scaffold.ts`)— 受管文件(managed file)三态判定 `writeManagedFile` / 一组落盘 `runPlan` + 8 个站点工厂(含对外文案;ADR-0029:custom-constraints.yml 示例站随 custom 约束面退役移除);模板正文住 `scaffold-templates.ts`,落盘注入面 `ScaffoldFileSystem` 可换内存替身(harness#132);CI 站点工厂 `harnessCheckCiFile` 带平台维度(github / gitlab,harness#143);两道 Git hook 工厂 `preCommitHookFile` / `prePushHookFile`(后者 harness#144,带可执行位)
|
|
16
16
|
- knowledge 投影面(`src/cli/commands/knowledge-view.ts`)— 11 个 knowledge 子操作的**display model** 渲染与出口:`emitKnowledgeView`(json/人读唯一分派 + 退出码)、`announce`(取数期进度行,`--json` 下静默)、`TONE_STYLES` 角色→样式单表、维度/规则 label 与 `toneForMaturity`/`toneForScore`/`toneForSeverity` 三张映射、`resolveKnowledgeBaseDir` + `openKnowledgeStore`(路径兜底与 store 构造单点)(harness#133)
|
|
17
17
|
- 各命令文件:check / validate / passes-gate / init / report / status / spec / sync-docs / knowledge / sdd / failure / release / constraints / spec-baseline-check
|
|
18
|
-
-
|
|
18
|
+
- `report` 的约束面走生效集(ADR-0033 修缺口):collectConstraints 传 getMergedConstraintsConfig 的 merged config(与 check.ts 同一入口),总数/分级计数按生效集——此前跑内置全集,config.yml 禁用与应用层条目(`.harness/constraints.yml`)都进不了报告面
|
|
19
|
+
- 6 门禁命令实现在 `acceptance` / `command` / `contract` / `performance` / `review` / `security`(其 CLI 元数据在 `src/gates/definitions.ts`,形状同为 `CommandDefinition`,ADR-0007);**判定一律穿过统一接口 `evaluate()`**,成败与措辞由共享面映射。`command` 只复用映射、保留自己的单行 ✓/✗ 输出(已对外的机器友好形状);`security audit` / `acceptance list` / `contract validate-schema` / `review status` / `command --list/--level` 是只展示不判断的子命令,直读报告面(`scan()` 等),不套骨架;`security secrets`(P1-8,ADR-0031,wayfinder 票08)是判定子命令但不经门禁——直跑 gitleaks 全历史扫描:二进制缺失 → skip(不 fail),有泄露 → fail(只列条数与文件、不打印密钥原文),干净 → ok;CI 的 secrets job(harness-governance.yml,fetch-depth: 0 + 固定版本安装 gitleaks)跑同一命令,安装后才是真门
|
|
19
20
|
- CLI 子命令 `command` 的两个分支共用同一台 gate 实例(#135/ADR-0024):默认分支经 `evaluate()` 取裁决、`--level` 经同一实例的 `getRiskLevel()` 取等级,命令侧不再引用模块级单例出口——「配置传进去却到不了判定」的那条路已封。`--strict` 旗帜随 `CommandGateConfig.strict`(零消费者、从不生效)一并删除
|
|
20
21
|
|
|
21
|
-
`constraints` 下挂治理子命令:`constraints report`(使用统计 + 退役候选诊断 + 配置健康,`--export` 脱敏;JSON 输出走 `--json-output`——原名 `--json` 与父命令同名会被 commander 消费在父侧、JSON 分支不可达,E1 复盘修正 M3.1 换名,闸见 `__tests__/constraints-report-json-flag.test.ts`)、`constraints retire`(交互选择 + 人确认退役;带 id 直达需显式 `--yes`(#24 人确认闸门),无 `--yes` 报错 + 非零退出码且不落盘;落 config.yml retired
|
|
22
|
+
`constraints` 下挂治理子命令:`constraints report`(使用统计 + 退役候选诊断 + 配置健康,`--export` 脱敏;JSON 输出走 `--json-output`——原名 `--json` 与父命令同名会被 commander 消费在父侧、JSON 分支不可达,E1 复盘修正 M3.1 换名,闸见 `__tests__/constraints-report-json-flag.test.ts`)、`constraints retire`(交互选择 + 人确认退役;带 id 直达需显式 `--yes`(#24 人确认闸门),无 `--yes` 报错 + 非零退出码且不落盘;落 config.yml retired 墓碑 + KnowledgeStore 沉淀——沉淀写口的 baseDir 走 knowledge-view `openKnowledgeStore` 同一解析点,与 knowledge 读口同根,不再硬编码 projectRoot 拼接(harness#177)。ADR-0029:注入漂移小节、prompt 注入清单、custom 落点与治理注入段同步已随文本注入层关停移除。ADR-0032:already_retired 只认 retired 墓碑,裸 enabled:false 由退休流程接管补墓碑+沉淀(票 02 断点 6);落盘后 git 仓内附 commit 提示,不替用户动 git(断点 4)。ADR-0033:findRetireTarget 扩到内置 + 应用层(`.harness/constraints.yml`)——应用层退休墓碑同写 config.yml(enabled:false + retired 同形),constraints.yml 条文保留不删,沉淀条目 tags 加 `source:app`)、`constraints reactivate`(点对点复活:删 retired 墓碑段 + 写 `constraint-reactivated-<id>` 新沉淀,不改历史(ADR-0032 决策 6.5,票 02 断点 5);直达同需 `--yes`,无交互模式;ADR-0033 起对应用层约束同路径可用)、`constraints pack-proposal`(升级提案材料打包,ADR-0033 决策 4,块 3 子项 5:条文 + checker 模板与参数 + traces 使用统计 + 升级理由留白的脱敏 markdown,缺省落 `.harness/reports/proposal-<id>-<YYYYMMDD>.md`,`--stdout` 打印不落盘;脱敏只做项目根路径→`<repoRoot>` 替换,params 原文带出并标注人工确认——打包是质量前置不是保密闸门,人拿材料去 harness 仓开 issue)。
|
|
22
23
|
|
|
23
24
|
## 依赖关系
|
|
24
25
|
- 依赖 `src/core/constraints/` 约束引擎
|
|
@@ -165,8 +165,8 @@ describe('check command(真 git fixture)', () => {
|
|
|
165
165
|
io
|
|
166
166
|
);
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
expect(io.outText()).toContain('✅
|
|
168
|
+
// ADR-0032 起凭证扫描为 error 级:code_implementation 下 error 评 2 条,warning 无命中不输出
|
|
169
|
+
expect(io.outText()).toContain('✅ error 级约束: 全部通过 (2 条)');
|
|
170
170
|
expect(io.outText()).toContain('✅ 约束检查通过');
|
|
171
171
|
expect(result).toEqual({ kind: 'ok' });
|
|
172
172
|
});
|
|
@@ -204,7 +204,7 @@ describe('check command(真 git fixture)', () => {
|
|
|
204
204
|
expect(result.kind).toBe('fail');
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
it('staged 硬编码凭证 →
|
|
207
|
+
it('staged 硬编码凭证 → error 级违规即阻断(ADR-0032 升级)', async () => {
|
|
208
208
|
const dir = gitRepo();
|
|
209
209
|
stageChange(
|
|
210
210
|
dir,
|
|
@@ -220,8 +220,26 @@ describe('check command(真 git fixture)', () => {
|
|
|
220
220
|
io
|
|
221
221
|
);
|
|
222
222
|
|
|
223
|
+
// error 级违规走 throw 契约(#119):异常外溢为 fail,消息即约束 message
|
|
224
|
+
expect(io.outText()).toContain('❌ 约束检查异常: 禁止在代码/文档/配置文件中硬编码密码');
|
|
225
|
+
expect(result.kind).toBe('fail');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('warning 级违规(治理契约缺失)→ 警告但不阻断', async () => {
|
|
229
|
+
const dir = gitRepo();
|
|
230
|
+
// 采用 harness 治理(config.yml 在场)但无 PRESERVE:governance 段 → governance_presence 判 warning
|
|
231
|
+
write(dir, '.harness/config.yml', 'preset: standard\n');
|
|
232
|
+
stageChange(dir, 'src/existing.ts', 'export const a = 2;\n');
|
|
233
|
+
passTraces(dir);
|
|
234
|
+
|
|
235
|
+
// 不显式传 trigger:governance_presence 的触发词是 file_modification,由 diff 推断
|
|
236
|
+
const result = await check(
|
|
237
|
+
{ preset: 'standard', staged: true, projectPath: dir },
|
|
238
|
+
io
|
|
239
|
+
);
|
|
240
|
+
|
|
223
241
|
expect(io.outText()).toContain('⚠️ warning 级约束警告: 1 条');
|
|
224
|
-
expect(io.outText()).toContain('-
|
|
242
|
+
expect(io.outText()).toContain('- governance_presence');
|
|
225
243
|
expect(io.outText()).toContain('✅ 约束检查通过');
|
|
226
244
|
expect(result).toEqual({ kind: 'ok' });
|
|
227
245
|
});
|