diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8c00e..abcd0dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to Pharabius are documented in this file. +## [3.8.0] - Unreleased + +### Candidate Decision Reporting and Audit Trail + +Makes candidate review decisions auditable and visible across reports, status, and governance export surfaces. + +### Added + +- **Report candidate decision summary** — Review Decision Summary table in foundation report +- **Lifecycle audit trail** — Candidate Lifecycle Audit Trail section with transitions, actors, rationale +- **Orphaned decision warnings** — Warns about review decisions for unknown candidate IDs +- **Governance export candidate decisions** — `build_candidate_decisions_summary()` helper, `candidate_decisions` field +- **Status reader review summary** — accepted/rejected/deferred/pending counts +- **23 new tests** covering report, audit, export, orphan detection, no-mutation + +### Design Rules + +- Reporting is read-only — no mutation of any artifact +- No debt-register promotion from candidate reporting +- Governance export is additive-only (`candidate_decisions` added, no existing fields changed) +- No forbidden field names in candidate export data + ## [3.7.0] - Unreleased ### Candidate Review and Promotion Workflow diff --git a/README.md b/README.md index e8fea27..408ae98 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Pharabius is a mature CLI engine with an early-stage platform. Current limitatio - _v3.5.0 adds **workflow lifecycle governance**: explicit state model for findings and work packages with transition validation. No auto-promotion._ - _v3.6.0 adds **evidence-to-finding candidate promotion**: external evidence can propose reviewable candidate findings. Candidates are not accepted findings._ - _v3.7.0 adds **candidate review workflow**: governed review of candidates with explicit decisions. Acceptance is review-level only, not debt-register promotion._ + - _v3.8.0 adds **candidate decision reporting**: audit trail, review summary in reports and governance export. Read-only — no mutation._ - **No live ticket sync** — No Jira, Linear, or GitHub Issues integration - **Platform frontend is prototype-grade** — 28 tests pass, build succeeds, but 5 pre-existing TypeScript errors in test mocks - **No portfolio governance** — Multi-repo governance workflows not implemented diff --git a/pyproject.toml b/pyproject.toml index a5b04b7..c1187ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pharabius" -version = "3.7.0" +version = "3.8.0" description = "Repository-first technical debt intelligence platform" readme = "README.md" requires-python = ">=3.11" diff --git a/src/pharabius/core/governance_export.py b/src/pharabius/core/governance_export.py index 6af5972..4b7e552 100644 --- a/src/pharabius/core/governance_export.py +++ b/src/pharabius/core/governance_export.py @@ -64,6 +64,7 @@ def build_governance_export( signal_summary: dict | None = None, governance_quality: GovernanceQualityMetrics | None = None, governance_trends: GovernanceTrendSummary | None = None, + candidate_decisions: dict | None = None, run_id: str | None = None, families_governed: int = 10, ) -> dict: @@ -71,6 +72,7 @@ def build_governance_export( Stable schema: schema_version, export_type, and all governance data. Does not introduce policy interpretation. + v3.8.0: Adds optional candidate_decisions summary. """ quality_dict = None if governance_quality is not None: @@ -103,6 +105,10 @@ def build_governance_export( }, } + # Candidate decisions summary (v3.8.0) + if candidate_decisions is not None: + export["candidate_decisions"] = candidate_decisions + return export @@ -139,3 +145,27 @@ def write_governance_export_jsonl( encoding="utf-8", ) return output_path + + +def build_candidate_decisions_summary( + *, + total_candidates: int = 0, + accepted: int = 0, + rejected: int = 0, + deferred: int = 0, + pending: int = 0, + by_connector: dict[str, int] | None = None, +) -> dict: + """Build candidate decisions summary for governance export. + + Additive-only: new fields may be added, existing fields never removed. + Does not include forbidden field names. + """ + return { + "total_candidates": total_candidates, + "accepted": accepted, + "rejected": rejected, + "deferred": deferred, + "pending": pending, + "by_connector": by_connector or {}, + } diff --git a/src/pharabius/core/reporter.py b/src/pharabius/core/reporter.py index 91ef52b..58c5f19 100644 --- a/src/pharabius/core/reporter.py +++ b/src/pharabius/core/reporter.py @@ -25,6 +25,8 @@ class ReportContext: evidence_store: EvidenceStore debt_register: DebtRegister candidate_artifact: Any = None # CandidateFindingsArtifact, optional + lifecycle_history: Any = None # LifecycleHistory, optional + candidate_decisions: Any = None # list[dict], optional def _load_json(path: Path) -> dict[str, Any]: @@ -99,12 +101,41 @@ def _context(repository_root: Path) -> ReportContext: except Exception: candidate_artifact = None + # Load lifecycle history (optional, v3.8.0) + lifecycle_history = None + lh_path = root / ".ai-debt" / "lifecycle-history.json" + if lh_path.exists(): + try: + from pharabius.schemas.lifecycle import LifecycleHistory + + lifecycle_history = LifecycleHistory.model_validate_json( + lh_path.read_text(encoding="utf-8") + ) + except Exception: + lifecycle_history = None + + # Load candidate review decisions (optional, v3.8.0) + candidate_decisions = None + review_path = root / ".ai-debt" / "review" / "decisions.json" + if review_path.exists(): + try: + review_data = json.loads(review_path.read_text(encoding="utf-8")) + candidate_decisions = [ + d + for d in review_data.get("decisions", []) + if isinstance(d, dict) and d.get("finding_id", "").startswith("CAND") + ] + except Exception: + candidate_decisions = None + return ReportContext( repository_root=root, profile=_load_profile(root), evidence_store=_load_evidence_store(root), debt_register=_load_debt_register(root), candidate_artifact=candidate_artifact, + lifecycle_history=lifecycle_history, + candidate_decisions=candidate_decisions, ) @@ -1305,17 +1336,38 @@ def _add_lifecycle_summary(lines: list[str], ctx: ReportContext) -> None: def _add_candidate_findings_section(lines: list[str], ctx: ReportContext) -> None: - """Add candidate findings section to the foundation report (v3.6.0). + """Add candidate findings section to the foundation report (v3.6.0, v3.8.0). Candidate findings are review artifacts, NOT accepted findings. This section makes them visible for review without affecting severity/priority summaries or governance metrics. + v3.8.0: Adds review decision audit trail and orphan warnings. """ artifact = ctx.candidate_artifact if artifact is None or not artifact.candidates: return summary = artifact.summary + candidate_ids = {c.id for c in artifact.candidates} + + # Build decision lookup + decided_ids: set[str] = set() + decision_map: dict[str, dict] = {} + if ctx.candidate_decisions: + for d in ctx.candidate_decisions: + fid = d.get("finding_id", "") + if fid in candidate_ids and fid not in decided_ids: + decided_ids.add(fid) + decision_map[fid] = d + + pending_ids = sorted(candidate_ids - decided_ids) + accepted_count = sum(1 for d in decision_map.values() if d.get("status") == "accepted") + rejected_count = sum( + 1 + for d in decision_map.values() + if d.get("status") in ("rejected", "risk-accepted", "duplicate", "already-fixed") + ) + deferred_count = sum(1 for d in decision_map.values() if d.get("status") == "deferred") lines.extend( [ @@ -1346,6 +1398,24 @@ def _add_candidate_findings_section(lines: list[str], ctx: ReportContext) -> Non for category, count in sorted(summary.by_category.items()): lines.append(f"| {category} | {count} |") + # Review decision summary (v3.8.0) + if decided_ids or pending_ids: + lines.extend( + [ + "", + "### Review Decision Summary", + "", + "| Status | Count |", + "|---|---:|", + f"| CandidateAccepted | {accepted_count} |", + f"| CandidateRejected | {rejected_count} |", + f"| CandidateDeferred | {deferred_count} |", + f"| Pending review | {len(pending_ids)} |", + "", + "> CandidateAccepted is review-level only, not debt-register promotion.", + ] + ) + lines.extend( [ "", @@ -1354,7 +1424,54 @@ def _add_candidate_findings_section(lines: list[str], ctx: ReportContext) -> Non ] ) for c in artifact.candidates[:20]: # Cap at 20 for report readability - lines.append(f"- **{c.id}**: {c.title} ({c.provenance.connector_name})") + decision_info = "" + if c.id in decision_map: + d = decision_map[c.id] + status = d.get("status", "unknown") + reviewer = d.get("reviewer", "") + reviewer_str = f" by {reviewer}" if reviewer else "" + decision_info = f" → {status}{reviewer_str}" + lines.append(f"- **{c.id}**: {c.title} ({c.provenance.connector_name}){decision_info}") if summary.total_candidates > 20: lines.append(f"- ... and {summary.total_candidates - 20} more") + + # Audit trail from lifecycle history (v3.8.0) + if ctx.lifecycle_history: + candidate_entries = [ + e + for e in ctx.lifecycle_history.entries + if e.artifact_type == "candidate" and e.artifact_id in candidate_ids + ] + if candidate_entries: + lines.extend( + [ + "", + "### Candidate Lifecycle Audit Trail", + "", + "| ID | From | To | Actor | Rationale |", + "|---|---|---|---|---|", + ] + ) + for entry in candidate_entries: + rationale = entry.rationale[:50] if entry.rationale else "-" + lines.append( + f"| {entry.artifact_id} | {entry.from_status} " + f"| {entry.to_status} | {entry.actor} | {rationale} |" + ) + + # Orphaned decision warnings (v3.8.0) + if ctx.candidate_decisions: + orphaned = [ + d for d in ctx.candidate_decisions if d.get("finding_id", "") not in candidate_ids + ] + if orphaned: + orphan_ids = ", ".join(d.get("finding_id", "?") for d in orphaned[:5]) + lines.extend( + [ + "", + f"**Warning:** {len(orphaned)} review decision(s) reference ", + f"unknown candidate IDs: {orphan_ids}", + ] + ) + lines.append("") diff --git a/tests/test_cli_command_surface.py b/tests/test_cli_command_surface.py index d901ebb..47066a2 100644 --- a/tests/test_cli_command_surface.py +++ b/tests/test_cli_command_surface.py @@ -99,4 +99,4 @@ class TestVersionFlag: def test_version_flag_works(self) -> None: result = runner.invoke(app, ["--version"]) assert result.exit_code == 0 - assert "3.7.0" in result.output + assert "3.8.0" in result.output diff --git a/tests/test_release_consistency.py b/tests/test_release_consistency.py index 018f9e8..aa66dce 100644 --- a/tests/test_release_consistency.py +++ b/tests/test_release_consistency.py @@ -13,7 +13,7 @@ # ruff: noqa: E402 from validate_release_consistency import validate_release_consistency -EXPECTED = "3.7.0" +EXPECTED = "3.8.0" class TestVersionSources: diff --git a/tests/test_v380_candidate_decision_reporting.py b/tests/test_v380_candidate_decision_reporting.py new file mode 100644 index 0000000..cb3b9d4 --- /dev/null +++ b/tests/test_v380_candidate_decision_reporting.py @@ -0,0 +1,471 @@ +"""Tests for v3.8.0 — Candidate Decision Reporting and Audit Trail. + +Covers: +- Candidate decision summary in reports +- Lifecycle audit trail in reports +- Orphaned decision warnings +- Governance export candidate decisions +- Status reader candidate decision summary +- No mutation of any artifact + +Key invariant: +Candidate decisions are visible and auditable, +but no candidate becomes an accepted finding. +""" + +from __future__ import annotations + +import json +from pathlib import Path + +from pharabius.core.connectors.candidate import write_candidate_artifact +from pharabius.core.connectors.candidate_review import review_candidate +from pharabius.core.governance_export import ( + build_candidate_decisions_summary, + build_governance_export, +) +from pharabius.schemas.candidate import ( + CandidateFinding, + CandidateFindingsArtifact, + CandidateProvenance, +) +from pharabius.schemas.review import DecisionStatus + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + + +def _make_candidate( + candidate_id: str = "CAND-0001", + connector_name: str = "trivy", +) -> CandidateFinding: + return CandidateFinding( + id=candidate_id, + category="TD-VULN", + title=f"Test finding {candidate_id}", + description="Test", + provenance=CandidateProvenance( + connector_name=connector_name, + source_format=connector_name, + evidence_count=1, + evidence_ids=["EXT-001"], + source_types=["external_scanner_result"], + ), + ) + + +def _setup_workspace( + tmp_path: Path, + *candidates: CandidateFinding, +) -> Path: + from collections import Counter + + by_connector = dict(Counter(c.provenance.connector_name for c in candidates)) + by_category = dict(Counter(c.category for c in candidates)) + + from pharabius.schemas.candidate import CandidateFindingsSummary + + summary = CandidateFindingsSummary( + total_candidates=len(candidates), + by_connector=by_connector, + by_category=by_category, + ) + artifact = CandidateFindingsArtifact(candidates=list(candidates), summary=summary) + write_candidate_artifact(artifact, tmp_path) + ai_debt = tmp_path / ".ai-debt" + ai_debt.mkdir(exist_ok=True) + (ai_debt / "project-profile.json").write_text( + json.dumps({"project_name": "test", "repository_root": str(tmp_path)}) + ) + (ai_debt / "evidence.json").write_text(json.dumps({"repository": "test", "evidence": []})) + (ai_debt / "debt-register.json").write_text( + json.dumps( + { + "project_name": "test", + "summary": { + "total_findings": 0, + "critical": 0, + "high": 0, + "medium": 0, + "low": 0, + }, + } + ) + ) + return tmp_path + + +# --------------------------------------------------------------------------- +# S03: Candidate decision report section +# --------------------------------------------------------------------------- + + +class TestCandidateDecisionReport: + """Report shows candidate review decisions.""" + + def test_report_shows_review_decision_summary(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace( + tmp_path, + _make_candidate("CAND-0001"), + _make_candidate("CAND-0002"), + _make_candidate("CAND-0003"), + ) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED, reviewer="alice") + review_candidate(tmp_path, "CAND-0002", DecisionStatus.REJECTED, reviewer="bob") + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Review Decision Summary" in content + assert "CandidateAccepted" in content + assert "CandidateRejected" in content + assert "Pending review" in content + + def test_report_shows_reviewer_on_candidates(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED, reviewer="alice") + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "alice" in content + + def test_report_shows_review_level_only_label(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "review-level only" in content + + def test_report_no_decisions_shows_pending(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Pending review" in content + + def test_report_without_candidates_no_candidate_section(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path) # No candidates + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Candidate Findings" not in content + + +# --------------------------------------------------------------------------- +# S03: Lifecycle audit trail in report +# --------------------------------------------------------------------------- + + +class TestLifecycleAuditTrail: + """Report shows lifecycle audit trail for candidates.""" + + def test_report_shows_lifecycle_audit_trail(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate( + tmp_path, + "CAND-0001", + DecisionStatus.ACCEPTED, + reviewer="alice", + rationale="Confirmed real vulnerability", + ) + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Candidate Lifecycle Audit Trail" in content + assert "Candidate" in content # from_status + assert "CandidateAccepted" in content # to_status + assert "alice" in content # actor + + def test_report_shows_rationale_in_audit_trail(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate( + tmp_path, + "CAND-0001", + DecisionStatus.REJECTED, + rationale="False positive — test fixture", + ) + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "False positive" in content + + def test_report_no_audit_trail_without_lifecycle_history(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + # No review → no lifecycle history + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Lifecycle Audit Trail" not in content + + +# --------------------------------------------------------------------------- +# S06: Orphaned decision warnings +# --------------------------------------------------------------------------- + + +class TestOrphanedDecisionWarnings: + """Report warns about decisions for unknown candidates.""" + + def test_orphaned_decision_warning_in_report(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + + # Manually inject an orphaned decision + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + # Add orphaned decision manually + sidecar = tmp_path / ".ai-debt" / "review" / "decisions.json" + data = json.loads(sidecar.read_text()) + data["decisions"].append( + { + "finding_id": "CAND-9999", + "status": "accepted", + "reviewed_at": "2026-06-07T00:00:00Z", + "reviewer": "test", + } + ) + sidecar.write_text(json.dumps(data, indent=2) + "\n") + + result = write_reports(tmp_path) + foundation = next(p for p in result.files_written if p.name == "foundation-audit-report.md") + content = foundation.read_text(encoding="utf-8") + + assert "Warning" in content + assert "CAND-9999" in content + + +# --------------------------------------------------------------------------- +# S05: Governance export visibility +# --------------------------------------------------------------------------- + + +class TestGovernanceExportCandidateDecisions: + """Governance export includes candidate decision summary.""" + + def test_export_includes_candidate_decisions(self) -> None: + summary = build_candidate_decisions_summary( + total_candidates=5, + accepted=2, + rejected=1, + deferred=0, + pending=2, + by_connector={"trivy": 3, "sarif": 2}, + ) + export = build_governance_export(candidate_decisions=summary) + + assert "candidate_decisions" in export + assert export["candidate_decisions"]["total_candidates"] == 5 + assert export["candidate_decisions"]["accepted"] == 2 + assert export["candidate_decisions"]["rejected"] == 1 + assert export["candidate_decisions"]["pending"] == 2 + + def test_export_without_candidate_decisions(self) -> None: + export = build_governance_export() + assert "candidate_decisions" not in export + + def test_export_no_forbidden_fields(self) -> None: + summary = build_candidate_decisions_summary() + for key in summary: + assert key.lower() not in { + "pass", + "fail", + "score", + "grade", + "compliant", + "noncompliant", + "healthy", + "unhealthy", + } + + def test_export_additive_only(self) -> None: + """Existing fields still present when candidate_decisions added.""" + export = build_governance_export(candidate_decisions={}) + assert "schema_version" in export + assert "governance_quality" in export + assert "governance_trends" in export + + def test_build_summary_defaults(self) -> None: + summary = build_candidate_decisions_summary() + assert summary["total_candidates"] == 0 + assert summary["accepted"] == 0 + assert summary["rejected"] == 0 + assert summary["deferred"] == 0 + assert summary["pending"] == 0 + assert summary["by_connector"] == {} + + +# --------------------------------------------------------------------------- +# S04: Status reader candidate decision summary +# --------------------------------------------------------------------------- + + +class TestStatusReaderCandidateDecisions: + """Status reader shows candidate review decisions.""" + + def test_status_shows_reviewed_counts(self, tmp_path: Path) -> None: + from pharabius.core.status_reader import read_status + + _setup_workspace( + tmp_path, + _make_candidate("CAND-0001"), + _make_candidate("CAND-0002"), + ) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + review_candidate(tmp_path, "CAND-0002", DecisionStatus.REJECTED) + + status = read_status(tmp_path) + assert "Reviewed:" in status + assert "accepted" in status + assert "rejected" in status + + def test_status_shows_pending(self, tmp_path: Path) -> None: + from pharabius.core.status_reader import read_status + + _setup_workspace( + tmp_path, + _make_candidate("CAND-0001"), + _make_candidate("CAND-0002"), + ) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + status = read_status(tmp_path) + assert "Pending" in status + + def test_status_no_candidate_artifact(self, tmp_path: Path) -> None: + """Status reader handles missing candidate artifact gracefully.""" + from pharabius.core.status_reader import read_status + + # Minimal workspace without candidates + ai_debt = tmp_path / ".ai-debt" + ai_debt.mkdir() + (ai_debt / "project-profile.json").write_text( + json.dumps({"project_name": "test", "repository_root": str(tmp_path)}) + ) + status = read_status(tmp_path) + # Candidates section absent when no artifact + assert "Candidates:" not in status + + +# --------------------------------------------------------------------------- +# S07: No mutation +# --------------------------------------------------------------------------- + + +class TestNoMutation: + """Reporting does not mutate any artifact.""" + + def test_candidate_artifact_unchanged_after_report(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + cand_path = tmp_path / ".ai-debt" / "candidate-findings.json" + orig = cand_path.read_text() + + write_reports(tmp_path) + + assert cand_path.read_text() == orig + + def test_debt_register_unchanged_after_report(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + reg_path = tmp_path / ".ai-debt" / "debt-register.json" + orig = reg_path.read_text() + + write_reports(tmp_path) + + assert reg_path.read_text() == orig + + def test_lifecycle_history_unchanged_after_report(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + lh_path = tmp_path / ".ai-debt" / "lifecycle-history.json" + orig = lh_path.read_text() + + write_reports(tmp_path) + + assert lh_path.read_text() == orig + + def test_review_sidecar_unchanged_after_report(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + sidecar = tmp_path / ".ai-debt" / "review" / "decisions.json" + orig = sidecar.read_text() + + write_reports(tmp_path) + + assert sidecar.read_text() == orig + + +# --------------------------------------------------------------------------- +# No debt-register promotion +# --------------------------------------------------------------------------- + + +class TestNoDebtRegisterPromotion: + """Reporting does not promote candidates to findings.""" + + def test_no_finding_created_from_accepted_candidate(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + write_reports(tmp_path) + + reg = json.loads((tmp_path / ".ai-debt" / "debt-register.json").read_text()) + assert reg["summary"]["total_findings"] == 0 + + def test_no_work_packages_from_candidates(self, tmp_path: Path) -> None: + from pharabius.core.reporter import write_reports + + _setup_workspace(tmp_path, _make_candidate("CAND-0001")) + review_candidate(tmp_path, "CAND-0001", DecisionStatus.ACCEPTED) + + write_reports(tmp_path) + + assert not (tmp_path / ".ai-debt" / "work-packages").exists()