@dommaker/harness 1.4.0 → 1.6.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 +23 -0
- package/README.md +0 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +28 -0
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +1 -39
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/knowledge.d.ts +0 -19
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +0 -105
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts +0 -2
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +0 -1
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.d.ts +0 -4
- package/dist/cli/commands/performance.d.ts.map +1 -1
- package/dist/cli/commands/performance.js +10 -20
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/report.d.ts +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +2 -55
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +4 -8
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/context/index.d.ts +2 -5
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -8
- package/dist/context/index.js.map +1 -1
- package/dist/context/token-budget.d.ts +0 -29
- package/dist/context/token-budget.d.ts.map +1 -1
- package/dist/context/token-budget.js +1 -65
- package/dist/context/token-budget.js.map +1 -1
- package/dist/context/types.d.ts +0 -1
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +0 -9
- package/dist/context/types.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +14 -0
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +27 -5
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +17 -6
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +48 -19
- package/dist/core/constraints/checkers/capability-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 +15 -6
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +2 -2
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +2 -1
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +41 -2
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +33 -0
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/git-evidence.d.ts +6 -3
- package/dist/core/constraints/git-evidence.d.ts.map +1 -1
- package/dist/core/constraints/git-evidence.js +6 -3
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -9
- package/dist/core/index.js.map +1 -1
- package/dist/core/spec/validator.d.ts +2 -0
- package/dist/core/spec/validator.d.ts.map +1 -1
- package/dist/core/spec/validator.js +9 -11
- package/dist/core/spec/validator.js.map +1 -1
- package/dist/core/validators/index.d.ts +1 -1
- package/dist/core/validators/index.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +1 -15
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +0 -125
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/failure/index.d.ts +0 -1
- package/dist/failure/index.d.ts.map +1 -1
- package/dist/failure/index.js +1 -7
- package/dist/failure/index.js.map +1 -1
- package/dist/gates/checker-gate.d.ts +2 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +10 -7
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +0 -4
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/performance.d.ts +7 -22
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +7 -89
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/types.d.ts +2 -8
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -22
- package/dist/index.js.map +1 -1
- package/dist/knowledge/index.d.ts +0 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +1 -3
- package/dist/knowledge/index.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +25 -10
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +147 -116
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/types/constraint.d.ts +8 -0
- 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/passes-gate.d.ts +0 -19
- package/dist/types/passes-gate.d.ts.map +1 -1
- package/dist/types/trace.d.ts +9 -0
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +1 -0
- package/src/__tests__/passes-gate-check.test.ts +20 -4
- package/src/__tests__/passes-gate.test.ts +18 -119
- package/src/__tests__/performance-gate.test.ts +3 -11
- package/src/__tests__/public-exports.test.ts +46 -16
- package/src/__tests__/trace-analyzer.test.ts +52 -2
- package/src/cli/commands/CONTEXT.md +5 -4
- package/src/cli/commands/__tests__/bin-exit-mapping.test.ts +6 -0
- package/src/cli/commands/__tests__/check.test.ts +74 -0
- package/src/cli/commands/__tests__/passes-gate-dead-options.test.ts +70 -0
- package/src/cli/commands/__tests__/passes-gate.test.ts +7 -3
- package/src/cli/commands/__tests__/performance.test.ts +5 -16
- package/src/cli/commands/__tests__/project-path-convention.test.ts +85 -23
- package/src/cli/commands/__tests__/registry.test.ts +52 -3
- package/src/cli/commands/__tests__/report-extra.test.ts +0 -19
- package/src/cli/commands/__tests__/report-false-green.test.ts +46 -0
- package/src/cli/commands/__tests__/report.test.ts +0 -20
- package/src/cli/commands/__tests__/status-analysis-wiring.test.ts +68 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +63 -116
- package/src/cli/commands/__tests__/status.test.ts +66 -148
- package/src/cli/commands/check.ts +39 -1
- package/src/cli/commands/definitions.ts +1 -39
- package/src/cli/commands/knowledge.ts +0 -119
- package/src/cli/commands/passes-gate.ts +0 -3
- package/src/cli/commands/performance.ts +13 -27
- package/src/cli/commands/report.ts +3 -61
- package/src/cli/commands/status.ts +5 -10
- package/src/context/CONTEXT.md +2 -3
- package/src/context/__tests__/token-budget.test.ts +1 -81
- package/src/context/index.ts +2 -7
- package/src/context/token-budget.ts +0 -73
- package/src/context/types.ts +0 -9
- package/src/core/CONTEXT.md +6 -6
- package/src/core/constraints/__tests__/collect-constraints.test.ts +66 -0
- package/src/core/constraints/checker.ts +41 -6
- package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +90 -31
- package/src/core/constraints/checkers/__tests__/check-outcome.test.ts +176 -0
- package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +18 -9
- package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +12 -4
- package/src/core/constraints/checkers/capability-sync.ts +56 -18
- package/src/core/constraints/checkers/docs-freshness.ts +18 -5
- package/src/core/constraints/checkers/index.ts +9 -2
- package/src/core/constraints/checkers/types.ts +58 -2
- package/src/core/constraints/git-evidence.ts +6 -3
- package/src/core/index.ts +0 -11
- package/src/core/spec/__tests__/validator.test.ts +24 -0
- package/src/core/spec/validator.ts +9 -10
- package/src/core/validators/__tests__/passes-gate.test.ts +2 -9
- package/src/core/validators/index.ts +0 -1
- package/src/core/validators/passes-gate.ts +1 -149
- package/src/failure/CONTEXT.md +8 -6
- package/src/failure/index.ts +0 -10
- package/src/gates/CONTEXT.md +4 -3
- package/src/gates/__tests__/checker-gate.test.ts +24 -0
- package/src/gates/__tests__/performance.test.ts +6 -74
- package/src/gates/checker-gate.ts +11 -15
- package/src/gates/definitions.ts +0 -4
- package/src/gates/performance.ts +9 -111
- package/src/gates/types.ts +2 -8
- package/src/index.ts +1 -36
- package/src/knowledge/CONTEXT.md +1 -2
- package/src/knowledge/index.ts +0 -1
- package/src/monitoring/CONTEXT.md +2 -2
- package/src/monitoring/trace-analyzer.ts +160 -126
- package/src/types/constraint.ts +16 -2
- package/src/types/passes-gate.ts +0 -26
- package/src/types/trace.ts +10 -0
- package/src/utils/__tests__/jsonl-skip-disposition.test.ts +0 -1
- package/dist/cli/commands/analyze-sessions.d.ts +0 -20
- package/dist/cli/commands/analyze-sessions.d.ts.map +0 -1
- package/dist/cli/commands/analyze-sessions.js +0 -290
- package/dist/cli/commands/analyze-sessions.js.map +0 -1
- package/dist/cli/commands/update-user-model.d.ts +0 -25
- package/dist/cli/commands/update-user-model.d.ts.map +0 -1
- package/dist/cli/commands/update-user-model.js +0 -397
- package/dist/cli/commands/update-user-model.js.map +0 -1
- package/dist/cli/session-mining/corrections.d.ts +0 -17
- package/dist/cli/session-mining/corrections.d.ts.map +0 -1
- package/dist/cli/session-mining/corrections.js +0 -58
- package/dist/cli/session-mining/corrections.js.map +0 -1
- package/dist/cli/session-mining/index.d.ts +0 -13
- package/dist/cli/session-mining/index.d.ts.map +0 -1
- package/dist/cli/session-mining/index.js +0 -29
- package/dist/cli/session-mining/index.js.map +0 -1
- package/dist/cli/session-mining/text.d.ts +0 -31
- package/dist/cli/session-mining/text.d.ts.map +0 -1
- package/dist/cli/session-mining/text.js +0 -126
- package/dist/cli/session-mining/text.js.map +0 -1
- package/dist/cli/session-mining/transcript.d.ts +0 -34
- package/dist/cli/session-mining/transcript.d.ts.map +0 -1
- package/dist/cli/session-mining/transcript.js +0 -130
- package/dist/cli/session-mining/transcript.js.map +0 -1
- package/dist/context/compaction.d.ts +0 -57
- package/dist/context/compaction.d.ts.map +0 -1
- package/dist/context/compaction.js +0 -165
- package/dist/context/compaction.js.map +0 -1
- package/dist/core/session/clean-state.d.ts +0 -17
- package/dist/core/session/clean-state.d.ts.map +0 -1
- package/dist/core/session/clean-state.js +0 -192
- package/dist/core/session/clean-state.js.map +0 -1
- package/dist/core/session/index.d.ts +0 -6
- package/dist/core/session/index.d.ts.map +0 -1
- package/dist/core/session/index.js +0 -15
- package/dist/core/session/index.js.map +0 -1
- package/dist/core/session/startup.d.ts +0 -47
- package/dist/core/session/startup.d.ts.map +0 -1
- package/dist/core/session/startup.js +0 -263
- package/dist/core/session/startup.js.map +0 -1
- package/dist/failure/constraint-handler.d.ts +0 -83
- package/dist/failure/constraint-handler.d.ts.map +0 -1
- package/dist/failure/constraint-handler.js +0 -138
- package/dist/failure/constraint-handler.js.map +0 -1
- package/dist/knowledge/lifecycle-hooks.d.ts +0 -62
- package/dist/knowledge/lifecycle-hooks.d.ts.map +0 -1
- package/dist/knowledge/lifecycle-hooks.js +0 -143
- package/dist/knowledge/lifecycle-hooks.js.map +0 -1
- package/dist/types/session.d.ts +0 -113
- package/dist/types/session.d.ts.map +0 -1
- package/dist/types/session.js +0 -6
- package/dist/types/session.js.map +0 -1
- package/src/__tests__/clean-state-extra.test.ts +0 -301
- package/src/__tests__/clean-state.test.ts +0 -169
- package/src/__tests__/constraint-handler.test.ts +0 -132
- package/src/__tests__/passes-gate-extra.test.ts +0 -93
- package/src/__tests__/session-startup.test.ts +0 -334
- package/src/cli/commands/__tests__/analyze-sessions.test.ts +0 -184
- package/src/cli/commands/__tests__/update-user-model.test.ts +0 -234
- package/src/cli/commands/analyze-sessions.ts +0 -335
- package/src/cli/commands/update-user-model.ts +0 -461
- package/src/cli/session-mining/__tests__/transcript.test.ts +0 -118
- package/src/cli/session-mining/corrections.ts +0 -56
- package/src/cli/session-mining/index.ts +0 -13
- package/src/cli/session-mining/text.ts +0 -117
- package/src/cli/session-mining/transcript.ts +0 -125
- package/src/context/__tests__/compaction.test.ts +0 -169
- package/src/context/compaction.ts +0 -201
- package/src/core/session/__tests__/startup.test.ts +0 -281
- package/src/core/session/clean-state.ts +0 -178
- package/src/core/session/index.ts +0 -15
- package/src/core/session/startup.ts +0 -253
- package/src/failure/constraint-handler.ts +0 -171
- package/src/knowledge/__tests__/lifecycle-hooks.test.ts +0 -140
- package/src/knowledge/lifecycle-hooks.ts +0 -202
- package/src/types/session.ts +0 -132
package/src/core/CONTEXT.md
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
# core/
|
|
2
2
|
|
|
3
3
|
## 职责
|
|
4
|
-
约束引擎核心:check/prompt 二元约束系统(ADR-0001)、生效集合并(effective-constraints)、检查点验证器(CSO/passes-gate)
|
|
4
|
+
约束引擎核心:check/prompt 二元约束系统(ADR-0001)、生效集合并(effective-constraints)、检查点验证器(CSO/passes-gate)、Spec 验证器、项目配置加载。
|
|
5
5
|
|
|
6
6
|
## 核心导出
|
|
7
|
-
- `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS) + 检查引擎(ConstraintChecker,拦截统一由 checkBeforeExecution 承担,ADR-0004) + 缓存(CheckCache:TTL 缓存 + 计数采样,H6/G5 起公开导出) + 注入渲染(injection-renderer) + 落点写入器(injection-writer:「声明→对照→幂等替换」中 marker-range 替换的唯一 writer——replaceStandaloneRange/replaceEnclosedRange/cutMarkerBlock + 半标记守护;落点路由读写两侧同住此模块 resolveInjectionTarget(CLAUDE.md 有标记段优先、否则 AGENTS.md PRESERVE:governance,studio #307)/resolveGovernanceLanding(init 写侧,含旧版无标记 Governance Rules 块豁免),ADR-0011) + Agent prompt 渲染(agent-prompt-renderer:trigger 参数化分组渲染,role 路由留 studio,H6/G6)/漂移校验(injection-drift:纯检测只读,路由消费 injection-writer)/使用统计(usage-report:constraints report·retire 的只读数据层,读 trace 两个入口——`readProjectTracesReport()` 带 `skippedLines`、`readProjectTraces()` 兼容包装丢计数;报告模型 `ConstraintsUsageReport` 的降级位 = `traceFileExists` + `skippedLines`,harness#100)/清单对照(capabilities-reconcile:CAPABILITIES.md 与代码实况的覆盖/幽灵判定唯一实现,capability_sync·docs_freshness·sync-docs 共消费,ADR-0009);CheckEnv 生产侧唯一构造点 `buildCheckEnv(context, providers|'none')`(checkers/types.ts:providers = 证据接线,git 两项绑 GitEvidence 实例,'none' = 显式不接 → evidence flag checker 按契约 skip)
|
|
8
|
-
- `git-evidence.ts` —
|
|
7
|
+
- `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS) + 检查引擎(ConstraintChecker,拦截统一由 checkBeforeExecution 承担,ADR-0004) + 缓存(CheckCache:TTL 缓存 + 计数采样,H6/G5 起公开导出) + 注入渲染(injection-renderer) + 落点写入器(injection-writer:「声明→对照→幂等替换」中 marker-range 替换的唯一 writer——replaceStandaloneRange/replaceEnclosedRange/cutMarkerBlock + 半标记守护;落点路由读写两侧同住此模块 resolveInjectionTarget(CLAUDE.md 有标记段优先、否则 AGENTS.md PRESERVE:governance,studio #307)/resolveGovernanceLanding(init 写侧,含旧版无标记 Governance Rules 块豁免),ADR-0011) + Agent prompt 渲染(agent-prompt-renderer:trigger 参数化分组渲染,role 路由留 studio,H6/G6)/漂移校验(injection-drift:纯检测只读,路由消费 injection-writer)/使用统计(usage-report:constraints report·retire 的只读数据层,读 trace 两个入口——`readProjectTracesReport()` 带 `skippedLines`、`readProjectTraces()` 兼容包装丢计数;报告模型 `ConstraintsUsageReport` 的降级位 = `traceFileExists` + `skippedLines`,harness#100)/清单对照(capabilities-reconcile:CAPABILITIES.md 与代码实况的覆盖/幽灵判定唯一实现,capability_sync·docs_freshness·sync-docs 共消费,ADR-0009);CheckEnv 生产侧唯一构造点 `buildCheckEnv(context, providers|'none')`(checkers/types.ts:providers = 证据接线,git 两项绑 GitEvidence 实例,'none' = 显式不接 → evidence flag checker 按契约 skip);判定接缝 `CheckOutcome = boolean | 'skip' | CheckDetail{pass, evidence}`(harness#119/ADR-0016)——编排层与 `gates/checker-gate` 一律经唯一归一点 `normalizeCheckOutcome()` 取三态 + 证据,不各自 `=== false`(对新形状会误判);证据行由 checker 自行措辞(自描述、不带缩进),组装与截断策略单点在 `formatEvidence()`/`MAX_EVIDENCE_ITEMS`(同住 checkers/types.ts);证据四出口 = `ConstraintResult.evidence` → CLI 结论块/提示块、`ExecutionTrace.evidence`、铁律 `ConstraintViolationError.message`(铁律违规直接 throw,异常文案是其证据唯一外溢面);检查引擎双出口——`checkConstraints`(block:首个铁律违规即抛,throw 契约不动)与 `collectConstraints`(collect:共享检查体、不抛、全量收集,report 的不抛出口,架构评审候选1)
|
|
8
|
+
- `git-evidence.ts` — check 链路的 git 取证唯一接缝(#87,范围按 ADR-0021 收窄;`spec/validator` 的 staged 列表同型复用):`createGitEvidence(projectPath, run?)` 返回 `GitEvidence{stagedDiff, changedFileNames(staged), headDirs}`,seam 上两个真 adapter(缺省 `realGitCommandRunner` 走真 git / 注入 runner 供计数与替身)。命令级 memo 落在此实例(含失败结果),实例生命周期 = 一次 check run,故 context-builder 与 ConstraintChecker 传同一实例即共用证据;判定语义与迁移前一致(diff 取证失败 → 空串,`git ls-tree` 失败 → null = 所有目录视为新);`parseHeadDirs`/`splitFileNames` 是配套纯函数
|
|
9
9
|
- `constraints/context-builder.ts` — 只装配不取证:`buildConstraintContext(options.evidence?)` 与 `detectTrigger(options.evidence?)` 经 GitEvidence 取 git 事实(不传 = 自建真 adapter),本模块无 child_process import;其余证据标志(traces/文档标记)仍为本地探测
|
|
10
10
|
- `effective-constraints.ts` — `getEffectiveConstraints(projectRoot, {preset?})`:全仓唯一生效集来源(内置 → preset → config.yml 禁用(内置与 custom 同效)→ custom 追加(禁用/已退役的不追加)→ scenes 过滤);`getMergedConstraintsConfig(projectRoot, {preset?})`:同链路的完整 MergedConstraintsConfig 形状(含 disabled/custom/unknownIds),内置工单 23 优先级规则(--preset 仅在无项目自定义配置时生效),check 命令经此入口;`lintEffectiveConfig` 配置诊断
|
|
11
11
|
- `effective-set.ts` — `filterEnabledEntries(knownIds, entries, {onUnknownId})`:约束侧(collect)与门禁侧(throw)共用的 config 条目筛选器
|
|
12
|
-
- `validators/` — checkpoints、passes-gate、CSO 验证器;`test-output.ts` —「测试产物解读」唯一实现:`extractFailures` 提取函数 + `judgeTestRun` 判定入口(退出码为主 + 行首锚定的文本失败信号交叉否决;文本救不回非零退出,`allowPartialPass` 只作用于文本否决那一维),passes-gate 与 `gates/acceptance` 的结论一律从它取、各自体内不写判定 `if`(解析收口 ADR-0012,判定依据 ADR-0014);**不读覆盖率**——harness 核心判定对覆盖率不取数不执法,判覆盖率的两处(CLI `passes-gate --coverage`、`gates/performance`)各自读 json-summary,`extractCoverage` 与 `TaskTestResult.coverage` 已随 ADR-0015 删除;`PassesGate.runTests(workDir)` 的执行与证据落盘根是**必传形参**,本层不再取 cwd(harness#95,约定正本见 `src/cli/commands/CONTEXT.md`);`detectTestCommand` 是测试命令探测唯一正本(模块级导出:test:ci → test 排 echo 占位 → test:e2e → test:coverage → Python 标记 pyproject.toml/pytest.ini → go.mod,探不到返回 undefined,兜底归调用方——CLI 映射 skip、PassesGate 内部 fail-closed,不再兜底 'npm test';CLI 本地版已删,架构评审 A2);PassesGate 扩展注册表(registerExtension/unregisterExtension/getExtensionNames/runAllTests/checkAllPasses + PassesGateExtension/ExtensionTestResult 两类型与包根导出)已整段删除——零 adapter 假想 seam 且扩展结果本就不参与 allowed 判定,需要扩展测试类型时按 ADR-0014 判例在 `judgeTestRun` 层加,不恢复旧 seam(harness#104,架构评审 B1
|
|
13
|
-
- `session/` — 会话管理
|
|
12
|
+
- `validators/` — checkpoints、passes-gate、CSO 验证器;`test-output.ts` —「测试产物解读」唯一实现:`extractFailures` 提取函数 + `judgeTestRun` 判定入口(退出码为主 + 行首锚定的文本失败信号交叉否决;文本救不回非零退出,`allowPartialPass` 只作用于文本否决那一维),passes-gate 与 `gates/acceptance` 的结论一律从它取、各自体内不写判定 `if`(解析收口 ADR-0012,判定依据 ADR-0014);**不读覆盖率**——harness 核心判定对覆盖率不取数不执法,判覆盖率的两处(CLI `passes-gate --coverage`、`gates/performance`)各自读 json-summary,`extractCoverage` 与 `TaskTestResult.coverage` 已随 ADR-0015 删除;`PassesGate.runTests(workDir)` 的执行与证据落盘根是**必传形参**,本层不再取 cwd(harness#95,约定正本见 `src/cli/commands/CONTEXT.md`);`detectTestCommand` 是测试命令探测唯一正本(模块级导出:test:ci → test 排 echo 占位 → test:e2e → test:coverage → Python 标记 pyproject.toml/pytest.ini → go.mod,探不到返回 undefined,兜底归调用方——CLI 映射 skip、PassesGate 内部 fail-closed,不再兜底 'npm test';CLI 本地版已删,架构评审 A2);PassesGate 扩展注册表(registerExtension/unregisterExtension/getExtensionNames/runAllTests/checkAllPasses + PassesGateExtension/ExtensionTestResult 两类型与包根导出)已整段删除——零 adapter 假想 seam 且扩展结果本就不参与 allowed 判定,需要扩展测试类型时按 ADR-0014 判例在 `judgeTestRun` 层加,不恢复旧 seam(harness#104,架构评审 B1);PassesGate 公开面 = `check()` + `runTests()` 两个真实消费点,`setPasses`/`getTestResult`/`checkTestFileChanges` 三方法与死数据 `PROTECTED_TEST_PATTERNS`、私有 `testResults` 缓存已随 ADR-0022(双仓零消费者)删除,历史 AC-007「保留 setPasses 向后兼容」同案推翻;包内模块,不进 `src/index.ts` 导出面
|
|
14
13
|
- `spec/validator` — SpecValidator
|
|
15
14
|
- `project-config-loader` — 项目配置加载 + 约束合并(mergeConstraints 内含 preset 裁剪:presets/ 纯数据 + 未知名回落 standard,禁用到未知 id 经 effective-set 共享筛选器 collect 模式);`getGovernanceConfig` 是全仓唯一允许手写钻取 `config.governance` 的点(工单 84),消费方一律经它或经 `resolveContextFiles`(三态:unconfigured / enabled-empty / enabled,dirs 元素类型在此收口)取数据,不得再自己 cast `Record<string, unknown>`;checker 对前两态一律 skip,自动探测回落只属于 init/扫描类工具流调用方
|
|
16
15
|
|
|
@@ -25,9 +24,10 @@
|
|
|
25
24
|
- check 层必须带真实 checker(注册表闭环,引用未注册 checker 构建报错)
|
|
26
25
|
- Iron Law 违规必须 throw ConstraintViolationError
|
|
27
26
|
- 上行数据一律注入,不在 core 内 require 上层(harness#88):trace 记录器经 `ConstraintChecker` 构造参数注入(缺省 no-op,`getInstance()`/`constraintChecker` 即未接线的默认实例,只评估不写 trace),真实收集器由组合根接线(CLI check/report、`bootstrapHarness`);CAPABILITIES.md 能力清单计数经 `capabilities-parser` 的 `CapabilityDefinitionSource` 由 cli 侧注入定义表
|
|
28
|
-
- git
|
|
27
|
+
- git **取证**(读判定证据)在 check 链路内只能经 `constraints/git-evidence.ts` 的 adapter 取(#87,适用范围按 ADR-0021 收窄为「check 链路唯一」,不再声称全仓唯一):`context-builder` / `checker` / `CheckEnv` / `validators` 这条判定链内不得出现 `execSync`/`execAsync`/`execFileAsync` 跑 git;`spec/validator` 的 staged 文件列表与 `changedFileNames(staged:true)` 同型,已收口(就地 `createGitEvidence(cwd)`,测试注入 runner);一次 run 一份实例、沿调用链显式传递(CLI check → buildConstraintContext → checkConstraints),memo 既不做成模块级全局也不做成单例字段。**链外站点记名豁免**(语义异质:不要 memo、不要 once 语义、失败处理各异,硬并入会造出宽 interface)——`cli/commands/release.ts`(发布流程编排,非判定证据)、`gates/review.ts` 与 `cli/commands/review.ts`(PR 审查流,gh/日志语义)、`knowledge/import.ts`(导入启发式,失败记 ImportError 降级)。豁免清单外新增 git 站点先回答「在不在判定链内」;`validators/passes-gate.ts` 的 `git diff --name-only` 站点已随 ADR-0022 删 `checkTestFileChanges` 消失,判定链内当下无站外 git 调用点
|
|
29
28
|
|
|
30
29
|
## 注意事项
|
|
31
30
|
- 零 Token 成本:所有分析纯文件操作,无 LLM 调用
|
|
32
31
|
- 约束配置支持 .harness/config.yml 自定义合并(preset 真实生效)
|
|
33
32
|
- 存在性探测约束(capability_sync/docs_freshness/context_doc_sync)在约定文件缺失,或 context_files 约定已立但无目标(enabled-empty)时 skip,不计 pass/fail;context_doc_sync 与 docs_freshness 对三态判定同构(工单 84)
|
|
33
|
+
- **fail 必须可归因到被评估的对象**(harness#119/ADR-0016):`capability_sync` 的 Step 1(staged 增量未登记)判违规,Step 2(T-058 全量完备性)与本次变更无因果、只出提示(`satisfied=true` + evidence);「有表格但零条目 + 确有源文件」的文档退化门仍判违规(显式,不借 Step 2 兜)。2026-09-08 前 `capability_sync` 恒红(studio 22/22)就是这条错位造成的。注意降级并不换来执法:`sync-docs --check` 单独跑才 exit 1,CI/ship 都先跑写入(file 模式自补行)再 `--check`,harness 自有 CI 那步还是 `continue-on-error`——仓库级漏登目前无自动拦截点,缺口与修法见 ADR-0016「影响」
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* collectConstraints — 收集模式(架构评审候选1)
|
|
3
|
+
*
|
|
4
|
+
* 与 checkConstraints 共享检查体,唯一差别是不 throw:
|
|
5
|
+
* 铁律违规不抛、全量收进 ironLaws、guidelines 照常、passed 如实。
|
|
6
|
+
* block 模式的 throw 契约由 checker-extra / iron-laws 既有用例钉住,这里只测 collect 侧。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from '@jest/globals';
|
|
10
|
+
import { ConstraintChecker } from '../checker';
|
|
11
|
+
import type { ConstraintContext, ConstraintResult } from '../../../types/constraint';
|
|
12
|
+
|
|
13
|
+
// 缺省 no-op trace 记录器:本套件不验 trace 面(trace 面由 trace-injection 套件钉住)
|
|
14
|
+
const checker = new ConstraintChecker();
|
|
15
|
+
|
|
16
|
+
/** 只违 no_completion_without_verification,其余铁律满足(flag 口径同 checker-extra) */
|
|
17
|
+
const VIOLATING: ConstraintContext = {
|
|
18
|
+
operation: 'code_implementation',
|
|
19
|
+
hasTest: false,
|
|
20
|
+
hasVerificationEvidence: false,
|
|
21
|
+
hasRequirement: true,
|
|
22
|
+
hasSingleTask: true,
|
|
23
|
+
taskDescription: 'single focused change',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const CLEAN: ConstraintContext = {
|
|
27
|
+
operation: 'code_implementation',
|
|
28
|
+
hasTest: true,
|
|
29
|
+
hasVerificationEvidence: true,
|
|
30
|
+
hasRequirement: true,
|
|
31
|
+
hasSingleTask: true,
|
|
32
|
+
taskDescription: 'single focused change',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe('collectConstraints(收集模式,不抛)', () => {
|
|
36
|
+
it('铁律违规不抛 —— resolves 而非 rejects', async () => {
|
|
37
|
+
await expect(checker.collectConstraints(VIOLATING)).resolves.toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('违规铁律如实进 ironLaws:satisfied=false 且 passed=false', async () => {
|
|
41
|
+
const result = await checker.collectConstraints(VIOLATING);
|
|
42
|
+
const violated = result.ironLaws.find((r: ConstraintResult) => r.id === 'no_completion_without_verification');
|
|
43
|
+
expect(violated).toBeDefined();
|
|
44
|
+
expect(violated!.satisfied).toBe(false);
|
|
45
|
+
expect(result.passed).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('首个违规不截断:触发域内后续铁律照常评估', async () => {
|
|
49
|
+
const result = await checker.collectConstraints(VIOLATING);
|
|
50
|
+
const ids = result.ironLaws.map((r: ConstraintResult) => r.id);
|
|
51
|
+
expect(ids).toContain('incremental_progress');
|
|
52
|
+
expect(ids).toContain('no_implementation_without_requirement');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('guidelines 照常执行,warningCount 与不满意条目同口径', async () => {
|
|
56
|
+
const result = await checker.collectConstraints(VIOLATING);
|
|
57
|
+
expect(result.guidelines.length).toBeGreaterThan(0);
|
|
58
|
+
expect(result.warningCount).toBe(result.guidelines.filter((g: ConstraintResult) => !g.satisfied).length);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('干净上下文对照:passed=true、ironLaws 全满意', async () => {
|
|
62
|
+
const result = await checker.collectConstraints(CLEAN);
|
|
63
|
+
expect(result.passed).toBe(true);
|
|
64
|
+
expect(result.ironLaws.every((r: ConstraintResult) => r.satisfied)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -22,7 +22,7 @@ import { matchesTrigger } from '../../utils/exec';
|
|
|
22
22
|
import { join, relative } from 'path';
|
|
23
23
|
import { CheckCache } from './check-cache';
|
|
24
24
|
import { findTsSourceFiles } from '../../utils/file-walk';
|
|
25
|
-
import { getConstraintCheck, buildCheckEnv, type CheckOutcome } from './checkers';
|
|
25
|
+
import { getConstraintCheck, buildCheckEnv, normalizeCheckOutcome, type CheckOutcome } from './checkers';
|
|
26
26
|
import { createGitEvidence, type GitEvidence } from './git-evidence';
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -112,9 +112,11 @@ export class ConstraintChecker {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
// 检查前置条件('skip' = 约定未采用/证据未接线:satisfied 置 true 但不计 pass/fail)
|
|
115
|
-
const outcome =
|
|
115
|
+
const outcome = normalizeCheckOutcome(
|
|
116
|
+
await this.checkPrecondition(constraint, context, evidence)
|
|
117
|
+
);
|
|
116
118
|
|
|
117
|
-
if (outcome
|
|
119
|
+
if (outcome.skipped) {
|
|
118
120
|
return {
|
|
119
121
|
id: constraint.id,
|
|
120
122
|
level: constraint.level,
|
|
@@ -126,7 +128,7 @@ export class ConstraintChecker {
|
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
const satisfied = outcome;
|
|
131
|
+
const satisfied = outcome.satisfied;
|
|
130
132
|
|
|
131
133
|
return {
|
|
132
134
|
id: constraint.id,
|
|
@@ -134,6 +136,7 @@ export class ConstraintChecker {
|
|
|
134
136
|
satisfied,
|
|
135
137
|
constraint,
|
|
136
138
|
message: satisfied ? undefined : constraint.message,
|
|
139
|
+
evidence: outcome.evidence.length > 0 ? outcome.evidence : undefined,
|
|
137
140
|
requiredAction: satisfied ? undefined : constraint.enforcement,
|
|
138
141
|
checkedAt: new Date(),
|
|
139
142
|
};
|
|
@@ -172,6 +175,7 @@ export class ConstraintChecker {
|
|
|
172
175
|
severity: this.getSeverity(constraint.level),
|
|
173
176
|
projectPath: context.projectPath,
|
|
174
177
|
sessionId: context.sessionId,
|
|
178
|
+
evidence: checkResult.evidence,
|
|
175
179
|
});
|
|
176
180
|
}
|
|
177
181
|
|
|
@@ -259,6 +263,35 @@ export class ConstraintChecker {
|
|
|
259
263
|
context: ConstraintContext,
|
|
260
264
|
customConfig?: MergedConstraintsConfig | null,
|
|
261
265
|
evidence?: GitEvidence
|
|
266
|
+
): Promise<ConstraintCheckResult> {
|
|
267
|
+
return this.runAllConstraints(context, customConfig, evidence, 'block');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 收集模式执行约束检查(harness report 的不抛出口,架构评审候选1)
|
|
272
|
+
*
|
|
273
|
+
* 与 checkConstraints 共享同一检查体,唯一差别是不 throw:
|
|
274
|
+
* 铁律违规照进 result.ironLaws、passed=false,后续铁律与 guidelines 照常执行,
|
|
275
|
+
* trace 逐条照记。报告类消费者拿全量视图;阻断语义只属于 checkConstraints
|
|
276
|
+
* (throw 契约是 #119 判定证据的外溢面,逐字不动)。
|
|
277
|
+
*/
|
|
278
|
+
async collectConstraints(
|
|
279
|
+
context: ConstraintContext,
|
|
280
|
+
customConfig?: MergedConstraintsConfig | null,
|
|
281
|
+
evidence?: GitEvidence
|
|
282
|
+
): Promise<ConstraintCheckResult> {
|
|
283
|
+
return this.runAllConstraints(context, customConfig, evidence, 'collect');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* checkConstraints / collectConstraints 的共享检查体;
|
|
288
|
+
* mode='block' 首个铁律违规即抛,mode='collect' 全量跑完不抛
|
|
289
|
+
*/
|
|
290
|
+
private async runAllConstraints(
|
|
291
|
+
context: ConstraintContext,
|
|
292
|
+
customConfig: MergedConstraintsConfig | null | undefined,
|
|
293
|
+
evidence: GitEvidence | undefined,
|
|
294
|
+
mode: 'block' | 'collect'
|
|
262
295
|
): Promise<ConstraintCheckResult> {
|
|
263
296
|
// run 起始:重置 src 扫描缓存(S7);git 证据 = 本 run 独占的 adapter 实例(工单 18 → #87)
|
|
264
297
|
this.cache.invalidate();
|
|
@@ -275,7 +308,7 @@ export class ConstraintChecker {
|
|
|
275
308
|
// context.operation 为主触发条件,extraTriggers 为次级推断(ADR-0001),任一命中即匹配
|
|
276
309
|
const operations = [context.operation, ...(context.extraTriggers ?? [])];
|
|
277
310
|
|
|
278
|
-
// 1. Iron Laws:
|
|
311
|
+
// 1. Iron Laws: block 模式首个违规即抛;collect 模式全量收集
|
|
279
312
|
for (const constraint of Object.values(constraints.ironLaws)) {
|
|
280
313
|
if (!matchesTrigger(constraint, operations)) continue;
|
|
281
314
|
|
|
@@ -285,7 +318,9 @@ export class ConstraintChecker {
|
|
|
285
318
|
|
|
286
319
|
if (!checkResult.satisfied) {
|
|
287
320
|
result.passed = false;
|
|
288
|
-
|
|
321
|
+
if (mode === 'block') {
|
|
322
|
+
throw new ConstraintViolationError(checkResult);
|
|
323
|
+
}
|
|
289
324
|
}
|
|
290
325
|
}
|
|
291
326
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
11
11
|
import { capabilitySync } from '../capability-sync';
|
|
12
|
-
import { buildCheckEnv, type CheckEnv } from '../types';
|
|
12
|
+
import { buildCheckEnv, normalizeCheckOutcome, type CheckEnv, type CheckOutcome } from '../types';
|
|
13
13
|
import { collectSourceFiles } from '../../capabilities-reconcile';
|
|
14
14
|
import { createProjectFixture } from '../../../../test-setup/project-fixture';
|
|
15
15
|
import type { ConstraintContext } from '../../../../types/constraint';
|
|
@@ -47,6 +47,12 @@ function makeEnv(
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** 判定归一:boolean 与 CheckDetail 两种返回形状统一断言(harness#119) */
|
|
51
|
+
const passed = (outcome: CheckOutcome): boolean => normalizeCheckOutcome(outcome).satisfied;
|
|
52
|
+
/** 证据行拼成单串,便于按路径断言 */
|
|
53
|
+
const evidenceText = (outcome: CheckOutcome): string =>
|
|
54
|
+
normalizeCheckOutcome(outcome).evidence.join('\n');
|
|
55
|
+
|
|
50
56
|
describe('capability_sync — skip 与文档格式门槛', () => {
|
|
51
57
|
it('无 CAPABILITIES.md → skip(ADR-0001 存在性探测,有无变更都一样)', async () => {
|
|
52
58
|
const dir = createProjectFixture({ name: 'cap-sync-none' });
|
|
@@ -56,84 +62,104 @@ describe('capability_sync — skip 与文档格式门槛', () => {
|
|
|
56
62
|
|
|
57
63
|
it('散文文档(无表格)+ 有变更 → 放行(历史语义)', async () => {
|
|
58
64
|
const dir = setupDir('prose', '# Capabilities\n\n- Feature: test', ['feature.ts']);
|
|
59
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, ['feature.ts']))).toBe(true);
|
|
65
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, ['feature.ts'])))).toBe(true);
|
|
60
66
|
});
|
|
61
67
|
|
|
62
68
|
it('清单格式(计数行)→ 放行,计数由 sync-docs 维护', async () => {
|
|
63
69
|
const dir = setupDir('listing', '# Capabilities\n\n## CLI Commands (25)\ncheck, validate\n');
|
|
64
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, ['src/foo.ts']))).toBe(true);
|
|
70
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, ['src/foo.ts'])))).toBe(true);
|
|
65
71
|
});
|
|
66
72
|
|
|
67
|
-
it('有表格但零条目 + 有变更 →
|
|
73
|
+
it('有表格但零条目 + 有变更 → 不得放行(step1 拦下,证据点名变更文件)', async () => {
|
|
68
74
|
const dir = setupDir('empty-table', `# Capabilities\n\n${TABLE_HEAD}`);
|
|
69
|
-
|
|
75
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, ['src/foo.ts']));
|
|
76
|
+
expect(passed(outcome)).toBe(false);
|
|
77
|
+
expect(evidenceText(outcome)).toContain('src/foo.ts');
|
|
70
78
|
});
|
|
71
79
|
|
|
72
|
-
it('有表格但零条目 + 源码有文件 → step2
|
|
80
|
+
it('有表格但零条目 + 源码有文件 → 文档退化门拦下(不靠 step2 兜,harness#119)', async () => {
|
|
73
81
|
const dir = setupDir('empty-table-scan', `# Capabilities\n\n${TABLE_HEAD}`, ['src/foo.ts']);
|
|
74
|
-
|
|
82
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
83
|
+
expect(passed(outcome)).toBe(false);
|
|
84
|
+
expect(evidenceText(outcome)).toContain('零条目');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('有表格但零条目 + 源码无文件 → 放行(门限定「确有可登记对象」,不扩大 fail 面)', async () => {
|
|
88
|
+
const dir = setupDir('empty-table-nosrc', `# Capabilities\n\n${TABLE_HEAD}`);
|
|
89
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, [])))).toBe(true);
|
|
75
90
|
});
|
|
76
91
|
});
|
|
77
92
|
|
|
78
|
-
describe('capability_sync — step1
|
|
93
|
+
describe('capability_sync — step1 增量覆盖(唯一判违规处,harness#119)', () => {
|
|
79
94
|
const run = (dir: string, staged: string[]) =>
|
|
80
95
|
capabilitySync.evaluate(makeEnv(dir, staged, {}));
|
|
81
96
|
|
|
82
|
-
it('变更文件未被登记 →
|
|
97
|
+
it('变更文件未被登记 → 失败,且证据点名该文件', async () => {
|
|
83
98
|
const dir = setupDir('step1-uncovered', `# C\n\n${TABLE_HEAD}| 旧 | old/module.ts | 旧 |\n`);
|
|
84
|
-
|
|
99
|
+
const outcome = await run(dir, ['new-module.ts']);
|
|
100
|
+
expect(passed(outcome)).toBe(false);
|
|
101
|
+
expect(evidenceText(outcome)).toContain('new-module.ts');
|
|
85
102
|
});
|
|
86
103
|
|
|
87
104
|
it('变更文件按登记路径覆盖 → 通过', async () => {
|
|
88
105
|
const dir = setupDir('step1-covered', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`);
|
|
89
|
-
expect(await run(dir, ['src/foo.ts'])).toBe(true);
|
|
106
|
+
expect(passed(await run(dir, ['src/foo.ts']))).toBe(true);
|
|
90
107
|
});
|
|
91
108
|
|
|
92
109
|
it('每个变更文件都必须被覆盖(every 而非 some)', async () => {
|
|
93
110
|
const dir = setupDir('step1-every', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`);
|
|
94
|
-
|
|
111
|
+
const outcome = await run(dir, ['src/foo.ts', 'scripts/bar.ts']);
|
|
112
|
+
expect(passed(outcome)).toBe(false);
|
|
113
|
+
expect(evidenceText(outcome)).toContain('scripts/bar.ts');
|
|
95
114
|
});
|
|
96
115
|
|
|
97
116
|
it('后缀碰撞不覆盖:xfoo.ts 不被 foo.ts 条目覆盖', async () => {
|
|
98
117
|
const dir = setupDir('step1-endswith', `# C\n\n${TABLE_HEAD}| foo | foo.ts | foo |\n`);
|
|
99
|
-
expect(await run(dir, ['web/xfoo.ts'])).toBe(false);
|
|
118
|
+
expect(passed(await run(dir, ['web/xfoo.ts']))).toBe(false);
|
|
100
119
|
});
|
|
101
120
|
|
|
102
121
|
it('子串误配不覆盖:docs/src/foo.tsx 不被 src/foo.ts 条目覆盖', async () => {
|
|
103
122
|
const dir = setupDir('step1-includes', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`);
|
|
104
|
-
expect(await run(dir, ['docs/src/foo.tsx'])).toBe(false);
|
|
123
|
+
expect(passed(await run(dir, ['docs/src/foo.tsx']))).toBe(false);
|
|
105
124
|
});
|
|
106
125
|
|
|
107
126
|
it('basename 条目按路径边界后缀覆盖(src/foo.ts 被 foo.ts 覆盖)', async () => {
|
|
108
127
|
const dir = setupDir('step1-suffix-ok', `# C\n\n${TABLE_HEAD}| foo | foo.ts | foo |\n`);
|
|
109
|
-
expect(await run(dir, ['src/foo.ts'])).toBe(true);
|
|
128
|
+
expect(passed(await run(dir, ['src/foo.ts']))).toBe(true);
|
|
110
129
|
});
|
|
111
130
|
|
|
112
131
|
it('测试文件与非代码变更不参与 step1', async () => {
|
|
113
132
|
const dir = setupDir('step1-noncode', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`);
|
|
114
133
|
expect(
|
|
115
|
-
await run(dir, ['src/__tests__/foo.test.ts', 'docs/readme.md', 'package.json'])
|
|
134
|
+
passed(await run(dir, ['src/__tests__/foo.test.ts', 'docs/readme.md', 'package.json']))
|
|
116
135
|
).toBe(true);
|
|
117
136
|
});
|
|
118
137
|
});
|
|
119
138
|
|
|
120
|
-
describe('capability_sync — step2 全量覆盖(file
|
|
121
|
-
it('全部源文件已登记 →
|
|
139
|
+
describe('capability_sync — step2 全量覆盖(file 模式:只提示,不判违规)', () => {
|
|
140
|
+
it('全部源文件已登记 → 通过且无提示', async () => {
|
|
122
141
|
const dir = setupDir(
|
|
123
142
|
'step2-ok',
|
|
124
143
|
`# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`,
|
|
125
144
|
['src/foo.ts']
|
|
126
145
|
);
|
|
127
|
-
|
|
146
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
147
|
+
expect(passed(outcome)).toBe(true);
|
|
148
|
+
expect(evidenceText(outcome)).toBe('');
|
|
128
149
|
});
|
|
129
150
|
|
|
130
|
-
it('有未登记源文件 →
|
|
151
|
+
it('有未登记源文件 → 仍通过,但提示点名该文件(harness#119 归位)', async () => {
|
|
131
152
|
const dir = setupDir(
|
|
132
153
|
'step2-missing',
|
|
133
154
|
`# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`,
|
|
134
155
|
['src/foo.ts', 'src/unlisted.ts']
|
|
135
156
|
);
|
|
136
|
-
|
|
157
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
158
|
+
expect(passed(outcome)).toBe(true);
|
|
159
|
+
const evidence = evidenceText(outcome);
|
|
160
|
+
expect(evidence).toContain('src/unlisted.ts');
|
|
161
|
+
expect(evidence).toContain('仓库级漂移');
|
|
162
|
+
expect(evidence).toContain('sync-docs');
|
|
137
163
|
});
|
|
138
164
|
|
|
139
165
|
it('basename 条目同样按边界后缀覆盖 step2(step1/step2 语义一致)', async () => {
|
|
@@ -142,16 +168,40 @@ describe('capability_sync — step2 全量覆盖(file 模式)', () => {
|
|
|
142
168
|
`# C\n\n${TABLE_HEAD}| foo | foo.ts | foo |\n`,
|
|
143
169
|
['src/foo.ts']
|
|
144
170
|
);
|
|
145
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, []))).toBe(true);
|
|
171
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, [])))).toBe(true);
|
|
146
172
|
});
|
|
147
173
|
|
|
148
|
-
it('不同路径同后缀文件不被误覆盖(lib/foo.ts 不覆盖 src/foo.ts
|
|
174
|
+
it('不同路径同后缀文件不被误覆盖(lib/foo.ts 不覆盖 src/foo.ts)→ 记为漂移', async () => {
|
|
149
175
|
const dir = setupDir(
|
|
150
176
|
'step2-boundary',
|
|
151
177
|
`# C\n\n${TABLE_HEAD}| foo | lib/foo.ts | foo |\n`,
|
|
152
178
|
['src/foo.ts']
|
|
153
179
|
);
|
|
154
|
-
|
|
180
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
181
|
+
expect(passed(outcome)).toBe(true);
|
|
182
|
+
expect(evidenceText(outcome)).toContain('src/foo.ts');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('step1 优先:变更未登记时判违规,证据是变更文件而非仓库漂移清单', async () => {
|
|
186
|
+
const dir = setupDir(
|
|
187
|
+
'step1-beats-step2',
|
|
188
|
+
`# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`,
|
|
189
|
+
['src/foo.ts', 'src/drifted.ts']
|
|
190
|
+
);
|
|
191
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, ['src/new.ts']));
|
|
192
|
+
expect(passed(outcome)).toBe(false);
|
|
193
|
+
expect(evidenceText(outcome)).toContain('src/new.ts');
|
|
194
|
+
expect(evidenceText(outcome)).not.toContain('src/drifted.ts');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('漂移项超过 10 个 → 证据截断并给出全量查看入口', async () => {
|
|
198
|
+
const files = ['src/foo.ts', ...Array.from({ length: 12 }, (_, i) => `src/drift${i}.ts`)];
|
|
199
|
+
const dir = setupDir('step2-truncate', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`, files);
|
|
200
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
201
|
+
expect(passed(outcome)).toBe(true);
|
|
202
|
+
const lines = normalizeCheckOutcome(outcome).evidence;
|
|
203
|
+
expect(lines).toHaveLength(12); // 说明行 + 10 条 + 截断行
|
|
204
|
+
expect(lines[lines.length - 1]).toContain('另 2 项');
|
|
155
205
|
});
|
|
156
206
|
});
|
|
157
207
|
|
|
@@ -163,7 +213,7 @@ describe('capability_sync — module 模式(未覆盖聚合为目录形状)'
|
|
|
163
213
|
['src/core/foo.ts', 'src/core/bar.ts'],
|
|
164
214
|
'module'
|
|
165
215
|
);
|
|
166
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, []))).toBe(true);
|
|
216
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, [])))).toBe(true);
|
|
167
217
|
});
|
|
168
218
|
|
|
169
219
|
it('文件条目精确匹配也算覆盖', async () => {
|
|
@@ -173,17 +223,22 @@ describe('capability_sync — module 模式(未覆盖聚合为目录形状)'
|
|
|
173
223
|
['src/core/foo.ts'],
|
|
174
224
|
'module'
|
|
175
225
|
);
|
|
176
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, []))).toBe(true);
|
|
226
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, [])))).toBe(true);
|
|
177
227
|
});
|
|
178
228
|
|
|
179
|
-
it('新目录未登记 →
|
|
229
|
+
it('新目录未登记 → 不判违规,提示按目录聚合', async () => {
|
|
180
230
|
const dir = setupDir(
|
|
181
231
|
'mod-uncovered',
|
|
182
232
|
`# C\n\n${TABLE_HEAD}| 核心 | src/core/ | 核心 |\n`,
|
|
183
233
|
['src/core/foo.ts', 'src/newdir/bar.ts'],
|
|
184
234
|
'module'
|
|
185
235
|
);
|
|
186
|
-
|
|
236
|
+
const outcome = await capabilitySync.evaluate(makeEnv(dir, []));
|
|
237
|
+
expect(passed(outcome)).toBe(true);
|
|
238
|
+
const evidence = evidenceText(outcome);
|
|
239
|
+
expect(evidence).toContain('未登记模块目录');
|
|
240
|
+
expect(evidence).toContain('src/newdir/');
|
|
241
|
+
expect(evidence).not.toContain('src/newdir/bar.ts');
|
|
187
242
|
});
|
|
188
243
|
|
|
189
244
|
it('module 模式文件条目按边界后缀覆盖(step1/step2 同规则)', async () => {
|
|
@@ -193,12 +248,12 @@ describe('capability_sync — module 模式(未覆盖聚合为目录形状)'
|
|
|
193
248
|
['src/foo.ts'],
|
|
194
249
|
'module'
|
|
195
250
|
);
|
|
196
|
-
expect(await capabilitySync.evaluate(makeEnv(dir, []))).toBe(true);
|
|
251
|
+
expect(passed(await capabilitySync.evaluate(makeEnv(dir, [])))).toBe(true);
|
|
197
252
|
});
|
|
198
253
|
});
|
|
199
254
|
|
|
200
255
|
describe('capability_sync — fail-open 可观测', () => {
|
|
201
|
-
it('证据读取异常时放行但输出 warn', async () => {
|
|
256
|
+
it('证据读取异常时放行但输出 warn,且异常原因进 evidence', async () => {
|
|
202
257
|
const dir = setupDir('failopen', `# C\n\n${TABLE_HEAD}| foo | src/foo.ts | foo |\n`);
|
|
203
258
|
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
204
259
|
const env: CheckEnv = {
|
|
@@ -207,7 +262,11 @@ describe('capability_sync — fail-open 可观测', () => {
|
|
|
207
262
|
throw new Error('git boom');
|
|
208
263
|
},
|
|
209
264
|
};
|
|
210
|
-
|
|
265
|
+
const outcome = await capabilitySync.evaluate(env);
|
|
266
|
+
// fail-open 语义不变(仍不拦),但「因异常而通过」必须留痕:warn 只进本地 stderr
|
|
267
|
+
expect(passed(outcome)).toBe(true);
|
|
268
|
+
expect(evidenceText(outcome)).toContain('git boom');
|
|
269
|
+
expect(evidenceText(outcome)).toContain('fail-open');
|
|
211
270
|
expect(warnSpy).toHaveBeenCalled();
|
|
212
271
|
warnSpy.mockRestore();
|
|
213
272
|
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查结果证据通道测试(harness#119)
|
|
3
|
+
*
|
|
4
|
+
* 背景:checker 只回 `boolean | 'skip'`,fail 的具体原因(哪个文件没登记)在 CLI
|
|
5
|
+
* 与 trace 两头都无处落脚——capability_sync 连红 22 次而无人能说出红在哪。
|
|
6
|
+
* 本套件锁住新接缝:CheckDetail(pass + evidence)经 normalizeCheckOutcome
|
|
7
|
+
* 归一后,落到 ConstraintResult.evidence 与 ExecutionTrace.evidence。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect } from '@jest/globals';
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import { execFileSync } from 'child_process';
|
|
15
|
+
import { ConstraintChecker } from '../../checker';
|
|
16
|
+
import { normalizeCheckOutcome } from '../types';
|
|
17
|
+
import { createProjectFixture } from '../../../../test-setup/project-fixture';
|
|
18
|
+
import type { ExecutionTrace } from '../../../../types/trace';
|
|
19
|
+
import { ConstraintViolationError } from '../../../../types/constraint';
|
|
20
|
+
import type { Constraint, ConstraintResult } from '../../../../types/constraint';
|
|
21
|
+
import type { MergedConstraintsConfig } from '../../../../types/project-config';
|
|
22
|
+
|
|
23
|
+
const CAPABILITY_SYNC: Constraint = {
|
|
24
|
+
id: 'capability_sync',
|
|
25
|
+
kind: 'check',
|
|
26
|
+
level: 'guideline',
|
|
27
|
+
rule: 'CODE CHANGES MUST UPDATE CAPABILITIES.MD',
|
|
28
|
+
message: '核心模块变更必须同步功能清单',
|
|
29
|
+
trigger: ['module_modification'],
|
|
30
|
+
enforcement: 'update-capabilities',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** 声明式夹具(harness#90):CAPABILITIES.md + 源文件,无 git,staged 证据自然为空 */
|
|
34
|
+
function fixture(name: string, files: Record<string, string>): string {
|
|
35
|
+
return createProjectFixture({ name: `cap-sync-${name}`, files });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('normalizeCheckOutcome — 三态 + 证据归一', () => {
|
|
39
|
+
it('boolean 兼容旧形状:true → satisfied / false → violated,evidence 空', () => {
|
|
40
|
+
expect(normalizeCheckOutcome(true)).toEqual({ satisfied: true, skipped: false, evidence: [] });
|
|
41
|
+
expect(normalizeCheckOutcome(false)).toEqual({ satisfied: false, skipped: false, evidence: [] });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("'skip' → skipped 且不记证据", () => {
|
|
45
|
+
expect(normalizeCheckOutcome('skip')).toEqual({ satisfied: true, skipped: true, evidence: [] });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('CheckDetail 透传 pass 与 evidence;缺省 evidence 归一为空数组', () => {
|
|
49
|
+
expect(normalizeCheckOutcome({ pass: false, evidence: ['a.ts'] })).toEqual({
|
|
50
|
+
satisfied: false,
|
|
51
|
+
skipped: false,
|
|
52
|
+
evidence: ['a.ts'],
|
|
53
|
+
});
|
|
54
|
+
expect(normalizeCheckOutcome({ pass: true })).toEqual({
|
|
55
|
+
satisfied: true,
|
|
56
|
+
skipped: false,
|
|
57
|
+
evidence: [],
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** 只含 capability_sync 的生效集:一次 run 一条 trace,不牵动其他约束 */
|
|
63
|
+
function onlyCapabilitySync(): MergedConstraintsConfig {
|
|
64
|
+
return {
|
|
65
|
+
ironLaws: {},
|
|
66
|
+
guidelines: { capability_sync: CAPABILITY_SYNC },
|
|
67
|
+
prompts: {},
|
|
68
|
+
disabled: [],
|
|
69
|
+
custom: [],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 跑一次 checkConstraints,返回 capability_sync 的结果与它那条 trace */
|
|
74
|
+
async function runGuideline(dir: string): Promise<{
|
|
75
|
+
result: ConstraintResult;
|
|
76
|
+
trace: ExecutionTrace;
|
|
77
|
+
}> {
|
|
78
|
+
const traces: ExecutionTrace[] = [];
|
|
79
|
+
const checker = new ConstraintChecker({ record: (t) => traces.push(t) });
|
|
80
|
+
const run = await checker.checkConstraints(
|
|
81
|
+
{ operation: 'module_modification', projectPath: dir },
|
|
82
|
+
onlyCapabilitySync()
|
|
83
|
+
);
|
|
84
|
+
const result = run.guidelines.find(r => r.id === 'capability_sync')!;
|
|
85
|
+
const trace = traces.find(t => t.constraintId === 'capability_sync')!;
|
|
86
|
+
return { result, trace };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 需要真 git 的用例专用手写根:夹具不建 git,而 staged 分区只能由真仓库产生 */
|
|
90
|
+
function gitProjectRoot(files: Record<string, string>): string {
|
|
91
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-evidence-git-'));
|
|
92
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
93
|
+
const target = path.join(dir, rel);
|
|
94
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
95
|
+
fs.writeFileSync(target, content, 'utf-8');
|
|
96
|
+
}
|
|
97
|
+
execFileSync('git', ['init', '-q'], { cwd: dir });
|
|
98
|
+
execFileSync('git', ['config', 'user.email', 'fixture@example.com'], { cwd: dir });
|
|
99
|
+
execFileSync('git', ['config', 'user.name', 'Fixture'], { cwd: dir });
|
|
100
|
+
execFileSync('git', ['add', '.'], { cwd: dir });
|
|
101
|
+
execFileSync('git', ['commit', '-q', '-m', 'baseline'], { cwd: dir });
|
|
102
|
+
return dir;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
describe('capability_sync 证据经编排层落到 ConstraintResult 与 trace', () => {
|
|
106
|
+
it('满足但存在仓库级未登记文件 → satisfied=true,evidence 带路径,trace 记 pass', async () => {
|
|
107
|
+
const dir = fixture('hint', {
|
|
108
|
+
'CAPABILITIES.md': '| 模块 | 文件 | 说明 |\n|------|------|------|\n| foo | src/foo.ts | foo |\n',
|
|
109
|
+
'src/foo.ts': 'export const a = 1;\n',
|
|
110
|
+
'src/unlisted.ts': 'export const b = 2;\n',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const { result, trace } = await runGuideline(dir);
|
|
114
|
+
|
|
115
|
+
expect(result.satisfied).toBe(true);
|
|
116
|
+
expect(result.skipped).toBeUndefined();
|
|
117
|
+
expect(result.evidence?.join('\n')).toContain('unlisted.ts');
|
|
118
|
+
expect(trace.result).toBe('pass');
|
|
119
|
+
expect(trace.evidence?.join('\n')).toContain('unlisted.ts');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('违规(staged 新文件未登记)→ satisfied=false,evidence 指出该文件,trace 记 fail', async () => {
|
|
123
|
+
const dir = gitProjectRoot({
|
|
124
|
+
'CAPABILITIES.md': '| 模块 | 文件 | 说明 |\n|------|------|------|\n| foo | src/foo.ts | foo |\n',
|
|
125
|
+
'src/foo.ts': 'export const a = 1;\n',
|
|
126
|
+
});
|
|
127
|
+
fs.writeFileSync(path.join(dir, 'src/brand-new.ts'), 'export const c = 3;\n');
|
|
128
|
+
execFileSync('git', ['add', '--', 'src/brand-new.ts'], { cwd: dir });
|
|
129
|
+
|
|
130
|
+
const { result, trace } = await runGuideline(dir);
|
|
131
|
+
|
|
132
|
+
expect(result.satisfied).toBe(false);
|
|
133
|
+
expect(result.evidence?.join('\n')).toContain('src/brand-new.ts');
|
|
134
|
+
expect(trace.result).toBe('fail');
|
|
135
|
+
expect(trace.evidence?.join('\n')).toContain('src/brand-new.ts');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('skip 不携带证据(未评估不得留下证据行)', async () => {
|
|
139
|
+
const dir = fixture('no-convention', { 'README.md': '# no capabilities convention\n' });
|
|
140
|
+
|
|
141
|
+
const { result, trace } = await runGuideline(dir);
|
|
142
|
+
|
|
143
|
+
expect(result.skipped).toBe(true);
|
|
144
|
+
expect(result.evidence).toBeUndefined();
|
|
145
|
+
expect(trace.result).toBe('skip');
|
|
146
|
+
expect(trace.evidence).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('证据随铁律异常外溢(CLI catch 分支只打印 error.message)', () => {
|
|
151
|
+
it('ConstraintViolationError 文案带出证据行', () => {
|
|
152
|
+
const error = new ConstraintViolationError({
|
|
153
|
+
id: 'docs_freshness',
|
|
154
|
+
level: 'iron_law',
|
|
155
|
+
satisfied: false,
|
|
156
|
+
message: '文档新鲜度检查未通过',
|
|
157
|
+
evidence: ['CAPABILITIES.md 登记的条目不存在:', 'src/gone.ts'],
|
|
158
|
+
checkedAt: new Date(),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(error.message).toContain('文档新鲜度检查未通过');
|
|
162
|
+
expect(error.message).toContain('src/gone.ts');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('无证据时文案保持原样(旧消费方断言不受影响)', () => {
|
|
166
|
+
const error = new ConstraintViolationError({
|
|
167
|
+
id: 'no_test_simplification',
|
|
168
|
+
level: 'iron_law',
|
|
169
|
+
satisfied: false,
|
|
170
|
+
message: '禁止简化测试绕过困难',
|
|
171
|
+
checkedAt: new Date(),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect(error.message).toBe('禁止简化测试绕过困难');
|
|
175
|
+
});
|
|
176
|
+
});
|