docs/env.md: every VICTORY_* switch, generated by cargo xtask env; warn on unknown ones #83

Closed
lcg007xd-c wants to merge 0 commits from upstream-pr/83 into main
lcg007xd-c commented 2026-11-25 22:08:54 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:08:54Z.


What

The code reads 256 VICTORY_* environment switches. The README, the other docs and victory.example.toml describe 54 of them (issue #1 points at the undocumented ones). There was no list, so nothing tells a user that a switch is spelled wrong or has been renamed. It just does nothing.

  • cargo xtask env writes docs/env.md. It lists every VICTORY_* name that appears as a whole string literal in the Rust source, the files that read it, and whether the hand-written docs describe it. The table doesn't try to describe each switch. It shows where to look, and which ones still need writing up.
  • A test watches the table. When the table is stale, env_table_is_current prints a warning naming the command that fixes it, and passes. With VICTORY_STRICT_TESTS=1 (the switch the shader test skips use) it fails. cargo xtask env --check always fails on a stale table.
  • victory-core reads the table back. At logging setup, every binary now warns about a set VICTORY_* variable that isn't in the table, for example: warning: VICTORY_RELAYS is set but is no known switch (docs/env.md): a typo?.

Friction

A PR that adds a switch without rerunning cargo xtask env only gets a test warning. No one's PR goes red over it. Until the table is regenerated, the startup warning also names that new switch, and its wording ("a typo?") allows for that.

Tests

  • env_table_is_current, plus only_whole_literals_count: "VICTORY_X" counts, but a message that starts with the prefix doesn't.
  • the_table_lists_the_log_filter and unknown_names_with_the_prefix_are_reported in victory-core.
  • I checked the table against a plain git grep of quoted VICTORY_ names: the two lists are identical. A CRLF checkout of the table still passes. With one row removed, the test warns by default and fails when strict.
  • The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally.

Not tested: the warning when running the real binary on Windows. It's one eprintln! in logging::init, which every binary calls.

🤖 Generated with Claude Code

<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:5500019465 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VitoriaBr2.0/pull/83). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T22:08:54Z. --- ## What The code reads 256 `VICTORY_*` environment switches. The README, the other docs and `victory.example.toml` describe 54 of them (issue #1 points at the undocumented ones). There was no list, so nothing tells a user that a switch is spelled wrong or has been renamed. It just does nothing. - **`cargo xtask env` writes `docs/env.md`.** It lists every `VICTORY_*` name that appears as a whole string literal in the Rust source, the files that read it, and whether the hand-written docs describe it. The table doesn't try to describe each switch. It shows where to look, and which ones still need writing up. - **A test watches the table.** When the table is stale, `env_table_is_current` prints a warning naming the command that fixes it, and passes. With `VICTORY_STRICT_TESTS=1` (the switch the shader test skips use) it fails. `cargo xtask env --check` always fails on a stale table. - **victory-core reads the table back.** At logging setup, every binary now warns about a set `VICTORY_*` variable that isn't in the table, for example: `warning: VICTORY_RELAYS is set but is no known switch (docs/env.md): a typo?`. ## Friction A PR that adds a switch without rerunning `cargo xtask env` only gets a test warning. No one's PR goes red over it. Until the table is regenerated, the startup warning also names that new switch, and its wording ("a typo?") allows for that. ## Tests - `env_table_is_current`, plus `only_whole_literals_count`: `"VICTORY_X"` counts, but a message that starts with the prefix doesn't. - `the_table_lists_the_log_filter` and `unknown_names_with_the_prefix_are_reported` in victory-core. - I checked the table against a plain `git grep` of quoted `VICTORY_` names: the two lists are identical. A CRLF checkout of the table still passes. With one row removed, the test warns by default and fails when strict. - The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. Not tested: the warning when running the real binary on Windows. It's one `eprintln!` in `logging::init`, which every binary calls. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lmouz823-lang commented 2026-11-28 04:41:12 +00:00 (Migrated from github.com)

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


