Skip to content

Commit 75f9e78

Browse files
committed
fix(test): use absolute config path and increase client timeout for CI
- Add get_workspace_root() helper to find workspace directory - Use absolute path for config file in start_test_server() - Add TERRAPHIM_CLIENT_TIMEOUT env var for configurable timeout - Set 120s timeout for server commands in tests The relative config path worked locally but failed in CI where the working directory differs. This follows the pattern from cross_mode_consistency_test.rs which already uses absolute paths.
1 parent 5c93427 commit 75f9e78

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

crates/terraphim_agent/src/client.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ pub struct ApiClient {
1111

1212
impl ApiClient {
1313
pub fn new(base_url: impl Into<String>) -> Self {
14+
// Use longer timeout for CI/CD environments where search may be slow
15+
let timeout_secs: u64 = match std::env::var("TERRAPHIM_CLIENT_TIMEOUT") {
16+
Ok(v) => v.parse().unwrap_or(60),
17+
Err(_) => 30,
18+
};
1419
let client = Client::builder()
15-
.timeout(std::time::Duration::from_secs(30))
20+
.timeout(std::time::Duration::from_secs(timeout_secs))
1621
.user_agent("Terraphim-TUI/1.0")
1722
.build()
1823
.unwrap_or_else(|_| Client::new());

crates/terraphim_agent/tests/integration_tests.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fs;
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
33
use std::process::{Child, Command, Stdio};
44

55
use anyhow::Result;
@@ -8,26 +8,55 @@ use std::str;
88
use std::thread;
99
use std::time::Duration;
1010

11+
/// Get workspace root directory by walking up to find [workspace] in Cargo.toml
12+
fn get_workspace_root() -> Result<PathBuf> {
13+
let mut current = std::env::current_dir()?;
14+
15+
loop {
16+
let cargo_toml = current.join("Cargo.toml");
17+
if cargo_toml.exists() {
18+
if let Ok(content) = fs::read_to_string(&cargo_toml) {
19+
if content.contains("[workspace]") {
20+
return Ok(current);
21+
}
22+
}
23+
}
24+
25+
if !current.pop() {
26+
break;
27+
}
28+
}
29+
30+
Ok(PathBuf::from("."))
31+
}
32+
1133
/// Test helper to start a real terraphim server
1234
async fn start_test_server() -> Result<(Child, String)> {
1335
let port = portpicker::pick_unused_port().expect("Failed to find unused port");
1436
let server_url = format!("http://localhost:{}", port);
1537

1638
println!("Starting test server on {}", server_url);
1739

40+
// Use absolute path for config to work in CI
41+
let workspace_root = get_workspace_root()?;
42+
let config_path = workspace_root.join("terraphim_server/default/terraphim_engineer_config.json");
43+
44+
println!("Using config path: {}", config_path.display());
45+
1846
let mut server = Command::new("cargo")
1947
.args([
2048
"run",
2149
"-p",
2250
"terraphim_server",
2351
"--",
2452
"--config",
25-
"terraphim_server/default/terraphim_engineer_config.json",
53+
config_path.to_str().unwrap(),
2654
])
2755
// The server reads its bind address from settings (env/file), not TERRAPHIM_SERVER_PORT.
2856
// Override the server bind host+port explicitly for tests.
2957
.env("TERRAPHIM_SERVER_HOSTNAME", format!("127.0.0.1:{}", port))
3058
.env("RUST_LOG", "warn") // Reduce log noise
59+
.current_dir(&workspace_root)
3160
.stdout(Stdio::piped())
3261
.stderr(Stdio::piped())
3362
.spawn()?;
@@ -89,7 +118,8 @@ fn run_server_command(server_url: &str, args: &[&str]) -> Result<(String, String
89118

90119
let mut cmd = Command::new("cargo");
91120
cmd.args(["run", "-p", "terraphim_agent", "--"])
92-
.args(&cmd_args);
121+
.args(&cmd_args)
122+
.env("TERRAPHIM_CLIENT_TIMEOUT", "120");
93123

94124
let output = cmd.output()?;
95125

@@ -283,9 +313,13 @@ async fn test_end_to_end_server_workflow() -> Result<()> {
283313
);
284314

285315
// 3. Test search with server
286-
let (_search_stdout, _, search_code) =
316+
let (search_stdout, search_stderr, search_code) =
287317
run_server_command(&server_url, &["search", "integration test", "--limit", "3"])?;
288-
assert_eq!(search_code, 0, "Server search should succeed");
318+
if search_code != 0 {
319+
println!("Search stdout: {}", search_stdout);
320+
println!("Search stderr: {}", search_stderr);
321+
}
322+
assert_eq!(search_code, 0, "Server search should succeed: {}", search_stderr);
289323
println!("✓ Server search completed");
290324

291325
// 4. Test role override in server mode

0 commit comments

Comments
 (0)