Config: an empty VICTORY_CONFIG means unset (port of VIctory#363) #52

Closed
lcg007xd-c wants to merge 0 commits from upstream-pr/52 into main
lcg007xd-c commented 2026-11-25 20:53:42 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T20:53:42Z.


What

Config::load treated an empty VICTORY_CONFIG as an explicit path. PathBuf::from("") is not a file, so startup aborted with "VICTORY_CONFIG points at , which does not exist". The other path variables already treat an empty value as unset. This one now does too: VICTORY_CONFIG= falls back to ./victory.toml (or to no config file), and a non-empty value still selects that exact file.

This comes up with launchers and scripts that always export the variable, sometimes empty.

Port

Cherry-pick (-x) of github.com/Marvisak/VIctory@fd44561 from upstream https://github.com/Marvisak/VIctory/pull/363. Enzo Souza Duarte is still the commit author. It applied cleanly.

Test

empty_config_env_is_ignored covers the empty and non-empty cases through the new explicit_config_path helper. The helper is new, so the test doesn't compile against the old code. The old behaviour is the bug: std::env::var_os returned Some(""), which was used as the path.

How this was checked (Linux, no Windows PC or game files)

  • The portable CI commands pass locally on this branch: cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings, then cargo test on the same crates (rebased on current main).
  • cargo clippy with the same crates and --target x86_64-pc-windows-msvc (check only, no link) is clean.
  • rustfmt --check is clean on the changed file.

Not tested: Windows runtime, GPU (D3D12/DXIL validation) and the game itself.

🤖 Generated with Claude Code

<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:5499002451 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VitoriaBr2.0/pull/52). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:53:42Z. --- ## What `Config::load` treated an empty `VICTORY_CONFIG` as an explicit path. `PathBuf::from("")` is not a file, so startup aborted with "VICTORY_CONFIG points at , which does not exist". The other path variables already treat an empty value as unset. This one now does too: `VICTORY_CONFIG=` falls back to `./victory.toml` (or to no config file), and a non-empty value still selects that exact file. This comes up with launchers and scripts that always export the variable, sometimes empty. ## Port Cherry-pick (`-x`) of https://github.com/Marvisak/VIctory/commit/fd44561 from upstream https://github.com/Marvisak/VIctory/pull/363. Enzo Souza Duarte is still the commit author. It applied cleanly. ## Test `empty_config_env_is_ignored` covers the empty and non-empty cases through the new `explicit_config_path` helper. The helper is new, so the test doesn't compile against the old code. The old behaviour is the bug: `std::env::var_os` returned `Some("")`, which was used as the path. ## How this was checked (Linux, no Windows PC or game files) - The portable CI commands pass locally on this branch: `cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings`, then `cargo test` on the same crates (rebased on current `main`). - `cargo clippy` with the same crates and `--target x86_64-pc-windows-msvc` (check only, no link) is clean. - `rustfmt --check` is clean on the changed file. Not tested: Windows runtime, GPU (D3D12/DXIL validation) and the game itself. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lmouz823-lang commented 2026-11-28 04:10:54 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T04:10:54Z.


I can take native Windows configuration-entry validation at exact head cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef. I will run the existing empty-config regression, then exercise public Config::load in separate processes for unset, explicitly empty, custom-file and missing-file cases. The probe will report the actual environment value so empty and unset are distinguishable. I will compare the empty-value case with the old call-site behavior, restore and rerun, then report the exact native results and limits here. AI-assisted with Codex.

<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7233776712 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/52#issuecomment-7233776712). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T04:10:54Z. --- I can take native Windows configuration-entry validation at exact head `cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef`. I will run the existing empty-config regression, then exercise public Config::load in separate processes for unset, explicitly empty, custom-file and missing-file cases. The probe will report the actual environment value so empty and unset are distinguishable. I will compare the empty-value case with the old call-site behavior, restore and rerun, then report the exact native results and limits here. AI-assisted with Codex.
lmouz823-lang commented 2026-11-28 04:17:28 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T04:17:28Z.


Native Windows/MSVC validation completed on exact head cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef, using Windows 11 build 26200 and Rust 1.98.1 in the default test profile.

The exact config::tests::empty_config_env_is_ignored test passes, and the complete victory-core --lib suite passes 15/15, with zero failed, ignored or filtered tests.

I also exercised the public victory_core::Config::load() entry point through a tiny external probe. Each scenario runs in a fresh process and external working directory. The driver clears inherited VICTORY_* variables, uses test-owned configuration and LOCALAPPDATA paths, and supplies empty values through Python's subprocess environment dictionary. The probe prints and asserts the actual std::env::var_os("VICTORY_CONFIG"), the selected source and the parsed game/cache/data markers.

