detached.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. """Detached-derived validation for board-viewer compact-package assets.
  2. Validates the packaged derived assets (hashes, geometry/counts, SVG safety)
  3. without requiring the original Allegro BRD on disk and without claiming BRD
  4. regeneration. Compact packages keep these assets as derived evidence only;
  5. `reference_regeneration_replay` remains `not_packaged_by_policy`.
  6. """
  7. from __future__ import annotations
  8. import hashlib
  9. import json
  10. import re
  11. from dataclasses import asdict, dataclass, field
  12. from datetime import datetime, timezone
  13. from pathlib import Path
  14. from typing import Any
  15. from jsonschema import Draft202012Validator
  16. from jsonschema.exceptions import ValidationError
  17. ROOT = Path(__file__).resolve().parents[3]
  18. BUILD_INFO_SCHEMA = ROOT / "schemas" / "board_viewer_build_info.schema.json"
  19. DATA_SCHEMA = ROOT / "schemas" / "board_viewer_data.schema.json"
  20. DERIVED_ASSETS: tuple[str, ...] = (
  21. "board-data.json",
  22. "build-info.json",
  23. "import-report.json",
  24. "board-copper.svg",
  25. "board-silkscreen.svg",
  26. "board-mask-edge.svg",
  27. "board-copper-back.svg",
  28. "board-silkscreen-back.svg",
  29. "board-mask-edge-back.svg",
  30. )
  31. # Backward-compatible alias (name kept; list now includes front+back SVGs).
  32. SIX_DERIVED_ASSETS: tuple[str, ...] = DERIVED_ASSETS
  33. HASHED_ASSET_NAMES: tuple[str, ...] = (
  34. "board-data.json",
  35. "import-report.json",
  36. "board-copper.svg",
  37. "board-silkscreen.svg",
  38. "board-mask-edge.svg",
  39. "board-copper-back.svg",
  40. "board-silkscreen-back.svg",
  41. "board-mask-edge-back.svg",
  42. )
  43. SVG_NAMES: tuple[str, ...] = (
  44. "board-copper.svg",
  45. "board-silkscreen.svg",
  46. "board-mask-edge.svg",
  47. "board-copper-back.svg",
  48. "board-silkscreen-back.svg",
  49. "board-mask-edge-back.svg",
  50. )
  51. CANONICAL_GENERATED_DIR = "tools/board-viewer/generated"
  52. # Compact packages relocate the derived assets under evidence/.
  53. COMPACT_EVIDENCE_GENERATED_DIRS = (
  54. "evidence/board-viewer",
  55. "evidence/board-viewer/generated",
  56. "CPLD/evidence/board-viewer",
  57. "CPLD/evidence/board-viewer/generated",
  58. )
  59. EVIDENCE_CLASS = "derived_evidence"
  60. def resolve_generated_dir(root: Path | str) -> Path:
  61. """Resolve board-viewer derived assets for live repo or compact extract."""
  62. base = Path(root)
  63. candidates = [
  64. base / CANONICAL_GENERATED_DIR,
  65. *[base / rel for rel in COMPACT_EVIDENCE_GENERATED_DIRS],
  66. # Some extracts nest under source/
  67. base / "source" / CANONICAL_GENERATED_DIR,
  68. base / "CPLD" / "source" / CANONICAL_GENERATED_DIR,
  69. ]
  70. for candidate in candidates:
  71. if (candidate / "board-data.json").is_file() and (
  72. candidate / "build-info.json"
  73. ).is_file():
  74. return candidate
  75. return base / CANONICAL_GENERATED_DIR
  76. AUTHORITY = "analysis_evidence_not_source_closure"
  77. REGENERATION_STATUS = "not_packaged_by_policy"
  78. VIEWBOX_TOLERANCE_MM = 0.1
  79. _SCRIPT_RE = re.compile(r"<\s*script\b", re.I)
  80. _EXTERNAL_HTTP_RE = re.compile(r"https?://(?!www\.w3\.org/)", re.I)
  81. _FILE_URL_RE = re.compile(r"file://", re.I)
  82. _ABS_WIN_RE = re.compile(r"[A-Za-z]:\\")
  83. _ABS_UNIX_RE = re.compile(r"/(?:home|Users|tmp|var/tmp)/")
  84. _HREF_EXT_RE = re.compile(r"(?:xlink:)?href\s*=\s*[\"'](?!#)", re.I)
  85. _URL_FUNC_RE = re.compile(r"url\(\s*[\"']?(?!#)", re.I)
  86. _RANDOM_RE = re.compile(
  87. r"Math\.random|Date\.now|uuid|randomUUID|crypto\.getRandomValues",
  88. re.I,
  89. )
  90. _VIEWBOX_RE = re.compile(r'viewBox\s*=\s*"([^"]+)"')
  91. @dataclass
  92. class Finding:
  93. check: str
  94. status: str
  95. detail: str
  96. @dataclass
  97. class DetachedDerivedReport:
  98. schema: str = "board-viewer-detached-derived-report-v1"
  99. generated_at_utc: str = ""
  100. status: str = "fail"
  101. evidence_class: str = EVIDENCE_CLASS
  102. authority: str = AUTHORITY
  103. canonical_relative_dir: str = CANONICAL_GENERATED_DIR
  104. reference_regeneration_replay: str = REGENERATION_STATUS
  105. regeneration_claim: str = "none"
  106. brd_file_present: bool = False
  107. packaging_policy: dict[str, Any] = field(default_factory=dict)
  108. assets: dict[str, Any] = field(default_factory=dict)
  109. provenance: dict[str, Any] = field(default_factory=dict)
  110. geometry: dict[str, Any] = field(default_factory=dict)
  111. counts: dict[str, Any] = field(default_factory=dict)
  112. svg_safety: dict[str, Any] = field(default_factory=dict)
  113. findings: list[Finding] = field(default_factory=list)
  114. summary: dict[str, int] = field(default_factory=dict)
  115. def add(self, check: str, status: str, detail: str) -> None:
  116. self.findings.append(Finding(check=check, status=status, detail=detail))
  117. def sha256_file(path: Path, chunk_size: int = 1024 * 1024) -> str:
  118. digest = hashlib.sha256()
  119. with path.open("rb") as stream:
  120. while chunk := stream.read(chunk_size):
  121. digest.update(chunk)
  122. return digest.hexdigest()
  123. def packaging_policy() -> dict[str, Any]:
  124. """Policy descriptor for packagers: keep derived assets once, as evidence."""
  125. return {
  126. "assets": list(DERIVED_ASSETS),
  127. "canonical_relative_dir": CANONICAL_GENERATED_DIR,
  128. "evidence_class": EVIDENCE_CLASS,
  129. "authority": AUTHORITY,
  130. "physical_inclusion": "single_copy_only",
  131. "duplicate_guidance": (
  132. "Ship exactly one physical copy under "
  133. f"{CANONICAL_GENERATED_DIR}/; do not also materialize the same "
  134. "bytes via a second external-source copy or reference mirror."
  135. ),
  136. "keep_svgs": True,
  137. "keep_reason": (
  138. "When compact packages exclude the Allegro BRD, the front+back SVGs plus "
  139. "board-data.json are the primary remote geometry/touchpoint evidence; "
  140. "ZIP cost is low relative to analysis value. Back SVGs are KiCad-mirrored "
  141. "about the vertical/Y axis (physical left-right flip)."
  142. ),
  143. "build_info_must_retain": [
  144. "sources.brd.sha256",
  145. "sources.generator_*.sha256",
  146. "generator_version",
  147. "toolchain",
  148. "assets.*.sha256",
  149. "counts",
  150. ],
  151. "reference_regeneration_replay": REGENERATION_STATUS,
  152. "detached_validation": (
  153. "Hashes, geometry/counts, and SVG safety only; never claim BRD "
  154. "regeneration when the BRD is absent."
  155. ),
  156. }
  157. def describe_derived_assets(generated_dir: Path | str) -> list[dict[str, Any]]:
  158. """Size/provenance rows packagers can attach to HANDOFF-INDEX / size-budget."""
  159. generated = Path(generated_dir)
  160. rows: list[dict[str, Any]] = []
  161. for name in DERIVED_ASSETS:
  162. path = generated / name
  163. role = (
  164. "derived_from_brd_visual"
  165. if name.endswith(".svg")
  166. else "derived_from_brd_parsed"
  167. )
  168. row: dict[str, Any] = {
  169. "asset": name,
  170. "path": f"{CANONICAL_GENERATED_DIR}/{name}",
  171. "exists": path.is_file(),
  172. "role": role,
  173. "evidence_class": EVIDENCE_CLASS,
  174. "authority": AUTHORITY,
  175. "note": (
  176. "Derived from the original Allegro BRD for remote analysis; "
  177. "not RTL/TD source closure. Regeneration is local-only / "
  178. f"{REGENERATION_STATUS} for compact packages."
  179. ),
  180. }
  181. if path.is_file():
  182. row["bytes"] = path.stat().st_size
  183. row["sha256"] = sha256_file(path)
  184. rows.append(row)
  185. return rows
  186. def _parse_viewbox(text: str) -> tuple[float, float, float, float] | None:
  187. match = _VIEWBOX_RE.search(text)
  188. if not match:
  189. return None
  190. parts = match.group(1).replace(",", " ").split()
  191. if len(parts) != 4:
  192. return None
  193. try:
  194. return float(parts[0]), float(parts[1]), float(parts[2]), float(parts[3])
  195. except ValueError:
  196. return None
  197. def _scan_svg_safety(name: str, text: str, report: DetachedDerivedReport) -> list[str]:
  198. issues: list[str] = []
  199. for label, pattern in (
  200. ("script", _SCRIPT_RE),
  201. ("external_http", _EXTERNAL_HTTP_RE),
  202. ("file_url", _FILE_URL_RE),
  203. ("absolute_windows_path", _ABS_WIN_RE),
  204. ("absolute_local_unix_path", _ABS_UNIX_RE),
  205. ("external_href", _HREF_EXT_RE),
  206. ("external_url_func", _URL_FUNC_RE),
  207. ("non_reproducible_randomness", _RANDOM_RE),
  208. ):
  209. hits = pattern.findall(text)
  210. if hits:
  211. issues.append(f"{label}:{len(hits)}")
  212. report.add(f"svg_safety.{name}.{label}", "fail", f"{len(hits)} hit(s)")
  213. else:
  214. report.add(f"svg_safety.{name}.{label}", "pass", "clean")
  215. return issues
  216. def _resolve_source_path(
  217. metadata_path: str, *, repository_root: Path, generated: Path
  218. ) -> Path:
  219. path = Path(metadata_path)
  220. if path.is_absolute():
  221. return path
  222. candidate = repository_root / path
  223. if candidate.is_file():
  224. return candidate
  225. return generated.parent.parent.parent / path
  226. def validate_detached_derived(
  227. generated_dir: Path | str,
  228. *,
  229. repository_root: Path | str = ROOT,
  230. require_brd_present: bool = False,
  231. ) -> DetachedDerivedReport:
  232. """Validate derived assets without claiming BRD regeneration."""
  233. generated = Path(generated_dir).resolve()
  234. repository = Path(repository_root).resolve()
  235. report = DetachedDerivedReport(
  236. generated_at_utc=datetime.now(timezone.utc).isoformat(),
  237. packaging_policy=packaging_policy(),
  238. )
  239. asset_rows: dict[str, Any] = {}
  240. missing: list[str] = []
  241. for name in DERIVED_ASSETS:
  242. path = generated / name
  243. entry: dict[str, Any] = {
  244. "path": str(path),
  245. "exists": path.is_file(),
  246. "evidence_class": EVIDENCE_CLASS,
  247. }
  248. if path.is_file():
  249. entry["bytes"] = path.stat().st_size
  250. entry["sha256"] = sha256_file(path)
  251. report.add(f"asset.exists.{name}", "pass", "present")
  252. else:
  253. missing.append(name)
  254. report.add(f"asset.exists.{name}", "fail", "missing")
  255. asset_rows[name] = entry
  256. report.assets = asset_rows
  257. if missing:
  258. report.add("assets.complete_set", "fail", f"missing:{','.join(missing)}")
  259. else:
  260. report.add(
  261. "assets.complete_set",
  262. "pass",
  263. f"{len(DERIVED_ASSETS)} derived assets present (front+back SVGs)",
  264. )
  265. build_info_path = generated / "build-info.json"
  266. board_data_path = generated / "board-data.json"
  267. import_report_path = generated / "import-report.json"
  268. build_info: dict[str, Any] | None = None
  269. board_data: dict[str, Any] | None = None
  270. if build_info_path.is_file():
  271. try:
  272. build_info = json.loads(build_info_path.read_text(encoding="utf-8"))
  273. schema = json.loads(BUILD_INFO_SCHEMA.read_text(encoding="utf-8"))
  274. Draft202012Validator(schema).validate(build_info)
  275. report.add("build_info.schema", "pass", "board-viewer-build-info-v1")
  276. except (OSError, json.JSONDecodeError, ValidationError, ValueError) as exc:
  277. build_info = None
  278. report.add("build_info.schema", "fail", str(exc))
  279. if build_info is not None:
  280. sources = build_info.get("sources") or {}
  281. brd_meta = sources.get("brd") or {}
  282. brd_sha = str(brd_meta.get("sha256") or "")
  283. brd_path_meta = str(brd_meta.get("path") or "")
  284. report.provenance["build_info_brd"] = brd_meta
  285. report.provenance["generator_version"] = build_info.get("generator_version")
  286. report.provenance["toolchain"] = build_info.get("toolchain")
  287. report.add(
  288. "provenance.brd_sha256_recorded",
  289. "pass" if re.fullmatch(r"[0-9a-f]{64}", brd_sha) else "fail",
  290. brd_sha or "missing",
  291. )
  292. generator_hashes = {
  293. key: value
  294. for key, value in sources.items()
  295. if str(key).startswith("generator_")
  296. }
  297. report.provenance["generator_source_hashes"] = {
  298. key: (value or {}).get("sha256") for key, value in generator_hashes.items()
  299. }
  300. report.add(
  301. "provenance.generator_hashes_recorded",
  302. "pass" if generator_hashes else "fail",
  303. f"{len(generator_hashes)} generator_* source entries",
  304. )
  305. brd_on_disk: Path | None = None
  306. if brd_path_meta:
  307. brd_on_disk = _resolve_source_path(
  308. brd_path_meta, repository_root=repository, generated=generated
  309. )
  310. report.brd_file_present = bool(brd_on_disk and brd_on_disk.is_file())
  311. if report.brd_file_present and brd_on_disk is not None:
  312. actual = sha256_file(brd_on_disk)
  313. match = actual == brd_sha
  314. report.provenance["brd_on_disk"] = {
  315. "path": str(brd_on_disk),
  316. "sha256": actual,
  317. "matches_build_info": match,
  318. }
  319. report.add(
  320. "provenance.brd_on_disk_optional",
  321. "pass" if match else "fail",
  322. actual if match else f"actual={actual} build-info={brd_sha}",
  323. )
  324. else:
  325. report.provenance["brd_on_disk"] = {
  326. "present": False,
  327. "note": (
  328. "BRD absence is expected for compact/detached packages; "
  329. "validation uses recorded build-info hashes only."
  330. ),
  331. }
  332. report.add(
  333. "provenance.brd_on_disk_optional",
  334. "fail" if require_brd_present else "pass",
  335. "missing (detached/compact expected)"
  336. if not require_brd_present
  337. else "missing but require_brd_present=True",
  338. )
  339. assets_meta = build_info.get("assets") or {}
  340. for name in HASHED_ASSET_NAMES:
  341. path = generated / name
  342. meta = assets_meta.get(name) or {}
  343. expected_sha = meta.get("sha256")
  344. expected_bytes = meta.get("bytes")
  345. if not path.is_file():
  346. continue
  347. actual_sha = asset_rows[name]["sha256"]
  348. actual_bytes = asset_rows[name]["bytes"]
  349. sha_ok = expected_sha == actual_sha
  350. bytes_ok = expected_bytes == actual_bytes
  351. asset_rows[name]["build_info_sha256"] = expected_sha
  352. asset_rows[name]["matches_build_info"] = sha_ok and bytes_ok
  353. report.add(
  354. f"asset.hash.{name}",
  355. "pass" if sha_ok and bytes_ok else "fail",
  356. actual_sha
  357. if sha_ok and bytes_ok
  358. else (
  359. f"sha={actual_sha} expected={expected_sha} "
  360. f"bytes={actual_bytes} expected_bytes={expected_bytes}"
  361. ),
  362. )
  363. # build-info.json is the manifest; it is not self-hashed in assets{}.
  364. report.add(
  365. "asset.hash.build-info.json",
  366. "pass",
  367. "manifest retained; digests cover sibling assets",
  368. )
  369. report.provenance["note"] = (
  370. "Detached validation never asserts BRD regeneration. "
  371. f"reference_regeneration_replay={REGENERATION_STATUS}."
  372. )
  373. report.add(
  374. "regeneration.claim",
  375. "pass",
  376. "none; not claiming BRD regeneration",
  377. )
  378. else:
  379. report.add("provenance.brd_sha256_recorded", "fail", "build-info unavailable")
  380. if import_report_path.is_file():
  381. try:
  382. import_report = json.loads(import_report_path.read_text(encoding="utf-8"))
  383. errors = import_report.get("errors") or []
  384. source_file = str(import_report.get("source_file") or "")
  385. report.provenance["import_report"] = {
  386. "source_file": source_file,
  387. "source_format": import_report.get("source_format"),
  388. "errors": errors,
  389. }
  390. report.add(
  391. "import_report.errors",
  392. "pass" if not errors else "fail",
  393. "none" if not errors else str(errors),
  394. )
  395. report.add(
  396. "import_report.source_file",
  397. "pass" if source_file.endswith(".brd") else "fail",
  398. source_file or "missing",
  399. )
  400. except (OSError, json.JSONDecodeError) as exc:
  401. report.add("import_report.parse", "fail", str(exc))
  402. board_view_box: dict[str, float] | None = None
  403. if board_data_path.is_file():
  404. try:
  405. board_data = json.loads(board_data_path.read_text(encoding="utf-8"))
  406. data_schema = json.loads(DATA_SCHEMA.read_text(encoding="utf-8"))
  407. Draft202012Validator(data_schema).validate(board_data)
  408. report.add("board_data.schema", "pass", str(board_data.get("schema")))
  409. except (OSError, json.JSONDecodeError, ValidationError, ValueError) as exc:
  410. board_data = None
  411. report.add("board_data.schema", "fail", str(exc))
  412. if board_data is not None and build_info is not None:
  413. board = board_data.get("board") or {}
  414. view_box = board.get("view_box") or {}
  415. board_view_box = {
  416. "x": float(view_box.get("x", 0.0)),
  417. "y": float(view_box.get("y", 0.0)),
  418. "width": float(view_box.get("width", 0.0)),
  419. "height": float(view_box.get("height", 0.0)),
  420. }
  421. bi_counts = build_info.get("counts") or {}
  422. bd_counts = board_data.get("counts") or {}
  423. touchpoints = board_data.get("touchpoints") or []
  424. resistors = board_data.get("resistors") or []
  425. count_checks = {
  426. "footprints": (bi_counts.get("footprints"), bd_counts.get("footprints")),
  427. "touchpoints": (bi_counts.get("touchpoints"), bd_counts.get("touchpoints")),
  428. "pads": (bi_counts.get("pads"), bd_counts.get("pads")),
  429. "resistors": (bi_counts.get("resistors"), bd_counts.get("resistors")),
  430. "resistor_pads": (bi_counts.get("resistor_pads"), bd_counts.get("resistor_pads")),
  431. "touchpoints_list_len": (
  432. bi_counts.get("touchpoints"),
  433. len(touchpoints) if isinstance(touchpoints, list) else None,
  434. ),
  435. "resistors_list_len": (
  436. bi_counts.get("resistors"),
  437. len(resistors) if isinstance(resistors, list) else None,
  438. ),
  439. }
  440. report.counts = {
  441. "build_info": bi_counts,
  442. "board_data": bd_counts,
  443. "touchpoints_list_len": len(touchpoints) if isinstance(touchpoints, list) else None,
  444. "resistors_list_len": len(resistors) if isinstance(resistors, list) else None,
  445. "checks": {},
  446. }
  447. all_counts_ok = True
  448. for key, (expected, actual) in count_checks.items():
  449. ok = expected == actual and expected is not None
  450. all_counts_ok = all_counts_ok and ok
  451. report.counts["checks"][key] = {
  452. "expected": expected,
  453. "actual": actual,
  454. "ok": ok,
  455. }
  456. report.add(
  457. f"counts.{key}",
  458. "pass" if ok else "fail",
  459. f"expected={expected} actual={actual}",
  460. )
  461. report.geometry["board_data_view_box"] = board_view_box
  462. report.add(
  463. "geometry.board_data_view_box",
  464. "pass"
  465. if board_view_box["width"] > 0 and board_view_box["height"] > 0
  466. else "fail",
  467. json.dumps(board_view_box),
  468. )
  469. if not all_counts_ok:
  470. report.add("counts.consistent", "fail", "mismatch between build-info and board-data")
  471. else:
  472. report.add("counts.consistent", "pass", "footprints/touchpoints/pads/resistors aligned")
  473. try:
  474. from .data import validate_resistor_index
  475. validate_resistor_index(board_data)
  476. report.add("resistors.index", "pass", "resistor index structure and annotation ⊆ index")
  477. except ValueError as exc:
  478. report.add("resistors.index", "fail", str(exc))
  479. svg_safety: dict[str, Any] = {}
  480. viewboxes: list[tuple[float, float, float, float]] = []
  481. for name in SVG_NAMES:
  482. path = generated / name
  483. entry: dict[str, Any] = {"exists": path.is_file()}
  484. if not path.is_file():
  485. svg_safety[name] = entry
  486. continue
  487. text = path.read_text(encoding="utf-8", errors="replace")
  488. issues = _scan_svg_safety(name, text, report)
  489. viewbox = _parse_viewbox(text)
  490. entry["safety_issues"] = issues
  491. entry["viewBox"] = None if viewbox is None else list(viewbox)
  492. if viewbox is not None:
  493. viewboxes.append(viewbox)
  494. if board_view_box is not None:
  495. dw = abs(viewbox[2] - board_view_box["width"])
  496. dh = abs(viewbox[3] - board_view_box["height"])
  497. dx = abs(viewbox[0] - board_view_box["x"])
  498. dy = abs(viewbox[1] - board_view_box["y"])
  499. ok = max(dw, dh, dx, dy) <= VIEWBOX_TOLERANCE_MM
  500. entry["coord_delta_vs_board_data_mm"] = {
  501. "dx": dx,
  502. "dy": dy,
  503. "dw": dw,
  504. "dh": dh,
  505. }
  506. report.add(
  507. f"geometry.svg.{name}",
  508. "pass" if ok else "fail",
  509. f"delta_mm dx={dx:.6f} dy={dy:.6f} dw={dw:.6f} dh={dh:.6f}",
  510. )
  511. else:
  512. report.add(f"geometry.svg.{name}", "fail", "missing/invalid viewBox")
  513. svg_safety[name] = entry
  514. if len(viewboxes) == len(SVG_NAMES) and len(set(viewboxes)) == 1:
  515. report.add("geometry.svg.consistent_across_layers", "pass", str(viewboxes[0]))
  516. elif viewboxes:
  517. report.add(
  518. "geometry.svg.consistent_across_layers",
  519. "fail",
  520. f"divergent viewBoxes: {viewboxes}",
  521. )
  522. report.svg_safety = svg_safety
  523. report.geometry["svg_viewboxes"] = [list(v) for v in viewboxes]
  524. summary = {"pass": 0, "fail": 0, "other": 0}
  525. for finding in report.findings:
  526. if finding.status in summary:
  527. summary[finding.status] += 1
  528. else:
  529. summary["other"] += 1
  530. report.summary = summary
  531. report.status = "pass" if summary["fail"] == 0 else "fail"
  532. report.reference_regeneration_replay = REGENERATION_STATUS
  533. report.regeneration_claim = "none"
  534. return report
  535. def report_to_dict(report: DetachedDerivedReport) -> dict[str, Any]:
  536. return asdict(report)