Repository navigation
Description
Summary
Three tests fail deterministically in full-parallel cargo test -p warp --lib runs — reproduced in 3 out of 3 full-suite attempts on this machine — because RootView::new (the production workspace-view constructor, app/src/workspace/view.rs:2862) unconditionally calls terminal::platform::init(), which on macOS calls env::set_current_dir(dirs::home_dir().unwrap()) with no #[cfg(not(test))] guard and no restoration afterward. The first test in the process that constructs a RootView (there are dozens across app/src/workspace/view_tests.rs) permanently changes the whole test binary's working directory to the user's home directory for the remainder of the run. Every subsequent test in the same process that resolves a relative path against the crate-root cwd then fails. This is a first-writer-wins process-global cache pollution, the same shape as #13974's BOOTSTRAP_CACHE/EXPERIMENT_LAYER_MAPPINGS/TELEMETRY cluster, but via the OS process cwd rather than an in-process static.
Affected tests
notebooks::file::tests::test_load_local—app/src/notebooks/file/mod_tests.rs:74notebooks::file::tests::test_load_before_session—app/src/notebooks/file/mod_tests.rs:233util::path::tests::test_resolve_command—app/src/util/path_tests.rs:21
All three currently report as failures on every contributor's full-suite PR gate.
Reproduction
All three pass in isolation:
cargo test -p warp --lib -- --exact notebooks::file::tests::test_load_local
cargo test -p warp --lib -- --exact notebooks::file::tests::test_load_before_session
cargo test -p warp --lib -- --exact util::path::tests::test_resolve_command
# => each: ok. 1 passed
Full suite fails deterministically (3/3 local runs on this 10-core machine reproduced all three, alongside the four already-tracked clusters #13972-#13975):
cargo test -p warp --lib
# run 1: 5765 passed; 12 failed, incl. all three of the above
# run 2: 5764 passed; 13 failed, incl. all three of the above
# run 3: 5764 passed; 13 failed, incl. all three of the above
Direct proof — instrumented test_load_local/test_load_before_session with eprintln!("cwd={:?}", std::env::current_dir()) immediately on entry and reran the full suite:
DEBUG test_load_local cwd=Ok("/Users/fbarthelemy") readme_exists=false
DEBUG test_load_before_session cwd=Ok("/Users/fbarthelemy") readme_exists=false
/Users/fbarthelemy is the invoking user's home directory — exactly the value dirs::home_dir() returns — not the expected crate-root cwd (app/) that cargo test starts the process in. This is the smoking-gun match to the mutation below.
For test_resolve_command, a minimal two-target repro isolates the exact polluting sibling module and fails 5/5 times with the specific assertion that fires under a real cwd/PATH-adjacent collision from the same test file family (pane_group::pane::local_harness_launch::tests, which also does its own scoped PATH/HOME env-var overrides via an RAII EnvVarGuard — see note below on why that module is a secondary, narrower contributor, not the primary cause):
cargo test -p warp --lib -- --test-threads=4 util::path::tests::test_resolve_command pane_group::pane::local_harness_launch::tests
# => util::path::tests::test_resolve_command FAILED, 5/5 runs
# panicked at app/src/util/path_tests.rs:43:5: assertion failed: resolve_executable("pwd").is_some()
Note: the local_harness_launch::tests pairing above is a second, independent trigger for test_resolve_command specifically (its EnvVarGuard::set("PATH", fake_bin_dir) calls are unsynchronized with test_resolve_command, which carries no #[serial] marker) — but it does not explain the two notebooks::file tests, which fail on a relative path, not PATH. The chdir-to-home mutation documented above is the common root cause across all three; the local_harness_launch PATH-guard interaction is a compounding, narrower issue affecting test_resolve_command alone (see Fix direction).
Root cause
RootView::new, the constructor for the app's main workspace view, unconditionally initializes terminal platform state on every call:
// app/src/workspace/view.rs:2862
terminal::platform::init().expect("Terminal platform initialized");On macOS, that function performs a real, permanent chdir:
// app/src/terminal/platform.rs:1-32
pub fn init() -> Result<()> {
#[cfg(target_os = "macos")]
mac::init()?;
Ok(())
}
#[cfg(target_os = "macos")]
mod mac {
pub fn init() -> Result<()> {
set_locale_environment();
// Switch to home directory.
env::set_current_dir(dirs::home_dir().unwrap()).unwrap();
Ok(())
}
...
}There is no #[cfg(test)]/#[cfg(not(test))] guard anywhere on this call path, and no code restores the original cwd afterward. app/src/workspace/view_tests.rs constructs RootView (via app.add_window(...) with the workspace view constructor) in dozens of tests, so the first such test to run in the process permanently relocates the whole test binary's working directory to $HOME for every test that runs after it — a first-writer-wins global side effect on the OS process, not an in-process Rust static, but the identical failure shape as the caches in #13974.
Every test that subsequently resolves a relative path against the crate-root cwd is affected:
test_load_local/test_load_before_sessioncallfile_notebook.open_local("../README.md", ...)(mod_tests.rs:81, 244) anddunce::canonicalize("../README.md")(mod_tests.rs:265), both of which resolve againststd::env::current_dir(). Once cwd is$HOME,../README.mdmeans$HOME/../README.md(or wherever$HOME's parent is), which does not exist —dunce::canonicalizereturnsOs { code: 2, kind: NotFound }, exactly the panic observed at mod_tests.rs:265:69, andFileModel::open'sasync_fs::read_to_stringon the same non-existent path logs "Unable to read local notebook file" beforetest_load_local'seditor.markdown(ctx).len() > 4assertion fails on empty content (mod_tests.rs:107:13).test_resolve_commandcallsresolve_executable("../script/run")(path_tests.rs:38, a relative path relying on cwd) andresolve_executable("pwd")/resolve_executable("env")(path_tests.rs:31, 43, PATH-based lookups). The relative-path assertion is directly cwd-sensitive;pwd/env, meanwhile, are additionally exposed to the separatelocal_harness_launch::testsPATH-guard race described above, sinceresolve_executablereads the process-globalenv::var_os("PATH")(app/src/util/path.rs:84) with no synchronization against concurrent test threads that holdPATHoverridden.
Fix direction
- Guard the
terminal::platform::init()call inRootView::new(app/src/workspace/view.rs:2862) so it does not run under test — e.g.#[cfg(not(test))], or route through a test-only mock/no-opplatform::initthe way other singletons in this constructor already use_for_test/mockvariants (ServerApiProvider::new_for_test(),AuthStateProvider::new_for_test(),AuthManager::new_for_test, etc., all visible in the same constructor). This is the single highest-leverage fix: it eliminates the chdir-to-home side effect for the entire test binary, not just these three tests. - Independently of the above,
resolve_executable's tests being sensitive to concurrentPATHmutation frompane_group::pane::local_harness_launch::testsis a real (if secondary) reliability gap: either add#[serial_test::serial]totest_resolve_commandin the same serial group thelocal_harness_launchPATH/HOME-mutating tests already use, or havetest_resolve_command's PATH-based assertions (env,pwd) callresolve_executable_in_pathwith an explicitly capturedPATHsnapshot rather than relying on the ambient process env, consistent with the guidance in that function's own doc comment about callers needing a specific PATH. - Longer term: any production code path that mutates true process-global OS state (cwd, env vars) on every construction of a commonly-tested view is a standing trap for the whole test suite. Consider whether
terminal::platform::init()should be idempotent/guarded at the call site (e.g.once_cell-gated to run at most once per process) rather than relying on every caller to know not to invoke it in tests.
Related
Related: #13853 (warp_editor render::tests Once-poisoning — same class, different crate) and the sibling flake tickets #13972, #13973, #13974, #13975, and #13979 (real-wall-clock Timer::after timing sensitivity — a different mechanism, filed from the same investigation). This ticket's mechanism (first-writer-wins mutation of true OS process state, not an in-process Rust static) is closest in shape to #13974's cumulative-cache cluster, but the "static" here is the kernel-tracked working directory itself.
Activity
warp-for-oss commentedon Jul 19, 2026
@fbartho
Here's what I found while triaging this issue:
This appears actionable without more reporter input. The current code supports the report's main finding: constructing the workspace view on macOS can change the process working directory during tests, which can explain later relative-path failures in the same test process.
Maintainer details
I concluded that rootView construction on macOS appears to leak a process-wide cwd change into the Rust test process, causing later relative-path tests to fail in full-suite runs..
Triage summary
This looks like an actionable macOS-specific test reliability bug. The report's main observed symptom is that several Rust unit tests pass in isolation but fail in full-parallel
cargo test -p warp --libruns after another test constructs the workspace root view.Code inspection supports the proposed primary root cause:
RootView::newcallsterminal::platform::init()during construction, and the macOS platform initializer changes the whole process working directory to the user's home directory without restoring the previous cwd. That can explain the notebook tests that open or canonicalize../README.mdafter the cwd has been changed away from Cargo's expected crate working directory.The
test_resolve_commandfailure also has a second plausible contributor: the test reads the ambient processPATH, while nearby local harness launch tests temporarily overridePATHbehind#[serial_test::serial];test_resolve_commanditself is not in that serial group. The cwd leak remains the common mechanism for the relative-path assertions, and the PATH interaction appears narrower to the executable lookup assertions.I did not find two or more existing open issues with the same RootView/cwd mechanism. The related full-suite flake issues (#13972-#13975, #13979) appear to cover sibling global-state or timing mechanisms rather than this specific cwd leak.
This is my automated analysis and may be incorrect. A maintainer will verify the details.
Powered by Oz
fbartho commentedon Jul 21, 2026
I proactively attempted an implementation based on the ticket as it's currently written: #14043.
If the ticket changes, I'm happy to update the PR to match a maintainer's guidance, just let me know!
fbartho commentedon Jul 28, 2026
Just nudging @oss-maintainers that this is still a real flake, and that I have a proposed fix here: #14043