/** * VerificationEvidence — 统一验证证据模型()。 * * 同时承载两种验证维度(V1/V2 统一): * - kind="command":命令执行验证(V2 verification_executor 输出,build/test 命令) * - kind="artifact_structure":产物结构验证(V1 validators 保留,findings + check_results) * * 公共字段:evidence_id/task_id/kind/passed/evaluated_at/engine_revision/evidence_source + provenance(verification_run_id/hmac)。 * stale 检测字段:artifact 维度含 ruleset_hash/verification_input_hash/artifact_git_hash + 共通 engine_revision。 * * 设计依据:设计报告。 * 落地范围(7-D0a):纯新增类型 + Store,不迁移任何消费者(7-D1+ 分阶段迁移 sf_verify/EvidenceEvaluator/consumeDeliverEvidence)。 * * 与 V1/V2 隔离:本类型独立,不修改 EvidenceView(V1)/VerificationResult(V2)。复用其子类型(GateFinding/check_results/VerificationFailure)。 */ import type { VerificationFailure } from "../verification_v2/verification_v2_types.js"; import type { GateFinding, EvidenceView, DomainName } from "../types.js"; /** 证据维度。command=命令执行(build/test);artifact_structure=产物结构验证(validators findings)。 */ export type VerificationEvidenceKind = "command" | "artifact_structure"; /** command 维度(V2 verification_executor 输出,kind="command" 时必填)。 */ export interface CommandEvidence { layer: "build" | "test"; command: string; output_digest?: string; duration_ms: number; failures: VerificationFailure[]; } /** artifact structure 维度(V1 validators 保留,kind="artifact_structure" 时必填)。 */ export interface ArtifactStructureEvidence { artifact_kind: string; domain: DomainName; gate_name: string; artifact_path: string; /** 产物 git hash(stale: content)。 */ artifact_git_hash: string; /** 完整验证输入摘要(stale: input)。 */ verification_input_hash?: string; /** 域规则集指纹(stale: ruleset)。 */ ruleset_hash: string; /** 检查发现(失败项)。 */ findings: GateFinding[]; /** 全量 check 结果(含 passed + 单项覆盖 metric)。复用 EvidenceView.check_results 类型(结构一致)。 */ check_results: EvidenceView["check_results"]; } /** 统一验证证据。kind 区分维度;command/artifact 按 kind 填充对应维度。 */ export interface VerificationEvidence { /** 当前 schema 版本(区别 V1 record schema_version=2 / V2 VerificationResult 无 schema_version)。 */ schema_version: 3; /** 唯一 id(格式 ev-<...>)。 */ evidence_id: string; task_id: string; /** V2 plan 绑定(command 维度常用)。 */ plan_id?: string; /** 验证维度。 */ kind: VerificationEvidenceKind; /** 是否通过(passed = 无 failure/finding)。 */ passed: boolean; /** 评估时间戳(ms)。 */ evaluated_at: number; /** 引擎判定修订指纹(stale: engine,共通)。 */ engine_revision: string; /** * 引擎 scope 判定修订指纹(该产物所属 engine scope 的判定闭包 hash;Part2 基础层,消费侧 Part3 接入)。 * optional:旧 evidence 无此字段 → 消费侧 Part3 按 undefined 回退全局 engine_revision 轴。 * HMAC 自然覆盖(canonicalize 枚举 Object.keys,undefined 被 filter 与落盘一致)。 */ engine_scope_revision?: string; /** 证据来源(artifact 维度=verification_service;command 维度=v2_executor)。 */ evidence_source: "verification_service" | "v2_executor"; /** command 维度(kind="command" 时必填)。 */ command?: CommandEvidence; /** artifact structure 维度(kind="artifact_structure" 时必填)。 */ artifact?: ArtifactStructureEvidence; /** 引用验证执行记录(artifact 维度的 run 事实,防手写 passed 绕门禁)。 */ verification_run_id?: string; /** HMAC provenance(签名服务签发,read 验签排除伪造;无 secret fail-closed)。 */ hmac?: string; } /** Evidence 失效标记(tombstone,)— 不删原 evidence 文件,V2 reader 默认过滤失效 evidence。 * 用于 apply_project_map 路径迁移/cleanup 等需失效旧 evidence 的场景(替代 hard delete,保 append-only 审计)。 * 自身 HMAC 防伪造失效:无 secret/验签失败的 tombstone 被排除 → 目标 evidence 保持有效(fail-safe 保留,不误失效)。 */ export interface EvidenceTombstone { schema_version: 1; /** 唯一 id(格式 ts-)。确定性派生使 invalidate 幂等(同 evidence 重失效覆盖同 tombstone)。 */ tombstone_id: string; /** 失效的目标 evidence_id。 */ evidence_id: string; /** 冗余 task_id(便于按 task 审计/查询)。 */ task_id: string; /** 失效时间(ms)。 */ invalidated_at: number; /** 失效原因(如 "project_map_path_migrated" / "cleanup")。 */ reason: string; /** HMAC provenance(防伪造失效;read 验签排除伪造 tombstone → evidence 保持有效)。 */ hmac?: string; }