feat(evidence): resolve curated evidence explicitly

This commit is contained in:
2026-08-24 20:52:56 +02:00
parent f5c7cc6198
commit 8adc085746
7 changed files with 442 additions and 4 deletions
+36
View File
@@ -14,6 +14,7 @@ from tht.evidence import (
EvidencePreparationError,
PiEvidenceRestructurer,
prepare_workspace_evidence,
resolve_workspace_evidence,
validate_workspace_evidence,
)
@@ -103,3 +104,38 @@ def validate_cmd(
if all(finding.code in {"orphaned_unit", "unresolved_review_item"} for finding in report.findings):
raise typer.Exit(code=3)
raise typer.Exit(code=1)
@evidence_app.command("resolve")
def resolve_cmd(
workspace_root: Path,
evidence_id: str,
retire: Annotated[bool, typer.Option(help="Retire the Evidence unit.")] = False,
source: Annotated[Path | None, typer.Option(help="Relink the unit to this source/ path.")] = None,
json_output: Annotated[bool, typer.Option("--json", help="Write machine JSON to stdout.")] = False,
) -> None:
"""Explicitly retire or relink one Evidence unit without publishing it."""
if retire == (source is not None):
raise typer.BadParameter("choose exactly one of --retire or --source")
root = _canonical_worktree(workspace_root)
try:
report = resolve_workspace_evidence(root, evidence_id, retire=retire, source=source)
except EvidencePreparationError as error:
_emit({"schemaVersion": 1, "operation": "evidence_resolve", "status": "failed", "code": error.code}, json_output)
exit_code = 2 if error.code in {
"evidence_id_invalid", "resolve_mode_invalid", "source_invalid",
} else 1
raise typer.Exit(code=exit_code) from error
_emit({
"schemaVersion": 1,
"operation": "evidence_resolve",
"status": "resolved",
"action": report.action,
"evidenceId": report.evidence_id,
"sourceFile": report.source_file,
"findings": _findings_payload(report.findings),
}, json_output)
if report.findings:
if all(finding.code in {"orphaned_unit", "unresolved_review_item"} for finding in report.findings):
raise typer.Exit(code=3)
raise typer.Exit(code=1)