Files
psxrecomp/runtime/tests/test_bios_selection_guards.py
Alex Vanderveen 0b6baa49c4 launcher: never offer "Generate & rebuild" for a BIOS in a bundled build
A shipped bundled build links OpenBIOS only and carries no CLI, sources
or toolchain, yet the codegen host forced the BIOS row on and a retail
pick answered with needs_regen ("Generate & rebuild to switch"), a step
that cannot run there.

- The BIOS row is shown only when a choice can mean something: a retail
  backend is linked, nothing is linked yet (setup host), or the codegen
  host actually wired Generate (prepare_with_progress). main.cpp decides
  after host_apply instead of the host forcing has_bios.
- ae_bios_verify short-circuits a bundled-only build with a plain
  "runs its bundled OpenBIOS only" message before the identity checks,
  whose "this build expects SCPH-1001" wording names the pinned stem,
  not a linked backend, and sets needs_regen only when Generate exists.
- test_bios_selection_guards pins both.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-30 17:54:53 -04:00

39 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Guard bundled-only BIOS selection against stale hidden player paths."""
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
MAIN = (ROOT / "runtime" / "src" / "main.cpp").read_text(encoding="utf-8")
# A bundled-only product must bypass both explicit and cached player paths
# before validate_bios_for_launch can produce an impossible mismatch dialog.
assert "const bool bundled_only =" in MAIN
assert "if (!bundled_only) {" in MAIN
assert MAIN.index("if (!bundled_only) {") < MAIN.index(
"if (!chosen.empty() && std::filesystem::exists(chosen))"
)
# The launcher must derive persistence from linked capabilities, not from the
# active image: psx_bios_image is deliberately zeroed until selection occurs.
assert "const bool bios_choice_supported =" in MAIN
assert "if (bios_choice_supported && ls.bios_path[0])" in MAIN
assert "ls.bios_path[0] && !psx_bios_image.image_bundled" not in MAIN
# A shipped bundled build links OpenBIOS only and carries no CLI, sources or
# toolchain. Its BIOS row must not be forced on, and a retail pick must not be
# answered with "Generate & rebuild": that offer is only real when the codegen
# host wired Generate (prepare_with_progress) or nothing is linked yet.
HOST = (ROOT / "host" / "psxrecomp_codegen_host.c").read_text(encoding="utf-8")
assert "gi->has_bios = 1;" not in HOST
assert MAIN.count("gi.has_bios = 1;") == 0
assert MAIN.count("g_lnch_can_regen = gi.prepare_with_progress != nullptr") == 2
assert "gi.has_bios = (psx_bios_has_selectable() || g_lnch_can_regen) ? 1 : 0;" in MAIN
assert "if (g_lnch_can_regen) {" in MAIN
assert MAIN.index("if (g_lnch_can_regen) {") < MAIN.index(
'"Generate & rebuild to switch (or use OpenBIOS)."')
assert "cannot be selected. Clear the BIOS field to play." in MAIN
print("BIOS selection capability guards passed")