forked from Skull-boy/agent-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validator_v1_1.py
More file actions
119 lines (90 loc) · 3.28 KB
/
Copy pathtest_validator_v1_1.py
File metadata and controls
119 lines (90 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from pathlib import Path
import pytest
from scyvera import validate_contract, SCHEMA_V1_1_PATH
ROOT = Path(__file__).resolve().parent.parent
FIXTURES_V1_1 = ROOT / "tests" / "fixtures" / "v1.1"
def test_v1_1_minimal_valid_contract():
contract = FIXTURES_V1_1 / "valid-minimal.yaml"
result = validate_contract(contract)
assert result.valid is True
assert result.errors == ()
def test_v1_1_full_valid_contract():
contract = FIXTURES_V1_1 / "valid-full.yaml"
result = validate_contract(contract)
assert result.valid is True
assert result.errors == ()
def test_v1_1_invalid_enum_fails():
contract = FIXTURES_V1_1 / "invalid-enum.yaml"
result = validate_contract(contract)
assert result.valid is False
assert len(result.errors) >= 1
assert any("state.persistence" in err.path or "persistence" in err.message for err in result.errors)
def test_v1_1_missing_identity_fails():
contract = FIXTURES_V1_1 / "invalid-missing-identity.yaml"
result = validate_contract(contract)
assert result.valid is False
assert len(result.errors) >= 1
def test_unsupported_version_fails():
contract = FIXTURES_V1_1 / "unsupported-version.yaml"
result = validate_contract(contract)
assert result.valid is False
assert len(result.errors) == 1
assert result.errors[0].path == "version"
assert "Unsupported specification version" in result.errors[0].message
def test_v1_1_explicit_schema_path():
contract = FIXTURES_V1_1 / "valid-minimal.yaml"
result = validate_contract(contract, schema_path=SCHEMA_V1_1_PATH)
assert result.valid is True
assert result.errors == ()
def test_v1_1_system_identity(tmp_path):
f = tmp_path / "system_contract.yaml"
f.write_text(
"version: 1.1\n"
"system:\n"
" name: Test System\n"
" purpose: Testing system identity\n"
"domain: software\n",
encoding="utf-8",
)
result = validate_contract(f)
assert result.valid is True
assert result.errors == ()
def test_v1_1_agent_identity_compatibility(tmp_path):
f = tmp_path / "agent_contract.yaml"
f.write_text(
"version: 1.1\n"
"agent:\n"
" name: Test Agent\n"
" purpose: Testing agent identity alias\n",
encoding="utf-8",
)
result = validate_contract(f)
assert result.valid is True
assert result.errors == ()
def test_v1_1_workflow_identity_compatibility(tmp_path):
f = tmp_path / "workflow_contract.yaml"
f.write_text(
"version: 1.1\n"
"workflow: Test Workflow\n",
encoding="utf-8",
)
result = validate_contract(f)
assert result.valid is True
assert result.errors == ()
def test_v1_1_wildcard_permission_rejected_at_schema_level(tmp_path):
"""Calling validate_contract() directly with permissions: ['*'] fails at the JSON schema level."""
contract_file = tmp_path / "contract.yaml"
contract_file.write_text(
"""version: 1.1
system:
name: wildcard-agent
purpose: Testing schema level wildcard rejection
permissions:
- "*"
""",
encoding="utf-8",
)
result = validate_contract(contract_file)
assert result.valid is False
assert len(result.errors) > 0
assert any("permissions.0" in err.path or "permissions" in err.path for err in result.errors)