Repository navigation
d3d12-core: ignore empty user-dir and log env vars - #2874
Conversation
|
Checked the empty user-directory fallback through Config::load in a child process with AI-assisted with OpenAI Codex. |
KelboLive
left a comment
There was a problem hiding this comment.
Correct and well-tested. All five LEONIDA_* path vars plus LOCALAPPDATA/XDG_CACHE_HOME/HOME now treat a zero-length value as unset, the new test pins both the fallback order and the all-empty error, and mutating the default_dir filter fails it exactly as described ("leonida\\cache" vs "/tmp/xdg/leonida/cache"). leonida-core 15/0, clippy clean, merge-tree clean.
The resolve_filter extraction is a real fix, not a tidy-up: EnvFilter::try_new("") returns Ok with an empty filter, i.e. silence everything — so an empty LEONIDA_LOG used to black out logging entirely rather than fall through to RUST_LOG. Worth one sentence in the commit, since that is the actual bug.
Two notes:
- "Empty" is zero-length for paths but trim-based for logging.
LEONIDA_CACHE_DIR=" "(orLOCALAPPDATA=" ") is still accepted and produces the relative" /leonida/cache"this PR is about. Pre-existing, but it is the same class; either trim path vars too or say "zero-length only" in the comment. - Behaviour change for a mute switch: anyone who exported
LEONIDA_LOG=deliberately now inheritsRUST_LOG.LEONIDA_LOG=offremains the explicit way — worth a line in the doc/comment.
VERIFY-2874 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS. Both changes fix a real defect, and each new test goes red when the change it belongs to is put back. Head 1. The user-directory fix, and what it was doing
fn default_dir(name: &str) -> Result<PathBuf> {
let base = std::env::var_os("LOCALAPPDATA")
.or_else(|| std::env::var_os("XDG_CACHE_HOME"))
.map(PathBuf::from)
.or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))
A relative path — the cache and data directories would land in the current working directory instead of the user's cache directory, and the let non_empty = |k: &str| env(k).filter(|v| !v.is_empty());
let base = non_empty("LOCALAPPDATA")
.or_else(|| non_empty("XDG_CACHE_HOME"))
.map(PathBuf::from)
.or_else(|| non_empty("HOME").map(|h| PathBuf::from(h).join(".cache")))The new test covers the three cases that matter: an empty 2. The log-filter fix, and a behaviour change worth naming
let filter = std::env::var("LEONIDA_LOG")
.or_else(|_| std::env::var("RUST_LOG"))
.ok()
.and_then(|v| EnvFilter::try_new(v).ok())
.unwrap_or_else(|| EnvFilter::new(default_level));Two problems: The pull request's let parse = |key: &str| {
env(key)
.map(|v| v.trim().to_owned())
.filter(|v| !v.is_empty())
.and_then(|v| EnvFilter::try_new(v).ok())
};
parse("LEONIDA_LOG").or_else(|| parse("RUST_LOG")).unwrap_or_else(|| EnvFilter::new(default_level))So the behaviour changes in one place beyond the empty-value case: an invalid 3. Red and green, and the discrimination
With both reverts in place the file is back to the pull request's version and the suite is 15 passed. 4. Two of the four new tests guard behaviour that was already there
let env_path = |k: &str| env(k).filter(|v| !v.is_empty()).map(PathBuf::from);So those two are regression guards for existing behaviour rather than fixes, and they would have passed against 5. What I did not check
AI-assisted: MiniMax M3.1 Flash. |
|
Verified by OreoFR on native Windows 11 (MSVC x64), Core Ultra 7 155H, RTX 4070 Laptop. Not the author. AI-assisted (Claude Code agent Head
Verdict from this side: the change does what it says, and its tests guard it. |
|
Merging. Head |
Claimed in the coordination issue as: D3D12-CORE-EMPTY-ENV-FALLBACK (#2570 (comment))
What and why
leonida-coreignored empty values forLEONIDA_GAME_DIR,LEONIDA_CACHE_DIR,LEONIDA_DATA_DIR,LEONIDA_TEST_TITLES, andLEONIDA_CONFIG, but two fallbacks still accepted empty strings:d3d12/crates/leonida-core/src/config.rs(default_dir):default_dircalledstd::env::var_osdirectly (bypassingConfig::resolve'senvlookup closure) and did not filter.filter(|v| !v.is_empty()). IfLOCALAPPDATA=""(orXDG_CACHE_HOME=""/HOME="") was set,default_dirreturned a relative path likeleonida/cacheinstead of falling through to the next directory or returning an explicit error.default_dirnow takes&envand filters out empty values consistently with the rest ofconfig.rs, and the existing unit test env stubs provide a fakeLOCALAPPDATAvalue so tests do not read host process environment variables.d3d12/crates/leonida-core/src/logging.rs(resolve_filter):std::env::var("LEONIDA_LOG").or_else(|_| std::env::var("RUST_LOG")).ok().and_then(|v| EnvFilter::try_new(v).ok())stopped atLEONIDA_LOG=""(or invalid syntax) instead of falling back toRUST_LOG, and passed""toEnvFilter::try_new("")(which parses to an empty filter that silences all logs instead of usingdefault_level).resolve_filter, trimming and ignoring empty env strings and falling back cleanly fromLEONIDA_LOG->RUST_LOG->default_level.Tested
Verified locally (Windows 11, Rust 1.98.1, no game data):
cargo test --locked -p leonida-corefailed on bothempty_user_dir_env_values_fall_back_and_missing_dirs_errorandempty_or_invalid_leonida_log_falls_back_to_rust_log_or_default(13 passed; 2 failed).cargo test --locked -p leonida-core:15 passed; 0 failedcargo clippy --locked -p leonida-core --all-targets -- -D warnings: 0 warnings, exit 0python -I scripts/check_no_game_data.py&git diff --check: cleanGPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)