Child environment and files Actual public-entry result
Unset, victory.toml present None, loads victory.toml and its markers
Explicit empty, victory.toml present Some(""), loads victory.toml and its markers
custom.toml, both files present Loads custom.toml and its distinct markers
missing.toml, default file present Expected missing-file error
Unset, default file absent None, source is None and default directories resolve under test LOCALAPPDATA
Explicit empty, default file absent Some(""), same default resolution

The negative control restores only the old Config::load selection line, leaving the helper and unit test intact. The helper unit test still passes, while both genuinely-empty public-entry scenarios fail with VICTORY_CONFIG points at ..., which does not exist and exit 101. The other four scenarios retain their expected behavior. This checks that the fix is wired into the public entry point.

After restoring the exact-head bytes, cleaning this task's core package and rebuilding both test and probe, the exact unit test, full 15-test library and all six public-entry scenarios pass again. Final source bytes match the head, the worktree is clean, and git diff --check passes. This validation required no additional repository patch.

AI assistance from Codex covered the probe, execution, independent review and this report.

External probe source and reproduction

Public-entry reproduction

Check out PR head cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef. Create a separate probe directory outside the checkout containing Cargo.toml, src/main.rs and public-probe-matrix.py from the blocks below. Replace <checkout> in the manifest with the absolute checkout path using forward slashes.

The driver runs six independent child processes with synthetic configuration, clears inherited VICTORY variables, and verifies the exact empty-value state reported by Rust. It uses a fresh temporary working directory and test-owned LOCALAPPDATA. The probe calls the public API and checks the selected source and all path markers.

Set $probeDir to the external probe directory, then run the commands below with Rust 1.98.1 and Python 3 available.

$probeDir = 'C:/Temp/pr52-config-probe'
$env:CARGO_TARGET_DIR = Join-Path $probeDir 'target'
cargo build --manifest-path (Join-Path $probeDir 'Cargo.toml')
python (Join-Path $probeDir 'public-probe-matrix.py') (Join-Path $probeDir 'target/debug/pr52-config-load-probe.exe')

For the negative control, replace only the Config::load selection line with let explicit = std::env::var_os("VICTORY_CONFIG").map(PathBuf::from);, retain the helper and unit test, rebuild the probe, and run the matrix. The first explicit-empty case exits 101. Restore the PR line, clean the task-specific core build and rebuild to repeat the passing matrix.

Cargo.toml

[package]
name = "pr52-config-load-probe"
version = "0.1.0"
edition = "2024"

[dependencies]
victory-core = { path = "<checkout>/crates/victory-core" }

src/main.rs

use std::ffi::OsString;
use std::path::PathBuf;

fn main() {
    let case = std::env::args().nth(1).expect("scenario argument");
    let raw = std::env::var_os("VICTORY_CONFIG");
    println!("VICTORY_CONFIG={raw:?}");
    let expected_raw = match case.as_str() {
        "unset-file" | "unset-defaults" => None,
        "empty-file" | "empty-defaults" => Some(OsString::new()),
        "custom" => Some(OsString::from("custom.toml")),
        "missing" => Some(OsString::from("missing.toml")),
        _ => panic!("unknown scenario {case}"),
    };
    assert_eq!(raw, expected_raw, "child environment fixture mismatch");

    let result = victory_core::Config::load();
    if case == "missing" {
        let error = result.expect_err("an explicit missing file must fail");
        let message = format!("{error:#}");
        println!("LOAD_ERROR={message}");
        assert!(message.contains("VICTORY_CONFIG points at missing.toml"));
        assert!(message.contains("does not exist"));
        println!("PASS {case}");
        return;
    }

    let config = result.unwrap_or_else(|error| panic!("Config::load failed: {error:#}"));
    println!("SOURCE={:?}", config.source);
    println!("GAME_DIR={:?}", config.game_dir);
    println!("CACHE_DIR={:?}", config.cache_dir);
    println!("DATA_DIR={:?}", config.data_dir);
    let (source, game, cache, data) = if case.ends_with("-defaults") {
        let base = PathBuf::from(std::env::var_os("LOCALAPPDATA").expect("test appdata"))
            .join("victory");
        (None, None, base.join("cache"), base.join("data"))
    } else if case == "custom" {
        (
            Some(PathBuf::from("custom.toml")),
            Some(PathBuf::from("game-custom")),
            PathBuf::from("cache-custom"),
            PathBuf::from("data-custom"),
        )
    } else {
        (
            Some(PathBuf::from("victory.toml")),
            Some(PathBuf::from("game-default")),
            PathBuf::from("cache-default"),
            PathBuf::from("data-default"),
        )
    };
    assert_eq!(config.source, source);
    assert_eq!(config.game_dir, game);
    assert_eq!(config.cache_dir, cache);
    assert_eq!(config.data_dir, data);
    println!("PASS {case}");
}

