mail-address-semantics/mas_conformance/runner.py
tegwick 59815701c1 Implement MAS v0.1 reference experiment (MAS-WP-0002 M0-M8, M9 first pass)
- mas_core: P2-maximal parser with required_profile, generator, statute
  schema + semantic lint + defaults-only inheritance, exact-host discovery
  with typed failures and same-origin redirects, pure policy resolver
- mas_conformance: vendored spec fixtures (drift-tested) + property and
  statute cases
- mas CLI: parse / explain / discover / lint-statute / test
- mas-gateway: generic mail -> MAS event -> HTTP (MTA pipe + webhook)
- examples: static great-service.example statute, reference ticket service
- docs/experiment-review.md: first-pass findings; live MTA test still open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 623586@bnt-lap001
Assistant-Session: 10b30928-5b3b-4c11-9934-5ecca07367d8
2026-10-08 00:24:43 +02:00

50 lines
1.6 KiB
Python

"""Run the conformance corpus against mas_core. Used by `mas test` and pytest."""
from __future__ import annotations
from dataclasses import dataclass, field
from mas_core.parser import MasSyntaxError, parse_for_profile
from . import address_fixtures, property_fixtures
@dataclass
class Report:
passed: int = 0
failures: list = field(default_factory=list)
@property
def ok(self) -> bool:
return not self.failures
def check_address_fixture(f: dict):
"""Return None on pass, else a failure description."""
try:
got = parse_for_profile(f["local_part"], f["profile"])
except MasSyntaxError as e:
if f["valid"]:
return f"unexpected invalid ({e.code}: {e})"
if "error" in f and f["error"] != e.code and f["id"].startswith("prop-"):
return f"wrong error code: expected {f['error']}, got {e.code}"
return None
if not f["valid"]:
return f"expected invalid, parsed as {got.to_fixture_dict()}"
if got.to_fixture_dict() != f["parsed"]:
return f"parse mismatch: got {got.to_fixture_dict()}, expected {f['parsed']}"
for key in ("required_profile", "generator_allowed", "base"):
if key in f and got.to_dict()[key] != f[key]:
return f"{key} mismatch: got {got.to_dict()[key]!r}, expected {f[key]!r}"
return None
def run_parser_corpus() -> Report:
report = Report()
for f in address_fixtures() + property_fixtures():
problem = check_address_fixture(f)
if problem:
report.failures.append((f["id"], f["local_part"], problem))
else:
report.passed += 1
return report