I can take native Windows entry-point validation at exact head de13cf4fb97c522f75b952b9a64cb60362bdfe10. I will check mixed-case known and unknown environment names through public logging::init in fresh processes, alongside switches::unread, since Windows environment lookup is case-insensitive. If this reproduces false warnings or missed typos, I will propose a small Windows-only comparison fix with a regression, preserve the reported spelling, and verify the generated environment table. I will report the precise head, existing merge-conflict status, before/after evidence and any skipped scope here. AI-assisted with Codex.

<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7234195160 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/83#issuecomment-7234195160). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T04:41:12Z. --- I can take native Windows entry-point validation at exact head `de13cf4fb97c522f75b952b9a64cb60362bdfe10`. I will check mixed-case known and unknown environment names through public logging::init in fresh processes, alongside switches::unread, since Windows environment lookup is case-insensitive. If this reproduces false warnings or missed typos, I will propose a small Windows-only comparison fix with a regression, preserve the reported spelling, and verify the generated environment table. I will report the precise head, existing merge-conflict status, before/after evidence and any skipped scope here. AI-assisted with Codex.
lmouz823-lang commented 2026-11-28 04:52:15 +00:00 (Migrated from github.com)

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


Native Windows validation found and fixed a name-comparison issue on exact head de13cf4fb97c522f75b952b9a64cb60362bdfe10. The attached patch targets that head, whose current merge status conflicts with main.

Windows environment variable names are case-insensitive. The original prefix and HashSet checks in switches::unread use exact spelling. This gives both an incorrect warning for a known mixed-case variable and a missed warning for an unknown variable with a lower-case prefix. Microsoft environment-variable documentation

I reproduced this through a tiny external binary calling the public logging::init("info"). Each case uses a fresh child process and external working directory. The driver clears inherited VICTORY variables and RUST_LOG, sets one test-owned value, prints the actual name from vars_os() and the result of reading its canonical upper-case name, then captures the startup warning. CANONICAL_READ uses the current case's name in upper case, so victory_LOGG is read as VICTORY_LOGG. Every canonical read returned Some("info"), including the mixed-case names.

Environment spelling Original startup warning With patch
VICTORY_LOG None, correct None
VICTORY_log Incorrectly warns it is unknown None
Victory_LOG None, correct None
VICTORY_LOGG Reports the typo Reports original spelling
victory_LOGG Misses the typo Reports original spelling
PR83_UNRELATED None, correct None

The fix creates an ASCII upper-case comparison key on Windows, preserving the original spelling in the returned warning names and their existing sort order. The non-Windows branch compares the original spelling. The added Windows-only regression supplies synthetic names and checks that both typo spellings survive while the known spellings are accepted. Its names are built from PREFIX so the environment-table generator cannot mistake test typos for supported switches.

  • The original two exact switches tests and full core suite pass, 16/16.
  • With the regression added to the original comparison, it runs one test and fails with exit 101.
  • With the comparison fixed, all three exact switches tests pass, the complete core library passes 17/17, and all six public logging scenarios produce the expected warnings.
  • The final formatted source was recompiled and the new exact test, full library and external probe were repeated successfully.
  • cargo xtask env --check reports current on both head and patch. docs/env.md is byte-identical. Core Clippy with -D warnings, rustfmt on the changed file, and git diff --check pass.

Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated build directory. No cases in the six-scenario startup matrix were skipped, and the final core suite has no ignored tests. Native Unix execution and integration onto current main remain unverified.

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

Focused patch against this PR head
diff --git a/crates/victory-core/src/switches.rs b/crates/victory-core/src/switches.rs
index a990c10..8a51ead 100644
--- a/crates/victory-core/src/switches.rs
+++ b/crates/victory-core/src/switches.rs
@@ -25,7 +25,16 @@ pub fn unread(vars: impl IntoIterator<Item = (OsString, OsString)>) -> Vec<Strin
     let mut unread: Vec<String> = vars
         .into_iter()
         .filter_map(|(k, _)| k.into_string().ok())
-        .filter(|k| k.starts_with(PREFIX) && !known.contains(k.as_str()))
+        .filter(|k| {
+            // Windows environment names are case-insensitive. Keep the original
+            // spelling for the warning, while matching the table's ASCII names.
+            let key = if cfg!(windows) {
+                k.to_ascii_uppercase()
+            } else {
+                k.clone()
+            };
+            key.starts_with(PREFIX) && !known.contains(key.as_str())
+        })
         .collect();
     unread.sort();
     unread