public-probe-matrix.py

import os
from pathlib import Path
import subprocess
import sys
import tempfile

probe = Path(sys.argv[1]).resolve()
with tempfile.TemporaryDirectory(prefix="pr52-config-") as temporary:
    root = Path(temporary)
    with_file = root / "with-config"
    no_file = root / "without-config"
    appdata = root / "appdata"
    for directory in (with_file, no_file, appdata):
        directory.mkdir()
    for marker, filename in (("default", "victory.toml"), ("custom", "custom.toml")):
        (with_file / filename).write_text(
            f'[paths]\ngame_dir = "game-{marker}"\ncache_dir = "cache-{marker}"\n'
            f'data_dir = "data-{marker}"\n', encoding="utf-8")
    cases = (
        ("unset-file", None, with_file),
        ("empty-file", "", with_file),
        ("custom", "custom.toml", with_file),
        ("missing", "missing.toml", with_file),
        ("unset-defaults", None, no_file),
        ("empty-defaults", "", no_file),
    )
    for case, value, cwd in cases:
        env = {k: v for k, v in os.environ.items() if not k.upper().startswith("VICTORY_")}
        env["LOCALAPPDATA"] = str(appdata)
        if value is not None:
            env["VICTORY_CONFIG"] = value
        result = subprocess.run([str(probe), case], cwd=cwd, env=env,
                                capture_output=True, text=True)
        print(result.stdout, end="")
        print(result.stderr, end="")
        result.check_returncode()
        expected = "None" if value is None else f'Some("{value}")'
        assert f"VICTORY_CONFIG={expected}" in result.stdout
        assert f"PASS {case}" in result.stdout
