Files
aitbc/apps/global-ai-agents/tests/test_unit_global_ai_agents.py
aitbc d26e6d3772
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
CLI Tests / test-cli (push) Failing after 13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 3s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m34s
Documentation Validation / validate-docs (push) Failing after 10s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m42s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 3s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
P2P Network Verification / p2p-verification (push) Successful in 3s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 33s
Package Tests / Python package - aitbc-core (push) Successful in 17s
Package Tests / Python package - aitbc-crypto (push) Successful in 11s
Security Scanning / security-scan (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Successful in 13s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 9s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Staking Tests / test-staking-service (push) Failing after 6s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
fix: replace datetime.UTC with timezone.utc for Python 3.12+ compatibility
2026-05-09 12:03:26 +02:00

159 lines
4.5 KiB
Python

"""Unit tests for global AI agents service"""
import pytest
import sys
import sys
from pathlib import Path
from datetime import datetime, timezone
from main import app, Agent, AgentMessage, CollaborationSession, AgentPerformance
@pytest.mark.unit
def test_app_initialization():
"""Test that the FastAPI app initializes correctly"""
assert app is not None
assert app.title == "AITBC Global AI Agent Communication Service"
assert app.version == "1.0.0"
@pytest.mark.unit
def test_agent_model():
"""Test Agent model"""
agent = Agent(
agent_id="agent_123",
name="Test Agent",
type="ai",
region="us-east-1",
capabilities=["trading", "analysis"],
status="active",
languages=["english", "chinese"],
specialization="trading",
performance_score=4.5
)
assert agent.agent_id == "agent_123"
assert agent.name == "Test Agent"
assert agent.type == "ai"
assert agent.status == "active"
assert agent.performance_score == 4.5
@pytest.mark.unit
def test_agent_empty_capabilities():
"""Test Agent with empty capabilities"""
agent = Agent(
agent_id="agent_123",
name="Test Agent",
type="ai",
region="us-east-1",
capabilities=[],
status="active",
languages=["english"],
specialization="general",
performance_score=4.5
)
assert agent.capabilities == []
@pytest.mark.unit
def test_agent_message_model():
"""Test AgentMessage model"""
message = AgentMessage(
message_id="msg_123",
sender_id="agent_123",
recipient_id="agent_456",
message_type="request",
content={"data": "test"},
priority="high",
language="english",
timestamp=datetime.now(timezone.utc)
)
assert message.message_id == "msg_123"
assert message.sender_id == "agent_123"
assert message.recipient_id == "agent_456"
assert message.message_type == "request"
assert message.priority == "high"
@pytest.mark.unit
def test_agent_message_broadcast():
"""Test AgentMessage with None recipient (broadcast)"""
message = AgentMessage(
message_id="msg_123",
sender_id="agent_123",
recipient_id=None,
message_type="broadcast",
content={"data": "test"},
priority="medium",
language="english",
timestamp=datetime.now(timezone.utc)
)
assert message.recipient_id is None
@pytest.mark.unit
def test_collaboration_session_model():
"""Test CollaborationSession model"""
session = CollaborationSession(
session_id="session_123",
participants=["agent_123", "agent_456"],
session_type="task_force",
objective="Complete trading task",
created_at=datetime.now(timezone.utc),
expires_at=datetime.now(timezone.utc),
status="active"
)
assert session.session_id == "session_123"
assert session.participants == ["agent_123", "agent_456"]
assert session.session_type == "task_force"
@pytest.mark.unit
def test_collaboration_session_empty_participants():
"""Test CollaborationSession with empty participants"""
session = CollaborationSession(
session_id="session_123",
participants=[],
session_type="research",
objective="Research task",
created_at=datetime.now(timezone.utc),
expires_at=datetime.now(timezone.utc),
status="active"
)
assert session.participants == []
@pytest.mark.unit
def test_agent_performance_model():
"""Test AgentPerformance model"""
performance = AgentPerformance(
agent_id="agent_123",
timestamp=datetime.now(timezone.utc),
tasks_completed=10,
response_time_ms=50.5,
accuracy_score=0.95,
collaboration_score=0.9,
resource_usage={"cpu": 50.0, "memory": 60.0}
)
assert performance.agent_id == "agent_123"
assert performance.tasks_completed == 10
assert performance.response_time_ms == 50.5
assert performance.accuracy_score == 0.95
@pytest.mark.unit
def test_agent_performance_negative_values():
"""Test AgentPerformance with negative values"""
performance = AgentPerformance(
agent_id="agent_123",
timestamp=datetime.now(timezone.utc),
tasks_completed=-10,
response_time_ms=-50.5,
accuracy_score=-0.95,
collaboration_score=-0.9,
resource_usage={}
)
assert performance.tasks_completed == -10
assert performance.response_time_ms == -50.5