Repository navigation
test(tauri): stop tests resolving paths against another test's HOME - #263
Merged
Merged
Conversation
CI on #261 failed once with tests::delete_file_repo_trash_rejects_paths_outside_the_repo_root left: Some("No such file or directory (os error 2)") right: Some("path-outside-workspace") and passed on rerun. The assertion is about path scope, so the error is reported miles away from its cause: `delete_file` first canonicalizes the target, then resolves the implicit default workspace root, and only then checks scope. The ENOENT came out of that middle step. `with_temp_home` replaces the process-global `HOME` for the duration of a test, because Tauri resolves `app_data_dir()` straight from it. Nothing kept other tests from reading `HOME` while it was replaced, so a test running concurrently resolved its default workspace root inside another test's temporary home and then raced the `fs::remove_dir_all` that deletes it. `create_dir_all` losing that race reports `No such file or directory (os error 2)`, which is what the scope assertion ended up printing. Instrumenting the resolver showed 10 such misresolutions in a single test run, so this was a race the suite hit often and only diagnosed rarely. Fix the resolution instead of the timing: - `default_save_dir` and `global_metadata_dir` now resolve through `test_resolved_home`, which prefers a thread-local override and otherwise uses the real home captured before any test replaced `HOME`. Nothing reads the mutable variable on the resolution path any more. - `with_temp_home` still writes `HOME` (Tauri needs it) but also installs the thread-local override, so tests that do install it keep their private layout, and tests that do not are immune. - `lock_home_env` ignores mutex poisoning, so one panicking test no longer turns every later test into a secondary failure. `a_replaced_home_does_not_leak_into_path_resolution` pins the invariant and fails against the previous resolution (`left: Some(".../tabst-tauri-test-foreign-home")`). Test-support only; production resolution still goes straight to `home_dir()` and `document_dir()`. Verified: `cargo test` 28 passed, `cargo fmt --check`, `cargo check`, `cargo clippy --all-targets` (no new warnings), `pnpm verify:tauri` end to end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The failure
CI on #261 failed once and passed on rerun:
The assertion is about path scope, so the error surfaces far from its cause.
delete_filefirst canonicalizes the target, then resolves the implicit default workspace root, and only then checks scope. The ENOENT came out of that middle step.Root cause
with_temp_homereplaces the process-globalHOMEvariable for the duration of a test, because Tauri resolvesapp_data_dir()straight from it. Nothing stopped other tests from readingHOMEwhile it was replaced.Instrumenting the resolver showed 10 misresolutions in one test run — a test running concurrently resolved its default workspace root inside another test's temporary home:
with_temp_homethen restoresHOMEand deletes that directory. Ifcreate_dir_allon the misresolved path loses the race againstremove_dir_all, it reportsNo such file or directory (os error 2)— which is exactly what the scope assertion ended up printing. That is why the failure is rare, unrelated to the assertion it breaks, and why a rerun "fixes" it.Change
Resolve deterministically instead of trying to win the timing:
default_save_dirandglobal_metadata_dirresolve throughtest_resolved_home, which prefers a thread-local override and otherwise uses the real home captured before any test replacedHOME. Nothing on the resolution path reads the mutable variable any more.with_temp_homestill writesHOME(Tauri needs it) but also installs the thread-local override, so tests that install it keep their private layout and tests that do not are immune.lock_home_envignores mutex poisoning, so one panicking test no longer turns every later test into a secondary failure.Production resolution is untouched: without
cfg(test)the override path compiles toNoneandhome_dir()/document_dir()stay the single source of truth.Verification
a_replaced_home_does_not_leak_into_path_resolutionis a new deterministic regression test. It fails against the previous resolution (left: Some(".../tabst-tauri-test-foreign-home"),right: Some("/Users/runner")) and passes now.cargo test— 28 passedcargo fmt --check,cargo check,cargo clippy --all-targets— clean, no new warningspnpm verify:tauri— end to endAn earlier version of this fix made the resolver lock the
HOMEmutex. That deadlocked the suite:scope_for_canonical_pathis called while holding the allowed-path registry mutex, so locking in the resolver inverted the lock order againstwith_temp_home. The capture-based approach avoids taking any lock on the resolution path.