use clap::ValueEnum as _;
#[test]
fn the_canonical_name_is_the_real_command() {
for integration in super::CLIENT_INTEGRATIONS {
let advertised = integration
.kind
.to_possible_value()
.expect("every client is selectable")
.get_name()
.to_string();
assert_eq!(
advertised, integration.command,
"{advertised} is advertised but the command is {}",
integration.command
);
assert_eq!(integration.kind.to_string(), integration.command);
assert_eq!(integration.kind.canonical_name(), integration.command);
}
}
#[test]
fn every_legacy_client_name_still_parses() {
for (legacy, expected) in [
("claude-code", super::ClientKind::ClaudeCode),
("cursor", super::ClientKind::Cursor),
("gemini-cli", super::ClientKind::GeminiCli),
("grok-cli", super::ClientKind::GrokCli),
("qwen-code", super::ClientKind::QwenCode),
] {
assert_eq!(
super::ClientKind::from_str(legacy, true),
Ok(expected),
"{legacy} must remain accepted"
);
}
for integration in super::CLIENT_INTEGRATIONS {
assert_eq!(
super::ClientKind::from_str(integration.command, true),
Ok(integration.kind),
"{} must parse",
integration.command
);
}
}
#[test]
fn a_file_written_under_the_legacy_name_is_still_found() {
let home = tempfile::tempdir().expect("temp home");
let clients = home.path().join(".config/link-assistant-router/clients");
std::fs::create_dir_all(&clients).expect("create managed directory");
let legacy = clients.join("claude-code.env");
std::fs::write(&legacy, "TOKEN=x").expect("write legacy file");
let manager = super::ClientManager::isolated(home.path());
assert_eq!(
manager.environment_path(super::ClientKind::ClaudeCode),
legacy,
"an existing legacy file must be honoured"
);
}
#[test]
fn a_fresh_installation_uses_the_canonical_name() {
let home = tempfile::tempdir().expect("temp home");
let manager = super::ClientManager::isolated(home.path());
let path = manager.environment_path(super::ClientKind::ClaudeCode);
assert!(
path.ends_with("claude.env"),
"expected the canonical name, got {}",
path.display()
);
}
#[test]
fn every_client_has_a_legacy_name() {
for kind in super::ClientKind::ALL {
assert!(!kind.legacy_name().is_empty(), "{kind} has no legacy name");
}
}
use super::*;
#[test]
fn rejects_non_http_router_urls() {
assert!(normalize_base_url("router.internal:8080").is_err());
}
#[test]
fn compact_diagnostics_do_not_echo_unbounded_upstream_bodies() {
let body = "x".repeat(500);
let compact = compact_body(&body);
assert!(compact.ends_with('…'));
assert!(compact.chars().count() <= 241);
}