Skip to content

feat: honor FOREST_PATH env var for data directory#7080

Open
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:feat/issue-6008-forest-path-env
Open

feat: honor FOREST_PATH env var for data directory#7080
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:feat/issue-6008-forest-path-env

Conversation

@0xDevNinja
Copy link
Copy Markdown
Contributor

@0xDevNinja 0xDevNinja commented May 19, 2026

Summary of changes

Changes introduced in this pull request:

  • Add a FOREST_PATH environment variable that overrides the data directory for forest, forest-cli, forest-tool and forest-wallet.
  • Precedence is env > config > defaults — when set, FOREST_PATH wins over client.data_dir from the config file; when unset, behavior is unchanged.
  • forest-wallet honors FOREST_PATH when set, otherwise keeps the existing Forest-Wallet ProjectDirs location for backwards compatibility.
  • Daemon logs the resolved data directory on startup (per the issue follow-up comment).
  • Docs entry in env_variables.md and a CHANGELOG.md entry under ### Added.

Reference issue to close (if applicable)

Closes #6008

Other information and links

Mirrors Lotus's LOTUS_PATH so operators switching between implementations get a consistent escape hatch. The wallet override is intentionally opt-in (no implicit migration of the existing Forest-Wallet ProjectDirs location).

A unit test (read_config_forest_path_env_override) exercises the env-over-config precedence with serial_test::serial so it doesn't race other env-touching tests.

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added FOREST_PATH environment variable to override the default data directory location, taking precedence over config file settings.
    • Daemon now logs the resolved data directory during startup for improved visibility.
  • Documentation

    • Added environment variable documentation for FOREST_PATH.

Review Change Stack

Adds a FOREST_PATH environment variable that overrides
`client.data_dir` for `forest`, `forest-cli`, `forest-tool` and
`forest-wallet`. Precedence is env > config > defaults. The daemon
also logs the resolved data directory on startup.

Closes ChainSafe#6008
@0xDevNinja 0xDevNinja requested a review from a team as a code owner May 19, 2026 07:21
@0xDevNinja 0xDevNinja requested review from LesnyRumcajs and sudo-shashank and removed request for a team May 19, 2026 07:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Walkthrough

Implement FOREST_PATH environment variable to override Forest's data directory across all Forest binaries with precedence over config file settings. Add constant, helper function, and config integration; update daemon logging and wallet initialization; include test coverage and user documentation.

Changes

FOREST_PATH Environment Variable Override

Layer / File(s) Summary
Define FOREST_PATH constant and helper function
src/cli_shared/mod.rs
Add public constant FOREST_PATH_ENV and helper function forest_path_from_env() that reads the environment variable when set to a non-empty value.
Integrate override into configuration reading
src/cli_shared/mod.rs
Update read_config to apply the env-derived path to config.client.data_dir when present. Add test that sets FOREST_PATH, invokes read_config, asserts the override took effect, and safely cleans up the env var.
Consume override in daemon and wallet
src/daemon/mod.rs, src/wallet/subcommands/wallet_cmd.rs
Daemon logs the resolved data directory during startup; wallet backend uses forest_path_from_env() with fallback to platform-specific ProjectDirs for wallet directory resolution.
Document FOREST_PATH feature
CHANGELOG.md, docs/docs/users/reference/env_variables.md
Changelog documents the new env variable and daemon logging; user docs describe its purpose, default behavior, and precedence over config file settings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • hanabi1224
  • akaladarshi
