-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_arm_reviewer.py
More file actions
99 lines (78 loc) · 3.02 KB
/
Copy pathtest_arm_reviewer.py
File metadata and controls
99 lines (78 loc) · 3.02 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
#!/usr/bin/env python3
"""
Test script to demonstrate ARM reviewer functionality
"""
import asyncio
import json
import sys
import os
# Add the src directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'mcp-arm-reviewer', 'src'))
from mcp_arm_reviewer.server import ARMReviewer
async def test_arm_reviewer():
"""Test the ARM reviewer with example files"""
print("🔍 ARM Reviewer Test Suite")
print("=" * 50)
# Test 1: Analyze the example JSON file
print("\n📄 Test 1: Analyzing example OpenAPI spec...")
with open('test_example.json', 'r') as f:
content = f.read()
reviewer = ARMReviewer()
errors = reviewer.analyze_file('test_example.json', content)
print(f"Found {len(errors)} issues:")
for error in errors:
print(f" [{error.severity.upper()}] {error.code}: {error.message}")
# Test 2: Create a problematic spec to show more errors
print("\n📄 Test 2: Analyzing problematic spec...")
problematic_spec = {
"swagger": "2.0",
"info": {
"title": "Bad Example",
"version": "1.0.0", # Wrong format
"description": "Example with ARM issues"
},
"definitions": {
"BadResource": {
# Missing x-ms-azure-resource
"type": "object",
"properties": {
"name": {"type": "string"}, # Missing id, type
"badArmId": {
"type": "string",
"format": "arm-id"
# Missing x-ms-arm-id-details
}
}
}
}
}
reviewer2 = ARMReviewer()
errors2 = reviewer2.analyze_file('bad_example.json', json.dumps(problematic_spec, indent=2))
print(f"Found {len(errors2)} issues:")
for error in errors2:
print(f" [{error.severity.upper()}] {error.code}: {error.message}")
# Test 3: Create a readme with versioning issues
print("\n📄 Test 3: Analyzing readme with versioning issues...")
readme_content = """# Service API
## Tag: package-2024-01-01
``` yaml $(tag) == 'package-2024-01-01'
input-file:
- Microsoft.Example/stable/2024-01-01/example.json
- Microsoft.Example/stable/2023-12-01/other.json
- Microsoft.Example/preview/2024-02-01-preview/preview.json
```
"""
reviewer3 = ARMReviewer()
errors3 = reviewer3.analyze_file('readme.md', readme_content)
print(f"Found {len(errors3)} issues:")
for error in errors3:
print(f" [{error.severity.upper()}] {error.code}: {error.message}")
print("\n✅ ARM Reviewer test complete!")
print("\nThe ARM reviewer can detect:")
print("- Missing ARM extensions (x-ms-azure-resource, x-ms-arm-id-details)")
print("- API version format issues")
print("- Uniform versioning violations")
print("- Missing required ARM resource properties")
print("- And much more!")
if __name__ == "__main__":
asyncio.run(test_arm_reviewer())