d3d12-core: ignore empty user-dir and log env vars #2874
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2874"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-12-01T13:03:39Z.
Claimed in the coordination issue as: D3D12-CORE-EMPTY-ENV-FALLBACK (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7312005362)
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)Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T13:17:04Z.
Checked the empty user-directory fallback through Config::load in a child process with
a8fcac74a+ed867d7b2on the Windows target under Wine 11.22. The child inherited explicit empty overrides, a nonemptyXDG_CACHE_HOMEcontaining a space, and a temporaryleonida.toml. Main resolved the cache as relativeleonida/cache, omitting the XDG directory. The PR used the XDG directory for cache and data and kept the config file’s synthetic folder and test-title entries. All 17 core tests passed, including the logging fallback test.AI-assisted with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T13:53:28Z.
Review: COMMENTED
Correct and well-tested. All five
LEONIDA_*path vars plusLOCALAPPDATA/XDG_CACHE_HOME/HOMEnow treat a zero-length value as unset, the new test pins both the fallback order and the all-empty error, and mutating thedefault_dirfilter fails it exactly as described ("leonida\\cache"vs"/tmp/xdg/leonida/cache").leonida-core15/0, clippy clean, merge-tree clean.The
resolve_filterextraction is a real fix, not a tidy-up:EnvFilter::try_new("")returnsOkwith an empty filter, i.e. silence everything — so an emptyLEONIDA_LOGused to black out logging entirely rather than fall through toRUST_LOG. Worth one sentence in the commit, since that is the actual bug.Two notes:
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.LEONIDA_LOG=deliberately now inheritsRUST_LOG.LEONIDA_LOG=offremains the explicit way — worth a line in the doc/comment.Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T15:35:48Z.
VERIFY-2874 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files
Verdict: PASS. Both changes fix a real defect, and each new test goes red when the change it belongs to is put back.
Head
a8fcac74, base the currentmain88a9f133, merge baseed867d7b, 1 commit, 2 files, +95/−15:d3d12/crates/leonida-core/src/config.rsandd3d12/crates/leonida-core/src/logging.rs.1. The user-directory fix, and what it was doing
main'sdefault_dir(config.rs:138):var_osreturnsSome("")for a variable that is set but empty, so an emptyLOCALAPPDATAwas used, andPathBuf::from("")joined withleonidaandcachegives:A relative path — the cache and data directories would land in the current working directory instead of the user's cache directory, and the
XDG_CACHE_HOME/HOMEfallbacks would never be reached. The pull request filters empty values out and passes the environment in so it can be tested:The new test covers the three cases that matter: an empty
LOCALAPPDATAfalls through toXDG_CACHE_HOME(/tmp/xdg/leonida/cache), emptyLOCALAPPDATAandXDG_CACHE_HOMEfall through toHOME(/tmp/home/.cache/leonida/cache), and all three empty is an error rather than a relative path.2. The log-filter fix, and a behaviour change worth naming
main'sinit():Two problems:
or_elseonly fires when the variable is unset, soLEONIDA_LOG=""was used as an empty filter (logging off) instead of falling through; andEnvFilter::try_newfailing sent the whole thing to the default level, ignoringRUST_LOG.The pull request's
resolve_filtertrims, ignores empty, and tries the next variable when one cannot be parsed:So the behaviour changes in one place beyond the empty-value case: an invalid
LEONIDA_LOGnow falls through toRUST_LOGbefore the default, wheremainwent straight to the default. The new test pins that (LEONIDA_LOG="invalid[filter"withRUST_LOG="debug"givesdebug). I think falling through is the better reading of "ignore the bad one", but it is a deliberate change and worth naming rather than leaving implicit.3. Red and green, and the discrimination
cargo test -p leonida-core(Linux, pinned toolchain):default_dirreverted tomain's empty-value handling (the test kept)config::tests::empty_user_dir_env_values_fall_back_and_missing_dirs_errorresolve_filterreverted to no trim / no empty filter (the test kept)logging::tests::empty_or_invalid_leonida_log_falls_back_to_rust_log_or_default,left: "" right: "warn"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
config::tests::empty_env_values_are_ignoredandempty_test_titles_env_is_ignoredcheck that an emptyLEONIDA_GAME_DIR/LEONIDA_TEST_TITLESis ignored. That was already the case inmain—env_pathhas filtered empty values all along (config.rs:81):So those two are regression guards for existing behaviour rather than fixes, and they would have passed against
main's production code. The two that do not pass againstmainare the ones in §3. Not a criticism of the pull request — a guard is worth having — but it is worth knowing which of the new tests carry the change.5. What I did not check
rustc 1.98.1).LOCALAPPDATAis the Windows variable, and the bug it fixes is most likely to be hit on Windows; I exercised it through the injected environment rather than through a real Windows process.leonida-gpu,leonida-hleandleonida-loaderdo not build on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows #2577"), so I ranleonida-coreon its own and not the workspace suite.tracing_subscriberoutput. The test comparesEnvFilter::to_string(), not what actually gets logged; I did not capture log lines.EnvFilter::try_newon other invalid inputs — I only exercised the empty, whitespace and one malformed value that the test uses.cargo clippy(already failing onmain, run as a report by the workflow) andcargo fmt(left out of the d3d12 workflow).AI-assisted: MiniMax M3.1 Flash.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T15:56:58Z.
Verified by OreoFR on native Windows 11 (MSVC x64), Core Ultra 7 155H, RTX 4070 Laptop. Not the author. AI-assisted (Claude Code agent
oreofr-agent, for OreoFR). No game files needed.Head
a8fcac74amerged into the currentmain0ff8a532f(tree2159e6be3, clean merge).cargo test --locked -p leonida-core→ 15 passed / 0 failed, includingconfig::tests::empty_user_dir_env_values_fall_back_and_missing_dirs_errorandlogging::tests::empty_or_invalid_leonida_log_falls_back_to_rust_log_or_default.default_dir(name, env)andresolve_filter(default_level, env), which this PR introduces, so they cannot run onmainas they are. Red by mutation instead, one at a time, each restored afterwards:config.rsdefault_dir:non_empty = |k| env(k)(empty-value filter removed) →empty_user_dir_env_values_fall_back_and_missing_dirs_errorFAILED, 14 others ok.logging.rsresolve_filter:.filter(|v| !v.is_empty())removed →empty_or_invalid_leonida_log_falls_back_to_rust_log_or_defaultFAILED, 14 others ok.Verdict from this side: the change does what it says, and its tests guard it.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T17:12:04Z.
Merging. Head
a8fcac74amerges cleanly with main0d4cbd589.Claim: kirigayakazima's PR, part of MoonEyes's DX12 train (Moon told on the bridge before this merge, no objection).
Red/green: by oreofr-agent (not the author), native Windows 11, comment above. Green
cargo test --locked -p leonida-core15/0 on main85ec1d33b+ this head (tree22b78d06f); red by mutation, each new test fails without its own fix. Main since gained only #2898 (leonida-hle, the Bink skip), which this crate does not use. Also verified by imShangLi (Linux) and merzleckeier.In-game run: not needed for the change itself (empty values of the user-directory and log variables at start-up, nothing that runs per frame). It was also in dadacap-main's train run: RTX 5080, 303 s in the world, 0 device loss.
CI: green on the head (all checks); main's CI green on
0d4cbd589.AI-assisted: yes, Claude Code agent
oreofr-agent, merged on OreoFR's (maintainer) written OK.