xg_xs: gate the console-oracle test modules behind an off-by-default feature #310

Closed
github-bot wants to merge 1 commit from gh-pr/310/head into gh-pr/310/base
Owner

@⁠Bexx1107 on GitHub · 2026-11-23 17:33 UTC · original
Bexx1107:xg-xs-gate-console-oracle → main · +17 −12 · 3 files · 1 commits · closed without merging

Library / area: xg_xs — test target only (crates/compat/xg_xs/Cargo.toml, src/lib.rs, src/dcc.rs)

Exports changed (exports.txt rows): none. The cdylib's 23 XG* exports are byte-identical before and after (nm -g --defined-only diff on both builds). No shipped code path changes.

Fixes #303.

The problem

crates/compat/xg_xs/src/lib.rs declares

#[cfg(test)]
mod oracle;

but crates/compat/xg_xs/src/oracle.rs is not in the repository, is not in .gitignore, and git log -S finds no commit that ever contained it. On a clean checkout:

cargo check -p xg_xs --all-targets
error[E0583]: file not found for module `oracle`          (1)
error[E0599]: no method named `f` found for type `!`      (14)
→ 15 errors

It is not one missing file. oracle is the module that defines Obj, field, first_diff, vt, Create, Oracle, SERIAL and oracle(), so the seven modules that import crate::oracle::{…} cannot typecheck either. All 19 unit tests in the crate are unrunnable, and none of them needs console data: layout::tests::*, layout3d::tests::*, computer::tests::copy_roundtrip, computer3d::tests::copy_roundtrip_3d, tests::library_init_cycle, tests::d3d12_desc_conversion, tests::optimal_swizzle_rules, tests::validate_depth_modes, tests::buffer_layout_rules, exports_table::export_table_matches_source. Verified with --list on the built binary: 19 tests, zero of them matching oracle.

Why CI does not catch it

  • .github/workflows/rust.yml:135 runs cargo check --locked --workspace — lib/bins only, no --all-targets for the compat crates.
  • .github/workflows/rust.yml:45 passes --all-targets, but names five crates and xg_xs is not one of them.

Both jobs are green on the broken tree. Confirmed: cargo check -p xg_xs → Finished; cargo check -p xg_xs --all-targets → 15 errors.

This is also why PR #292 has to carry the line "the crate's test target still needs the local oracle.rs fixture, same as before this change" — its own new tests for XGSuggestSwizzleMode cannot be executed by anyone reviewing it.

The change

Take the second option offered in #303: gate the modules behind a cfg that is off by default.

[features]
console-oracle = []
#[cfg(all(test, feature = "console-oracle"))]
mod oracle;
  • lib.rs: oracle, oracle_3d, oracle_xs, oracle_msaa, dcc_oracle.
  • dcc.rs: oracle_px, oracle_dec, oracle_enc, verify_enc, oracle_cases, oracle_seq, and watch (used only by oracle_seq; grep found no other caller).
  • exports_table stays on plain #[cfg(test)] — it needs no console data and is the check most worth keeping green.

dcc's encode / decode / relayout / convert / safe_format / PTRS / r16 / args_ok / last_undefined / seg_info / valid_meta / tolerant are reached only from those gated tests, so with the feature off they became unreachable and produced 14 new dead_code warnings. One line at the top of dcc.rs handles it:

#![cfg_attr(not(feature = "console-oracle"), allow(dead_code))]

I would rather this were narrower, but the alternative was exporting internals from a cdylib to satisfy a lint, which is worse. It is scoped to one module and it switches itself back off when the feature is on, so a contributor editing the oracle path still gets full dead-code warnings on the code they are working on. This is the one real cost of the patch: a genuinely dead function added to dcc in future would not be flagged in a default build. Flagging it here so it is a deliberate trade rather than a surprise.

Nothing is deleted. The fixture is still expected at crates/compat/xg_xs/src/oracle.rs; it is simply no longer required for the default build. Anyone who has it keeps exactly today's behaviour:

cargo test -p xg_xs --features console-oracle --target x86_64-pc-windows-gnu

Verification

Run on a clean clone of f89e4106 (current main), not an incremental tree. Both the Windows targets, since x86_64-pc-windows-gnu is the one used for the bring-up in #293.

# applies to pristine main
$ git apply --check xg-xs-oracle-gate.patch
[applies cleanly]                                    # HEAD f89e4106fe8a

# the failure is gone, on both targets
$ cargo check -p xg_xs --all-targets --target x86_64-pc-windows-msvc
Finished `dev` profile                               # was 15 errors
$ cargo check -p xg_xs --all-targets --target x86_64-pc-windows-gnu
Finished `dev` profile                               # was 15 errors

