"""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()