Files
foxhunt/fxt/tests/cli_integration_test.rs
jgrusewski 2da5bafc0e refactor: rename tli→fxt, delete legacy scripts/RunPod/deploy artifacts
- Rename tli/ directory to fxt/, update package + binary name to "fxt"
- Replace all `use tli::` → `use fxt::` across 52 Rust files
- Update build.rs proto paths (tli/proto → fxt/proto) in 6 services
- Update Dockerfiles, CI workflows, deploy.sh for new paths
- Delete ~170 legacy shell scripts (kept 15 essential ones)
- Delete RunPod Python client (runpod/), tests (tests/runpod/)
- Delete foxhunt-deploy crate (RunPod-only deployment tool)
- Delete terraform/runpod/ (moved to Scaleway)
- Delete ML Python hyperopt scripts (replaced by Rust Argmin PSO)
- Delete .gitlab-ci.yml (using GitHub + Gitea)
- Remove foxhunt-deploy from workspace members

504 files changed, -74,355 lines of legacy code removed.
Workspace compiles clean (0 errors, 0 warnings).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 10:32:21 +01:00

295 lines
8.2 KiB
Rust

//! TLI CLI Integration Tests
//!
//! Tests CLI argument parsing, command routing, and error handling for the TLI binary.
//! These tests use `assert_cmd` to invoke the TLI binary and verify behavior.
// Suppress false-positive unused_crate_dependencies warnings
// dev-dependencies are shared across ALL test targets in the crate
// This test may not use all deps, but they are required by other integration tests
#![allow(unused_crate_dependencies)]
use assert_cmd::Command;
use predicates::prelude::*;
/// Test that TLI binary can be invoked with --help
#[test]
fn test_tli_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains(
"Foxhunt Trading System Terminal Interface",
))
.stdout(predicate::str::contains("--api-gateway-url"))
.stdout(predicate::str::contains("--log-level"));
}
/// Test tune command help output
#[test]
fn test_tune_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains(
"Start, monitor, and manage hyperparameter tuning",
));
}
/// Test tune start command help
#[test]
fn test_tune_start_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("start")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--model"))
.stdout(predicate::str::contains("--trials"));
}
/// Test tune status command help
#[test]
fn test_tune_status_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("status")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--job-id"));
}
/// Test auth command help output
#[test]
fn test_auth_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("auth")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains(
"Login, logout, and manage authentication tokens",
));
}
/// Test auth login command help
#[test]
fn test_auth_login_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("auth")
.arg("login")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--username"));
}
/// Test auth status command (no authentication required)
#[test]
fn test_auth_status_no_auth() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("auth")
.arg("status")
.assert()
.success() // Should succeed even without authentication
.stdout(predicate::str::contains("Authentication Status"));
}
/// Test auth logout command (no authentication required)
#[test]
fn test_auth_logout_no_auth() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("auth")
.arg("logout")
.assert()
.success() // Should succeed even if not logged in
.stdout(predicate::str::contains("Logged out"));
}
/// Test that tune commands require authentication
/// This test expects failure when not authenticated
#[test]
fn test_tune_requires_auth() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("status")
.arg("--job-id")
.arg("550e8400-e29b-41d4-a716-446655440000")
.assert()
.failure() // Should fail without authentication
.stderr(predicate::str::contains("Not authenticated"));
}
/// Test environment variable support for API Gateway URL
#[test]
fn test_env_var_api_gateway_url() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.env("API_GATEWAY_URL", "http://test.example.com:50051")
.arg("--help")
.assert()
.success();
}
/// Test environment variable support for log level
#[test]
fn test_env_var_log_level() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.env("TLI_LOG_LEVEL", "debug")
.arg("--help")
.assert()
.success();
}
/// Test CLI flag precedence over environment variables
#[test]
fn test_cli_flag_precedence() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.env("API_GATEWAY_URL", "http://env.example.com")
.arg("--api-gateway-url")
.arg("http://cli.example.com")
.arg("--help")
.assert()
.success();
}
/// Test invalid command
#[test]
fn test_invalid_command() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("invalid_command")
.assert()
.failure()
.stderr(predicate::str::contains("error"));
}
/// Test tune start with invalid model type
#[test]
fn test_tune_start_invalid_model() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("start")
.arg("--model")
.arg("INVALID_MODEL_TYPE")
.arg("--trials")
.arg("10")
.assert()
.failure(); // Should fail validation (even before auth check)
}
/// Test tune start missing required argument
#[test]
fn test_tune_start_missing_trials() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("start")
.arg("--model")
.arg("DQN")
// Missing --trials argument (but has default, so will fail on auth instead)
.assert()
.failure() // Will fail due to authentication requirement
.stderr(predicate::str::contains("Not authenticated"));
}
/// Test tune status with malformed UUID
#[test]
fn test_tune_status_invalid_uuid() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("status")
.arg("--job-id")
.arg("not-a-valid-uuid")
.assert()
.failure() // Should fail (either auth check or UUID validation)
.stderr(predicate::str::contains("").or(predicate::str::contains(""))); // Error may vary
}
/// Test dashboard command (without launching terminal)
/// Note: This test will fail if it actually tries to launch the TUI,
/// but helps verify command parsing
#[test]
#[ignore = "Ignored because it tries to launch terminal UI"]
fn test_dashboard_command() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("dashboard")
.timeout(std::time::Duration::from_secs(2))
.assert();
// Will timeout or fail trying to connect, but that's expected
}
/// Test version flag
#[test]
fn test_version_flag() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("tli"));
}
/// Test that all valid tune models are accepted by help
#[test]
fn test_tune_valid_models_in_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("start")
.arg("--help")
.assert()
.success();
// Help should display without errors, model validation happens at runtime
}
/// Test tune best command help
#[test]
fn test_tune_best_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("best")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--job-id"))
.stdout(predicate::str::contains("--export"));
}
/// Test tune stop command help
#[test]
fn test_tune_stop_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("tune")
.arg("stop")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--job-id"))
.stdout(predicate::str::contains("--reason"));
}
/// Test multiple CLI flags together
#[test]
fn test_multiple_cli_flags() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("--api-gateway-url")
.arg("http://test.example.com")
.arg("--log-level")
.arg("debug")
.arg("--help")
.assert()
.success();
}
/// Test auth refresh command help
#[test]
fn test_auth_refresh_help() {
let mut cmd = Command::cargo_bin("tli").unwrap();
cmd.arg("auth")
.arg("refresh")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("Refresh access token"));
}