Add sys import to test files and remove obsolete integration tests
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s

- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api
- Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests)
- Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests)
- Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
This commit is contained in:
aitbc
2026-04-23 16:43:17 +02:00
parent b8b1454573
commit e60cc3226c
134 changed files with 14321 additions and 1873 deletions

View File

@@ -0,0 +1,186 @@
"""Edge case and error handling tests for global AI agents service"""
import pytest
import sys
import sys
from pathlib import Path
from fastapi.testclient import TestClient
from datetime import datetime, timedelta
from main import app, Agent, AgentMessage, CollaborationSession, AgentPerformance, global_agents, agent_messages, collaboration_sessions, agent_performance
@pytest.fixture(autouse=True)
def reset_state():
"""Reset global state before each test"""
global_agents.clear()
agent_messages.clear()
collaboration_sessions.clear()
agent_performance.clear()
yield
global_agents.clear()
agent_messages.clear()
collaboration_sessions.clear()
agent_performance.clear()
@pytest.mark.unit
def test_agent_empty_name():
"""Test Agent with empty name"""
agent = Agent(
agent_id="agent_123",
name="",
type="ai",
region="us-east-1",
capabilities=["trading"],
status="active",
languages=["english"],
specialization="trading",
performance_score=4.5
)
assert agent.name == ""
@pytest.mark.unit
def test_agent_negative_performance_score():
"""Test Agent with negative performance score"""
agent = Agent(
agent_id="agent_123",
name="Test Agent",
type="ai",
region="us-east-1",
capabilities=["trading"],
status="active",
languages=["english"],
specialization="trading",
performance_score=-4.5
)
assert agent.performance_score == -4.5
@pytest.mark.unit
def test_agent_performance_out_of_range_score():
"""Test AgentPerformance with out of range scores"""
performance = AgentPerformance(
agent_id="agent_123",
timestamp=datetime.utcnow(),
tasks_completed=10,
response_time_ms=50.5,
accuracy_score=2.0,
collaboration_score=2.0,
resource_usage={}
)
assert performance.accuracy_score == 2.0
assert performance.collaboration_score == 2.0
@pytest.mark.unit
def test_agent_message_empty_content():
"""Test AgentMessage with empty content"""
message = AgentMessage(
message_id="msg_123",
sender_id="agent_123",
recipient_id="agent_456",
message_type="request",
content={},
priority="high",
language="english",
timestamp=datetime.utcnow()
)
assert message.content == {}
@pytest.mark.integration
def test_list_agents_with_no_agents():
"""Test listing agents when no agents exist"""
client = TestClient(app)
response = client.get("/api/v1/agents")
assert response.status_code == 200
data = response.json()
assert data["total_agents"] == 0
@pytest.mark.integration
def test_get_agent_messages_agent_not_found():
"""Test getting messages for nonexistent agent"""
client = TestClient(app)
response = client.get("/api/v1/messages/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_get_collaboration_not_found():
"""Test getting nonexistent collaboration session"""
client = TestClient(app)
response = client.get("/api/v1/collaborations/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_send_collaboration_message_session_not_found():
"""Test sending message to nonexistent collaboration session"""
client = TestClient(app)
response = client.post("/api/v1/collaborations/nonexistent/message", params={"sender_id": "agent_123"}, json={"content": "test"})
assert response.status_code == 404
@pytest.mark.integration
def test_send_collaboration_message_sender_not_participant():
"""Test sending message from non-participant"""
client = TestClient(app)
# Register agent and create collaboration
agent = Agent(
agent_id="agent_123",
name="Agent 1",
type="ai",
region="us-east-1",
capabilities=["trading"],
status="active",
languages=["english"],
specialization="trading",
performance_score=4.5
)
client.post("/api/v1/agents/register", json=agent.model_dump())
session = CollaborationSession(
session_id="session_123",
participants=["agent_123"],
session_type="research",
objective="Research task",
created_at=datetime.utcnow(),
expires_at=datetime.utcnow() + timedelta(hours=1),
status="active"
)
client.post("/api/v1/collaborations/create", json=session.model_dump(mode='json'))
response = client.post("/api/v1/collaborations/session_123/message", params={"sender_id": "nonexistent"}, json={"content": "test"})
assert response.status_code == 400
@pytest.mark.integration
def test_get_agent_performance_agent_not_found():
"""Test getting performance for nonexistent agent"""
client = TestClient(app)
response = client.get("/api/v1/performance/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_dashboard_with_no_data():
"""Test dashboard with no data"""
client = TestClient(app)
response = client.get("/api/v1/network/dashboard")
assert response.status_code == 200
data = response.json()
assert data["dashboard"]["network_overview"]["total_agents"] == 0
@pytest.mark.integration
def test_optimize_network_with_no_agents():
"""Test network optimization with no agents"""
client = TestClient(app)
response = client.get("/api/v1/network/optimize")
assert response.status_code == 200
data = response.json()
assert "optimization_results" in data