Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a0cffe-206f-7323-89d3-b20ca4cf4bf9
54 lines
2.6 KiB
Python
54 lines
2.6 KiB
Python
"""Acceptance examples for the working metadata contract, not a corpus validator."""
|
|
from pathlib import Path
|
|
import re
|
|
|
|
import yaml
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def test_schema_examples_resolve_against_template_and_vocabulary():
|
|
vocabulary = yaml.safe_load((ROOT / "canon/vocabulary.yaml").read_text())
|
|
template = yaml.safe_load((ROOT / "templates/Pattern.md").read_text().split("---", 2)[1])
|
|
fixture = yaml.safe_load((ROOT / "research/examples/schema-contract.yaml").read_text())
|
|
assert fixture["fixture_only"] is True
|
|
records = fixture["patterns"]
|
|
ids = {p["id"] for p in records}
|
|
assert len(ids) == len(records)
|
|
sources = {s["id"]: s for s in fixture["sources"]}
|
|
assert "scale" not in template and "requires" not in template
|
|
assert template["status"] == "draft"
|
|
assert template["evidence"]["maturity"] == "hypothesis"
|
|
for record in records:
|
|
assert set(record) == set(template)
|
|
assert re.fullmatch(r"FEP-\d{4}", record["id"])
|
|
for field, vocab in (("family", "families"), ("scales", "scales")):
|
|
assert record[field] and set(record[field]) <= set(vocabulary[vocab])
|
|
assert record["status"] in vocabulary["statuses"]
|
|
assert record["evidence"]["maturity"] in vocabulary["maturities"]
|
|
forces = set(record["forces"]["improves"] + record["forces"]["worsens"])
|
|
assert len(forces) >= 2 and forces <= set(vocabulary["forces"])
|
|
evidence = {item["id"]: item for item in record["evidence"]["sources"]}
|
|
for item in evidence.values():
|
|
source = sources[item["source"]]
|
|
assert item["review"] == source["review"]
|
|
text = (ROOT / item["review"]).read_text()
|
|
assert item["locator"]
|
|
for claim in item["claims"]:
|
|
assert claim in source["claims"]
|
|
assert f"## {claim}\n" in text
|
|
for relation in record["relations"]:
|
|
assert relation["type"] in vocabulary["pattern_relations"]
|
|
assert relation["target"]["kind"] == "pattern"
|
|
assert relation["target"]["ref"] in ids
|
|
assert relation["rationale"]
|
|
assert set(relation["evidence"]) <= evidence.keys()
|
|
|
|
|
|
def test_force_document_and_serialized_vocabulary_agree():
|
|
text = (ROOT / "canon/Forces.md").read_text()
|
|
keys = re.findall(r"^- `([^`]+)` —", text, flags=re.M)
|
|
vocabulary = yaml.safe_load((ROOT / "canon/vocabulary.yaml").read_text())
|
|
assert keys == vocabulary["forces"]
|
|
assert len(keys) == len(set(keys))
|
|
assert all(re.fullmatch(r"[a-z]+(?:-[a-z]+)*", key) for key in keys)
|