@dommaker/harness 1.12.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.
- package/CHANGELOG.md +19 -0
- package/dist/cli/commands/check.js +3 -3
- package/dist/cli/commands/check.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/core/app-constraints-loader.d.ts +5 -3
- package/dist/core/app-constraints-loader.d.ts.map +1 -1
- package/dist/core/app-constraints-loader.js +20 -7
- package/dist/core/app-constraints-loader.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +5 -3
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +31 -10
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +21 -8
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +7 -1
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +41 -26
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +3 -0
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +7 -10
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +6 -6
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +14 -9
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.js +1 -1
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +11 -4
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +117 -30
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.d.ts +16 -2
- package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.js +115 -15
- package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
- package/dist/core/constraints/checkers/templated/exec.d.ts +19 -0
- package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/exec.js +124 -0
- package/dist/core/constraints/checkers/templated/exec.js.map +1 -0
- package/dist/core/constraints/checkers/templated/index.d.ts +1 -0
- package/dist/core/constraints/checkers/templated/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/templated/index.js +3 -1
- package/dist/core/constraints/checkers/templated/index.js.map +1 -1
- package/dist/core/constraints/checkers/templates-registry.d.ts +2 -1
- package/dist/core/constraints/checkers/templates-registry.d.ts.map +1 -1
- package/dist/core/constraints/checkers/templates-registry.js +3 -1
- package/dist/core/constraints/checkers/templates-registry.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +67 -6
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +51 -6
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts +1 -0
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +4 -0
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts +1 -0
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +6 -1
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/definitions.d.ts +7 -0
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +10 -0
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/git-evidence.d.ts +10 -0
- package/dist/core/constraints/git-evidence.d.ts.map +1 -1
- package/dist/core/constraints/git-evidence.js +2 -0
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/index.d.ts +3 -1
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +8 -1
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -1
- package/dist/core/index.js.map +1 -1
- package/dist/gates/checker-gate.d.ts +5 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +10 -3
- package/dist/gates/checker-gate.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 +6 -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/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.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 +32 -3
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +6 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/trace.d.ts +7 -0
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +2 -2
- package/src/__tests__/app-constraints-loader.test.ts +86 -3
- package/src/__tests__/checker-extra.test.ts +80 -4
- package/src/__tests__/checker-primitives-sdk.test.ts +70 -0
- package/src/__tests__/exec-checker-full-chain.test.ts +118 -0
- package/src/__tests__/layering.test.ts +3 -1
- package/src/__tests__/pretool-use-hook.test.ts +211 -4
- package/src/__tests__/public-exports.test.ts +5 -0
- package/src/__tests__/public-type-surface.test.ts +22 -0
- package/src/__tests__/public-value-surface.test.ts +5 -0
- package/src/cli/commands/CONTEXT.md +1 -1
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -4
- package/src/cli/commands/__tests__/check.test.ts +2 -0
- package/src/cli/commands/__tests__/security.test.ts +89 -1
- package/src/cli/commands/check.ts +3 -3
- package/src/cli/commands/security.ts +99 -0
- package/src/core/CONTEXT.md +6 -6
- package/src/core/app-constraints-loader.ts +23 -8
- package/src/core/constraints/__tests__/git-evidence.test.ts +20 -0
- package/src/core/constraints/__tests__/run-env.test.ts +2 -0
- package/src/core/constraints/checker.ts +35 -12
- package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +21 -3
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +20 -12
- package/src/core/constraints/checkers/__tests__/docs-freshness-degraded.test.ts +89 -0
- package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +4 -2
- package/src/core/constraints/checkers/__tests__/exec-checker.test.ts +99 -0
- package/src/core/constraints/checkers/__tests__/fixtures/public-repo-sanitization.mjs +40 -0
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +23 -2
- package/src/core/constraints/checkers/__tests__/input-contract.test.ts +135 -0
- package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +15 -2
- package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +110 -5
- package/src/core/constraints/checkers/__tests__/no-test-simplification.test.ts +144 -21
- package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +6 -2
- package/src/core/constraints/checkers/capability-sync.ts +24 -10
- package/src/core/constraints/checkers/context-doc-sync.ts +8 -1
- package/src/core/constraints/checkers/docs-freshness.ts +44 -26
- package/src/core/constraints/checkers/governance-presence.ts +7 -8
- package/src/core/constraints/checkers/index.ts +22 -10
- package/src/core/constraints/checkers/iron-flags.ts +1 -1
- package/src/core/constraints/checkers/no-hardcoded-credentials.ts +135 -29
- package/src/core/constraints/checkers/no-test-simplification.ts +128 -17
- package/src/core/constraints/checkers/templated/exec.ts +138 -0
- package/src/core/constraints/checkers/templated/index.ts +1 -0
- package/src/core/constraints/checkers/templates-registry.ts +4 -2
- package/src/core/constraints/checkers/types.ts +106 -9
- package/src/core/constraints/definitions/guidelines.ts +4 -0
- package/src/core/constraints/definitions/iron-laws.ts +6 -1
- package/src/core/constraints/definitions.ts +10 -0
- package/src/core/constraints/git-evidence.ts +13 -0
- package/src/core/constraints/index.ts +22 -0
- package/src/core/index.ts +16 -0
- package/src/gates/CONTEXT.md +3 -3
- package/src/gates/__tests__/checker-gate.test.ts +19 -2
- package/src/gates/checker-gate.ts +11 -4
- package/src/gates/command.ts +6 -2
- package/src/gates/definitions.ts +6 -1
- package/src/index.ts +26 -0
- package/src/pretool-use-hook.ts +104 -10
- package/src/types/constraint.ts +35 -3
- package/src/types/trace.ts +8 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 示例业务检查器(harness#181 验收示例):public-repo-sanitization
|
|
4
|
+
*
|
|
5
|
+
* 场景原型 = studio 侧安全底线 public_repo_sanitization(ADR-0032 ①):公开发布仓的
|
|
6
|
+
* 受跟踪文本不得残留开发机现场绝对路径(/Users/<name>/、/home/<name>/),文档示例的
|
|
7
|
+
* 占位符形态(/Users/<you>/ 等尖括号段)豁免。
|
|
8
|
+
*
|
|
9
|
+
* 模板填不了的点:命中判定带豁免谓词,regex-scan「命中即违规」表达不了——正是
|
|
10
|
+
* ADR-0035 决策 3 的 exec 档场景。
|
|
11
|
+
*
|
|
12
|
+
* 协议(与 exec 模板约定):argv = 待扫文件(相对项目根;exec 模板以项目根为 cwd 执行);
|
|
13
|
+
* 命中逐条打印到 stdout 并 exit 1;干净 exit 0。业务知识不出业务仓:本脚本即业务判定本体。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
const MACHINE_PATH = /\/(?:Users|home)\/([^/\s'"]+)\//g;
|
|
20
|
+
|
|
21
|
+
const hits = [];
|
|
22
|
+
for (const rel of process.argv.slice(2)) {
|
|
23
|
+
let content;
|
|
24
|
+
try {
|
|
25
|
+
content = readFileSync(join(process.cwd(), rel), 'utf-8');
|
|
26
|
+
} catch {
|
|
27
|
+
continue; // 文件不可读(已删除/二进制)→ 跳过
|
|
28
|
+
}
|
|
29
|
+
content.split('\n').forEach((line, i) => {
|
|
30
|
+
for (const m of line.matchAll(MACHINE_PATH)) {
|
|
31
|
+
if (m[1].startsWith('<')) continue; // 占位符豁免:/Users/<you>/
|
|
32
|
+
hits.push(`${rel}:${i + 1} 残留开发机现场路径 ${m[0]}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (hits.length > 0) {
|
|
38
|
+
for (const hit of hits) console.log(hit);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
@@ -59,8 +59,29 @@ describe('governance_presence checker', () => {
|
|
|
59
59
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it('未采用 harness 治理(无 .harness/config.yml)→ skip', async () => {
|
|
63
|
-
|
|
62
|
+
it('未采用 harness 治理(无 .harness/config.yml)→ 带原因的 skip(harness#182)', async () => {
|
|
63
|
+
const outcome = normalizeCheckOutcome(await governancePresence.evaluate(makeEnv(tempDir)));
|
|
64
|
+
expect(outcome.skipped).toBe(true);
|
|
65
|
+
expect(outcome.skipReason).toContain('未采用 harness 治理');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('config.yml YAML 损坏 → 仍按「已采用」评估(harness#182:不再恰在配置出问题时闭嘴)', async () => {
|
|
69
|
+
fs.mkdirSync(path.join(tempDir, '.harness'), { recursive: true });
|
|
70
|
+
fs.writeFileSync(path.join(tempDir, '.harness', 'config.yml'), 'preset: [broken\n - {unclosed');
|
|
71
|
+
// 两处都没有治理契约 → fail(旧行为:解析抛错被吞 → 误判未采用 → skip)
|
|
72
|
+
const outcome = normalizeCheckOutcome(await governancePresence.evaluate(makeEnv(tempDir)));
|
|
73
|
+
expect(outcome.skipped).toBe(false);
|
|
74
|
+
expect(outcome.satisfied).toBe(false);
|
|
75
|
+
expect(outcome.evidence.join('\n')).toContain('治理契约');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('config.yml YAML 损坏 + AGENTS.md 有 PRESERVE:governance → pass(损坏配置不影响在场判定)', async () => {
|
|
79
|
+
fs.mkdirSync(path.join(tempDir, '.harness'), { recursive: true });
|
|
80
|
+
fs.writeFileSync(path.join(tempDir, '.harness', 'config.yml'), 'preset: [broken\n - {unclosed');
|
|
81
|
+
fs.writeFileSync(path.join(tempDir, 'AGENTS.md'), `# AGENTS.md\n\n${GOVERNANCE_BLOCK}\n`);
|
|
82
|
+
const outcome = normalizeCheckOutcome(await governancePresence.evaluate(makeEnv(tempDir)));
|
|
83
|
+
expect(outcome.skipped).toBe(false);
|
|
84
|
+
expect(outcome.satisfied).toBe(true);
|
|
64
85
|
});
|
|
65
86
|
|
|
66
87
|
it('新模型:AGENTS.md 有非空 PRESERVE:governance 段 → pass', async () => {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查器输入契约测试(harness#182)
|
|
3
|
+
*
|
|
4
|
+
* 「检查器失效 ≠ 对象合规」的接缝锁定:
|
|
5
|
+
* - findMissingInputs:checker 声明的 needs 与环境供给比对(缺证据 / flag 未接线)
|
|
6
|
+
* - 编排层降级:git 取证失败 → 带原因的 skipped,不进入 evaluate(不再对空 diff 假 pass)
|
|
7
|
+
* - skipReason 落 ConstraintResult 与 ExecutionTrace(可统计的失效信号)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect } from '@jest/globals';
|
|
11
|
+
import { ConstraintChecker } from '../../checker';
|
|
12
|
+
import { createGitEvidence } from '../../git-evidence';
|
|
13
|
+
import {
|
|
14
|
+
buildCheckEnv,
|
|
15
|
+
findMissingInputs,
|
|
16
|
+
normalizeCheckOutcome,
|
|
17
|
+
type ConstraintCheck,
|
|
18
|
+
} from '../types';
|
|
19
|
+
import { noTestSimplification } from '../no-test-simplification';
|
|
20
|
+
import type { Constraint, ConstraintContext } from '../../../../types/constraint';
|
|
21
|
+
import type { MergedConstraintsConfig } from '../../../../types/project-config';
|
|
22
|
+
import type { ExecutionTrace } from '../../../../types/trace';
|
|
23
|
+
|
|
24
|
+
const NO_TEST_SIMPLIFICATION: Constraint = {
|
|
25
|
+
id: 'no_test_simplification',
|
|
26
|
+
kind: 'check',
|
|
27
|
+
severity: 'error',
|
|
28
|
+
rule: 'DO NOT DELETE TESTS',
|
|
29
|
+
message: '禁止简化测试绕过困难',
|
|
30
|
+
trigger: 'commit',
|
|
31
|
+
enforcement: 'restore-tests',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const CONTEXT: ConstraintContext = { operation: 'commit', projectPath: '/nonexistent' };
|
|
35
|
+
|
|
36
|
+
function envOf(context: ConstraintContext, available: Record<string, boolean>) {
|
|
37
|
+
return buildCheckEnv(context, {
|
|
38
|
+
stagedDiff: async () => '',
|
|
39
|
+
stagedDiffNames: async () => '',
|
|
40
|
+
srcScan: () => [],
|
|
41
|
+
available: (input) => available[input] ?? true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('findMissingInputs — needs 与环境供给比对', () => {
|
|
46
|
+
it('未声明 needs → 无缺项', () => {
|
|
47
|
+
expect(findMissingInputs({ id: 'x', evaluate: () => true }, envOf(CONTEXT, {}))).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('evidenceAvailable 报不可得 → 缺项自描述', () => {
|
|
51
|
+
const missing = findMissingInputs(noTestSimplification, envOf(CONTEXT, { stagedDiff: false }));
|
|
52
|
+
expect(missing).toEqual(['staged diff 不可得(git 取证失败或未接线)']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('contextFlags 为 undefined → 缺项点名标志', () => {
|
|
56
|
+
const check: ConstraintCheck = {
|
|
57
|
+
id: 'flag-check',
|
|
58
|
+
needs: { contextFlags: ['hasVerificationEvidence'] },
|
|
59
|
+
evaluate: () => true,
|
|
60
|
+
};
|
|
61
|
+
expect(findMissingInputs(check, envOf(CONTEXT, {}))).toEqual([
|
|
62
|
+
'证据标志 hasVerificationEvidence 未接线',
|
|
63
|
+
]);
|
|
64
|
+
expect(
|
|
65
|
+
findMissingInputs(check, envOf({ ...CONTEXT, hasVerificationEvidence: false }, {}))
|
|
66
|
+
).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('手写 env 未提供 evidenceAvailable → 按全部可得(旧形状兼容)', () => {
|
|
70
|
+
const env = buildCheckEnv(CONTEXT, {
|
|
71
|
+
stagedDiff: async () => '',
|
|
72
|
+
stagedDiffNames: async () => '',
|
|
73
|
+
srcScan: () => [],
|
|
74
|
+
});
|
|
75
|
+
expect(findMissingInputs(noTestSimplification, env)).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('normalizeCheckOutcome — CheckSkip 归一', () => {
|
|
80
|
+
it('{ skip, reason } → skipped + skipReason,evidence 恒空(未评估不留证据行)', () => {
|
|
81
|
+
expect(normalizeCheckOutcome({ skip: true, reason: '输入不可得' })).toEqual({
|
|
82
|
+
satisfied: true,
|
|
83
|
+
skipped: true,
|
|
84
|
+
evidence: [],
|
|
85
|
+
skipReason: '输入不可得',
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** 只含 no_test_simplification 的生效集:一次 run 一条 trace */
|
|
91
|
+
function onlyNoTestSimplification(): MergedConstraintsConfig {
|
|
92
|
+
return { constraints: { no_test_simplification: NO_TEST_SIMPLIFICATION }, disabled: [] };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe('编排层输入契约降级(git 取证失败 → 带原因的 skipped)', () => {
|
|
96
|
+
const throwingRunner = () => {
|
|
97
|
+
throw new Error('not a git repository');
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
it('git 失败 → skipped + skipReason,不阻断(fail-open 但不假 pass)', async () => {
|
|
101
|
+
const checker = new ConstraintChecker();
|
|
102
|
+
const git = createGitEvidence('/nonexistent', throwingRunner);
|
|
103
|
+
|
|
104
|
+
const result = await checker.check(NO_TEST_SIMPLIFICATION, CONTEXT, git);
|
|
105
|
+
|
|
106
|
+
expect(result.skipped).toBe(true);
|
|
107
|
+
expect(result.satisfied).toBe(true);
|
|
108
|
+
expect(result.skipReason).toContain('staged diff 不可得');
|
|
109
|
+
expect(result.message).toContain('staged diff 不可得');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('git 失败 → trace 记 result:skip 且携带 skipReason(失效可统计)', async () => {
|
|
113
|
+
const traces: ExecutionTrace[] = [];
|
|
114
|
+
const checker = new ConstraintChecker({ record: (t) => traces.push(t) });
|
|
115
|
+
const git = createGitEvidence('/nonexistent', throwingRunner);
|
|
116
|
+
|
|
117
|
+
const run = await checker.checkConstraints(CONTEXT, onlyNoTestSimplification(), git);
|
|
118
|
+
|
|
119
|
+
expect(run.passed).toBe(true);
|
|
120
|
+
expect(run.errors[0].skipped).toBe(true);
|
|
121
|
+
const trace = traces.find(t => t.constraintId === 'no_test_simplification')!;
|
|
122
|
+
expect(trace.result).toBe('skip');
|
|
123
|
+
expect(trace.skipReason).toContain('staged diff 不可得');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('git 正常 → 进入评估(对照:契约齐备不降级)', async () => {
|
|
127
|
+
const checker = new ConstraintChecker();
|
|
128
|
+
const git = createGitEvidence('/nonexistent', () => '');
|
|
129
|
+
|
|
130
|
+
const result = await checker.check(NO_TEST_SIMPLIFICATION, CONTEXT, git);
|
|
131
|
+
|
|
132
|
+
expect(result.skipped).toBeUndefined();
|
|
133
|
+
expect(result.satisfied).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -21,10 +21,23 @@ const evaluate = (
|
|
|
21
21
|
|
|
22
22
|
describe('iron flags — 三态与字段映射', () => {
|
|
23
23
|
it('no_completion_without_verification → 读 hasVerificationEvidence', async () => {
|
|
24
|
-
|
|
24
|
+
// 未接线 → 带原因的 skip(harness#182:undefined flag 不再静默 skip)
|
|
25
|
+
expect(await evaluate(noCompletionWithoutVerification, {})).toEqual({
|
|
26
|
+
skip: true,
|
|
27
|
+
reason: '证据标志 hasVerificationEvidence 未接线',
|
|
28
|
+
});
|
|
25
29
|
expect(await evaluate(noCompletionWithoutVerification, { hasVerificationEvidence: false })).toBe(false);
|
|
26
30
|
expect(await evaluate(noCompletionWithoutVerification, { hasVerificationEvidence: true })).toBe(true);
|
|
27
31
|
// 相邻字段不串台:hasTest 不能顶替
|
|
28
|
-
expect(await evaluate(noCompletionWithoutVerification, { hasTest: true })).
|
|
32
|
+
expect(await evaluate(noCompletionWithoutVerification, { hasTest: true })).toEqual({
|
|
33
|
+
skip: true,
|
|
34
|
+
reason: '证据标志 hasVerificationEvidence 未接线',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('声明 contextFlags 输入契约(harness#182):编排层据此在 evaluate 前降级', () => {
|
|
39
|
+
expect(noCompletionWithoutVerification.needs).toEqual({
|
|
40
|
+
contextFlags: ['hasVerificationEvidence'],
|
|
41
|
+
});
|
|
29
42
|
});
|
|
30
43
|
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* no_hardcoded_credentials 检查器旁测(ADR-0001
|
|
2
|
+
* no_hardcoded_credentials 检查器旁测(ADR-0001;harness#184 收窄正则版 + fail 证据行)
|
|
3
3
|
*
|
|
4
4
|
* 注意:测试夹具中的假凭证一律用字符串拼接构造,
|
|
5
5
|
* 避免本文件自身被凭证扫描(含 harness 自身 staged diff)命中。
|
|
6
6
|
* 测试面 = evaluate(env)(架构评审候选4,自 src/__tests__/ 就近迁入)。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'fs';
|
|
10
|
+
import { tmpdir } from 'os';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
import { describe, it, expect, afterAll } from '@jest/globals';
|
|
10
13
|
import {
|
|
11
14
|
noHardcodedCredentials,
|
|
12
15
|
containsHardcodedCredential,
|
|
@@ -27,6 +30,8 @@ function makeEnv(stagedDiff: string): CheckEnv {
|
|
|
27
30
|
const AWS_KEY = 'AKIA' + '1234567890ABCDEF';
|
|
28
31
|
const PEM_HEADER = '-----BEGIN ' + 'RSA PRIVATE KEY-----';
|
|
29
32
|
const PASSWORD_ASSIGN = 'const dbPass' + 'word = "sup3r-s3cret-value";';
|
|
33
|
+
const JWT =
|
|
34
|
+
'eyJ' + 'hbGciOiJIUzI1NiJ9.' + 'eyJ' + 'zdWIiOiIxMjM0NTY3ODkwIn0.' + 'dozjgNryP4J3jVmNHl0w5N_XgL0n';
|
|
30
35
|
|
|
31
36
|
describe('containsHardcodedCredential', () => {
|
|
32
37
|
it('命中 PEM 私钥头', () => {
|
|
@@ -45,6 +50,38 @@ describe('containsHardcodedCredential', () => {
|
|
|
45
50
|
expect(containsHardcodedCredential('api' + '_key: "abcdef123456789"')).toBe(true);
|
|
46
51
|
});
|
|
47
52
|
|
|
53
|
+
it('命中 .env 裸值(无引号赋值)', () => {
|
|
54
|
+
expect(containsHardcodedCredential('DB_TO' + 'KEN=abc123def456ghi')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('命中无引号 YAML 值', () => {
|
|
58
|
+
expect(containsHardcodedCredential('pass' + 'word: secret123')).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('命中 URL 内嵌凭证', () => {
|
|
62
|
+
expect(containsHardcodedCredential('const url = "postgres:/' + '/user:pw12345@db.host/app";')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('命中 JSON 带引号键', () => {
|
|
66
|
+
expect(containsHardcodedCredential('"pass' + 'word": "realvalue123"')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('命中非清单变量名 credential/privateKey/signingKey', () => {
|
|
70
|
+
expect(containsHardcodedCredential('cred' + 'ential = "realvalue123";')).toBe(true);
|
|
71
|
+
expect(containsHardcodedCredential('private' + 'Key = "realvalue123";')).toBe(true);
|
|
72
|
+
expect(containsHardcodedCredential('signing' + '_key: realvalue123')).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('命中 JWT', () => {
|
|
76
|
+
expect(containsHardcodedCredential(`const tok = "${JWT}";`)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('行内出现 test 不再整行豁免真实值', () => {
|
|
80
|
+
expect(
|
|
81
|
+
containsHardcodedCredential('const pass' + 'word = "realvalue123"; // test fixture')
|
|
82
|
+
).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
|
|
48
85
|
it('豁免环境变量引用', () => {
|
|
49
86
|
expect(
|
|
50
87
|
containsHardcodedCredential('const pass' + 'word = process.env.DB_PASSWORD;')
|
|
@@ -57,6 +94,16 @@ describe('containsHardcodedCredential', () => {
|
|
|
57
94
|
).toBe(false);
|
|
58
95
|
});
|
|
59
96
|
|
|
97
|
+
it('豁免 TS 类型注解(值是类型名而非字面量)', () => {
|
|
98
|
+
expect(containsHardcodedCredential('api' + 'Key: string|undefined;')).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('豁免 URL 中的变量插值占位', () => {
|
|
102
|
+
expect(
|
|
103
|
+
containsHardcodedCredential('postgres://user:' + '${' + 'DB_PASS}@host/db')
|
|
104
|
+
).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
60
107
|
it('普通代码不误报', () => {
|
|
61
108
|
expect(
|
|
62
109
|
containsHardcodedCredential('export function add(a: number, b: number) { return a + b; }')
|
|
@@ -65,15 +112,22 @@ describe('containsHardcodedCredential', () => {
|
|
|
65
112
|
});
|
|
66
113
|
|
|
67
114
|
describe('noHardcodedCredentials checker', () => {
|
|
68
|
-
it('staged diff 新增行命中凭证 → fail', async () => {
|
|
115
|
+
it('staged diff 新增行命中凭证 → fail,证据带文件+行号', async () => {
|
|
69
116
|
const diff = [
|
|
70
117
|
'diff --git a/src/config.ts b/src/config.ts',
|
|
71
118
|
'--- a/src/config.ts',
|
|
72
119
|
'+++ b/src/config.ts',
|
|
73
|
-
'@@ -
|
|
120
|
+
'@@ -3,3 +3,4 @@',
|
|
121
|
+
' line3',
|
|
122
|
+
'+line4',
|
|
74
123
|
'+' + PASSWORD_ASSIGN,
|
|
75
124
|
].join('\n');
|
|
76
|
-
|
|
125
|
+
const outcome = await noHardcodedCredentials.evaluate(makeEnv(diff));
|
|
126
|
+
expect(outcome).not.toBe(true);
|
|
127
|
+
expect(typeof outcome).toBe('object');
|
|
128
|
+
const detail = outcome as { pass: boolean; evidence?: string[] };
|
|
129
|
+
expect(detail.pass).toBe(false);
|
|
130
|
+
expect(detail.evidence?.some(l => l.includes('src/config.ts:5'))).toBe(true);
|
|
77
131
|
});
|
|
78
132
|
|
|
79
133
|
it('staged diff 仅删除行含凭证 → pass(删除凭证是好事)', async () => {
|
|
@@ -89,4 +143,55 @@ describe('noHardcodedCredentials checker', () => {
|
|
|
89
143
|
it('staged diff 为空且无可读变更文件 → pass', async () => {
|
|
90
144
|
expect(await noHardcodedCredentials.evaluate(makeEnv(''))).toBe(true);
|
|
91
145
|
});
|
|
146
|
+
|
|
147
|
+
it('diff 路径按文件过滤:.env.example 的真实值形态不误报', async () => {
|
|
148
|
+
const diff = [
|
|
149
|
+
'diff --git a/.env.example b/.env.example',
|
|
150
|
+
'--- a/.env.example',
|
|
151
|
+
'+++ b/.env.example',
|
|
152
|
+
'@@ -0,0 +1 @@',
|
|
153
|
+
'+DB_TO' + 'KEN=abc123def456ghi',
|
|
154
|
+
].join('\n');
|
|
155
|
+
expect(await noHardcodedCredentials.evaluate(makeEnv(diff))).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('diff 路径按文件过滤:文档中的 PEM 头样例不误报', async () => {
|
|
159
|
+
const diff = [
|
|
160
|
+
'diff --git a/docs/keys.md b/docs/keys.md',
|
|
161
|
+
'--- a/docs/keys.md',
|
|
162
|
+
'+++ b/docs/keys.md',
|
|
163
|
+
'@@ -0,0 +1 @@',
|
|
164
|
+
'+' + PEM_HEADER,
|
|
165
|
+
].join('\n');
|
|
166
|
+
expect(await noHardcodedCredentials.evaluate(makeEnv(diff))).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('diff 不可用时退化为变更文件内容扫描', () => {
|
|
170
|
+
const dir = mkdtempSync(join(tmpdir(), 'harness-cred-test-'));
|
|
171
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
172
|
+
|
|
173
|
+
function contentEnv(files: string[]): CheckEnv {
|
|
174
|
+
return {
|
|
175
|
+
...createRunEnv(dir),
|
|
176
|
+
context: { operation: 'commit', projectPath: dir, changedFiles: files },
|
|
177
|
+
stagedDiff: async () => '',
|
|
178
|
+
stagedDiffNames: async () => '',
|
|
179
|
+
srcScan: () => [],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
it('内容路径命中 → fail,证据带文件+行号', async () => {
|
|
184
|
+
writeFileSync(join(dir, '.env'), '# comment\nDB_TO' + 'KEN=abc123def456ghi\n');
|
|
185
|
+
const outcome = await noHardcodedCredentials.evaluate(contentEnv(['.env']));
|
|
186
|
+
expect(typeof outcome).toBe('object');
|
|
187
|
+
const detail = outcome as { pass: boolean; evidence?: string[] };
|
|
188
|
+
expect(detail.pass).toBe(false);
|
|
189
|
+
expect(detail.evidence?.some(l => l.includes('.env:2'))).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('内容路径同样豁免模板文件', async () => {
|
|
193
|
+
writeFileSync(join(dir, '.env.example'), 'DB_TO' + 'KEN=abc123def456ghi\n');
|
|
194
|
+
expect(await noHardcodedCredentials.evaluate(contentEnv(['.env.example']))).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
92
197
|
});
|
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
await evaluate('
|
|
44
|
-
)
|
|
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('
|
|
48
|
-
expect(
|
|
171
|
+
it('声明 stagedDiff 输入契约(harness#182):git 取证失败由编排层降级,不假 pass', () => {
|
|
172
|
+
expect(noTestSimplification.needs).toEqual({ evidence: ['stagedDiff'] });
|
|
49
173
|
});
|
|
50
174
|
|
|
51
|
-
it('git diff 失败 →
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 () => {
|