@@ -55,4 +64,23 @@ mod tests {
         ];
         assert_eq!(unread(vars), [typo]);
     }
+    #[cfg(windows)]
+    #[test]
+    fn windows_environment_names_are_compared_without_case() {
+        let var = |name: String| (OsString::from(name), OsString::from("info"));
+        let lower_prefix = PREFIX.to_ascii_lowercase();
+        let upper_typo = format!("{PREFIX}LOGG");
+        let lower_typo = format!("{lower_prefix}LOGG");
+        let vars = [
+            var(format!("{PREFIX}LOG")),
+            var(format!("{PREFIX}log")),
+            var(format!("{lower_prefix}LOG")),
+            var(upper_typo.clone()),
+            var(lower_typo.clone()),
+            var("PATH".into()),
+        ];
+        let mut expected = vec![upper_typo, lower_typo];
+        expected.sort();
+        assert_eq!(unread(vars), expected);
+    }
 }
External probe and reproduction

Public logging entry-point reproduction

Create an external probe directory with the three files below. Replace <checkout> in the manifest with the exact PR checkout path using forward slashes. Set $probeDir to that external directory. Run the matrix on the unmodified head with before, then apply the patch, rebuild and use after.

$probeDir = 'C:/Temp/pr83-logging-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/pr83-logging-probe.exe') before
# Apply the comparison/test patch to the PR checkout, then rebuild.
cargo build --manifest-path (Join-Path $probeDir 'Cargo.toml')
python (Join-Path $probeDir 'public-probe-matrix.py') (Join-Path $probeDir 'target/debug/pr83-logging-probe.exe') after

The before matrix asserts both observed incorrect warnings and the four successful controls. The after matrix requires all six warnings to follow Windows environment-name semantics.

Cargo.toml

[package]
name = "pr83-logging-probe"
version = "0.1.0"
edition = "2024"

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

src/main.rs

fn main() {
    let key = std::env::args().nth(1).expect("test variable name");
    let matching_names: Vec<_> = std::env::vars_os()
        .filter(|(name, _)| name.to_string_lossy().eq_ignore_ascii_case(&key))
        .map(|(name, _)| name)
        .collect();
    println!("ENUMERATED_NAMES={matching_names:?}");
    println!(
        "CANONICAL_READ={:?}",
        std::env::var_os(key.to_ascii_uppercase())
    );
    println!(
        "UNREAD={:?}",
        victory_core::switches::unread(std::env::vars_os())
    );
    victory_core::logging::init("info");
}

public-probe-matrix.py

import argparse
import os
from pathlib import Path
import subprocess
import tempfile

parser = argparse.ArgumentParser()
parser.add_argument("probe", type=Path)
parser.add_argument("phase", choices=["before", "after"])
args = parser.parse_args()
probe = args.probe.resolve()
cases = [
    ("canonical-known", "VICTORY_LOG", False),
    ("suffix-mixed-known", "VICTORY_log", False),
    ("prefix-mixed-known", "Victory_LOG", False),
    ("upper-typo", "VICTORY_LOGG", True),
    ("lower-prefix-typo", "victory_LOGG", True),
    ("unrelated", "PR83_UNRELATED", False),
]
with tempfile.TemporaryDirectory(prefix="pr83-logging-") as cwd:
    for case, key, should_warn in cases:
        env = {k: v for k, v in os.environ.items()
               if not k.upper().startswith("VICTORY_") and k.upper() != "RUST_LOG"}
        env[key] = "info"
        result = subprocess.run([str(probe), key], env=env, cwd=cwd,
                                capture_output=True, text=True, check=True)
        print(case)
        print(result.stdout, end="")
        print(result.stderr, end="")
        assert f'ENUMERATED_NAMES=["{key}"]' in result.stdout
        assert 'CANONICAL_READ=Some("info")' in result.stdout
        warning = f"warning: {key} is set but is no known switch (docs/env.md): a typo?"
        warnings = [line for line in result.stderr.splitlines() if line.startswith("warning:")]
        expected = [warning] if should_warn else []
        if args.phase == "before" and case == "suffix-mixed-known":
            assert warnings == [warning]
        elif args.phase == "before" and case == "lower-prefix-typo":
            assert warnings == []
        else:
            assert warnings == expected

