prj-canon-federation/tools/test_interfaces.py
tegwick 49b03943c8 Complete G7 reciprocal canon interfaces and source-review evidence
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a070b5-4994-7271-bd8b-7c3dbcedec4b
2026-09-06 01:04:34 +02:00

60 lines
2.3 KiB
Python

"""Regression checks for G7 rejection paths; run beside the three canon checkouts."""
from pathlib import Path
import unittest
from unittest.mock import patch
import yaml
import jsonschema
from validate_interfaces import validate
WORKSPACE = Path(__file__).resolve().parents[2]
READ_TEXT = Path.read_text
class InterfaceGateTests(unittest.TestCase):
def reject_card(self, repo, mutate, message, error=ValueError):
suffix = 'canon/interfaces/federation.yaml' if repo == 'the-custodian' else 'infospace/interfaces/federation.yaml'
target = WORKSPACE / repo / suffix
def read(path, *args, **kwargs):
content = READ_TEXT(path, *args, **kwargs)
if path == target:
card = yaml.safe_load(content)
mutate(card)
return yaml.safe_dump(card)
return content
with patch.object(Path, 'read_text', read):
with self.assertRaisesRegex(error, message):
validate(WORKSPACE)
def test_missing_reciprocal_peer_is_rejected(self):
self.reject_card('info-tech-canon', lambda c: c['peers'].pop(), 'peer coverage')
def test_duplicate_evidence_owner_is_rejected(self):
self.reject_card('commerce-canon', lambda c: c['exports'][0]['concepts'].append('Evidence'),
'Duplicate domain owner: Evidence')
def test_family_model_promotion_is_rejected(self):
def promote(card):
entry = next(e for e in card['exports'] if e['artifact'] == 'family-area')
entry['kind'] = 'domain-model'
self.reject_card('info-tech-canon', promote, 'Family promoted')
def test_custodian_domain_claim_is_rejected(self):
self.reject_card('the-custodian', lambda c: c['exports'][0]['concepts'].append('Evidence'),
'Governance claims domain semantics')
def test_invalid_schema_shape_is_rejected(self):
self.reject_card('info-tech-canon', lambda c: c.update(consumer={'repo': 'info-tech-canon'}),
"is not of type 'string'", jsonschema.ValidationError)
def test_import_exceeding_export_is_rejected(self):
def extend(card):
card['imports'][1]['concepts'].append('Undeclared concept')
self.reject_card('commerce-canon', extend, 'Import exceeds export')
if __name__ == '__main__':
unittest.main()