Skip to content

test(host-runtime): write test keystores to the temp dir, not the real one - #1850

Open
Virgile-pct wants to merge 2 commits into
mainfrom
fix/windows-test-keystore
Open

Virgile-pct wants to merge 2 commits into
mainfrom
fix/windows-test-keystore

Conversation

@Virgile-pct

@Virgile-pct Virgile-pct commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1847, which stopped this suite from deleting the node key and measured the owner keystore as still outstanding. This closes that one.

What happens today

Six tests write their keystore fixture to default_keystore_path():

let temp = tempfile::tempdir().unwrap();
let _home_guard = HomeEnvGuard::set(temp.path());
let owner = OwnerKeypair::generate();
let keystore_path = default_keystore_path().unwrap();   // the real home
save_keystore(&keystore_path, &owner, None, true).unwrap();

default_keystore_path() resolves through dirs::home_dir() in mesh-llm-identity and has no test override. The #[cfg(test)] hook that protects the node key lives in host-runtime, so it cannot reach a path resolved inside another crate, and HomeEnvGuard has no effect on it.

Measured on Windows 11 against 3f4f1c35a, one full cargo test -p mesh-llm-host-runtime, comparing ~/.mesh-llm/owner-keystore.json before and after: same size, same fifteen fields, six of them different. owner_id, created_at, and both the signing and encryption key pairs. The developer's owner identity is replaced by running the suite.

What this changes

Each of the six call sites already had a tempfile::tempdir() on the line above, and each already handed the path to state.set_owner_key_path(). The default location was only ever somewhere to put the fixture; the code under test reads whatever path it is given. They now write into that temp directory.

Six lines, plus one import that became unused.

Measured effect

Same box, same command, comparing ~/.mesh-llm before and after:

#1847 this branch
node key unchanged unchanged
owner-keystore.json rewritten unchanged
passed / failed 3457 / 17 3457 / 17

The 17 failures are identical to the parent commit, compared by diffing both complete sorted lists rather than by eye. No new failures, and none of the six tests changed state: they passed before and still pass, they were simply passing while overwriting the developer's identity.

What still remains

The skippy hash cache still writes into ~/.mesh-llm/cache/hashes, six files per run, because tests leave MESH_LLM_HASH_CACHE_DIR unset and hash_cache.rs falls back to the home. That is a cache rather than identity material, so I left it out of this branch rather than mixing a third concern in. Happy to take it next if you want the suite to touch nothing at all.

Gates

  • cargo test -p mesh-llm-host-runtime: 3457 passed, 17 failed, as above.
  • cargo fmt --all --check: clean.
  • cargo clippy -p mesh-llm-host-runtime --all-targets: 8 lints, and the complete sorted set is identical to main.
  • cargo run -p xtask -- repo-consistency no-console-print: passed.
  • scripts/check-env-mutation-contract.py and python -m unittest scripts.tests.test_env_mutation_contract: passed, census unchanged at 234 sites.

Summary by CodeRabbit

  • Tests
    • Updated API tests to use temporary keystore locations consistently.
    • Improved test isolation for configuration diagnostics and control-plane scenarios.

…l 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.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ddd66524-e56a-4548-98a8-dc974126ed67

📥 Commits

Reviewing files that changed from the base of the PR and between 3f4f1c3 and 1cadd28.

📒 Files selected for processing (3)
  • crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs
  • crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs
  • crates/mesh-llm-host-runtime/src/api/tests/mod.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

API tests now save owner keystores under temporary directories instead of using the default keystore path. The test module removes the unused default_keystore_path import.

Changes

Temporary keystore test updates

Layer / File(s) Summary
Use temporary owner keystore paths
crates/mesh-llm-host-runtime/src/api/tests/apply_config_diagnostics.rs, crates/mesh-llm-host-runtime/src/api/tests/control_plane.rs, crates/mesh-llm-host-runtime/src/api/tests/mod.rs
Diagnostic and control-plane tests use owner-keystore.json within temporary directories. The API test imports retain only OwnerKeypair and save_keystore.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: ndizazzo

Merge Risk: ⚪ Minimal · up to e400c

The change prevents these tests from modifying the developer’s real owner keystore without altering their intended behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: test keystores now use temporary directories instead of the real keystore path.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-test-keystore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@i386 i386 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the synchronized exact head. Windows keystore tests use isolated temporary paths without changing production behavior; the full host-runtime package suite passes locally.

@i386
i386 enabled auto-merge (squash) September 15, 2026 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants