mirror of
https://github.com/Such-Software/adaptive-multi-protocol-browser.git
synced 2026-10-17 14:31:46 +02:00
Show route metadata in fixture checks
This commit is contained in:
@@ -185,6 +185,8 @@ def _cmd_fixture(args) -> int:
|
|||||||
"AMPBROWSER_FIXTURE "
|
"AMPBROWSER_FIXTURE "
|
||||||
f"site={check.site_id} "
|
f"site={check.site_id} "
|
||||||
f"protocol={check.protocol} "
|
f"protocol={check.protocol} "
|
||||||
|
f"route_match={check.route_match} "
|
||||||
|
f"fixture_path={check.fixture_path} "
|
||||||
f"url={check.url} "
|
f"url={check.url} "
|
||||||
f"expected_transport={check.expected_transport} "
|
f"expected_transport={check.expected_transport} "
|
||||||
f"actual_transport={check.actual_transport} "
|
f"actual_transport={check.actual_transport} "
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ SUPPORTED_SCHEMAS = {"ampg.fixture-manifest.v1"}
|
|||||||
class FixtureCheck:
|
class FixtureCheck:
|
||||||
site_id: str
|
site_id: str
|
||||||
protocol: str
|
protocol: str
|
||||||
|
route_match: str
|
||||||
|
fixture_path: str
|
||||||
url: str
|
url: str
|
||||||
expected_transport: str
|
expected_transport: str
|
||||||
actual_transport: str
|
actual_transport: str
|
||||||
@@ -77,6 +79,7 @@ def _check_fixture(site_id: str, fixture: Any, path: Path) -> FixtureCheck:
|
|||||||
expected_transport = _string(checks, "transport")
|
expected_transport = _string(checks, "transport")
|
||||||
expected_profile = _string(checks, "profile")
|
expected_profile = _string(checks, "profile")
|
||||||
interaction = _interaction_policy(fixture)
|
interaction = _interaction_policy(fixture)
|
||||||
|
route_metadata = _route_metadata(fixture)
|
||||||
|
|
||||||
route = route_url(url)
|
route = route_url(url)
|
||||||
failures: list[str] = []
|
failures: list[str] = []
|
||||||
@@ -98,6 +101,8 @@ def _check_fixture(site_id: str, fixture: Any, path: Path) -> FixtureCheck:
|
|||||||
return FixtureCheck(
|
return FixtureCheck(
|
||||||
site_id=site_id,
|
site_id=site_id,
|
||||||
protocol=protocol,
|
protocol=protocol,
|
||||||
|
route_match=route_metadata["match"],
|
||||||
|
fixture_path=route_metadata["fixture_path"],
|
||||||
url=route.normalized,
|
url=route.normalized,
|
||||||
expected_transport=expected_transport,
|
expected_transport=expected_transport,
|
||||||
actual_transport=route.transport,
|
actual_transport=route.transport,
|
||||||
@@ -140,6 +145,16 @@ def _interaction_policy(fixture: dict[str, Any]) -> dict[str, Any]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _route_metadata(fixture: dict[str, Any]) -> dict[str, str]:
|
||||||
|
raw = fixture.get("route", {})
|
||||||
|
if not isinstance(raw, dict):
|
||||||
|
raise ValueError(f"{fixture.get('protocol', 'fixture')}: route must be a table")
|
||||||
|
return {
|
||||||
|
"match": _optional_string(raw, "match", "/"),
|
||||||
|
"fixture_path": _optional_string(raw, "fixture_path", "/"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _optional_string(data: dict[str, Any], key: str, default: str) -> str:
|
def _optional_string(data: dict[str, Any], key: str, default: str) -> str:
|
||||||
value = data.get(key, default)
|
value = data.get(key, default)
|
||||||
if not isinstance(value, str) or not value:
|
if not isinstance(value, str) or not value:
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ AMPB can check AMPG fixture manifests without contacting any network. The check
|
|||||||
that each generated fixture URL routes to the expected AMPB transport and profile, and
|
that each generated fixture URL routes to the expected AMPB transport and profile, and
|
||||||
that its declared interaction policy fits that transport.
|
that its declared interaction policy fits that transport.
|
||||||
|
|
||||||
|
Route-expanded fixtures may include `route.match` and `route.fixture_path`, which identify
|
||||||
|
the route group that produced the fixture.
|
||||||
|
|
||||||
## Command
|
## Command
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class FixtureCheckTest(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"protocol": "ipfs",
|
"protocol": "ipfs",
|
||||||
"url": "ipfs://bafyexample",
|
"url": "ipfs://bafyexample",
|
||||||
|
"route": {"match": "/snapshot/*", "fixture_path": "/snapshot/"},
|
||||||
"checks": {"transport": "ipfs", "profile": "ipfs"},
|
"checks": {"transport": "ipfs", "profile": "ipfs"},
|
||||||
"interaction": {"tier": "static"},
|
"interaction": {"tier": "static"},
|
||||||
},
|
},
|
||||||
@@ -44,6 +45,8 @@ class FixtureCheckTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertTrue(result.ok)
|
self.assertTrue(result.ok)
|
||||||
self.assertEqual(3, len(result.checks))
|
self.assertEqual(3, len(result.checks))
|
||||||
|
self.assertEqual("/snapshot/*", result.checks[2].route_match)
|
||||||
|
self.assertEqual("/snapshot/", result.checks[2].fixture_path)
|
||||||
|
|
||||||
def test_reports_route_mismatch(self) -> None:
|
def test_reports_route_mismatch(self) -> None:
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
|||||||
Reference in New Issue
Block a user