RFC-014: Contract Governor Shared Infrastructure — 8. Testing
AIGP Specification › RFC-014: Contract Governor Shared Infrastructure › 8. Testing
← 7. Runtime Integration · Section index · 9. Summary →
8. Testing
8.1 Unit Tests (per amigo)
Each amigo tests its own contract + stipulation combination:
def test_contract_validates_against_stipulations(): """Contract MUST pass all stipulation checks.""" governor = build_governor_from_ingredients() result = governor.validate_all() assert result.valid, f"Validation failed: {result.errors}"
def test_allowed_operations_pass(): """Every allowed operation MUST validate.""" governor = build_governor_from_ingredients() for op_id in ALLOWED_OPERATIONS: result = governor.validate_operation(operation_id=op_id, payload={}) assert result.valid, f"{op_id} should be allowed"
def test_blocked_operations_rejected(): """Blocked operations MUST be rejected.""" governor = build_governor_from_ingredients() for op_id in BLOCKED_OPERATIONS: result = governor.validate_operation(operation_id=op_id, payload={}) assert not result.valid, f"{op_id} should be blocked"8.2 Cross-Amigo Version Test
A CI job validates version alignment across all four amigos:
def test_version_alignment(): """All amigos MUST pin the same contract-governor version.""" versions = set() for amigo in ["identity-service", "analytics-service", "governance-server", "runbook-service"]: req_file = f"{amigo}/docker/requirements.txt" version = extract_pinned_version(req_file, "contract-governor") versions.add(version) assert len(versions) == 1, f"Version drift detected: {versions}"8.3 Stipulation Inheritance Test
def test_base_stipulations_inherited(): """Per-amigo stipulations MUST inherit base required_fields.""" base = load_base_stipulation() for amigo in ["identity-service", "analytics-service", "governance-server", "runbook-service"]: amigo_stip = load_amigo_stipulation(amigo) for field in base["required_fields"]: assert field in amigo_stip.effective_required_fields, \ f"{amigo} missing base required field: {field}"8.4 Contract Compatibility Test
def test_contract_schema_valid(): """Each amigo's gandalf-api.yaml MUST be valid OpenAPI 3.x.""" for amigo in ["identity-service", "analytics-service", "governance-server", "runbook-service"]: contract = load_yaml(f"{amigo}/ingredients/gandalf-api.yaml") assert contract["openapi"].startswith("3."), \ f"{amigo} contract is not OpenAPI 3.x"