Core regression commands follow.

cargo test --locked -p victory-core --lib switches::tests::windows_environment_names_are_compared_without_case -- --exact --nocapture --test-threads=1
cargo test --locked -p victory-core --lib -- --nocapture --test-threads=1
cargo clippy --locked -p victory-core --all-targets -- -D warnings
cargo xtask env --check
<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7234310386 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/83#issuecomment-7234310386). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T04:52:15Z. --- Native Windows validation found and fixed a name-comparison issue on exact head `de13cf4fb97c522f75b952b9a64cb60362bdfe10`. The attached patch targets that head, whose current merge status conflicts with main. Windows environment variable names are case-insensitive. The original prefix and `HashSet` checks in `switches::unread` use exact spelling. This gives both an incorrect warning for a known mixed-case variable and a missed warning for an unknown variable with a lower-case prefix. [Microsoft environment-variable documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4) I reproduced this through a tiny external binary calling the public `logging::init("info")`. Each case uses a fresh child process and external working directory. The driver clears inherited VICTORY variables and RUST_LOG, sets one test-owned value, prints the actual name from `vars_os()` and the result of reading its canonical upper-case name, then captures the startup warning. `CANONICAL_READ` uses the current case's name in upper case, so `victory_LOGG` is read as `VICTORY_LOGG`. Every canonical read returned `Some("info")`, including the mixed-case names. | Environment spelling | Original startup warning | With patch | | --- | --- | --- | | `VICTORY_LOG` | None, correct | None | | `VICTORY_log` | Incorrectly warns it is unknown | None | | `Victory_LOG` | None, correct | None | | `VICTORY_LOGG` | Reports the typo | Reports original spelling | | `victory_LOGG` | Misses the typo | Reports original spelling | | `PR83_UNRELATED` | None, correct | None | The fix creates an ASCII upper-case comparison key on Windows, preserving the original spelling in the returned warning names and their existing sort order. The non-Windows branch compares the original spelling. The added Windows-only regression supplies synthetic names and checks that both typo spellings survive while the known spellings are accepted. Its names are built from PREFIX so the environment-table generator cannot mistake test typos for supported switches. - The original two exact switches tests and full core suite pass, **16/16**. - With the regression added to the original comparison, it runs one test and fails with exit 101. - With the comparison fixed, all three exact switches tests pass, the complete core library passes **17/17**, and all six public logging scenarios produce the expected warnings. - The final formatted source was recompiled and the new exact test, full library and external probe were repeated successfully. - `cargo xtask env --check` reports current on both head and patch. `docs/env.md` is byte-identical. Core Clippy with `-D warnings`, rustfmt on the changed file, and `git diff --check` pass. Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated build directory. No cases in the six-scenario startup matrix were skipped, and the final core suite has no ignored tests. Native Unix execution and integration onto current main remain unverified. AI assistance from Codex covered the patch, probe, execution and this report. <details> <summary>Focused patch against this PR head</summary> ```diff diff --git a/crates/victory-core/src/switches.rs b/crates/victory-core/src/switches.rs index a990c10..8a51ead 100644 --- a/crates/victory-core/src/switches.rs +++ b/crates/victory-core/src/switches.rs @@ -25,7 +25,16 @@ pub fn unread(vars: impl IntoIterator<Item = (OsString, OsString)>) -> Vec<Strin let mut unread: Vec<String> = vars .into_iter() .filter_map(|(k, _)| k.into_string().ok()) - .filter(|k| k.starts_with(PREFIX) && !known.contains(k.as_str())) + .filter(|k| { + // Windows environment names are case-insensitive. Keep the original + // spelling for the warning, while matching the table's ASCII names. + let key = if cfg!(windows) { + k.to_ascii_uppercase() + } else { + k.clone() + }; + key.starts_with(PREFIX) && !known.contains(key.as_str()) + }) .collect(); unread.sort(); unread @@ -55,4 +64,23 @@ mod tests { ]; assert_eq!(unread(vars), [typo]); } + #[cfg(windows)] + #[test] + fn windows_environment_names_are_compared_without_case() { + let var = |name: String| (OsString::from(name), OsString::from("info")); + let lower_prefix = PREFIX.to_ascii_lowercase(); + let upper_typo = format!("{PREFIX}LOGG"); + let lower_typo = format!("{lower_prefix}LOGG"); + let vars = [ + var(format!("{PREFIX}LOG")), + var(format!("{PREFIX}log")), + var(format!("{lower_prefix}LOG")), + var(upper_typo.clone()), + var(lower_typo.clone()), + var("PATH".into()), + ]; + let mut expected = vec![upper_typo, lower_typo]; + expected.sort(); + assert_eq!(unread(vars), expected); + } } ``` </details> <details> <summary>External probe and reproduction</summary> ## Public logging entry-point reproduction Create an external probe directory with the three files below. Replace `<checkout>` in the manifest with the exact PR checkout path using forward slashes. Set `$probeDir` to that external directory. Run the matrix on the unmodified head with `before`, then apply the patch, rebuild and use `after`. ```powershell $probeDir = 'C:/Temp/pr83-logging-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/pr83-logging-probe.exe') before # Apply the comparison/test patch to the PR checkout, then rebuild. cargo build --manifest-path (Join-Path $probeDir 'Cargo.toml') python (Join-Path $probeDir 'public-probe-matrix.py') (Join-Path $probeDir 'target/debug/pr83-logging-probe.exe') after ``` The `before` matrix asserts both observed incorrect warnings and the four successful controls. The `after` matrix requires all six warnings to follow Windows environment-name semantics. ### Cargo.toml ```toml [package] name = "pr83-logging-probe" version = "0.1.0" edition = "2024" [dependencies] victory-core = { path = "<checkout>/crates/victory-core" } ``` ### src/main.rs ```rust fn main() { let key = std::env::args().nth(1).expect("test variable name"); let matching_names: Vec<_> = std::env::vars_os() .filter(|(name, _)| name.to_string_lossy().eq_ignore_ascii_case(&key)) .map(|(name, _)| name) .collect(); println!("ENUMERATED_NAMES={matching_names:?}"); println!( "CANONICAL_READ={:?}", std::env::var_os(key.to_ascii_uppercase()) ); println!( "UNREAD={:?}", victory_core::switches::unread(std::env::vars_os()) ); victory_core::logging::init("info"); } ``` ### public-probe-matrix.py ```python import argparse import os from pathlib import Path import subprocess import tempfile parser = argparse.ArgumentParser() parser.add_argument("probe", type=Path) parser.add_argument("phase", choices=["before", "after"]) args = parser.parse_args() probe = args.probe.resolve() cases = [ ("canonical-known", "VICTORY_LOG", False), ("suffix-mixed-known", "VICTORY_log", False), ("prefix-mixed-known", "Victory_LOG", False), ("upper-typo", "VICTORY_LOGG", True), ("lower-prefix-typo", "victory_LOGG", True), ("unrelated", "PR83_UNRELATED", False), ] with tempfile.TemporaryDirectory(prefix="pr83-logging-") as cwd: for case, key, should_warn in cases: env = {k: v for k, v in os.environ.items() if not k.upper().startswith("VICTORY_") and k.upper() != "RUST_LOG"} env[key] = "info" result = subprocess.run([str(probe), key], env=env, cwd=cwd, capture_output=True, text=True, check=True) print(case) print(result.stdout, end="") print(result.stderr, end="") assert f'ENUMERATED_NAMES=["{key}"]' in result.stdout assert 'CANONICAL_READ=Some("info")' in result.stdout warning = f"warning: {key} is set but is no known switch (docs/env.md): a typo?" warnings = [line for line in result.stderr.splitlines() if line.startswith("warning:")] expected = [warning] if should_warn else [] if args.phase == "before" and case == "suffix-mixed-known": assert warnings == [warning] elif args.phase == "before" and case == "lower-prefix-typo": assert warnings == [] else: assert warnings == expected ``` Core regression commands follow. ```powershell cargo test --locked -p victory-core --lib switches::tests::windows_environment_names_are_compared_without_case -- --exact --nocapture --test-threads=1 cargo test --locked -p victory-core --lib -- --nocapture --test-threads=1 cargo clippy --locked -p victory-core --all-targets -- -D warnings cargo xtask env --check ``` </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!83
No description provided.