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 @@
"""Global infrastructure service tests"""

View File

@@ -0,0 +1,195 @@
"""Edge case and error handling tests for global infrastructure service"""
import pytest
import sys
import sys
from pathlib import Path
from fastapi.testclient import TestClient
from datetime import datetime
from main import app, Region, GlobalDeployment, LoadBalancer, PerformanceMetrics, global_regions, deployments, load_balancers, performance_metrics
@pytest.fixture(autouse=True)
def reset_state():
"""Reset global state before each test"""
global_regions.clear()
deployments.clear()
load_balancers.clear()
performance_metrics.clear()
yield
global_regions.clear()
deployments.clear()
load_balancers.clear()
performance_metrics.clear()
@pytest.mark.unit
def test_region_negative_capacity():
"""Test Region with negative capacity"""
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=-1000,
current_load=-500,
latency_ms=-50,
compliance_level="full"
)
assert region.capacity == -1000
assert region.current_load == -500
@pytest.mark.unit
def test_region_empty_name():
"""Test Region with empty name"""
region = Region(
region_id="us-west-1",
name="",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
assert region.name == ""
@pytest.mark.unit
def test_deployment_empty_target_regions():
"""Test GlobalDeployment with empty target regions"""
deployment = GlobalDeployment(
deployment_id="deploy_123",
service_name="test-service",
target_regions=[],
configuration={},
deployment_strategy="blue_green",
health_checks=[]
)
assert deployment.target_regions == []
@pytest.mark.unit
def test_load_balancer_negative_health_check_interval():
"""Test LoadBalancer with negative health check interval"""
balancer = LoadBalancer(
balancer_id="lb_123",
name="Main LB",
algorithm="round_robin",
target_regions=["us-east-1"],
health_check_interval=-30,
failover_threshold=3
)
assert balancer.health_check_interval == -30
@pytest.mark.unit
def test_performance_metrics_negative_values():
"""Test PerformanceMetrics with negative values"""
metrics = PerformanceMetrics(
region_id="us-east-1",
timestamp=datetime.utcnow(),
cpu_usage=-50.5,
memory_usage=-60.2,
network_io=-1000.5,
disk_io=-500.3,
active_connections=-100,
response_time_ms=-45.2
)
assert metrics.cpu_usage == -50.5
assert metrics.active_connections == -100
@pytest.mark.integration
def test_list_regions_with_no_regions():
"""Test listing regions when no regions exist"""
client = TestClient(app)
response = client.get("/api/v1/regions")
assert response.status_code == 200
data = response.json()
assert data["total_regions"] == 0
@pytest.mark.integration
def test_list_deployments_with_no_deployments():
"""Test listing deployments when no deployments exist"""
client = TestClient(app)
response = client.get("/api/v1/deployments")
assert response.status_code == 200
data = response.json()
assert data["total_deployments"] == 0
@pytest.mark.integration
def test_list_load_balancers_with_no_balancers():
"""Test listing load balancers when no balancers exist"""
client = TestClient(app)
response = client.get("/api/v1/load-balancers")
assert response.status_code == 200
data = response.json()
assert data["total_balancers"] == 0
@pytest.mark.integration
def test_get_deployment_not_found():
"""Test getting nonexistent deployment"""
client = TestClient(app)
response = client.get("/api/v1/deployments/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_get_region_performance_no_data():
"""Test getting region performance when no data exists"""
client = TestClient(app)
response = client.get("/api/v1/performance/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_get_region_compliance_nonexistent():
"""Test getting compliance for nonexistent region"""
client = TestClient(app)
response = client.get("/api/v1/compliance/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_create_load_balancer_nonexistent_region():
"""Test creating load balancer with nonexistent region"""
client = TestClient(app)
balancer = LoadBalancer(
balancer_id="lb_123",
name="Main LB",
algorithm="round_robin",
target_regions=["nonexistent"],
health_check_interval=30,
failover_threshold=3
)
response = client.post("/api/v1/load-balancers/create", json=balancer.model_dump())
assert response.status_code == 400
@pytest.mark.integration
def test_list_deployments_with_status_filter():
"""Test listing deployments with status filter"""
client = TestClient(app)
response = client.get("/api/v1/deployments?status=pending")
assert response.status_code == 200
data = response.json()
assert "status_filter" in data
@pytest.mark.integration
def test_global_dashboard_with_no_data():
"""Test global dashboard with no data"""
client = TestClient(app)
response = client.get("/api/v1/global/dashboard")
assert response.status_code == 200
data = response.json()
assert data["dashboard"]["infrastructure"]["total_regions"] == 0

View File

@@ -0,0 +1,353 @@
"""Integration tests for global infrastructure service"""
import pytest
import sys
import sys
from pathlib import Path
from fastapi.testclient import TestClient
from datetime import datetime
from main import app, Region, GlobalDeployment, LoadBalancer, PerformanceMetrics, global_regions, deployments, load_balancers, performance_metrics
@pytest.fixture(autouse=True)
def reset_state():
"""Reset global state before each test"""
global_regions.clear()
deployments.clear()
load_balancers.clear()
performance_metrics.clear()
yield
global_regions.clear()
deployments.clear()
load_balancers.clear()
performance_metrics.clear()
@pytest.mark.integration
def test_root_endpoint():
"""Test root endpoint"""
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["service"] == "AITBC Global Infrastructure Service"
assert data["status"] == "running"
@pytest.mark.integration
def test_health_check_endpoint():
"""Test health check endpoint"""
client = TestClient(app)
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "total_regions" in data
assert "active_regions" in data
@pytest.mark.integration
def test_register_region():
"""Test registering a new region"""
client = TestClient(app)
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
response = client.post("/api/v1/regions/register", json=region.model_dump())
assert response.status_code == 200
data = response.json()
assert data["region_id"] == "us-west-1"
assert data["status"] == "registered"
@pytest.mark.integration
def test_register_duplicate_region():
"""Test registering duplicate region"""
client = TestClient(app)
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
response = client.post("/api/v1/regions/register", json=region.model_dump())
assert response.status_code == 400
@pytest.mark.integration
def test_list_regions():
"""Test listing all regions"""
client = TestClient(app)
response = client.get("/api/v1/regions")
assert response.status_code == 200
data = response.json()
assert "regions" in data
assert "total_regions" in data
@pytest.mark.integration
def test_get_region():
"""Test getting specific region"""
client = TestClient(app)
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
response = client.get("/api/v1/regions/us-west-1")
assert response.status_code == 200
data = response.json()
assert data["region_id"] == "us-west-1"
@pytest.mark.integration
def test_get_region_not_found():
"""Test getting nonexistent region"""
client = TestClient(app)
response = client.get("/api/v1/regions/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_create_deployment():
"""Test creating a deployment"""
client = TestClient(app)
# Register region first
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
deployment = GlobalDeployment(
deployment_id="deploy_123",
service_name="test-service",
target_regions=["us-west-1"],
configuration={"replicas": 3},
deployment_strategy="blue_green",
health_checks=["/health"]
)
response = client.post("/api/v1/deployments/create", json=deployment.model_dump())
assert response.status_code == 200
data = response.json()
assert data["deployment_id"]
assert data["status"] == "pending"
@pytest.mark.integration
def test_create_deployment_nonexistent_region():
"""Test creating deployment with nonexistent region"""
client = TestClient(app)
deployment = GlobalDeployment(
deployment_id="deploy_123",
service_name="test-service",
target_regions=["nonexistent"],
configuration={"replicas": 3},
deployment_strategy="blue_green",
health_checks=["/health"]
)
response = client.post("/api/v1/deployments/create", json=deployment.model_dump())
assert response.status_code == 400
@pytest.mark.integration
def test_get_deployment():
"""Test getting deployment details"""
client = TestClient(app)
# Register region first
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
deployment = GlobalDeployment(
deployment_id="deploy_123",
service_name="test-service",
target_regions=["us-west-1"],
configuration={"replicas": 3},
deployment_strategy="blue_green",
health_checks=["/health"]
)
create_response = client.post("/api/v1/deployments/create", json=deployment.model_dump())
deployment_id = create_response.json()["deployment_id"]
response = client.get(f"/api/v1/deployments/{deployment_id}")
assert response.status_code == 200
data = response.json()
assert data["deployment_id"] == deployment_id
@pytest.mark.integration
def test_list_deployments():
"""Test listing all deployments"""
client = TestClient(app)
response = client.get("/api/v1/deployments")
assert response.status_code == 200
data = response.json()
assert "deployments" in data
assert "total_deployments" in data
@pytest.mark.integration
def test_create_load_balancer():
"""Test creating a load balancer"""
client = TestClient(app)
# Register region first
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
balancer = LoadBalancer(
balancer_id="lb_123",
name="Main LB",
algorithm="round_robin",
target_regions=["us-west-1"],
health_check_interval=30,
failover_threshold=3
)
response = client.post("/api/v1/load-balancers/create", json=balancer.model_dump())
assert response.status_code == 200
data = response.json()
assert data["balancer_id"]
assert data["status"] == "active"
@pytest.mark.integration
def test_list_load_balancers():
"""Test listing all load balancers"""
client = TestClient(app)
response = client.get("/api/v1/load-balancers")
assert response.status_code == 200
data = response.json()
assert "load_balancers" in data
assert "total_balancers" in data
@pytest.mark.integration
def test_record_performance_metrics():
"""Test recording performance metrics"""
client = TestClient(app)
metrics = PerformanceMetrics(
region_id="us-west-1",
timestamp=datetime.utcnow(),
cpu_usage=50.5,
memory_usage=60.2,
network_io=1000.5,
disk_io=500.3,
active_connections=100,
response_time_ms=45.2
)
response = client.post("/api/v1/performance/metrics", json=metrics.model_dump(mode='json'))
assert response.status_code == 200
data = response.json()
assert data["metrics_id"]
assert data["status"] == "recorded"
@pytest.mark.integration
def test_get_region_performance():
"""Test getting region performance metrics"""
client = TestClient(app)
# Record metrics first
metrics = PerformanceMetrics(
region_id="us-west-1",
timestamp=datetime.utcnow(),
cpu_usage=50.5,
memory_usage=60.2,
network_io=1000.5,
disk_io=500.3,
active_connections=100,
response_time_ms=45.2
)
client.post("/api/v1/performance/metrics", json=metrics.model_dump(mode='json'))
response = client.get("/api/v1/performance/us-west-1")
assert response.status_code == 200
data = response.json()
assert data["region_id"] == "us-west-1"
assert "statistics" in data
@pytest.mark.integration
def test_get_region_compliance():
"""Test getting region compliance information"""
client = TestClient(app)
# Register region first
region = Region(
region_id="us-west-1",
name="US West",
location="North America",
endpoint="https://us-west-1.api.aitbc.dev",
status="active",
capacity=8000,
current_load=2000,
latency_ms=50,
compliance_level="full"
)
client.post("/api/v1/regions/register", json=region.model_dump())
response = client.get("/api/v1/compliance/us-west-1")
assert response.status_code == 200
data = response.json()
assert data["region_id"] == "us-west-1"
assert "compliance_level" in data
@pytest.mark.integration
def test_get_global_dashboard():
"""Test getting global dashboard"""
client = TestClient(app)
response = client.get("/api/v1/global/dashboard")
assert response.status_code == 200
data = response.json()
assert "dashboard" in data
assert "infrastructure" in data["dashboard"]

View File

@@ -0,0 +1,93 @@
"""Unit tests for global infrastructure service"""
import pytest
import sys
import sys
from pathlib import Path
from datetime import datetime
from main import app, Region, GlobalDeployment, LoadBalancer, PerformanceMetrics
@pytest.mark.unit
def test_app_initialization():
"""Test that the FastAPI app initializes correctly"""
assert app is not None
assert app.title == "AITBC Global Infrastructure Service"
assert app.version == "1.0.0"
@pytest.mark.unit
def test_region_model():
"""Test Region model"""
region = Region(
region_id="us-east-1",
name="US East",
location="North America",
endpoint="https://us-east-1.api.aitbc.dev",
status="active",
capacity=10000,
current_load=3500,
latency_ms=45,
compliance_level="full"
)
assert region.region_id == "us-east-1"
assert region.name == "US East"
assert region.status == "active"
assert region.capacity == 10000
assert region.compliance_level == "full"
@pytest.mark.unit
def test_global_deployment_model():
"""Test GlobalDeployment model"""
deployment = GlobalDeployment(
deployment_id="deploy_123",
service_name="test-service",
target_regions=["us-east-1", "eu-west-1"],
configuration={"replicas": 3},
deployment_strategy="blue_green",
health_checks=["/health", "/ready"]
)
assert deployment.deployment_id == "deploy_123"
assert deployment.service_name == "test-service"
assert deployment.target_regions == ["us-east-1", "eu-west-1"]
assert deployment.deployment_strategy == "blue_green"
@pytest.mark.unit
def test_load_balancer_model():
"""Test LoadBalancer model"""
balancer = LoadBalancer(
balancer_id="lb_123",
name="Main LB",
algorithm="round_robin",
target_regions=["us-east-1", "eu-west-1"],
health_check_interval=30,
failover_threshold=3
)
assert balancer.balancer_id == "lb_123"
assert balancer.name == "Main LB"
assert balancer.algorithm == "round_robin"
assert balancer.health_check_interval == 30
@pytest.mark.unit
def test_performance_metrics_model():
"""Test PerformanceMetrics model"""
metrics = PerformanceMetrics(
region_id="us-east-1",
timestamp=datetime.utcnow(),
cpu_usage=50.5,
memory_usage=60.2,
network_io=1000.5,
disk_io=500.3,
active_connections=100,
response_time_ms=45.2
)
assert metrics.region_id == "us-east-1"
assert metrics.cpu_usage == 50.5
assert metrics.memory_usage == 60.2
assert metrics.active_connections == 100
assert metrics.response_time_ms == 45.2