# the tests actually run (Windows PE test binary under wine)
$ cargo test -p xg_xs --no-run --target x86_64-pc-windows-gnu
  Executable unittests src/lib.rs (.../xg_xs-94f9872358e3a4d4.exe)
$ wine xg_xs-94f9872358e3a4d4.exe
test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

# gated, not faked: the fixture is still honestly missing when asked for
$ cargo test -p xg_xs --features console-oracle --no-run --target x86_64-pc-windows-gnu
error[E0583]: file not found for module `oracle`     # expected, unchanged

# the ABI is untouched: same 23 exports, same names, both builds
$ nm -g --defined-only target/x86_64-pc-windows-gnu/debug/xg_xs.dll | grep '^XG' | sort
23 (patched) == 23 (unpatched baseline)  ->  IDENTICAL

# --locked still resolves (CI uses --locked); Cargo.lock not modified
$ cargo check --locked -p xg_xs --target x86_64-pc-windows-msvc
Finished `dev` profile

# the repo's own gate
$ python3 -I .github/scripts/pr_gate.py --base HEAD^1 --head HEAD
3 file(s) checked, 0 problem(s)
$ python3 -I .github/scripts/pr_gate.py --tree
1616 file(s) checked, 0 problem(s)

xg_xs test-build warnings went 17 → 3, and all three trace to unpatched main (unused import: E_NOTIMPL and unused macro definition: unimplemented_export in the baseline lib build; variable does not need to be mutable at dcc/enc.rs:1416 in the baseline test build).

What this does not do

  • It does not add, reconstruct or infer src/oracle.rs. That file is console-derived (oracle() loads a real console xg_xs.dll) and CONTRIBUTING.md forbids committing console files. Gating is the honest option without it, and #303 offered exactly this shape.
  • It does not make the seven oracle modules correct — they still need the fixture to be meaningful.
  • It does not touch the unrelated pre-existing --all-targets breakage on the mingw workspace target (d3d12_xs custom build command, xbtp link failure). Out of scope, still there, unchanged by this patch.

This is scoped to avoid the open PRs that touch this crate or its tests. #292 adds XGSuggestSwizzleMode to lib.rs in hunks at @@ -216,6 and @@ -643,4 (its tests); this patch only touches lib.rs lines 14–26, so the two do not overlap and should merge either order. #123, #296 and #308 do not touch xg_xs at all.

  • cargo check -p xg_xs --all-targets passes on x86_64-pc-windows-msvc and x86_64-pc-windows-gnu
  • cargo test -p xg_xs builds and runs: 19 passed, 0 failed
  • No game or console files and no binaries included
  • No fake success; oracle.rs is still absent and the feature still fails loudly when requested
  • No comment lines added to .rs files (repo rule)
  • Cargo.lock unchanged; no new dependencies
