Files
foxhunt/services/api_gateway/build.rs
jgrusewski df64dbc04c 🚀 Wave 127 Phase 2: Protocol Translation + E2E Infrastructure (Agents 168-172)
## Summary
Major architectural fixes enabling E2E testing through protocol translation layer
and complete infrastructure resolution. Trading Service confirmed 100% implemented.

## Agents 168-172 Achievements

**Agent 168** - Port Configuration Fix:
- Fixed 3-layer port mismatch (tests→API Gateway→backends)
- Test files: localhost:50051 → localhost:50050
- Result: Infrastructure 100% correct, E2E testing unblocked

**Agent 169** - Root Cause Discovery:
- Confirmed Trading Service 100% implemented (all 11 methods exist)
- Identified protocol mismatch as root cause (TLI↔Trading proto)
- Documented all method implementations and field mappings

**Agent 170** - Protocol Translation Implementation:
- Implemented TLI↔Trading proto translation layer (+227 lines)
- Phase 2: 5 core methods (submit_order, cancel_order, get_order_status, get_account_info, get_positions)
- Phase 4: 2 streaming methods (subscribe_market_data, subscribe_order_updates)
- Dual proto compilation setup in build.rs

**Agent 171** - Backend Port Fix:
- Fixed API Gateway backend URLs (50051→50052, 50052→50053)
- Discovered authentication forwarding blocker
- Validated port connectivity working

**Agent 172** - Authentication Forwarding:
- Implemented auth metadata forwarding for all 7 translated methods
- Fixed gRPC Request ownership patterns (metadata clone before into_inner)
- Updated E2E test JWT secret for compliance (88-char base64)

## Files Modified

### API Gateway
- `services/api_gateway/build.rs`: Dual proto compilation
- `services/api_gateway/src/grpc/trading_proxy.rs`: +227 lines (translation + auth)
- `services/api_gateway/src/main.rs`: Port configuration
- `services/api_gateway/src/auth/interceptor.rs`: JWT validation
- `services/api_gateway/src/grpc/backtesting_proxy.rs`: Port updates

### Integration Tests
- `services/integration_tests/tests/trading_service_e2e.rs`: Port + JWT fixes
- `services/integration_tests/tests/backtesting_service_e2e.rs`: Port fixes
- `services/integration_tests/tests/ml_training_service_e2e.rs`: Port fixes

### Other Services
- `services/backtesting_service/src/main.rs`: Port configuration
- Multiple test files: Compliance, risk, pipeline tests

## Test Status
- E2E baseline: 6/54 (11.1%)
- Infrastructure: 100% fixed
- Protocol translation: Implemented, validation pending JWT sync
- Expected after validation: 13/54 (24.1%) with 7 methods working

## Technical Achievements
- Protocol adapter pattern (TLI↔Trading proto)
- gRPC metadata forwarding (5 auth headers)
- Dual proto compilation architecture
- Stream translation with unfold pattern
- Zero-copy enum pass-through

## Remaining Work
- JWT secret synchronization (in progress)
- Agent 170 Phase 5: 15 extended methods
- ML Training Service startup
- Backtesting Service route implementation (9 methods)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 19:35:59 +02:00

83 lines
3.7 KiB
Rust

//! Build script for API Gateway service
//!
//! Compiles protobuf definitions for:
//! - Config service (foxhunt.config from config_service.proto)
//! - TLI services (Trading, Backtesting, MLService from trading.proto) - client-facing interface
//! - Trading Service backend (trading.proto) - backend service interface
//! - ML Training Service (ml_training.proto)
fn main() -> Result<(), Box<dyn std::error::Error>> {
// NOTE: Tonic 0.14+ uses tonic_prost_build instead of tonic_build
let config = tonic_prost_build::configure();
// Compile Config Service proto
config
.clone()
.build_server(true)
.build_client(true)
.compile_well_known_types(true)
.extern_path(".google.protobuf", "::prost_types")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.server_mod_attribute(".", "#[allow(unused_qualifications)]")
.client_mod_attribute(".", "#[allow(unused_qualifications)]")
.compile_protos(
&["proto/config_service.proto"],
&["proto"]
)?;
// Compile TLI proto which contains TradingService, BacktestingService, and MLService
// API Gateway acts as server (receives requests from TLI clients)
// Keep client generation for backtesting_proxy compatibility
config
.clone()
.build_server(true) // Act as server for incoming requests
.build_client(true) // Generate client for backtesting service compatibility
.compile_well_known_types(true)
.extern_path(".google.protobuf", "::prost_types")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.server_mod_attribute(".", "#[allow(unused_qualifications)]")
.client_mod_attribute(".", "#[allow(unused_qualifications)]")
.compile_protos(
&["../../tli/proto/trading.proto"],
&["../../tli/proto"]
)?;
// Compile Trading Service backend proto (package: trading)
// API Gateway acts as client (forwards translated requests to Trading Service)
config
.clone()
.build_server(false) // API Gateway is only a client to Trading Service
.build_client(true) // Generate client to call backend
.compile_well_known_types(true)
.extern_path(".google.protobuf", "::prost_types")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.server_mod_attribute(".", "#[allow(unused_qualifications)]")
.client_mod_attribute(".", "#[allow(unused_qualifications)]")
.compile_protos(
&["../trading_service/proto/trading.proto"],
&["../trading_service/proto"]
)?;
// Compile ML Training Service protobuf (client + server for proxying)
config
.clone()
.build_server(true) // API Gateway acts as server (receives proxy requests)
.build_client(true) // API Gateway acts as client (forwards to backend)
.compile_well_known_types(true)
.extern_path(".google.protobuf", "::prost_types")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.server_mod_attribute(".", "#[allow(unused_qualifications)]")
.client_mod_attribute(".", "#[allow(unused_qualifications)]")
.compile_protos(
&["../ml_training_service/proto/ml_training.proto"],
&["../ml_training_service/proto"]
)?;
println!("cargo:rerun-if-changed=proto/config_service.proto");
println!("cargo:rerun-if-changed=../../tli/proto/trading.proto");
println!("cargo:rerun-if-changed=../trading_service/proto/trading.proto");
println!("cargo:rerun-if-changed=../ml_training_service/proto/ml_training.proto");
Ok(())
}