Files
aitbc/apps/stubs/global-ai-agents/tests/test_unit_global_ai_agents.py
aitbc 3897bcbf24
Some checks failed
CLI Tests / test-cli (push) Failing after 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m40s
Documentation Validation / validate-docs (push) Failing after 12s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 2m42s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 34s
Package Tests / Python package - aitbc-core (push) Successful in 27s
Package Tests / Python package - aitbc-crypto (push) Successful in 13s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 18s
Python Tests / test-python (push) Failing after 50s
Security Scanning / security-scan (push) Failing after 43s
Multi-Node Stress Testing / stress-test (push) Successful in 12s
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
refactor: move version to separate module and improve logging
- Created aitbc/_version.py with centralized version definition
- Updated aitbc/__init__.py to import __version__ from _version module
- Updated constants.py to use __version__ for PACKAGE_VERSION
- Replaced print() calls with logger in decorators.py, events.py, queue_manager.py, and state.py
- Added logger initialization using get_logger(__name__) in config.py, decorators.py, events.py, queue_manager.py, and state.py
- Added cli/commands
2026-05-11 20:12:01 +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