from __future__ import annotations from pathlib import Path from dx_productivity.part_replace.certification import Certification from dx_productivity.part_replace.models import ( ExternalChecks, ImpactCell, Issue, MappingRule, ProjectState, VerificationResult, ) from dx_productivity.part_replace.reports import ( BatchReport, write_differences_json, write_impact_csv, write_summary_html, ) RULE = MappingRule("OLD-1", "NEW-1") def _report(*states: ProjectState, old_part_number: str = "OLD-1") -> BatchReport: rule = MappingRule(old_part_number, "NEW-1") result = VerificationResult( project_id="project-a", rule=rule, expected_logical_keys=("/MAIN|R1",), changed_logical_keys=("/MAIN|R1",), issues=( Issue("connectivity_changed", "error", "Pin 1 net changed"), Issue("library_attribute_changed", "info", "Value updated"), ), passed=False, ) return BatchReport( job_id="job-42", generated_time="2026-09-02T01:02:03Z", input_hashes={"job.json": "abc123", "events.jsonl": "def456"}, project_states={f"project-{index}": state for index, state in enumerate(states, start=1)}, impact_cells=(ImpactCell("project-a", rule, 1, 2),), verification_results=(result,), external_checks={"project-a": ExternalChecks(packager=True, erc=None, netlist=False)}, certifications=( Certification( created_utc="2026-09-01T00:00:00Z", dxdesigner_build="7.9.5", rule=rule, target_fingerprint="target-fingerprint", library_identity="library-r42", representative_project_fingerprint="trial-fingerprint", evidence_paths=("before.json", "after.json"), ), ), backup_path="C:/Backups/job-42", resume_action="Reconcile blocked projects before continuing.", advisory_attachments=("ai-review.json",), ) def test_html_report_escapes_part_numbers_and_has_no_remote_content(tmp_path: Path) -> None: # Catches direct interpolation that lets a part number create executable or remote HTML. output = tmp_path / "report.html" write_summary_html(output, _report(ProjectState.BLOCKED, old_part_number='