fix(test): unbreak Windows runtime tests#267
Merged
Merged
Conversation
Five tests compiled on Windows but failed at runtime — fix each at the
underlying cause rather than disabling.
- profiles loader: stop poking process-global env vars by hand; use
the shared `EnvGuard` from `test_support` so the test serialises
against every other env-mutating test in the crate.
- sed validation: cfg-split the deny-substring and cwd path so the
test matches the platform's native separator (`/` on POSIX, `\`
on Windows). The expected `PathBuf` derives from the cwd join so
it stays separator-agnostic.
- brief attachments: a `TempDir`-based "outside" file lives under
`%USERPROFILE%\AppData\Local\Temp` on Windows, so the home-prefix
check accepts it (HOME-env override doesn't reach `dirs::home_dir()`
on Windows). Use `/etc/hostname` on POSIX and a stable system path
outside the user profile on Windows.
- config_tool (both tests): introduce `agent_config_dir()` in
`crates/lib/src/config/mod.rs` that honors `XDG_CONFIG_HOME` on
every platform (the base `dirs::config_dir()` ignores it on
Windows). Route every existing `dirs::config_dir().map(|d|
d.join("agent-code"))` call site through the new helper so a
single `XDG_CONFIG_HOME` override is hermetic on Linux, macOS,
and Windows alike.
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.
Summary
Five tests compiled on Windows but failed at runtime on
main. Each had a distinct cross-platform bug; this PR fixes them at the underlying cause rather than disabling.services::profiles::tests::load_profile_migrates_legacy_token_field_and_rewrites_on_disk— replace hand-rolled env stashing with the sharedEnvGuardfromcrates/lib/src/test_support.rsso the test serialises against every other env-mutating test.tools::bash::sed_validation::tests::relative_paths_are_resolved_against_cwd— cfg-split the deny-substring + cwd path so the test matches the platform's native separator (/on POSIX,\on Windows). The expectedPathBufderives fromcwd.join(".git/HEAD")so it stays separator-agnostic.tools::brief::tests::validate_attachments_rejects_outside_cwd_and_home—/etc/hostnamedoesn't exist on Windows (existence check fires first, masking the boundary check). ATempDir-based outside file would also lose to thedirs::home_dir()containment check on Windows because tempdirs sit under%USERPROFILE%\AppData\Local\Tempanddirs::home_dir()ignoresHOMEthere. Use/etc/hostnameon POSIX andC:\Windows\System32\drivers\etc\hostson Windows.tools::config_tool::tests::set_user_scope_writes_to_xdg_config_home+tools::config_tool::tests::concurrent_set_calls_persist_both_keys— both tests assumedXDG_CONFIG_HOMEwould redirectdirs::config_dir()on every platform. It doesn't on Windows (dirsreads%APPDATA%viaSHGetKnownFolderPath). Introducecrate::config::agent_config_dir()that consultsXDG_CONFIG_HOMEfirst on every platform, route everydirs::config_dir().map(|d| d.join(\"agent-code\"))call site through it, and the tests' single env override becomes hermetic on Linux, macOS, and Windows alike.The new
agent_config_dir()helper supersedes the in-tree patterndirs::config_dir().map(|d| d.join(\"agent-code\"))everywhere it appeared (15 call sites incrates/libandcrates/cli); the only remainingdirs::config_dir()call is inside the helper itself. The schedule e2e tests incrates/cli/tests/schedule.rsthat currently#[cfg_attr(target_os = \"windows\", ignore)]for this exact reason are intentionally left alone — re-enabling them is out of scope for this PR.Test plan
cargo fmt --all -- --checkcleancargo check --all-targetscleancargo clippy --all-targets -- -D warningscleancargo test --all-targetspasses on Linux (modulo pre-existingbwrap_*sandbox failures from missing user-namespace permissions)