forked from Skull-boy/agent-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_contracts.py
More file actions
58 lines (38 loc) · 1.34 KB
/
Copy pathvalidate_contracts.py
File metadata and controls
58 lines (38 loc) · 1.34 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
from pathlib import Path
import sys
import yaml
from scyvera import validate_contract
ROOT = Path(__file__).resolve().parent.parent
SCHEMA_PATH = ROOT / "schemas" / "v1" / "contract.schema.json"
IMPLEMENTATIONS_PATH = ROOT / "implementations"
def main():
contracts = sorted(IMPLEMENTATIONS_PATH.rglob("contract.yaml"))
if not contracts:
print("No contract.yaml files found.")
return 1
failures = 0
for contract_path in contracts:
relative_path = contract_path.relative_to(ROOT)
try:
result = validate_contract(contract_path)
if result.valid:
print(f"PASS {relative_path}")
continue
print(f"FAIL {relative_path}")
for error in result.errors:
if error.path:
print(f" {error.path}: {error.message}")
else:
print(f" {error.message}")
failures += 1
except (OSError, yaml.YAMLError) as error:
print(f"FAIL {relative_path}")
print(f" {error}")
failures += 1
print()
print(f"Validated {len(contracts)} contract(s).")
print(f"Passed: {len(contracts) - failures}")
print(f"Failed: {failures}")
return 1 if failures else 0
if __name__ == "__main__":
sys.exit(main())