Spaces:
Running
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): (none)
Deleted (gone from the repo + Dockerfile COPY set): test/test_atlas_registry_alignment.py, test/test_brainhealth_wiring.py, test/test_council_contract.py, test/test_holographic_zero_cdn.py, test/test_public_verify_routes.py, test/test_source_attestation.py, tools/readiness-harness/test_experience_contract.py
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- test/test_atlas_registry_alignment.py +0 -71
- test/test_brainhealth_wiring.py +0 -44
- test/test_council_contract.py +0 -82
- test/test_holographic_zero_cdn.py +0 -133
- test/test_public_verify_routes.py +0 -56
- test/test_source_attestation.py +0 -64
- tools/readiness-harness/test_experience_contract.py +0 -60
test/test_atlas_registry_alignment.py
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
"""Regression tests for the canonical Atlas roster and brain-trust lens."""
|
| 2 |
-
from __future__ import annotations
|
| 3 |
-
|
| 4 |
-
import re
|
| 5 |
-
import unittest
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
|
| 8 |
-
import szl3d_holographic
|
| 9 |
-
import szl_kc_atlas
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
class AtlasRegistryAlignmentTests(unittest.TestCase):
|
| 13 |
-
def setUp(self) -> None:
|
| 14 |
-
self.map = szl_kc_atlas.atlas_map(seed=42)
|
| 15 |
-
|
| 16 |
-
def test_denominator_is_the_canonical_shell_registry(self) -> None:
|
| 17 |
-
shell_ids = [row["id"] for row in szl3d_holographic.SURFACES]
|
| 18 |
-
atlas_ids = [
|
| 19 |
-
row["id"]
|
| 20 |
-
for cluster in self.map["clusters"]
|
| 21 |
-
for row in cluster["surfaces"]
|
| 22 |
-
]
|
| 23 |
-
self.assertEqual(self.map["registry"]["source"], "szl3d_holographic.SURFACES")
|
| 24 |
-
self.assertTrue(self.map["registry"]["loaded"])
|
| 25 |
-
self.assertEqual(self.map["surface_count"], len(shell_ids))
|
| 26 |
-
self.assertCountEqual(atlas_ids, shell_ids)
|
| 27 |
-
self.assertEqual(len(atlas_ids), len(set(atlas_ids)))
|
| 28 |
-
|
| 29 |
-
def test_coverage_cannot_hide_roster_drift(self) -> None:
|
| 30 |
-
self.assertEqual(self.map["coverage_denominator"], "szl3d_holographic.SURFACES")
|
| 31 |
-
self.assertEqual(self.map["total_classified"], self.map["surface_count"])
|
| 32 |
-
self.assertEqual(self.map["coverage"], 1.0)
|
| 33 |
-
self.assertEqual(self.map["orphans"], [])
|
| 34 |
-
self.assertEqual(self.map["unknown_assignments"], [])
|
| 35 |
-
self.assertEqual(self.map["double_counts"], [])
|
| 36 |
-
self.assertRegex(self.map["registry"]["sha256"], r"^[0-9a-f]{64}$")
|
| 37 |
-
|
| 38 |
-
def test_atlas_is_included_and_unclaimed_labels_stay_unspecified(self) -> None:
|
| 39 |
-
by_id = {
|
| 40 |
-
row["id"]: row
|
| 41 |
-
for cluster in self.map["clusters"]
|
| 42 |
-
for row in cluster["surfaces"]
|
| 43 |
-
}
|
| 44 |
-
self.assertIn("atlas", by_id)
|
| 45 |
-
self.assertTrue(self.map["atlas_membership"]["included_in_surface_count"])
|
| 46 |
-
self.assertEqual(by_id["atlas"]["label"], "MODELED")
|
| 47 |
-
# `circuits` was added after the embedded Wave-27 label snapshot and its canonical
|
| 48 |
-
# title makes no maturity claim. The Atlas must not silently promote it.
|
| 49 |
-
self.assertEqual(by_id["circuits"]["label"], "UNSPECIFIED")
|
| 50 |
-
|
| 51 |
-
def test_brain_lens_is_read_only_and_reproducible_in_the_surface(self) -> None:
|
| 52 |
-
js = (Path(__file__).parents[1] / "static" / "3d" / "surfaces" / "atlas.js").read_text(encoding="utf-8")
|
| 53 |
-
self.assertIn("/api/a11oy/v1/brain/health", js)
|
| 54 |
-
self.assertIn("/api/a11oy/v1/brain/gaps", js)
|
| 55 |
-
self.assertIn("brain/health?q=", js)
|
| 56 |
-
self.assertIn("brain/gaps?q=", js)
|
| 57 |
-
self.assertIn("Purpose · Try · Evidence · Limits · Reproduce", js)
|
| 58 |
-
self.assertIn("no memory write, no model call, no action", js)
|
| 59 |
-
self.assertNotRegex(js, re.compile(r"fetch\([^\n]+method\s*:\s*[\"']POST", re.I))
|
| 60 |
-
|
| 61 |
-
def test_registry_module_aliases_resolve(self) -> None:
|
| 62 |
-
surface_dir = Path(__file__).parents[1] / "static" / "3d" / "surfaces"
|
| 63 |
-
for surface in szl3d_holographic.SURFACES:
|
| 64 |
-
module_id = surface.get("module", surface["id"])
|
| 65 |
-
self.assertTrue((surface_dir / (module_id + ".js")).is_file(), surface["id"])
|
| 66 |
-
markets = next(row for row in szl3d_holographic.SURFACES if row["id"] == "markets")
|
| 67 |
-
self.assertEqual(markets["module"], "finance")
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if __name__ == "__main__":
|
| 71 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/test_brainhealth_wiring.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
import unittest
|
| 4 |
-
|
| 5 |
-
import szl_brainhealth as health
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class BrainHealthWiringTests(unittest.TestCase):
|
| 9 |
-
def test_real_sibling_entrypoints_and_call_styles_are_explicit(self) -> None:
|
| 10 |
-
specs = {row["key"]: row for row in health.COMPONENTS}
|
| 11 |
-
self.assertEqual(specs["freshness"]["funcs"], ("build_aggregate",))
|
| 12 |
-
self.assertEqual(specs["provenance"]["call_style"], "ns_q_k")
|
| 13 |
-
self.assertEqual(specs["contradiction"]["funcs"], ("run_detection",))
|
| 14 |
-
self.assertEqual(specs["uncertainty"]["funcs"], ("handle_uncertainty",))
|
| 15 |
-
|
| 16 |
-
def test_uncertainty_is_inverted_to_trust_direction(self) -> None:
|
| 17 |
-
payload = health._normalize_component_payload(
|
| 18 |
-
"uncertainty",
|
| 19 |
-
{"label": "MODELED", "verdict": "HIGHLY-UNCERTAIN", "uncertainty": 0.91, "abstain_recommended": True},
|
| 20 |
-
)
|
| 21 |
-
self.assertEqual(payload["trust_value"], 0.09)
|
| 22 |
-
self.assertTrue(payload["abstain"])
|
| 23 |
-
|
| 24 |
-
def test_descriptive_prose_does_not_create_a_false_adverse_signal(self) -> None:
|
| 25 |
-
payload = {
|
| 26 |
-
"label": "MODELED",
|
| 27 |
-
"verdict": "WEAK-GROUNDING",
|
| 28 |
-
"should_abstain": False,
|
| 29 |
-
"note": "the system abstains only when evidence is insufficient",
|
| 30 |
-
}
|
| 31 |
-
self.assertIsNone(health._detect_adverse(payload, ("ungrounded",)))
|
| 32 |
-
|
| 33 |
-
def test_freshness_uses_real_node_distribution(self) -> None:
|
| 34 |
-
payload = health._normalize_component_payload(
|
| 35 |
-
"freshness",
|
| 36 |
-
{"label": "MEASURED", "node_count": 100, "verdict_counts": {"FRESH": 5, "AGING": 15, "STALE": 80}},
|
| 37 |
-
)
|
| 38 |
-
self.assertEqual(payload["trust_value"], 0.2)
|
| 39 |
-
self.assertTrue(payload["stale_dominant"])
|
| 40 |
-
self.assertEqual(payload["verdict"], "STALE-DOMINANT")
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if __name__ == "__main__":
|
| 44 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/test_council_contract.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
import unittest
|
| 2 |
-
|
| 3 |
-
from fastapi import FastAPI
|
| 4 |
-
from fastapi.testclient import TestClient
|
| 5 |
-
|
| 6 |
-
import a11oy_ayllu as ayllu
|
| 7 |
-
import a11oy_nemo_core as nemo
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class CouncilContractTests(unittest.TestCase):
|
| 11 |
-
def _result(self):
|
| 12 |
-
return {
|
| 13 |
-
"participants": ["Amaru", "Yupaq"],
|
| 14 |
-
"mode": "single-round",
|
| 15 |
-
"rounds": [
|
| 16 |
-
{"persona": "Amaru", "round": 1, "model": "test-model",
|
| 17 |
-
"stub": False, "answer": "Architecture proposal."},
|
| 18 |
-
{"persona": "Yupaq", "round": 1, "model": "test-model",
|
| 19 |
-
"stub": False, "answer": "Evidence gap."},
|
| 20 |
-
],
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
def test_generic_nemo_route_is_governance_first(self):
|
| 24 |
-
route = nemo.govern_route("Review a high-consequence agent action", top_k=2)
|
| 25 |
-
self.assertEqual(route["experts_selected"], ["governance", "code"])
|
| 26 |
-
self.assertEqual(route["routing_evidence_state"], "HEURISTIC")
|
| 27 |
-
self.assertEqual(route["experts"][0]["selection_basis"],
|
| 28 |
-
"explicit-governance-first-fallback")
|
| 29 |
-
|
| 30 |
-
def test_contract_is_proposal_only_and_replay_is_deterministic(self):
|
| 31 |
-
routing = {"state": "HEURISTIC", "experts_selected": ["governance"]}
|
| 32 |
-
one = ayllu._build_council_contract("review this", self._result(), routing)
|
| 33 |
-
two = ayllu._build_council_contract("review this", self._result(), routing)
|
| 34 |
-
self.assertEqual(one["schema"], ayllu.COUNCIL_SCHEMA)
|
| 35 |
-
self.assertEqual(one["decision_state"], "PROPOSAL_ONLY")
|
| 36 |
-
self.assertEqual(one["semantic_consensus"]["state"], "NOT_MEASURED")
|
| 37 |
-
self.assertTrue(one["human_checkpoint"]["required"])
|
| 38 |
-
self.assertEqual(one["evidence_state"], "LIVE")
|
| 39 |
-
self.assertEqual(one["replay"]["key"], two["replay"]["key"])
|
| 40 |
-
|
| 41 |
-
def test_runtime_signer_is_preferred(self):
|
| 42 |
-
def signer(payload):
|
| 43 |
-
return {"signed": True, "payload": "encoded", "signatures": [{"sig": "x"}]}
|
| 44 |
-
|
| 45 |
-
receipt = ayllu._make_receipt({"decision": "proposal"}, sign_fn=signer)
|
| 46 |
-
self.assertTrue(receipt["signed"])
|
| 47 |
-
self.assertEqual(receipt["payload"], "encoded")
|
| 48 |
-
|
| 49 |
-
def test_manifest_discloses_no_trained_weights(self):
|
| 50 |
-
manifest = ayllu.council_manifest()
|
| 51 |
-
self.assertFalse(manifest["nemo"]["weights_present"])
|
| 52 |
-
self.assertEqual(manifest["nemo"]["training_state"], "NOT_PERFORMED")
|
| 53 |
-
self.assertEqual(manifest["limits"]["decision_state"], "PROPOSAL_ONLY")
|
| 54 |
-
|
| 55 |
-
def test_http_council_emits_signed_contract(self):
|
| 56 |
-
app = FastAPI()
|
| 57 |
-
app.state.szl_sign_receipt = lambda payload: {
|
| 58 |
-
"signed": True, "payload": "encoded", "signatures": [{"sig": "test"}]}
|
| 59 |
-
ayllu.register(app)
|
| 60 |
-
|
| 61 |
-
async def fake_complete(system, prompt, **kwargs):
|
| 62 |
-
return {"text": "bounded answer", "model": "test-model", "stub": False}
|
| 63 |
-
|
| 64 |
-
original = ayllu._backend.model_complete
|
| 65 |
-
ayllu._backend.model_complete = fake_complete
|
| 66 |
-
try:
|
| 67 |
-
response = TestClient(app).post(
|
| 68 |
-
"/api/a11oy/v1/ayllu/council",
|
| 69 |
-
json={"prompt": "Review this proposal", "personas": ["Amaru"]})
|
| 70 |
-
finally:
|
| 71 |
-
ayllu._backend.model_complete = original
|
| 72 |
-
self.assertEqual(response.status_code, 200)
|
| 73 |
-
body = response.json()
|
| 74 |
-
self.assertEqual(body["contract"]["decision_state"], "PROPOSAL_ONLY")
|
| 75 |
-
self.assertTrue(body["receipt"]["signed"])
|
| 76 |
-
self.assertEqual(body["contract"]["routing"]["state"], "HEURISTIC")
|
| 77 |
-
self.assertEqual(body["contract"]["chain"]["state"], "LIVE")
|
| 78 |
-
self.assertTrue(body["contract"]["chain"]["chain_verified"])
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
if __name__ == "__main__":
|
| 82 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/test_holographic_zero_cdn.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
| 1 |
-
"""Zero-CDN and honest same-origin evidence contract regressions."""
|
| 2 |
-
from __future__ import annotations
|
| 3 |
-
|
| 4 |
-
import hashlib
|
| 5 |
-
import unittest
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
from unittest.mock import patch
|
| 8 |
-
|
| 9 |
-
from fastapi import FastAPI
|
| 10 |
-
from fastapi.testclient import TestClient
|
| 11 |
-
|
| 12 |
-
import szl3d_holographic as holographic
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class HolographicZeroCdnTests(unittest.TestCase):
|
| 16 |
-
def _json(self, url: str):
|
| 17 |
-
if "api/models" in url:
|
| 18 |
-
return [{"downloads": 3}, {"downloads": 7}]
|
| 19 |
-
if "api/datasets" in url:
|
| 20 |
-
return [{"downloads": 11}]
|
| 21 |
-
if "api/spaces" in url:
|
| 22 |
-
return [{"likes": 5}]
|
| 23 |
-
if "api/collections" in url:
|
| 24 |
-
return [{"slug": "governed-estate"}]
|
| 25 |
-
if "api.github.com" in url:
|
| 26 |
-
return [{"stargazers_count": 2}]
|
| 27 |
-
raise AssertionError(f"unexpected test URL: {url}")
|
| 28 |
-
|
| 29 |
-
@staticmethod
|
| 30 |
-
def _health(_url: str):
|
| 31 |
-
return {"read_state": "LIVE", "health_state": "ok", "up": True}
|
| 32 |
-
|
| 33 |
-
def test_authored_3d_tree_has_no_external_runtime_fetch(self):
|
| 34 |
-
violations = list(holographic.no_cdn_violations(holographic._base_dir()))
|
| 35 |
-
self.assertEqual(violations, [])
|
| 36 |
-
brain = (Path(__file__).parents[1] / "static" / "3d" / "brain.html").read_text(encoding="utf-8")
|
| 37 |
-
self.assertIn('fetch(BRAIN_EVIDENCE', brain)
|
| 38 |
-
self.assertIn('const BRAIN_EVIDENCE = "/api/a11oy/v1/holographic/brain/evidence"', brain)
|
| 39 |
-
self.assertNotIn('fetch("https://', brain)
|
| 40 |
-
self.assertNotIn("fetch('https://", brain)
|
| 41 |
-
|
| 42 |
-
def test_complete_observation_is_live_and_measured(self):
|
| 43 |
-
formula_source = "theorem one : True := by trivial\n theorem two : True := by trivial\n"
|
| 44 |
-
payload = holographic.brain_evidence(
|
| 45 |
-
fetch_json=self._json,
|
| 46 |
-
fetch_text=lambda _url: formula_source,
|
| 47 |
-
fetch_health=self._health,
|
| 48 |
-
expected_formula_sha256=hashlib.sha256(formula_source.encode("utf-8")).hexdigest(),
|
| 49 |
-
)
|
| 50 |
-
self.assertEqual(payload["state"], "LIVE")
|
| 51 |
-
self.assertEqual(payload["live_lobes"], payload["lobe_count"])
|
| 52 |
-
self.assertEqual(payload["lobes"]["formulas"]["theorem_count"], 2)
|
| 53 |
-
self.assertEqual(payload["lobes"]["formulas"]["integrity_state"], "VERIFIED")
|
| 54 |
-
self.assertFalse(payload["lobes"]["formulas"]["mutable_reference"])
|
| 55 |
-
self.assertEqual(payload["lobes"]["models"]["downloads_sum"], 10)
|
| 56 |
-
self.assertEqual(payload["lobes"]["fleet"]["up_count"], 5)
|
| 57 |
-
self.assertFalse(payload["limits"]["cache_or_last_good_fallback"])
|
| 58 |
-
self.assertTrue(payload["limits"]["fixed_allowlist"])
|
| 59 |
-
|
| 60 |
-
def test_failed_composite_source_is_not_hidden_by_partial_count(self):
|
| 61 |
-
def partial_json(url: str):
|
| 62 |
-
if "author=zai-org" in url:
|
| 63 |
-
raise TimeoutError("test timeout")
|
| 64 |
-
return self._json(url)
|
| 65 |
-
|
| 66 |
-
formula_source = "theorem one : True := by trivial\n"
|
| 67 |
-
payload = holographic.brain_evidence(
|
| 68 |
-
fetch_json=partial_json,
|
| 69 |
-
fetch_text=lambda _url: formula_source,
|
| 70 |
-
fetch_health=self._health,
|
| 71 |
-
expected_formula_sha256=hashlib.sha256(formula_source.encode("utf-8")).hexdigest(),
|
| 72 |
-
)
|
| 73 |
-
frontier = payload["lobes"]["frontier"]
|
| 74 |
-
self.assertEqual(payload["state"], "DEGRADED")
|
| 75 |
-
self.assertEqual(frontier["state"], "UNAVAILABLE")
|
| 76 |
-
self.assertIsNone(frontier["count"])
|
| 77 |
-
failed = next(row for row in frontier["sources"] if row["org"] == "zai-org")
|
| 78 |
-
self.assertEqual(failed["reason"], "upstream_unreachable_or_timeout")
|
| 79 |
-
|
| 80 |
-
def test_formula_source_is_commit_pinned_and_hash_allowlisted(self):
|
| 81 |
-
url = holographic._BRAIN_SOURCES["formulas"]
|
| 82 |
-
self.assertIn(holographic._BRAIN_FORMULA_COMMIT, url)
|
| 83 |
-
self.assertNotIn("/main/", url)
|
| 84 |
-
self.assertEqual(len(holographic._BRAIN_FORMULA_COMMIT), 40)
|
| 85 |
-
self.assertEqual(len(holographic._BRAIN_FORMULA_SHA256), 64)
|
| 86 |
-
|
| 87 |
-
def test_formula_integrity_is_persistently_visible_not_hover_only(self):
|
| 88 |
-
brain = (Path(__file__).parents[1] / "static" / "3d" / "brain.html").read_text(encoding="utf-8")
|
| 89 |
-
self.assertIn('proof.id = "formula-attestation"', brain)
|
| 90 |
-
self.assertIn('proof.setAttribute("aria-live", "polite")', brain)
|
| 91 |
-
self.assertIn('s.source_commit', brain)
|
| 92 |
-
self.assertIn('s.content_sha256', brain)
|
| 93 |
-
self.assertIn('s.integrity_state', brain)
|
| 94 |
-
self.assertIn('setFormulaAttestation(s.attestation, "VERIFIED")', brain)
|
| 95 |
-
self.assertIn('integrity UNAVAILABLE · no theorem count trusted', brain)
|
| 96 |
-
|
| 97 |
-
def test_formula_hash_mismatch_is_unavailable_not_measured(self):
|
| 98 |
-
payload = holographic.brain_evidence(
|
| 99 |
-
fetch_json=self._json,
|
| 100 |
-
fetch_text=lambda _url: "theorem tampered : True := by trivial\n",
|
| 101 |
-
fetch_health=self._health,
|
| 102 |
-
)
|
| 103 |
-
formula = payload["lobes"]["formulas"]
|
| 104 |
-
self.assertEqual(payload["state"], "DEGRADED")
|
| 105 |
-
self.assertEqual(formula["state"], "UNAVAILABLE")
|
| 106 |
-
self.assertEqual(formula["reason"], "source_integrity_mismatch")
|
| 107 |
-
self.assertNotIn("theorem_count", formula)
|
| 108 |
-
|
| 109 |
-
def test_route_is_get_only_no_store_and_same_contract(self):
|
| 110 |
-
app = FastAPI()
|
| 111 |
-
expected = {
|
| 112 |
-
"schema": "a11oy.holographic.brain-evidence.v1",
|
| 113 |
-
"state": "UNAVAILABLE",
|
| 114 |
-
"lobes": {},
|
| 115 |
-
}
|
| 116 |
-
with patch.object(holographic, "brain_evidence", return_value=expected):
|
| 117 |
-
holographic.register(app, ns="a11oy")
|
| 118 |
-
client = TestClient(app)
|
| 119 |
-
response = client.get("/api/a11oy/v1/holographic/brain/evidence")
|
| 120 |
-
self.assertEqual(response.status_code, 200)
|
| 121 |
-
self.assertEqual(response.json(), expected)
|
| 122 |
-
self.assertEqual(response.headers["cache-control"], "no-store")
|
| 123 |
-
methods = {
|
| 124 |
-
method
|
| 125 |
-
for route in app.routes
|
| 126 |
-
if getattr(route, "path", None) == "/api/a11oy/v1/holographic/brain/evidence"
|
| 127 |
-
for method in route.methods
|
| 128 |
-
}
|
| 129 |
-
self.assertEqual(methods, {"GET"})
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
if __name__ == "__main__":
|
| 133 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/test_public_verify_routes.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
import base64
|
| 2 |
-
import json
|
| 3 |
-
import unittest
|
| 4 |
-
|
| 5 |
-
from fastapi import FastAPI
|
| 6 |
-
from fastapi.testclient import TestClient
|
| 7 |
-
|
| 8 |
-
import szl_public_verify
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
class PublicVerifyRouteTests(unittest.TestCase):
|
| 12 |
-
def setUp(self):
|
| 13 |
-
self.app = FastAPI()
|
| 14 |
-
|
| 15 |
-
@self.app.api_route("/api/a11oy/{path:path}", methods=["GET", "POST"])
|
| 16 |
-
async def proxy_catch_all(path: str):
|
| 17 |
-
return {"caught_by": "proxy", "path": path}
|
| 18 |
-
|
| 19 |
-
szl_public_verify.register(self.app, ns="a11oy")
|
| 20 |
-
self.client = TestClient(self.app)
|
| 21 |
-
|
| 22 |
-
def test_exact_routes_are_before_proxy(self):
|
| 23 |
-
paths = [getattr(route, "path", None) for route in self.app.router.routes]
|
| 24 |
-
self.assertLess(paths.index("/api/a11oy/v1/verify/receipt"),
|
| 25 |
-
paths.index("/api/a11oy/{path:path}"))
|
| 26 |
-
|
| 27 |
-
def test_get_exact_path_returns_manifest(self):
|
| 28 |
-
response = self.client.get("/api/a11oy/v1/verify/receipt")
|
| 29 |
-
self.assertEqual(response.status_code, 200)
|
| 30 |
-
self.assertEqual(response.json()["schema"],
|
| 31 |
-
"szl.public-receipt-verifier/manifest/v1")
|
| 32 |
-
|
| 33 |
-
def test_post_exact_path_reaches_verifier(self):
|
| 34 |
-
response = self.client.post("/api/a11oy/v1/verify/receipt", json={})
|
| 35 |
-
self.assertEqual(response.status_code, 400)
|
| 36 |
-
self.assertNotIn("caught_by", response.json())
|
| 37 |
-
|
| 38 |
-
def test_in_image_receipt_uses_runtime_verifier(self):
|
| 39 |
-
self.app.state.szl_verify_receipt = lambda envelope: {
|
| 40 |
-
"signature_valid": True, "detail": "verified by test runtime key"}
|
| 41 |
-
payload = base64.b64encode(json.dumps({"decision": "proposal"}).encode()).decode()
|
| 42 |
-
envelope = {
|
| 43 |
-
"payloadType": "application/vnd.szl.receipt+json",
|
| 44 |
-
"payload": payload,
|
| 45 |
-
"signatures": [{"keyid": "a11oy-inimage-ecdsa-p256", "sig": "test"}],
|
| 46 |
-
}
|
| 47 |
-
response = self.client.post("/api/a11oy/v1/verify/receipt",
|
| 48 |
-
json={"envelope": envelope})
|
| 49 |
-
self.assertEqual(response.status_code, 200)
|
| 50 |
-
signature = response.json()["checks"][0]
|
| 51 |
-
self.assertEqual(signature["status"], "VERIFIED")
|
| 52 |
-
self.assertEqual(signature["verify_key_url"], "/cosign.pub")
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
if __name__ == "__main__":
|
| 56 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/test_source_attestation.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import unittest
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
from unittest.mock import patch
|
| 5 |
-
|
| 6 |
-
from fastapi import FastAPI
|
| 7 |
-
from fastapi.responses import HTMLResponse
|
| 8 |
-
from fastapi.testclient import TestClient
|
| 9 |
-
|
| 10 |
-
import szl_source_attestation as source
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
-
SOURCE_OBSERVATION = {
|
| 15 |
-
"repository": "szl-holdings/a11oy",
|
| 16 |
-
"commit": "adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 17 |
-
"path": "",
|
| 18 |
-
"relation": "declared-source-with-hf-overlay",
|
| 19 |
-
"state": "VERIFIED_REFERENCE",
|
| 20 |
-
"evidence_url": "https://github.com/szl-holdings/a11oy/commit/adac37574f88a30ff099f3ec7f548685d4166e6f",
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class SourceAttestationTests(unittest.TestCase):
|
| 25 |
-
def setUp(self):
|
| 26 |
-
self.app = FastAPI()
|
| 27 |
-
|
| 28 |
-
@self.app.get("/{full_path:path}")
|
| 29 |
-
async def spa_fallback(full_path: str): # noqa: ARG001
|
| 30 |
-
return HTMLResponse("<html>SPA</html>")
|
| 31 |
-
|
| 32 |
-
source.register(
|
| 33 |
-
self.app,
|
| 34 |
-
"SZLHOLDINGS/a11oy",
|
| 35 |
-
SOURCE_OBSERVATION,
|
| 36 |
-
"PENDING_GITHUB_SYNC",
|
| 37 |
-
)
|
| 38 |
-
self.client = TestClient(self.app)
|
| 39 |
-
|
| 40 |
-
def test_exact_route_precedes_spa_and_returns_bounded_json(self):
|
| 41 |
-
paths = [getattr(route, "path", None) for route in self.app.router.routes]
|
| 42 |
-
self.assertLess(paths.index("/.well-known/szl-source.json"), paths.index("/{full_path:path}"))
|
| 43 |
-
with patch.dict(os.environ, {"SPACE_REPOSITORY_COMMIT": "a" * 40}):
|
| 44 |
-
response = self.client.get("/.well-known/szl-source.json")
|
| 45 |
-
self.assertEqual(200, response.status_code)
|
| 46 |
-
self.assertEqual("application/json", response.headers["content-type"])
|
| 47 |
-
self.assertEqual("no-store", response.headers["cache-control"])
|
| 48 |
-
self.assertEqual("COMPUTED", response.headers["x-szl-evidence-state"])
|
| 49 |
-
self.assertEqual("STRUCTURAL_ONLY", response.headers["x-szl-verification-state"])
|
| 50 |
-
self.assertEqual("READ_ONLY", response.headers["x-szl-authority-state"])
|
| 51 |
-
body = response.json()
|
| 52 |
-
self.assertEqual("a" * 40, body["deployment"]["hf_revision"])
|
| 53 |
-
self.assertEqual("PENDING_GITHUB_SYNC", body["alignment_state"])
|
| 54 |
-
self.assertEqual("VERIFIED_REFERENCE", body["source"]["state"])
|
| 55 |
-
for claim in ("github_parity", "reproducible_build", "build_provenance"):
|
| 56 |
-
self.assertEqual("NOT_CLAIMED", body["claims"][claim])
|
| 57 |
-
|
| 58 |
-
def test_docker_runtime_includes_module(self):
|
| 59 |
-
dockerfile = (ROOT / "Dockerfile").read_text(encoding="utf-8")
|
| 60 |
-
self.assertIn("szl_source_attestation.py", dockerfile)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools/readiness-harness/test_experience_contract.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
"""Static regression checks for the A11OY experience/data-contract first wave."""
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
import json
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
import unittest
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
class ExperienceContractTests(unittest.TestCase):
|
| 14 |
-
@classmethod
|
| 15 |
-
def setUpClass(cls) -> None:
|
| 16 |
-
cls.matrix = json.loads((ROOT / "tools/readiness-harness/tabs.json").read_text(encoding="utf-8"))
|
| 17 |
-
cls.landing = (ROOT / "a11oy_landing.html").read_text(encoding="utf-8")
|
| 18 |
-
cls.console = (ROOT / "pages/console.html").read_text(encoding="utf-8")
|
| 19 |
-
cls.server = (ROOT / "serve.py").read_text(encoding="utf-8")
|
| 20 |
-
cls.dockerfile = (ROOT / "Dockerfile").read_text(encoding="utf-8")
|
| 21 |
-
|
| 22 |
-
def test_matrix_is_publicly_shipped(self) -> None:
|
| 23 |
-
self.assertIn(
|
| 24 |
-
"COPY tools/readiness-harness/tabs.json ./tools/readiness-harness/tabs.json",
|
| 25 |
-
self.dockerfile,
|
| 26 |
-
)
|
| 27 |
-
self.assertEqual(self.matrix["version"], "1.1")
|
| 28 |
-
self.assertEqual(set(self.matrix["stateVocabulary"]), {
|
| 29 |
-
"LIVE", "MEASURED", "MODELED", "SNAPSHOT", "SAMPLE", "CACHED", "UNAVAILABLE",
|
| 30 |
-
})
|
| 31 |
-
|
| 32 |
-
def test_endpoint_methods_match_console_calls(self) -> None:
|
| 33 |
-
endpoints = self.matrix["endpoints"]
|
| 34 |
-
self.assertEqual(endpoints["/api/a11oy/v1/policy/compliance"]["method"], "POST")
|
| 35 |
-
self.assertEqual(endpoints["/api/a11oy/v1/operator/recommend"]["method"], "GET")
|
| 36 |
-
self.assertIn("orgPost('core','/api/a11oy/v1/policy/compliance'", self.console)
|
| 37 |
-
self.assertIn("orgGet('core','/api/a11oy/v1/operator/recommend'", self.console)
|
| 38 |
-
|
| 39 |
-
def test_readiness_endpoint_has_compact_honest_state(self) -> None:
|
| 40 |
-
self.assertIn('view: str = "full"', self.server)
|
| 41 |
-
self.assertIn('"X-A11OY-Data-State": "SNAPSHOT"', self.server)
|
| 42 |
-
self.assertIn('"X-A11OY-Transport-State": "REACHABLE"', self.server)
|
| 43 |
-
self.assertIn('"X-A11OY-Data-State": "UNAVAILABLE"', self.server)
|
| 44 |
-
self.assertIn('matrix if view != "summary" else None', self.server)
|
| 45 |
-
|
| 46 |
-
def test_landing_has_accessible_live_pulse(self) -> None:
|
| 47 |
-
self.assertIn('class="skip-link" href="#main"', self.landing)
|
| 48 |
-
self.assertIn('id="estate-pulse"', self.landing)
|
| 49 |
-
self.assertIn('/readiness/tab-matrix?view=summary', self.landing)
|
| 50 |
-
self.assertNotIn('href="/warhacker"', self.landing)
|
| 51 |
-
|
| 52 |
-
def test_console_navigation_is_keyboard_native_and_runtime_checked(self) -> None:
|
| 53 |
-
self.assertIn("document.createElement('button')", self.console)
|
| 54 |
-
self.assertIn('id="runtime-status" role="status" aria-live="polite"', self.console)
|
| 55 |
-
self.assertIn('class="skip-link" href="#content"', self.console)
|
| 56 |
-
self.assertNotIn('<span class="live"><span class="live-dot"></span>LIVE</span>', self.console)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
if __name__ == "__main__":
|
| 60 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|