Buckets:
squaredcuber/loss-aware-dro-repro-artifacts / bundle /v0 /presentation /tests /test_evidence_binding.py
| from __future__ import annotations | |
| import json | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| PRESENTATION = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(PRESENTATION)) | |
| from bind_verified_analysis import ( # noqa: E402 | |
| ANALYSIS_COPY, | |
| BROWSER_DATA, | |
| CLAIM_IDS, | |
| LOCK_FILE, | |
| EvidenceBindingError, | |
| verify_bound, | |
| ) | |
| from validate_package import validate # noqa: E402 | |
| def _copy_bound(tmp_path: Path) -> Path: | |
| destination = tmp_path / "presentation" | |
| destination.mkdir() | |
| for name in (ANALYSIS_COPY, BROWSER_DATA, LOCK_FILE): | |
| shutil.copy2(PRESENTATION / name, destination / name) | |
| return destination | |
| def test_ready_package_passes_and_claims_are_ordered() -> None: | |
| assert validate(require_ready=True) == "verified" | |
| payload = json.loads((PRESENTATION / ANALYSIS_COPY).read_text(encoding="utf-8")) | |
| assert list(payload["claims"]) == CLAIM_IDS | |
| assert [payload["claims"][key]["verdict"] for key in CLAIM_IDS] == [ | |
| "partially_verified", "inconclusive", "inconclusive", "inconclusive", "inconclusive", "partially_verified" | |
| ] | |
| def test_matrix_and_recovery_seal_are_exact() -> None: | |
| payload = json.loads((PRESENTATION / ANALYSIS_COPY).read_text(encoding="utf-8")) | |
| assert payload["matrix"]["validated_rows"] == 14000 | |
| assert payload["matrix"]["recovered_rows"] == 5 | |
| assert payload["matrix"]["rejected_rows"] == 0 | |
| assert payload["seal"]["aggregate_identity"] == "sha256:4b4b1ef2383fecf4baa1565e7f9fbf2bc1b300b0b55dc67ba934f2bac5cf771a" | |
| assert payload["seal"]["aggregate_results_sha256"] == "025f51a63fd75de100390b13374942cc5b57400d900b36c544777f9e67e0bd78" | |
| def test_browser_tamper_is_rejected(tmp_path: Path) -> None: | |
| destination = _copy_bound(tmp_path) | |
| path = destination / BROWSER_DATA | |
| path.write_text(path.read_text(encoding="utf-8").replace("14000", "14001", 1), encoding="utf-8") | |
| with pytest.raises(EvidenceBindingError, match="browser evidence differs"): | |
| verify_bound(destination) | |
| def test_bound_analysis_tamper_is_rejected(tmp_path: Path) -> None: | |
| destination = _copy_bound(tmp_path) | |
| path = destination / ANALYSIS_COPY | |
| payload = json.loads(path.read_text(encoding="utf-8")) | |
| payload["claims"]["A5"]["verdict"] = "verified" | |
| path.write_text(json.dumps(payload), encoding="utf-8") | |
| with pytest.raises(EvidenceBindingError, match="payload hash is invalid"): | |
| verify_bound(destination) | |
| def test_chart_values_come_from_sealed_distribution_first_points() -> None: | |
| payload = json.loads((PRESENTATION / ANALYSIS_COPY).read_text(encoding="utf-8")) | |
| coverage = payload["charts"]["coverage"] | |
| regression = payload["charts"]["regression"] | |
| assert [item["sample_size"] for item in coverage] == list(range(10, 101, 10)) | |
| assert [item["sample_size"] for item in regression] == [10, 20, 30, 40, 50] | |
| assert coverage[0]["mean"] == pytest.approx(0.752) | |
| assert coverage[-1]["upper"] == pytest.approx(0.87) | |
| assert regression[0]["mean"] == pytest.approx(0.04031158725906639) | |
| assert all(item["lower"] > 0 for item in regression) | |
| def test_copy_has_no_mojibake_or_em_dash() -> None: | |
| copy = "".join((PRESENTATION / name).read_text(encoding="utf-8") for name in ("index.html", "app.js")) | |
| assert "\u2014" not in copy | |
| assert not any(mark in copy for mark in ("Â", "Î", "Ã")) | |
Xet Storage Details
- Size:
- 3.46 kB
- Xet hash:
- 8737b425f84c35f6997eb82bac1e704a0982c8566a5b332666e84c624a09c6ec
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.