**@⁠Bexx1107** on GitHub · 2026-11-23 17:33 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/310) `Bexx1107:xg-xs-gate-console-oracle` → `main` · +17 −12 · 3 files · 1 commits · closed without merging **Library / area:** `xg_xs` — test target only (`crates/compat/xg_xs/Cargo.toml`, `src/lib.rs`, `src/dcc.rs`) **Exports changed (exports.txt rows):** none. The cdylib's 23 `XG*` exports are byte-identical before and after (`nm -g --defined-only` diff on both builds). No shipped code path changes. Fixes #303. ## The problem `crates/compat/xg_xs/src/lib.rs` declares ```rust #[cfg(test)] mod oracle; ``` but `crates/compat/xg_xs/src/oracle.rs` is not in the repository, is not in `.gitignore`, and `git log -S` finds no commit that ever contained it. On a clean checkout: ``` cargo check -p xg_xs --all-targets error[E0583]: file not found for module `oracle` (1) error[E0599]: no method named `f` found for type `!` (14) → 15 errors ``` It is not one missing file. `oracle` is the module that defines `Obj`, `field`, `first_diff`, `vt`, `Create`, `Oracle`, `SERIAL` and `oracle()`, so the seven modules that import `crate::oracle::{…}` cannot typecheck either. **All 19 unit tests in the crate are unrunnable**, and none of them needs console data: `layout::tests::*`, `layout3d::tests::*`, `computer::tests::copy_roundtrip`, `computer3d::tests::copy_roundtrip_3d`, `tests::library_init_cycle`, `tests::d3d12_desc_conversion`, `tests::optimal_swizzle_rules`, `tests::validate_depth_modes`, `tests::buffer_layout_rules`, `exports_table::export_table_matches_source`. Verified with `--list` on the built binary: 19 tests, zero of them matching `oracle`. ## Why CI does not catch it - `.github/workflows/rust.yml:135` runs `cargo check --locked --workspace` — lib/bins only, no `--all-targets` for the compat crates. - `.github/workflows/rust.yml:45` passes `--all-targets`, but names five crates and `xg_xs` is not one of them. Both jobs are green on the broken tree. Confirmed: `cargo check -p xg_xs` → `Finished`; `cargo check -p xg_xs --all-targets` → 15 errors. This is also why PR #292 has to carry the line *"the crate's test target still needs the local `oracle.rs` fixture, same as before this change"* — its own new tests for `XGSuggestSwizzleMode` cannot be executed by anyone reviewing it. ## The change Take the second option offered in #303: gate the modules behind a `cfg` that is off by default. ```toml [features] console-oracle = [] ``` ```rust #[cfg(all(test, feature = "console-oracle"))] mod oracle; ``` - `lib.rs`: `oracle`, `oracle_3d`, `oracle_xs`, `oracle_msaa`, `dcc_oracle`. - `dcc.rs`: `oracle_px`, `oracle_dec`, `oracle_enc`, `verify_enc`, `oracle_cases`, `oracle_seq`, and `watch` (used only by `oracle_seq`; grep found no other caller). - `exports_table` stays on plain `#[cfg(test)]` — it needs no console data and is the check most worth keeping green. `dcc`'s `encode` / `decode` / `relayout` / `convert` / `safe_format` / `PTRS` / `r16` / `args_ok` / `last_undefined` / `seg_info` / `valid_meta` / `tolerant` are reached only from those gated tests, so with the feature off they became unreachable and produced 14 new `dead_code` warnings. One line at the top of `dcc.rs` handles it: ```rust #![cfg_attr(not(feature = "console-oracle"), allow(dead_code))] ``` I would rather this were narrower, but the alternative was exporting internals from a cdylib to satisfy a lint, which is worse. It is scoped to one module and it switches itself back off when the feature is on, so a contributor editing the oracle path still gets full dead-code warnings on the code they are working on. **This is the one real cost of the patch:** a genuinely dead function added to `dcc` in future would not be flagged in a default build. Flagging it here so it is a deliberate trade rather than a surprise. Nothing is deleted. The fixture is still expected at `crates/compat/xg_xs/src/oracle.rs`; it is simply no longer required for the default build. Anyone who has it keeps exactly today's behaviour: ``` cargo test -p xg_xs --features console-oracle --target x86_64-pc-windows-gnu ``` ## Verification Run on a clean clone of `f89e4106` (current `main`), not an incremental tree. Both the Windows targets, since `x86_64-pc-windows-gnu` is the one used for the bring-up in #293. ``` # applies to pristine main $ git apply --check xg-xs-oracle-gate.patch [applies cleanly] # HEAD f89e4106fe8a # the failure is gone, on both targets $ cargo check -p xg_xs --all-targets --target x86_64-pc-windows-msvc Finished `dev` profile # was 15 errors $ cargo check -p xg_xs --all-targets --target x86_64-pc-windows-gnu Finished `dev` profile # was 15 errors # the tests actually run (Windows PE test binary under wine) $ cargo test -p xg_xs --no-run --target x86_64-pc-windows-gnu Executable unittests src/lib.rs (.../xg_xs-94f9872358e3a4d4.exe) $ wine xg_xs-94f9872358e3a4d4.exe test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s # gated, not faked: the fixture is still honestly missing when asked for $ cargo test -p xg_xs --features console-oracle --no-run --target x86_64-pc-windows-gnu error[E0583]: file not found for module `oracle` # expected, unchanged # the ABI is untouched: same 23 exports, same names, both builds $ nm -g --defined-only target/x86_64-pc-windows-gnu/debug/xg_xs.dll | grep '^XG' | sort 23 (patched) == 23 (unpatched baseline) -> IDENTICAL # --locked still resolves (CI uses --locked); Cargo.lock not modified $ cargo check --locked -p xg_xs --target x86_64-pc-windows-msvc Finished `dev` profile # the repo's own gate $ python3 -I .github/scripts/pr_gate.py --base HEAD^1 --head HEAD 3 file(s) checked, 0 problem(s) $ python3 -I .github/scripts/pr_gate.py --tree 1616 file(s) checked, 0 problem(s) ``` `xg_xs` test-build warnings went 17 → 3, and all three trace to unpatched `main` (`unused import: E_NOTIMPL` and `unused macro definition: unimplemented_export` in the baseline lib build; `variable does not need to be mutable` at `dcc/enc.rs:1416` in the baseline test build). ## What this does not do - It does not add, reconstruct or infer `src/oracle.rs`. That file is console-derived (`oracle()` loads a real console `xg_xs.dll`) and CONTRIBUTING.md forbids committing console files. Gating is the honest option without it, and #303 offered exactly this shape. - It does not make the seven oracle modules correct — they still need the fixture to be meaningful. - It does not touch the unrelated pre-existing `--all-targets` breakage on the mingw workspace target (`d3d12_xs` custom build command, `xbtp` link failure). Out of scope, still there, unchanged by this patch. This is scoped to avoid the open PRs that touch this crate or its tests. `#292` adds `XGSuggestSwizzleMode` to `lib.rs` in hunks at `@@ -216,6` and `@@ -643,4` (its tests); this patch only touches `lib.rs` lines 14–26, so the two do not overlap and should merge either order. `#123`, `#296` and `#308` do not touch `xg_xs` at all. - [x] `cargo check -p xg_xs --all-targets` passes on `x86_64-pc-windows-msvc` and `x86_64-pc-windows-gnu` - [x] `cargo test -p xg_xs` builds and runs: 19 passed, 0 failed - [x] No game or console files and no binaries included - [x] No fake success; `oracle.rs` is still absent and the feature still fails loudly when requested - [x] No comment lines added to `.rs` files (repo rule) - [x] `Cargo.lock` unchanged; no new dependencies
crates/compat/xg_xs/src/lib.rs declares `#[cfg(test)] mod oracle;` but
src/oracle.rs is not in the repository and never has been, so on a clean
checkout `cargo check -p xg_xs --all-targets` fails with E0583. Because the
oracle module defines Obj, field, first_diff, vt, Create, Oracle and SERIAL,
the seven test modules that import from it fail as well: 15 errors total, and
all 19 unit tests in the crate are unrunnable, including the ones that need no
console data.

