Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/fbuild-daemon/src/handlers/emulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mod tests_outcome;
#[cfg(test)]
mod tests_process;
#[cfg(test)]
mod tests_project_dir;
#[cfg(test)]
mod tests_select_runner;

// --- Public API re-exports (preserve `handlers::emulator::*` paths) ---
Expand Down
13 changes: 10 additions & 3 deletions crates/fbuild-daemon/src/handlers/emulator/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ pub async fn test_emu(
.request_id
.clone()
.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
let project_dir = PathBuf::from(&req.project_dir);
// Resolve against the caller's cwd, not the daemon's (FastLED/fbuild#1415).
let project_dir = crate::handlers::operations::resolve_request_project_dir(
&req.project_dir,
req.caller_cwd.as_deref(),
);

// Mark the daemon as busy for the full build + emulate lifecycle.
// Without this guard the 30 s self-eviction loop sees an "empty"
Expand All @@ -157,15 +161,18 @@ pub async fn test_emu(
let _op_guard = crate::handlers::operations::OperationGuard::new(
&ctx,
fbuild_core::DaemonState::Building,
Some(format!("test-emu {}", req.project_dir)),
Some(format!("test-emu {}", project_dir.display())),
);

if !project_dir.exists() {
return (
StatusCode::BAD_REQUEST,
Json(OperationResponse::fail(
request_id,
format!("project directory does not exist: {}", req.project_dir),
format!(
"project directory does not exist: {}",
project_dir.display()
),
)),
);
}
Expand Down
58 changes: 58 additions & 0 deletions crates/fbuild-daemon/src/handlers/emulator/tests_project_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! `POST /api/test-emu` must read a relative `project_dir` against the
//! caller's cwd, not the daemon's (FastLED/fbuild#1415).

use super::select::test_emu;
use crate::context::DaemonContext;
use crate::models::TestEmuRequest;
use axum::Json;
use axum::extract::State;
use std::sync::Arc;

fn request(project_dir: &str, caller_cwd: &std::path::Path) -> TestEmuRequest {
serde_json::from_value(serde_json::json!({
"project_dir": project_dir,
"caller_cwd": caller_cwd.to_str().unwrap(),
}))
.unwrap()
}

#[tokio::test]
async fn relative_project_dir_resolves_against_caller_cwd() {
let (shutdown_tx, _rx) = tokio::sync::watch::channel(false);
let ctx = Arc::new(DaemonContext::new(0, shutdown_tx, "test".to_string()));
let caller = tempfile::tempdir_in(fbuild_paths::temp_subdir("daemon-tests")).unwrap();
// A platform no runner knows: reaching this error proves the handler read
// the caller's platformio.ini rather than the daemon cwd's (which has none).
std::fs::write(
caller.path().join("platformio.ini"),
"[env:x]\nplatform = bogus-platform-1415\nboard = x\n",
)
.unwrap();

let (_, Json(resp)) = test_emu(State(ctx), Json(request(".", caller.path()))).await;

assert!(!resp.success);
assert!(
resp.message.contains("bogus-platform-1415"),
"handler did not read the caller's project: {}",
resp.message
);
}

#[tokio::test]
async fn missing_relative_project_dir_reports_the_resolved_path() {
let (shutdown_tx, _rx) = tokio::sync::watch::channel(false);
let ctx = Arc::new(DaemonContext::new(0, shutdown_tx, "test".to_string()));
let caller = tempfile::tempdir_in(fbuild_paths::temp_subdir("daemon-tests")).unwrap();

let (_, Json(resp)) = test_emu(State(ctx), Json(request("nope", caller.path()))).await;

assert!(!resp.success);
let expected = caller.path().join("nope");
assert!(
resp.message.contains(&expected.display().to_string()),
"message should name the resolved path {}: {}",
expected.display(),
resp.message
);
}
2 changes: 1 addition & 1 deletion crates/fbuild-daemon/src/handlers/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ pub use reset::reset;

// `pub(crate)` re-exports for sibling handler modules
// (`handlers::emulator` consumes these).
pub(crate) use common::{OperationGuard, qemu_extra_build_flags};
pub(crate) use common::{OperationGuard, qemu_extra_build_flags, resolve_request_project_dir};
pub(crate) use monitor::{MonitorOutcome, MonitorState};
Loading