mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
feat(qa): add RDNA2 coverage history snapshots and stale-branch reports.
Persists inventory snapshots between revisions and classifies ahead, behind and diverged contributor branches. Signed-off-by: Ranveer Soni <git@ranveersoni.me>
This commit is contained in:
3 files changed
+162
No files matched your search
@@ -0,0 +1,45 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Historical RDNA2 coverage snapshots for revision-to-revision reports."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import asdict
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .rdna2_plan import Inventory, coverage_diff, dumps_inventory, load_inventories, summarize_inventory
|
||||
|
||||
|
||||
def snapshot_inventory(root: Path) -> Inventory:
|
||||
return summarize_inventory(load_inventories(root))
|
||||
|
||||
|
||||
def write_snapshot(path: Path, inventory: Inventory, *, revision: str) -> None:
|
||||
payload = asdict(inventory)
|
||||
payload["revision"] = revision
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
def read_snapshot(path: Path) -> tuple[str, Inventory]:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
revision = str(data.pop("revision", "unknown"))
|
||||
inv = Inventory(
|
||||
identified=int(data["identified"]),
|
||||
declared=int(data["declared"]),
|
||||
decoder_supported=int(data["decoder_supported"]),
|
||||
reference_verified=int(data["reference_verified"]),
|
||||
metal_verified=int(data["metal_verified"]),
|
||||
unsupported=int(data["unsupported"]),
|
||||
by_family=dict(data.get("by_family", {})),
|
||||
)
|
||||
return revision, inv
|
||||
|
||||
|
||||
def historical_report(before_path: Path, after_path: Path) -> dict[str, Any]:
|
||||
before_rev, before = read_snapshot(before_path)
|
||||
after_rev, after = read_snapshot(after_path)
|
||||
diff = coverage_diff(before, after)
|
||||
diff["before_revision"] = before_rev
|
||||
diff["after_revision"] = after_rev
|
||||
return diff
|
||||
@@ -0,0 +1,66 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Stale branch and divergent history diagnostics (read-only)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import Iterable
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BranchSync:
|
||||
branch: str
|
||||
upstream: str
|
||||
ahead: int
|
||||
behind: int
|
||||
diverged: bool
|
||||
stale: bool
|
||||
detail: str
|
||||
|
||||
|
||||
def classify_sync(
|
||||
*,
|
||||
branch: str,
|
||||
upstream: str,
|
||||
ahead: int,
|
||||
behind: int,
|
||||
stale_behind_threshold: int = 1,
|
||||
) -> BranchSync:
|
||||
diverged = ahead > 0 and behind > 0
|
||||
stale = behind >= stale_behind_threshold
|
||||
if diverged:
|
||||
detail = f"diverged: ahead={ahead} behind={behind}"
|
||||
elif stale:
|
||||
detail = f"behind upstream by {behind}"
|
||||
elif ahead > 0:
|
||||
detail = f"ahead of upstream by {ahead}"
|
||||
else:
|
||||
detail = "in sync"
|
||||
return BranchSync(
|
||||
branch=branch,
|
||||
upstream=upstream,
|
||||
ahead=ahead,
|
||||
behind=behind,
|
||||
diverged=diverged,
|
||||
stale=stale,
|
||||
detail=detail,
|
||||
)
|
||||
|
||||
|
||||
def format_sync_reports(reports: Iterable[BranchSync]) -> str:
|
||||
lines = ["# Branch synchronization", ""]
|
||||
for report in reports:
|
||||
if report.diverged:
|
||||
mark = "DIVERGED"
|
||||
elif report.stale:
|
||||
mark = "STALE"
|
||||
else:
|
||||
mark = "ok"
|
||||
lines.append(
|
||||
f"- [{mark}] `{report.branch}` vs `{report.upstream}`: {report.detail}"
|
||||
)
|
||||
lines.append("")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def as_jsonable(report: BranchSync) -> dict:
|
||||
return asdict(report)
|
||||
Reference in new issue
Block a user