Skip to content

test: isolate filesystem tests from the real ~/.foc-devnet - #240

Merged
Kubuxu merged 2 commits into
FilOzone:mainfrom
OzzyHelper:koan/isolate-test-home
Nov 20, 2026
Merged

Kubuxu merged 2 commits into
FilOzone:mainfrom
OzzyHelper:koan/isolate-test-home

Conversation

@OzzyHelper

@OzzyHelper OzzyHelper commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Cargo tests no longer read or write the real ~/.foc-devnet, and two tests that asserted nothing meaningful are fixed.

Why

cargo test ran production persistence code against the developer's real home. test_save_and_load_run_id wrote and then deleted ~/.foc-devnet/state/current_runid.json, silently breaking stop/status for a running devnet; the keys/mnemonic tests also overwrote ~/.foc-devnet/keys.

How

  • Added a test-only home override in paths::foc_devnet_home(), guarded by a process-wide TestHome lock so parallel tests cannot race on it.
  • Used TestHome in every test that touches foc-devnet paths (keys, mnemonic, run-ID persistence, latest symlink, build/disk status).
  • create_latest_symlink's test used to re-implement the logic with temp dirs; it now calls the real function and covers broken-link recreation and existing-link replacement.
  • Removed test_print_running_status, which only asserted is_ok() while shelling out to Docker.

Testing

The Rust toolchain is not installed in this environment, so cargo test could not be run here. Changes are confined to test code plus a #[cfg(test)]-only branch. Please run:

FIX=0 ./scripts/lint.sh
cargo test --all-targets --all-features

Security note (outside this PR's scope): generate_keys logs the full mnemonic (src/commands/init/keys.rs:75) and every private key (:99-108) at info level. These are local devnet test keys, but logging the master mnemonic is poor hygiene; worth redacting or dropping to debug! in a follow-up.


Quality Report

Changes: 8 files changed, 187 insertions(+), 73 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: 1 issue(s)

  • Branch is not pushed to remote

Unit tests exercised production write paths (key generation, mnemonic
storage, run-ID persistence) against the real home directory. Running
cargo test therefore overwrote ~/.foc-devnet/keys and, worse,
deleted the active ~/.foc-devnet/state/current_runid.json.

Add a test-only home override in paths::foc_devnet_home, guarded by a
process-wide lock so parallel tests cannot race on it, and use it in
every test that touches foc-devnet paths.

Also fix two tests that verified nothing:
- create_latest_symlink's test reimplemented the logic with temp dirs
  instead of calling the function; it now calls it.
- print_running_status's test only asserted is_ok() while shelling out
  to Docker; it is removed.
@FilOzzy FilOzzy added this to FOC Nov 19, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Nov 19, 2026
@Kubuxu

Kubuxu commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@OzzyHelper rebase fix lint

@OzzyHelper

Copy link
Copy Markdown
Contributor Author

❌ Permission denied. Only users with write access can trigger bot commands.

@Kubuxu

Kubuxu commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@OzzyHelper rebase, fix the lint

@OzzyHelper

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/isolate-test-home was rebased onto main and review feedback was applied.

Changes applied

  • Fixed cargo fmt failure in src/run_id/mod.rs:155 — collapsed chained expect onto one line per rustfmt output.
  • Fixed cargo fmt failure in src/run_id/persistence.rs:97 — reformatted assert! to multi-line block per rustfmt output.
  • Rebase check: branch already based on current origin/main (4eb3d66); no rebase needed.

Stats

8 files changed, 189 insertions(+), 73 deletions(-)
Actions performed
  • Already-solved check: skipped (Claude call failed)
  • Rebased koan/isolate-test-home onto origin/main
  • Applied review feedback
  • Pre-push CI check: previous run #44565061351 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/isolate-test-home to fork
  • Private review gate skipped: disabled by config
  • Force-push guard: all original PR content verified preserved
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@FilOzzy FilOzzy moved this from 📌 Triage to ⌨️ In Progress in FOC Nov 19, 2026
@Kubuxu
Kubuxu marked this pull request as ready for review November 20, 2026 13:51
@Kubuxu
Kubuxu requested a review from beck-8 as a code owner November 20, 2026 13:51
Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:51
@Kubuxu
Kubuxu merged commit c3b45b9 into FilOzone:main Nov 20, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from ⌨️ In Progress to 🎉 Done in FOC Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the changes that isolate filesystem tests from developers’ local state.

No open issues 🎉

What changed in this PR

This PR isolates filesystem tests from the developer’s real ~/.foc-devnet, protecting local network state and keys while improving persistence and symlink coverage. Production path resolution remains unchanged.

Changes:

  • Add a test-only home override with a shared lock to serialize path-dependent tests.
  • Exercise real persistence and symlink functions using temporary directories.
  • Remove the Docker-dependent running-status smoke test and extend image-name parsing coverage.
File Description
src/​run_id/​persistence.rs Isolate run-ID persistence and verify file creation and deletion.
src/​run_id/​mod.rs Test real symlink recreation and replacement in temporary directories.
src/​paths.rs Add TestHome and share its lock with environment-variable tests.
src/​crypto/​mnemonic.rs Add isolated mnemonic round-trip and missing-file tests.
src/​commands/​status/​running.rs Remove Docker smoke test and cover unprefixed image names.
src/​commands/​status/​disk_usage.rs Measure a temporary home during tests.
src/​commands/​status/​build_status.rs Restrict test binary lookups to a temporary home.
src/​commands/​init/​keys.rs Isolate key generation and verify persisted keys reload correctly.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

3 participants