From 1cadd28cdab6e3ec6dd35675f90bc0b5fc7e8e12 Mon Sep 17 00:00:00 2001 From: Virgile Pourchet Date: Sun, 13 Sep 2026 20:28:38 +0200 Subject: [PATCH] test(host-runtime): write test keystores to the temp dir, not the real one Six tests wrote their owner keystore fixture to `default_keystore_path()`, which resolves through `dirs::home_dir()` in `mesh-llm-identity` and has no test override. On Windows that is the developer's real `~/.mesh-llm/owner-keystore.json`, so running the suite replaced it with a fresh `owner_id` and two fresh key pairs, six of its fifteen fields. #1847 stopped the same suite from deleting the node key, and measured this one as still outstanding. The `#[cfg(test)]` hook that protects the node key lives in host-runtime, so it cannot reach a path resolved inside `mesh-llm-identity`. Each of the six call sites already had a `tempfile::tempdir()` on the line above and already handed the path to `state.set_owner_key_path()`, so the default location was only ever a place to write the fixture. They now write into that temp directory instead. Measured on Windows 11 against `3f4f1c35a`, comparing `~/.mesh-llm` before and after a full `cargo test -p mesh-llm-host-runtime`: the keystore hash is now unchanged, as is the node key. 3457 passed and 17 failed, the same 17 as the parent commit, compared by diffing both complete sorted lists. One write into the real home remains: the skippy hash cache still lands in `~/.mesh-llm/cache/hashes` because tests leave `MESH_LLM_HASH_CACHE_DIR` unset. That is a cache rather than identity material, and it is not addressed here. --- .../src/api/tests/apply_config_diagnostics.rs | 4 ++-- .../mesh-llm-host-runtime/src/api/tests/control_plane.rs | 8 ++++---- crates/mesh-llm-host-runtime/src/api/tests/mod.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs b/crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs index b9354537ca..502b7ce9fb 100644 --- a/crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs +++ b/crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs @@ -42,7 +42,7 @@ async fn control_plane_api_apply_config_serializes_structured_diagnostics() { let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let OwnerControlApplyTestServer { @@ -125,7 +125,7 @@ async fn control_plane_api_apply_config_serializes_success_warning_diagnostics() let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let OwnerControlApplyTestServer { diff --git a/crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs b/crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs index afe9c0acb8..d659cf5d0b 100644 --- a/crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs +++ b/crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs @@ -183,7 +183,7 @@ async fn control_plane_api_cli_requires_explicit_endpoint_and_runs_local_orchest let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let control_server = spawn_owner_control_test_server().await; @@ -231,7 +231,7 @@ async fn control_plane_api_apply_config_uses_full_mesh_config_contract() { let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let get_server = spawn_owner_control_test_server().await; @@ -323,7 +323,7 @@ async fn control_plane_api_apply_config_reports_revision_conflict() { let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let OwnerControlApplyTestServer { @@ -421,7 +421,7 @@ async fn control_plane_api_reports_remote_endpoint_unreachable() { let temp = tempfile::tempdir().unwrap(); let _home_guard = HomeEnvGuard::set(temp.path()); let owner = OwnerKeypair::generate(); - let keystore_path = default_keystore_path().unwrap(); + let keystore_path = temp.path().join("owner-keystore.json"); save_keystore(&keystore_path, &owner, None, true).unwrap(); let endpoint_token = unreachable_owner_control_endpoint_token().await; diff --git a/crates/mesh-llm-host-runtime/src/api/tests/mod.rs b/crates/mesh-llm-host-runtime/src/api/tests/mod.rs index 229f5c8148..d3a46974a7 100644 --- a/crates/mesh-llm-host-runtime/src/api/tests/mod.rs +++ b/crates/mesh-llm-host-runtime/src/api/tests/mod.rs @@ -1,6 +1,6 @@ use super::*; use crate::api::status::decode_runtime_model_path; -use crate::crypto::{OwnerKeypair, default_keystore_path, save_keystore}; +use crate::crypto::{OwnerKeypair, save_keystore}; use crate::plugin; use crate::plugins::blobstore; use base64::Engine;