<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7233892187 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/52#issuecomment-7233892187). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T04:17:28Z. --- Native Windows/MSVC validation completed on exact head `cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef`, using Windows 11 build 26200 and Rust 1.98.1 in the default test profile. The exact `config::tests::empty_config_env_is_ignored` test passes, and the complete `victory-core --lib` suite passes **15/15**, with zero failed, ignored or filtered tests. I also exercised the public `victory_core::Config::load()` entry point through a tiny external probe. Each scenario runs in a fresh process and external working directory. The driver clears inherited `VICTORY_*` variables, uses test-owned configuration and LOCALAPPDATA paths, and supplies empty values through Python's subprocess environment dictionary. The probe prints and asserts the actual `std::env::var_os("VICTORY_CONFIG")`, the selected source and the parsed game/cache/data markers. | Child environment and files | Actual public-entry result | | --- | --- | | Unset, `victory.toml` present | `None`, loads `victory.toml` and its markers | | Explicit empty, `victory.toml` present | **`Some("")`**, loads `victory.toml` and its markers | | `custom.toml`, both files present | Loads `custom.toml` and its distinct markers | | `missing.toml`, default file present | Expected missing-file error | | Unset, default file absent | `None`, source is None and default directories resolve under test LOCALAPPDATA | | Explicit empty, default file absent | **`Some("")`**, same default resolution | The negative control restores only the old `Config::load` selection line, leaving the helper and unit test intact. The helper unit test still passes, while both genuinely-empty public-entry scenarios fail with `VICTORY_CONFIG points at ..., which does not exist` and exit 101. The other four scenarios retain their expected behavior. This checks that the fix is wired into the public entry point. After restoring the exact-head bytes, cleaning this task's core package and rebuilding both test and probe, the exact unit test, full 15-test library and all six public-entry scenarios pass again. Final source bytes match the head, the worktree is clean, and `git diff --check` passes. This validation required no additional repository patch. AI assistance from Codex covered the probe, execution, independent review and this report. <details> <summary>External probe source and reproduction</summary> ## Public-entry reproduction Check out PR head `cd78a0d9cf5da2f5a98f79b3f15af33dd7a6b7ef`. Create a separate probe directory outside the checkout containing `Cargo.toml`, `src/main.rs` and `public-probe-matrix.py` from the blocks below. Replace `<checkout>` in the manifest with the absolute checkout path using forward slashes. The driver runs six independent child processes with synthetic configuration, clears inherited VICTORY variables, and verifies the exact empty-value state reported by Rust. It uses a fresh temporary working directory and test-owned LOCALAPPDATA. The probe calls the public API and checks the selected source and all path markers. Set `$probeDir` to the external probe directory, then run the commands below with Rust 1.98.1 and Python 3 available. ```powershell $probeDir = 'C:/Temp/pr52-config-probe' $env:CARGO_TARGET_DIR = Join-Path $probeDir 'target' cargo build --manifest-path (Join-Path $probeDir 'Cargo.toml') python (Join-Path $probeDir 'public-probe-matrix.py') (Join-Path $probeDir 'target/debug/pr52-config-load-probe.exe') ``` For the negative control, replace only the `Config::load` selection line with `let explicit = std::env::var_os("VICTORY_CONFIG").map(PathBuf::from);`, retain the helper and unit test, rebuild the probe, and run the matrix. The first explicit-empty case exits 101. Restore the PR line, clean the task-specific core build and rebuild to repeat the passing matrix. ### Cargo.toml ```toml [package] name = "pr52-config-load-probe" version = "0.1.0" edition = "2024" [dependencies] victory-core = { path = "<checkout>/crates/victory-core" } ``` ### src/main.rs ```rust use std::ffi::OsString; use std::path::PathBuf; fn main() { let case = std::env::args().nth(1).expect("scenario argument"); let raw = std::env::var_os("VICTORY_CONFIG"); println!("VICTORY_CONFIG={raw:?}"); let expected_raw = match case.as_str() { "unset-file" | "unset-defaults" => None, "empty-file" | "empty-defaults" => Some(OsString::new()), "custom" => Some(OsString::from("custom.toml")), "missing" => Some(OsString::from("missing.toml")), _ => panic!("unknown scenario {case}"), }; assert_eq!(raw, expected_raw, "child environment fixture mismatch"); let result = victory_core::Config::load(); if case == "missing" { let error = result.expect_err("an explicit missing file must fail"); let message = format!("{error:#}"); println!("LOAD_ERROR={message}"); assert!(message.contains("VICTORY_CONFIG points at missing.toml")); assert!(message.contains("does not exist")); println!("PASS {case}"); return; } let config = result.unwrap_or_else(|error| panic!("Config::load failed: {error:#}")); println!("SOURCE={:?}", config.source); println!("GAME_DIR={:?}", config.game_dir); println!("CACHE_DIR={:?}", config.cache_dir); println!("DATA_DIR={:?}", config.data_dir); let (source, game, cache, data) = if case.ends_with("-defaults") { let base = PathBuf::from(std::env::var_os("LOCALAPPDATA").expect("test appdata")) .join("victory"); (None, None, base.join("cache"), base.join("data")) } else if case == "custom" { ( Some(PathBuf::from("custom.toml")), Some(PathBuf::from("game-custom")), PathBuf::from("cache-custom"), PathBuf::from("data-custom"), ) } else { ( Some(PathBuf::from("victory.toml")), Some(PathBuf::from("game-default")), PathBuf::from("cache-default"), PathBuf::from("data-default"), ) }; assert_eq!(config.source, source); assert_eq!(config.game_dir, game); assert_eq!(config.cache_dir, cache); assert_eq!(config.data_dir, data); println!("PASS {case}"); } ``` ### public-probe-matrix.py ```python import os from pathlib import Path import subprocess import sys import tempfile probe = Path(sys.argv[1]).resolve() with tempfile.TemporaryDirectory(prefix="pr52-config-") as temporary: root = Path(temporary) with_file = root / "with-config" no_file = root / "without-config" appdata = root / "appdata" for directory in (with_file, no_file, appdata): directory.mkdir() for marker, filename in (("default", "victory.toml"), ("custom", "custom.toml")): (with_file / filename).write_text( f'[paths]\ngame_dir = "game-{marker}"\ncache_dir = "cache-{marker}"\n' f'data_dir = "data-{marker}"\n', encoding="utf-8") cases = ( ("unset-file", None, with_file), ("empty-file", "", with_file), ("custom", "custom.toml", with_file), ("missing", "missing.toml", with_file), ("unset-defaults", None, no_file), ("empty-defaults", "", no_file), ) for case, value, cwd in cases: env = {k: v for k, v in os.environ.items() if not k.upper().startswith("VICTORY_")} env["LOCALAPPDATA"] = str(appdata) if value is not None: env["VICTORY_CONFIG"] = value result = subprocess.run([str(probe), case], cwd=cwd, env=env, capture_output=True, text=True) print(result.stdout, end="") print(result.stderr, end="") result.check_returncode() expected = "None" if value is None else f'Some("{value}")' assert f"VICTORY_CONFIG={expected}" in result.stdout assert f"PASS {case}" in result.stdout ``` </details>

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
uiliannn/VItoriaBr!52
No description provided.