-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_integration.py
More file actions
310 lines (268 loc) · 10.8 KB
/
test_integration.py
File metadata and controls
310 lines (268 loc) · 10.8 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env python3
"""
Integration test script to verify IATP v0.2.0 functionality
"""
import sys
import subprocess
import time
import httpx
import asyncio
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
class TestRunner:
def __init__(self):
self.processes = []
self.passed = 0
self.failed = 0
def log(self, msg, level="INFO"):
prefix = {
"INFO": "ℹ️ ",
"SUCCESS": "✅",
"ERROR": "❌",
"WARN": "⚠️ "
}.get(level, " ")
print(f"{prefix} {msg}")
def test_imports(self):
"""Test that all modules import correctly"""
self.log("Testing imports...", "INFO")
try:
from iatp.models import (
CapabilityManifest,
TrustLevel,
AgentCapabilities,
ReversibilityLevel,
PrivacyContract,
RetentionPolicy
)
from iatp.sidecar import create_sidecar
from iatp.security import SecurityValidator
from iatp.telemetry import FlightRecorder
self.log("All imports successful", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Import failed: {e}", "ERROR")
self.failed += 1
return False
def test_manifest_creation(self):
"""Test creating a capability manifest"""
self.log("Testing manifest creation...", "INFO")
try:
from iatp.models import (
CapabilityManifest,
TrustLevel,
AgentCapabilities,
ReversibilityLevel,
PrivacyContract,
RetentionPolicy
)
manifest = CapabilityManifest(
agent_id="test-agent",
trust_level=TrustLevel.TRUSTED,
capabilities=AgentCapabilities(
reversibility=ReversibilityLevel.FULL,
idempotency=True,
sla_latency="2000ms",
rate_limit=100
),
privacy_contract=PrivacyContract(
retention=RetentionPolicy.EPHEMERAL,
human_review=False
)
)
assert manifest.agent_id == "test-agent"
assert manifest.trust_level == TrustLevel.TRUSTED
self.log("Manifest creation successful", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Manifest creation failed: {e}", "ERROR")
self.failed += 1
return False
def test_trust_score(self):
"""Test trust score calculation"""
self.log("Testing trust score calculation...", "INFO")
try:
from iatp.models import (
CapabilityManifest,
TrustLevel,
AgentCapabilities,
ReversibilityLevel,
PrivacyContract,
RetentionPolicy
)
# High trust agent
high_trust = CapabilityManifest(
agent_id="high-trust",
trust_level=TrustLevel.VERIFIED_PARTNER,
capabilities=AgentCapabilities(
reversibility=ReversibilityLevel.FULL,
idempotency=True
),
privacy_contract=PrivacyContract(
retention=RetentionPolicy.EPHEMERAL,
human_review=False
)
)
score = high_trust.calculate_trust_score()
assert score >= 10, f"Expected score >= 10, got {score}"
# Low trust agent
low_trust = CapabilityManifest(
agent_id="low-trust",
trust_level=TrustLevel.UNTRUSTED,
capabilities=AgentCapabilities(
reversibility=ReversibilityLevel.NONE,
idempotency=False
),
privacy_contract=PrivacyContract(
retention=RetentionPolicy.PERMANENT,
human_review=True
)
)
score = low_trust.calculate_trust_score()
assert score <= 2, f"Expected score <= 2, got {score}"
self.log(f"Trust score calculation correct (high: {high_trust.calculate_trust_score()}, low: {low_trust.calculate_trust_score()})", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Trust score calculation failed: {e}", "ERROR")
self.failed += 1
return False
def test_sensitive_data_detection(self):
"""Test sensitive data detection"""
self.log("Testing sensitive data detection...", "INFO")
try:
from iatp.security import SecurityValidator
validator = SecurityValidator()
# Test credit card detection
cc_data = {"payment": "4532-0151-1283-0366"}
result = validator.detect_sensitive_data(cc_data)
assert "credit_card" in result, "Credit card not detected"
# Test SSN detection
ssn_data = {"ssn": "123-45-6789"}
result = validator.detect_sensitive_data(ssn_data)
assert "ssn" in result, "SSN not detected"
# Test clean data
clean_data = {"message": "Hello world"}
result = validator.detect_sensitive_data(clean_data)
assert "credit_card" not in result and "ssn" not in result, "False positive detected"
self.log("Sensitive data detection working correctly", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Sensitive data detection failed: {e}", "ERROR")
self.failed += 1
return False
def test_go_sidecar_files(self):
"""Test that Go sidecar files exist"""
self.log("Testing Go sidecar files...", "INFO")
try:
go_files = [
project_root / "sidecar" / "go" / "main.go",
project_root / "sidecar" / "go" / "go.mod",
project_root / "sidecar" / "go" / "Dockerfile",
project_root / "sidecar" / "go" / "README.md",
]
for file in go_files:
assert file.exists(), f"Missing: {file}"
self.log("All Go sidecar files present", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Go sidecar files check failed: {e}", "ERROR")
self.failed += 1
return False
def test_experiment_files(self):
"""Test that experiment files exist"""
self.log("Testing experiment files...", "INFO")
try:
exp_files = [
project_root / "experiments" / "cascading_hallucination" / "agent_a_user.py",
project_root / "experiments" / "cascading_hallucination" / "agent_b_summarizer.py",
project_root / "experiments" / "cascading_hallucination" / "agent_c_database.py",
project_root / "experiments" / "cascading_hallucination" / "sidecar_c.py",
project_root / "experiments" / "cascading_hallucination" / "run_experiment.py",
project_root / "experiments" / "cascading_hallucination" / "README.md",
]
for file in exp_files:
assert file.exists(), f"Missing: {file}"
self.log("All experiment files present", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Experiment files check failed: {e}", "ERROR")
self.failed += 1
return False
def test_docker_files(self):
"""Test that Docker files exist"""
self.log("Testing Docker files...", "INFO")
try:
docker_files = [
project_root / "docker-compose.yml",
project_root / "docker" / "Dockerfile.agent",
project_root / "docker" / "Dockerfile.sidecar-python",
project_root / "docker" / "README.md",
]
for file in docker_files:
assert file.exists(), f"Missing: {file}"
self.log("All Docker files present", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Docker files check failed: {e}", "ERROR")
self.failed += 1
return False
def test_distribution_files(self):
"""Test that distribution files exist"""
self.log("Testing distribution files...", "INFO")
try:
dist_files = [
project_root / "setup.py",
project_root / "MANIFEST.in",
project_root / "CHANGELOG.md",
project_root / "BLOG.md",
project_root / "RFC_SUBMISSION.md",
]
for file in dist_files:
assert file.exists(), f"Missing: {file}"
# Check setup.py version
with open(project_root / "setup.py") as f:
content = f.read()
assert "0.2.0" in content, "Version not updated in setup.py"
self.log("All distribution files present", "SUCCESS")
self.passed += 1
return True
except Exception as e:
self.log(f"Distribution files check failed: {e}", "ERROR")
self.failed += 1
return False
def run_all_tests(self):
"""Run all tests"""
print("\n" + "="*60)
print("IATP v0.2.0 Integration Tests")
print("="*60 + "\n")
# Run tests
self.test_imports()
self.test_manifest_creation()
self.test_trust_score()
self.test_sensitive_data_detection()
self.test_go_sidecar_files()
self.test_experiment_files()
self.test_docker_files()
self.test_distribution_files()
# Summary
print("\n" + "="*60)
print(f"Test Results: {self.passed} passed, {self.failed} failed")
print("="*60 + "\n")
if self.failed == 0:
print("✅ All tests passed! IATP v0.2.0 is ready.")
return 0
else:
print(f"❌ {self.failed} test(s) failed. Please review.")
return 1
if __name__ == "__main__":
runner = TestRunner()
exit_code = runner.run_all_tests()
sys.exit(exit_code)