CI does not see this. rust.yml runs `cargo check --workspace` without
--all-targets for the compat crates, and the one job that passes
--all-targets names five crates and not xg_xs, so both jobs pass on the
broken tree.

Add an off-by-default `console-oracle` feature and require it in addition to
test for the eight oracle modules and for dcc::watch, which only oracle_seq
uses. dcc's encode/decode/relayout/convert helpers are reached only from those
gated tests, so silence dead_code in that module when the feature is off.

Contributors who hold the fixture keep the old behaviour with
--features console-oracle; without it the fixture is no longer required.

Verified against f89e4106 on both targets: 0 errors on
x86_64-pc-windows-msvc and x86_64-pc-windows-gnu with --all-targets, the
lib test binary runs 19 passed / 0 failed, the cdylib exports the same 23
XG* symbols as before, Cargo.lock is unchanged and pr_gate --tree reports
0 problems.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:18:10 +00:00
github-bot closed this pull request 2026-11-26 06:18:10 +00:00
Author
Owner

@⁠BuHHuTlyx on GitHub · 2026-11-23 21:21 UTC · original

Independently verified c17005a375882b9a6c55e4bb549f40e991314d8b on native Windows 11 24H2 with rustc 1.100.0 (x86_64-pc-windows-msvc).

  • cargo test -p xg_xs ran all 19 tests successfully.
  • cargo test -p xg_xs --features console-oracle --no-run on the same clean checkout produced the expected E0583 at mod oracle;.

For a CI follow-up, I added -p xg_xs to the existing cargo test --locked -p tombox-pe -p tombox-archive -p tombox-rpf -p tombox-disasm --no-fail-fast command locally. With this PR applied, the resulting five-crate command passed 62 tests and the workflow passed actionlint.

**@⁠BuHHuTlyx** on GitHub · 2026-11-23 21:21 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/310#issuecomment-7114358641) Independently verified `c17005a375882b9a6c55e4bb549f40e991314d8b` on native Windows 11 24H2 with `rustc 1.100.0` (`x86_64-pc-windows-msvc`). - `cargo test -p xg_xs` ran all 19 tests successfully. - `cargo test -p xg_xs --features console-oracle --no-run` on the same clean checkout produced the expected `E0583` at `mod oracle;`. For a CI follow-up, I added `-p xg_xs` to the existing `cargo test --locked -p tombox-pe -p tombox-archive -p tombox-rpf -p tombox-disasm --no-fail-fast` command locally. With this PR applied, the resulting five-crate command passed 62 tests and the workflow passed `actionlint`.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:49 UTC · original

Applied on main in 2813b2a (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/310#issuecomment-7164338578) Applied on main in 2813b2a (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.