Files
aitbc/apps/governance-service
aitbc f6900d6bf6 Add pytest test files for microservices
- Created test files for GPU service (tests/test_main.py)
- Created test files for Marketplace service (tests/test_main.py)
- Created test files for Trading service (tests/test_main.py)
- Created test files for Governance service (tests/test_main.py)
- Created integration tests for API gateway (tests/test_gateway.py)
- Added pytest dependencies to all service pyproject.toml files
- Created TEST_COVERAGE_REQUIREMENTS.md documenting coverage targets and best practices

This completes Phase 8: Create pytest test files for microservices
2026-04-30 11:57:09 +02:00
..

AITBC Governance Service

Manages governance operations.

Installation

cd /opt/aitbc
poetry install --with governance-service

Database Setup

Create a separate database for the governance service:

sudo -u postgres psql -f apps/governance-service/scripts/setup-database.sql

Or manually:

CREATE DATABASE aitbc_governance;
CREATE USER aitbc_governance WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE aitbc_governance TO aitbc_governance;

Running

# Development
python -m governance_service.main

# Production (systemd)
sudo systemctl start governance-service
sudo systemctl enable governance-service

Endpoints

  • GET /health - Health check
  • GET /governance/status - Get governance status
  • GET /v1/governance/profiles - Get governance profiles
  • GET /v1/governance/profiles/{profile_id} - Get specific profile
  • POST /v1/governance/profiles - Create new profile
  • GET /v1/governance/proposals - Get proposals
  • GET /v1/governance/proposals/{proposal_id} - Get specific proposal
  • POST /v1/governance/proposals - Create new proposal
  • GET /v1/governance/votes - Get votes
  • POST /v1/governance/votes - Create new vote
  • GET /v1/governance/treasury - Get DAO treasury
  • GET /v1/governance/analytics - Get governance analytics

Testing

Prerequisites

  • PostgreSQL running and aitbc_governance database created
  • Poetry dependencies installed

Database Setup

sudo -u postgres psql -f scripts/setup-database.sql

Start Service (Development)

python -m governance_service.main

Health Check

curl http://localhost:8105/health

Expected response:

{"status": "healthy", "service": "governance-service"}

Governance Status

curl http://localhost:8105/governance/status

Expected response:

{
  "status": "operational",
  "service": "governance-service",
  "message": "Governance service is running"
}

Get Governance Proposals

curl http://localhost:8105/v1/governance/proposals

Expected response:

[]

Create Governance Proposal

curl -X POST http://localhost:8105/v1/governance/proposals \
  -H "Content-Type: application/json" \
  -d '{
    "proposer_id": "test_proposer",
    "title": "Test Proposal",
    "description": "Test description",
    "category": "general",
    "voting_starts": "2026-05-01T00:00:00Z",
    "voting_ends": "2026-05-08T00:00:00Z"
  }'

Test Through Gateway

  1. Start the API gateway:

    python -m api_gateway.main
    
  2. Test governance endpoints through the gateway:

    curl http://localhost:8080/governance/health
    curl http://localhost:8080/governance/v1/governance/proposals
    

For comprehensive testing procedures, see MICROSERVICES_TESTING_GUIDE.md.

Service Configuration

  • Port: 8105
  • Database: aitbc_governance
  • Gateway route: /governance/*

Migration Status

Completed:

  • Extracted governance domain models (GovernanceProfile, Proposal, Vote, DaoTreasury, TransparencyReport)
  • Extracted governance services (GovernanceService with CRUD operations)
  • Set up database session management
  • Extracted governance router endpoints
  • Created systemd service configuration
  • Created database setup script

Remaining:

  • Remove governance routers from coordinator-api
  • Remove governance services from coordinator-api
  • Remove governance domain models from coordinator-api
  • Run database migration script to create aitbc_governance database
  • Install and enable systemd service
  • End-to-end testing with gateway

Note: The governance service is ~50K lines, so full removal from coordinator-api requires careful coordination to avoid breaking existing functionality. The foundation is in place for gradual migration.