🚥 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 Title accurately summarizes the main change: adding FOREST_PATH environment variable support for overriding data directory.
Linked Issues check ✅ Passed PR meets all coding requirements: FOREST_PATH env var implemented across forest binaries with correct precedence, env-var override logic added, documentation updated, and unit tests included.
Out of Scope Changes check ✅ Passed All changes directly support FOREST_PATH implementation. Logging the resolved data directory and env-var documentation are complementary in-scope additions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli_shared/mod.rs`:
- Around line 85-99: The test read_config_forest_path_env_override mutates the
global FOREST_PATH_ENV without restoring any prior value, so capture the
previous value (Option<String>) before calling std::env::set_var and install a
drop guard that will restore the previous state (std::env::set_var(previous) or
std::env::remove_var if None) when it goes out of scope; update the test (around
uses of FOREST_PATH_ENV and read_config) to use this guard so cleanup runs even
on panic and the global process state is preserved for other tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3c359569-6f3e-4580-9a69-d14f2f8b9ae7

📥 Commits

Reviewing files that changed from the base of the PR and between 0f4957f and fa7bf56.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • docs/docs/users/reference/env_variables.md
  • src/cli_shared/mod.rs
  • src/daemon/mod.rs
  • src/wallet/subcommands/wallet_cmd.rs

Comment thread src/cli_shared/mod.rs
Comment on lines +85 to +99
#[test]
#[serial_test::serial]
fn read_config_forest_path_env_override() {
let temp_dir = tempfile::tempdir().expect("couldn't create temp dir");
// SAFETY: tests touching the process environment are gated by `#[serial]`.
unsafe {
std::env::set_var(FOREST_PATH_ENV, temp_dir.path());
}
let (_, config) = read_config(None, None).unwrap();
// SAFETY: tests touching the process environment are gated by `#[serial]`.
unsafe {
std::env::remove_var(FOREST_PATH_ENV);
}
assert_eq!(config.client.data_dir, temp_dir.path());
}
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Restore the previous FOREST_PATH value in the test cleanup

Line 96 always removes the variable. If FOREST_PATH was already set before this test, global process state is changed for later tests. Save the previous value and restore it via a drop guard so cleanup still runs on panic.

Proposed fix
 #[test]
 #[serial_test::serial]
 fn read_config_forest_path_env_override() {
     let temp_dir = tempfile::tempdir().expect("couldn't create temp dir");
+    let previous_forest_path = std::env::var_os(FOREST_PATH_ENV);
+    struct ForestPathEnvGuard(Option<std::ffi::OsString>);
+    impl Drop for ForestPathEnvGuard {
+        fn drop(&mut self) {
+            // SAFETY: tests touching the process environment are gated by `#[serial]`.
+            unsafe {
+                if let Some(value) = &self.0 {
+                    std::env::set_var(FOREST_PATH_ENV, value);
+                } else {
+                    std::env::remove_var(FOREST_PATH_ENV);
+                }
+            }
+        }
+    }
+    let _guard = ForestPathEnvGuard(previous_forest_path);
     // SAFETY: tests touching the process environment are gated by `#[serial]`.
     unsafe {
         std::env::set_var(FOREST_PATH_ENV, temp_dir.path());
     }
     let (_, config) = read_config(None, None).unwrap();
-    // SAFETY: tests touching the process environment are gated by `#[serial]`.
-    unsafe {
-        std::env::remove_var(FOREST_PATH_ENV);
-    }
     assert_eq!(config.client.data_dir, temp_dir.path());
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli_shared/mod.rs` around lines 85 - 99, The test
read_config_forest_path_env_override mutates the global FOREST_PATH_ENV without
restoring any prior value, so capture the previous value (Option<String>) before
calling std::env::set_var and install a drop guard that will restore the
previous state (std::env::set_var(previous) or std::env::remove_var if None)
when it goes out of scope; update the test (around uses of FOREST_PATH_ENV and
read_config) to use this guard so cleanup runs even on panic and the global
process state is preserved for other tests.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.22%. Comparing base (e0bca2a) to head (fa7bf56).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/wallet/subcommands/wallet_cmd.rs 0.00% 5 Missing ⚠️
src/daemon/mod.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/cli_shared/mod.rs 96.77% <100.00%> (+1.42%) ⬆️
src/daemon/mod.rs 26.99% <0.00%> (-0.05%) ⬇️
src/wallet/subcommands/wallet_cmd.rs 26.36% <0.00%> (-0.13%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f4957f...fa7bf56. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Customize Forest data directory via env variable

1 participant