Skip to content

Core: ignore empty LOCALAPPDATA, XDG_CACHE_HOME, and HOME in default directory resolution - #2579

Open
reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/core-config-default-dir-empty-env
Open

reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/core-config-default-dir-empty-env

Conversation

@reeledMarek

Copy link
Copy Markdown
Contributor

Summary

In victory-core/src/config.rs, empty environment variables (LOCALAPPDATA="", XDG_CACHE_HOME="", HOME="") were treated as valid base paths, causing default cache/config directories to resolve to relative paths under the current working directory instead of falling back properly.

Now empty values are ignored during default directory resolution.

Testing

  • cargo test -p victory-core --locked (14/14 passed, including synthetic tests for empty env values)
  • cargo clippy -p victory-core --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings (clean)
  • cargo test -p xtask --locked (6/6 passed)

@reeledMarek
reeledMarek force-pushed the fix/core-config-default-dir-empty-env branch from 49f72ee to 61349a7 Compare November 25, 2026 20:05

@lcg007xd-c lcg007xd-c left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified on Linux (Rust 1.99.0)

Branch: current main (13f91ca) + this PR (merges cleanly; it also merges cleanly with #2578).

  • cargo test --locked -p victory-core: 14 passed.
  • With the .filter(|v| !v.is_empty()) in default_dir_from removed (refactor kept), default_dir_ignores_empty_user_env_vars fails. So the test pins the fix.
  • cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-core --all-targets -- -D warnings: clean, same as main.

Review

The fix is correct, and it makes default_dir consistent with resolve's own env_path, which already drops empty values (config.rs:85). No defect found.

Prior art: the same fix was in #243 ("Config: skip an empty or relative cache base for the default directories"), which was folded into #241. #241 was then closed unmerged yesterday after a needs-rebase triage. So nothing on main covers this, and this PR is the live version. Two small follow-ups, either here or later:

  1. Relative values. #243 also skipped relative bases. The XDG Base Directory spec says implementations should treat a relative path in these variables as invalid and ignore it. XDG_CACHE_HOME=foo still yields foo/victory/cache under the working directory here, which is usually the checkout, and subdir then fails with the asset-policy error. Adding .filter(|p| p.is_absolute()) to get would cover it.
  2. Hermetic resolve. Config::resolve takes an injectable env, but its fallback still calls default_dir, which reads the real process environment (config.rs:93-97). Passing resolve's env through to default_dir_from would make the existing resolve tests independent of the host's LOCALAPPDATA/HOME.

Not verified

  • Windows runtime behaviour with an empty LOCALAPPDATA. Only the logic is covered, through the injected env.

Reviewed with Claude Code.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (small). In victory-core/src/config.rs, default_dir took an empty LOCALAPPDATA, XDG_CACHE_HOME or HOME as a base. That gave a relative victory/<name> under the current folder. Now empty values fall through to the next variable, and then to the existing "set VICTORY_CACHE_DIR and VICTORY_DATA_DIR" error. This matches how the same file already treats empty VICTORY_GAME_DIR/VICTORY_CONFIG (see its existing tests). The default_dir_from split with an injected env follows the file's pattern, and the test covers both the fallback and the error.

CI: check passing. Merges cleanly into current main. A recommendation to look at it, not an approval.


Generated by Claude Code

@Will-0f-D

Copy link
Copy Markdown

Independent native Windows verification of this PR at
61349a7fcf3d651aa812cf8b8c7369f68f7011ed, with main
63bcca43c6a00a758510398fa43096ce7e4f7df0 as the negative control.

Environment: Windows 11 Pro x64 (10.0.26300), Rust 1.98.1,
x86_64-pc-windows-msvc.

I built the same standalone probe against each checkout. Each case invokes
the public Config::load() API in a separate child process, removing the
relevant environment variables first and using a working directory with no
victory.toml. This tests the real environment path rather than calling
the injected helper directly. Both cache_dir and data_dir are checked.

Check Main PR head
Independent 10-case environment matrix 5 pass, 5 fail 10 pass
cargo test -p victory-core --locked 13 pass 14 pass
cargo clippy -p victory-core --all-targets --locked -- -D warnings not run clean
cargo test -p xtask --locked not run 6 pass

The five negative-control failures are:

  • All three base variables empty should produce the existing missing-base error.
  • Empty LOCALAPPDATA should fall through to a valid XDG_CACHE_HOME.
  • Empty LOCALAPPDATA and XDG_CACHE_HOME should fall through to a valid HOME.
  • Absent LOCALAPPDATA and empty XDG_CACHE_HOME should fall through to HOME.
  • Empty HOME with the other bases absent should produce the missing-base error.

Main returns relative paths for these cases; this PR produces the expected
fallbacks or error. The passing controls cover all bases absent, normal
LOCALAPPDATA/XDG/HOME precedence, HOME's .cache component, and explicit
VICTORY_CACHE_DIR/VICTORY_DATA_DIR overrides when the bases are empty.

No game files, GPU or gameplay used. No production code changes or duplicate
fix: credit for the implementation remains with the PR author.

AI-assisted verification and probe authoring with OpenAI Codex. This is a
focused verification report, not a full-workspace test or formal approval.

@fuzeofficlal fuzeofficlal 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.

Looks good. Verified merged onto main (63bcca43) on Windows 11:

  • default_dir_from (crates/victory-core/src/config.rs:147-159) cleanly filters empty values via .filter(|v| !v.is_empty()), matching the existing env_path and explicit_config_path conventions in config.rs and preserving non-UTF-8 OsString paths.
  • cargo xtask policy (191 files ok), cargo clippy --locked -p victory-core --all-targets -- -D warnings (default and --all-features), and cargo test --locked -p victory-core (14/14, including default_dir_ignores_empty_user_env_vars) all pass.
  • Additional verification passed across the full 27-state (LOCALAPPDATA, XDG_CACHE_HOME, HOME) x {unset, "", valid} matrix, a Windows unpaired-surrogate OsString path check, and 3 real Windows 11 child-process Config::load() checks confirming empty LOCALAPPDATA falls through to XDG_CACHE_HOME, then HOME/.cache, and returns Err when all three are empty.

(Non-blocking note: Config::resolve still calls default_dir directly rather than threading its env closure into default_dir_from, which is fine as-is and can be left for a separate cleanup if ever needed.)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants