fix: quit, proxy and setup folder read once

A chosen quit is read from the state, so the version note after the
quit line no longer sends it to stdout where the launcher misses it.

The proxy the screen names is the one urllib uses for the list's URL
(scheme variable or system settings, NO_PROXY honoured), recorded in
the ListProblem when the request fails.

The setup screen and the plan format from facts read once (the BIOS
folder of each setup, the retroarch.cfg naming dest), never by a frame
in the thread that reads the keys.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:46 +01:00
1 parent 05b6b9edcf
commit 475dfe0e0a
14 files changed
+207 -51

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "4ab8d5b3aca7c3b897751da854953d463c0a7eebdae6bb6be23c40fc124aa259"
$defaultInstallSha256 = "2b5ff4827b1bce9f6b56773ead57aaeb0e3849bb59006b84a0347b6e609e37e9"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+64 -13
View File
@@ -4512,6 +4512,12 @@ def setup_bios_folder(plat: str, path: Path) -> Path:
return path / "bios" if rule is not None and rule.manifest == plat else path
def setup_folders(setups: list) -> dict:
"""The BIOS folder each found setup announces, keyed by (platform,
folder), read once for a screen that shows them on every frame."""
return {(plat, path): setup_bios_folder(plat, path) for plat, path, *_rest in setups}
def card_setup(named: str, plat: str) -> CardSetup | None:
"""The card setup a name stands for with plat's list: a system by its
own name, or a list that is one (MinUI). RetroArch names a list, not a
@@ -7747,6 +7753,24 @@ def install_bounded_opener() -> None:
urllib.request.install_opener(urllib.request.build_opener(*handlers))
def request_proxy(url: str) -> str:
"""What sends a request for url through a proxy, as urllib's
ProxyHandler decides it: the variable naming the proxy for the URL's
scheme, "system settings" for one set in the Windows registry or the
macOS settings, "" when the request goes direct (none set, or the host
bypassed by NO_PROXY or the system's exceptions)."""
parts = urllib.parse.urlsplit(url)
proxy = urllib.request.getproxies().get(parts.scheme)
host = parts.netloc.rpartition("@")[2]
if not proxy or (host and urllib.request.proxy_bypass(host)):
return ""
wanted = f"{parts.scheme}_proxy"
# urllib lets the lower-case variable win over the upper-case one.
names = sorted((name for name in os.environ if name.lower() == wanted
and os.environ[name] == proxy), key=lambda name: name != wanted)
return names[0] if names else "system settings"
# The wait for each answer of a file list, its first byte included: a
# server that takes the connection and never answers (a captive portal, a
# stuck proxy) held the run 93 s on three waits of 30 s. A list is a few
@@ -8570,6 +8594,8 @@ class ListProblem(NamedTuple):
clock, no_ca, no_ssl), with words saying it. garbled is an answer that
is not JSON at all: a Wi-Fi sign-in page or a cut download. fatal is the
code line mode ends on, 0 when the run carries on without the list.
proxy names what sent a network request through a proxy (a variable or
the system settings), empty when it went direct.
"""
plat: str
@@ -8582,6 +8608,7 @@ class ListProblem(NamedTuple):
attempts: int = MAX_RETRIES
garbled: bool = False
fatal: int = 1
proxy: str = ""
@property
def overridden(self) -> bool:
@@ -8613,7 +8640,8 @@ def _download_failure(plat: str, url: str, remote: Remote, exc: Exception,
status=exc.code, fatal=fatal))
code, words = network_words(exc)
return ListFailure(ListProblem(plat, code, words, where=url, remote=remote, fatal=fatal,
attempts=getattr(exc, "attempts", MAX_RETRIES)))
attempts=getattr(exc, "attempts", MAX_RETRIES),
proxy=request_proxy(url)))
def missing_list_advice(plat: str, again: str, ref: str) -> str:
@@ -13804,6 +13832,9 @@ class TuiState:
self.now: float = time.monotonic()
# (platform, folder, label) for each setup found here.
self.setups: list = []
# The BIOS folder each setup announces, keyed by (platform, folder):
# read once when the setups are found, never by a frame.
self.setup_folders: dict = {}
# (platform, card) of each mounted drive whose files fit two systems
# (share_doubt): offered under each, never taken for one.
self.doubts: list = []
@@ -26106,11 +26137,12 @@ def _download_lines(failure: ListProblem) -> tuple[str, list[str]]:
# A handheld with no Wi-Fi has the pack as its way.
"Or copy a pack to the card and run the installer with --from-pack "
"PACK: no network is needed then."]
proxy = next((name for name in ("HTTPS_PROXY", "https_proxy", "ALL_PROXY",
"all_proxy") if os.environ.get(name)), "")
if proxy:
# Named, never shown: the value can hold a password.
lines.append(f"{proxy} is set, so the connection goes through a proxy: "
# Named, never shown: the value can hold a password.
if failure.proxy == "system settings":
lines.append("The system settings set a proxy, so the connection goes through "
"it: check that it answers.")
elif failure.proxy:
lines.append(f"{failure.proxy} is set, so the connection goes through a proxy: "
"check that it answers.")
return "No connection", lines
@@ -26607,7 +26639,7 @@ def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list:
_styled(headline, "title"),
_styled(f"BIOS folder: {_short_path(_plan_folder(state, dest), state.home)}", "path"),
]
found_in = _retroarch_config_at(dest) if dest is not None else None
found_in = state.facts.get("config") if dest is not None else None
if found_in:
# Right under the folder it names: after the save lines it read as
# naming them.
@@ -27655,8 +27687,10 @@ def _aligned_devices(rows: list[TuiRow], width: int) -> list[TuiRow]:
def _view_setup(state: TuiState, width: int, height: int) -> tuple:
rows = tui_rows(state)
focus = rows[min(state.focus.get("setup", 0), len(rows) - 1)]
after = ([f"BIOS folder: {shown_path(setup_bios_folder(*state.setups[focus.value][:2]))}"]
if focus.action == "setup" else [])
after = []
if focus.action == "setup":
plat, path, _label = state.setups[focus.value]
after.append(f"BIOS folder: {shown_path(state.setup_folders[plat, path])}")
before = ["Found on this machine:" if state.setups
else "A drive here could be either of these:" if state.doubts
else "Nothing was found here."]
@@ -29232,7 +29266,9 @@ def _tui_folder_facts(state: TuiState) -> dict:
free = None
cores = (installed_cores(core_dirs(state.platform, dest))
if state.platform in CORE_PLATFORMS else [])
return {"free": free, "writable": _folder_writable(dest), "cores": cores}
# The retroarch.cfg that names dest, said under it on the plan.
return {"free": free, "writable": _folder_writable(dest), "cores": cores,
"config": _retroarch_config_at(dest)}
def _row_folder(row: TuiRow) -> Path:
@@ -30887,6 +30923,7 @@ def _tui_detect(state: TuiState, os_type: str) -> None:
with detection_held():
state.setups, state.mounted_setups = found_setups(os_type)
frontends = detect_frontends(os_type)
state.setup_folders = setup_folders(state.setups)
# Said on the normal screen before this one covered it, and kept
# above the list: a status line under 18 setups was never drawn.
state.refused = [refused_words(folder, why, _short_path(folder, state.home))
@@ -31205,11 +31242,23 @@ def _closing_lines(state: TuiState) -> list[str]:
for line in state.error)]
if state.exit_code == 0:
return [f"RetroBIOS: everything is in place in {state.dest}."]
if state.quit_asked:
if _quit_closing(state):
return [TUI_QUIT_WORDS]
return ["RetroBIOS: stopped. Nothing was installed."]
def _quit_closing(state: TuiState) -> bool:
"""Whether the screen closes on the quit the user asked for: no install
ran, no result, error or crash to report, and the exit not a success."""
if state.screen not in ("result", "details") and state.download is not None:
return False
if state.screen in ("crashed", "error", "result"):
return False
if state.screen == "details" and "result" in state.stack:
return False
return state.exit_code != 0 and state.quit_asked
TUI_QUIT_WORDS = "RetroBIOS: quit. Nothing was installed."
@@ -31226,8 +31275,10 @@ def _terminal_words(lines: list[str]) -> list[str]:
def tui_quit_chosen(state: TuiState) -> bool:
"""Whether the screen ended on a quit the user chose, nothing installed."""
return tui_farewell(state) == [TUI_QUIT_WORDS]
"""Whether the screen ended on a quit the user chose, nothing installed:
read from the state, so a version note after the quit line changes
nothing."""
return not state.idle_closed and _quit_closing(state)
CTRL_Z_NO_SHELL = ("Ctrl-Z is ignored: no shell started this installer, and none could "
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="4ab8d5b3aca7c3b897751da854953d463c0a7eebdae6bb6be23c40fc124aa259"
DEFAULT_INSTALL_SHA256="2b5ff4827b1bce9f6b56773ead57aaeb0e3849bb59006b84a0347b6e609e37e9"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1461082,
"sha256": "4ab8d5b3aca7c3b897751da854953d463c0a7eebdae6bb6be23c40fc124aa259",
"size": 1463517,
"sha256": "2b5ff4827b1bce9f6b56773ead57aaeb0e3849bb59006b84a0347b6e609e37e9",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1514707,
"sha256": "d01f7e24d3077693463721e82ab79cae1ed0a04ff63eb886b2514e0bbd99e605"
"size": 1517142,
"sha256": "49e0e307999989bacd59356939e137fcce171a1b8116c246c560259de4e921ca"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1461082,
"sha256": "4ab8d5b3aca7c3b897751da854953d463c0a7eebdae6bb6be23c40fc124aa259",
"size": 1463517,
"sha256": "2b5ff4827b1bce9f6b56773ead57aaeb0e3849bb59006b84a0347b6e609e37e9",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1461082,
"sha256": "4ab8d5b3aca7c3b897751da854953d463c0a7eebdae6bb6be23c40fc124aa259",
"size": 1463517,
"sha256": "2b5ff4827b1bce9f6b56773ead57aaeb0e3849bb59006b84a0347b6e609e37e9",
"executable": false
},
{
+6
View File
@@ -464,6 +464,12 @@ def setup_bios_folder(plat: str, path: Path) -> Path:
return path / "bios" if rule is not None and rule.manifest == plat else path
def setup_folders(setups: list) -> dict:
"""The BIOS folder each found setup announces, keyed by (platform,
folder), read once for a screen that shows them on every frame."""
return {(plat, path): setup_bios_folder(plat, path) for plat, path, *_rest in setups}
def card_setup(named: str, plat: str) -> CardSetup | None:
"""The card setup a name stands for with plat's list: a system by its
own name, or a list that is one (MinUI). RetroArch names a list, not a
+6 -2
View File
@@ -10,7 +10,7 @@ from typing import NamedTuple
from installer.events import EVENTS
from installer.host_fs import _is_file, read_local_json
from installer.manifest import _check_standalone_layouts, _validate_manifest, _validate_targets
from installer.network import _address_lines, _fetch_json, network_words
from installer.network import _address_lines, _fetch_json, network_words, request_proxy
from installer.offline import LOCAL, _Offline, offline_named, offline_undo, offline_words
from installer.platforms import TARGET_PLATFORMS, display_name
from installer.remote import (
@@ -40,6 +40,8 @@ class ListProblem(NamedTuple):
clock, no_ca, no_ssl), with words saying it. garbled is an answer that
is not JSON at all: a Wi-Fi sign-in page or a cut download. fatal is the
code line mode ends on, 0 when the run carries on without the list.
proxy names what sent a network request through a proxy (a variable or
the system settings), empty when it went direct.
"""
plat: str
@@ -52,6 +54,7 @@ class ListProblem(NamedTuple):
attempts: int = MAX_RETRIES
garbled: bool = False
fatal: int = 1
proxy: str = ""
@property
def overridden(self) -> bool:
@@ -83,7 +86,8 @@ def _download_failure(plat: str, url: str, remote: Remote, exc: Exception,
status=exc.code, fatal=fatal))
code, words = network_words(exc)
return ListFailure(ListProblem(plat, code, words, where=url, remote=remote, fatal=fatal,
attempts=getattr(exc, "attempts", MAX_RETRIES)))
attempts=getattr(exc, "attempts", MAX_RETRIES),
proxy=request_proxy(url)))
def missing_list_advice(plat: str, again: str, ref: str) -> str:
+19
View File
@@ -11,6 +11,7 @@ import sys
import threading
import time
import urllib.error
import urllib.parse
import urllib.request
from pathlib import Path
from typing import Any
@@ -225,6 +226,24 @@ def install_bounded_opener() -> None:
urllib.request.install_opener(urllib.request.build_opener(*handlers))
def request_proxy(url: str) -> str:
"""What sends a request for url through a proxy, as urllib's
ProxyHandler decides it: the variable naming the proxy for the URL's
scheme, "system settings" for one set in the Windows registry or the
macOS settings, "" when the request goes direct (none set, or the host
bypassed by NO_PROXY or the system's exceptions)."""
parts = urllib.parse.urlsplit(url)
proxy = urllib.request.getproxies().get(parts.scheme)
host = parts.netloc.rpartition("@")[2]
if not proxy or (host and urllib.request.proxy_bypass(host)):
return ""
wanted = f"{parts.scheme}_proxy"
# urllib lets the lower-case variable win over the upper-case one.
names = sorted((name for name in os.environ if name.lower() == wanted
and os.environ[name] == proxy), key=lambda name: name != wanted)
return names[0] if names else "system settings"
# The wait for each answer of a file list, its first byte included: a
# server that takes the connection and never answers (a captive portal, a
# stuck proxy) held the run 93 s on three waits of 30 s. A list is a few
+4 -1
View File
@@ -32,6 +32,7 @@ from installer.destination import (
)
from installer.detect_os import _DETECTED_OS, _FROM_CARD, detected_os, detected_shown
from installer.embedded import CARD_PLATFORMS, _a
from installer.frontend_folders import _retroarch_config_at
from installer.games import games_probe
from installer.host_fs import _exists, _folder_writable, _is_dir, _nearest_folder, closed_folder
from installer.install_record import RECORD_NARROWING, _RECORD_SAID, record_options, setup_record
@@ -748,7 +749,9 @@ def _tui_folder_facts(state: TuiState) -> dict:
free = None
cores = (installed_cores(core_dirs(state.platform, dest))
if state.platform in CORE_PLATFORMS else [])
return {"free": free, "writable": _folder_writable(dest), "cores": cores}
# The retroarch.cfg that names dest, said under it on the plan.
return {"free": free, "writable": _folder_writable(dest), "cores": cores,
"config": _retroarch_config_at(dest)}
def _row_folder(row: TuiRow) -> Path:
+6 -7
View File
@@ -1,8 +1,6 @@
"""What the full screen says of a file list or board list it could not have."""
from __future__ import annotations
import os
from installer.lists import ListProblem, manifest_failure_lines, missing_list_advice
from installer.offline import offline_named, offline_undo
from installer.platforms import display_name
@@ -38,11 +36,12 @@ def _download_lines(failure: ListProblem) -> tuple[str, list[str]]:
# A handheld with no Wi-Fi has the pack as its way.
"Or copy a pack to the card and run the installer with --from-pack "
"PACK: no network is needed then."]
proxy = next((name for name in ("HTTPS_PROXY", "https_proxy", "ALL_PROXY",
"all_proxy") if os.environ.get(name)), "")
if proxy:
# Named, never shown: the value can hold a password.
lines.append(f"{proxy} is set, so the connection goes through a proxy: "
# Named, never shown: the value can hold a password.
if failure.proxy == "system settings":
lines.append("The system settings set a proxy, so the connection goes through "
"it: check that it answers.")
elif failure.proxy:
lines.append(f"{failure.proxy} is set, so the connection goes through a proxy: "
"check that it answers.")
return "No connection", lines
+2 -2
View File
@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, NamedTuple
from installer.destination import _last_name
from installer.from_folders import MAX_SCANNED_FILES
from installer.frontend_folders import _retroarch_config_at, save_where_words
from installer.frontend_folders import save_where_words
from installer.install_record import record_changes, record_says
from installer.manifest import GAME_DATA, OTHER_SYSTEMS
from installer.offline import LOCAL, _offline_only, offline_named, offline_undo
@@ -285,7 +285,7 @@ def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list:
_styled(headline, "title"),
_styled(f"BIOS folder: {_short_path(_plan_folder(state, dest), state.home)}", "path"),
]
found_in = _retroarch_config_at(dest) if dest is not None else None
found_in = state.facts.get("config") if dest is not None else None
if found_in:
# Right under the folder it names: after the save lines it read as
# naming them.
+5 -3
View File
@@ -6,7 +6,7 @@ import textwrap
from collections.abc import Callable
from typing import TYPE_CHECKING
from installer.cards import _GAMES_PART_CARDS, card_setup, setup_bios_folder
from installer.cards import _GAMES_PART_CARDS, card_setup
from installer.destination import card_where
from installer.detect_os import detected_shown
from installer.embedded import CARD_PLATFORMS, _a
@@ -113,8 +113,10 @@ def _aligned_devices(rows: list[TuiRow], width: int) -> list[TuiRow]:
def _view_setup(state: TuiState, width: int, height: int) -> tuple:
rows = tui_rows(state)
focus = rows[min(state.focus.get("setup", 0), len(rows) - 1)]
after = ([f"BIOS folder: {shown_path(setup_bios_folder(*state.setups[focus.value][:2]))}"]
if focus.action == "setup" else [])
after = []
if focus.action == "setup":
plat, path, _label = state.setups[focus.value]
after.append(f"BIOS folder: {shown_path(state.setup_folders[plat, path])}")
before = ["Found on this machine:" if state.setups
else "A drive here could be either of these:" if state.doubts
else "Nothing was found here."]
+26 -4
View File
@@ -19,7 +19,14 @@ from collections.abc import Callable
from pathlib import Path
from typing import TYPE_CHECKING, TextIO
from installer.cards import _SHARE_FOLDERS, _mounted_cards, card_bound, card_platform, share_doubt
from installer.cards import (
_SHARE_FOLDERS,
_mounted_cards,
card_bound,
card_platform,
setup_folders,
share_doubt,
)
from installer.console import QUIT_CODE
from installer.destination import card_choice, dest_default
from installer.detect_frontends import detect_frontends
@@ -139,6 +146,7 @@ def _tui_detect(state: TuiState, os_type: str) -> None:
with detection_held():
state.setups, state.mounted_setups = found_setups(os_type)
frontends = detect_frontends(os_type)
state.setup_folders = setup_folders(state.setups)
# Said on the normal screen before this one covered it, and kept
# above the list: a status line under 18 setups was never drawn.
state.refused = [refused_words(folder, why, _short_path(folder, state.home))
@@ -457,11 +465,23 @@ def _closing_lines(state: TuiState) -> list[str]:
for line in state.error)]
if state.exit_code == 0:
return [f"RetroBIOS: everything is in place in {state.dest}."]
if state.quit_asked:
if _quit_closing(state):
return [TUI_QUIT_WORDS]
return ["RetroBIOS: stopped. Nothing was installed."]
def _quit_closing(state: TuiState) -> bool:
"""Whether the screen closes on the quit the user asked for: no install
ran, no result, error or crash to report, and the exit not a success."""
if state.screen not in ("result", "details") and state.download is not None:
return False
if state.screen in ("crashed", "error", "result"):
return False
if state.screen == "details" and "result" in state.stack:
return False
return state.exit_code != 0 and state.quit_asked
TUI_QUIT_WORDS = "RetroBIOS: quit. Nothing was installed."
@@ -478,8 +498,10 @@ def _terminal_words(lines: list[str]) -> list[str]:
def tui_quit_chosen(state: TuiState) -> bool:
"""Whether the screen ended on a quit the user chose, nothing installed."""
return tui_farewell(state) == [TUI_QUIT_WORDS]
"""Whether the screen ended on a quit the user chose, nothing installed:
read from the state, so a version note after the quit line changes
nothing."""
return not state.idle_closed and _quit_closing(state)
CTRL_Z_NO_SHELL = ("Ctrl-Z is ignored: no shell started this installer, and none could "
+3
View File
@@ -84,6 +84,9 @@ class TuiState:
self.now: float = time.monotonic()
# (platform, folder, label) for each setup found here.
self.setups: list = []
# The BIOS folder each setup announces, keyed by (platform, folder):
# read once when the setups are found, never by a frame.
self.setup_folders: dict = {}
# (platform, card) of each mounted drive whose files fit two systems
# (share_doubt): offered under each, never taken for one.
self.doubts: list = []
+56 -9
View File
@@ -392,6 +392,7 @@ def fresh_state() -> install.TuiState:
state = install.TuiState(os_type="linux", home=HOME)
state.setups = [("retroarch", SYSTEM_DIR, "RetroArch"),
("batocera", Path("/userdata/bios"), "KNULLI (Batocera files)")]
state.setup_folders = install.setup_folders(state.setups)
return state
@@ -2349,6 +2350,7 @@ class TicksBarAndPaths(unittest.TestCase):
["RetroArch (retroarch/system)", "RetroArch (ra2/system)"])
state = fresh_state()
state.setups = setups
state.setup_folders = install.setup_folders(setups)
self.assertIn("RetroArch (Flatpak)", "\n".join(install.tui_view(state, 40, 15)))
# A Flatpak whose config names a system folder outside its sandbox.
elsewhere = HOME / "bios"
@@ -3140,7 +3142,8 @@ class CardsSpaceAndConfirm(unittest.TestCase):
inbox = __import__("queue").Queue()
with mock.patch.object(install, "_fetch_json", side_effect=error), \
mock.patch.dict(os.environ, env or {}):
for name in ("HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"):
for name in ("HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy",
"NO_PROXY", "no_proxy"):
if name not in (env or {}):
os.environ.pop(name, None)
install._tui_fetch("retroarch", inbox)
@@ -3166,6 +3169,26 @@ class CardsSpaceAndConfirm(unittest.TestCase):
_title, lines = self.fetch_failure(error)
self.assertFalse(any("PROXY" in line for line in lines))
def test_a_proxy_urllib_does_not_use_is_not_named(self):
"""NO_PROXY sends the host direct, and urllib reads no ALL_PROXY
for HTTPS: the screen blamed a proxy the request never went through."""
error = urllib_error(ConnectionRefusedError(111, "Connection refused"))
for env in ({"HTTPS_PROXY": "http://127.0.0.1:9", "NO_PROXY": "raw.githubusercontent.com"},
{"ALL_PROXY": "http://127.0.0.1:9"}):
with self.subTest(env=env):
_title, lines = self.fetch_failure(error, env)
self.assertFalse(any("proxy" in line.lower() for line in lines), lines)
def test_a_system_proxy_is_named(self):
"""A Windows or macOS proxy set in the settings, no variable."""
error = urllib_error(ConnectionRefusedError(111, "Connection refused"))
with mock.patch.object(install.urllib.request, "getproxies",
return_value={"https": "http://10.0.0.1:3128"}), \
mock.patch.object(install.urllib.request, "proxy_bypass", return_value=False):
_title, lines = self.fetch_failure(error)
self.assertIn("The system settings set a proxy, so the connection goes through "
"it: check that it answers.", lines)
def test_list_that_is_no_json_is_said_in_words(self):
try:
install.json.loads("<html>")
@@ -3199,10 +3222,27 @@ class CardsSpaceAndConfirm(unittest.TestCase):
@in_full
def test_the_plan_says_which_config_named_the_folder(self):
config = HOME / ".config/retroarch/retroarch.cfg"
with mock.patch.dict(install._RETROARCH_CONFIGS, {SYSTEM_DIR: (config, config.parent)}):
text = "\n".join(install.tui_view(checked_state(), 80, 24))
state = checked_state()
with mock.patch.dict(install._RETROARCH_CONFIGS, {state.dest: (config, config.parent)}):
state.facts = install._tui_folder_facts(state)
# Read with the folder's facts, never by a frame.
with mock.patch.object(install, "_retroarch_config_at", side_effect=AssertionError):
text = "\n".join(install.tui_view(state, 80, 24))
self.assertIn("Named by ~/.config/retroarch/retroarch.cfg", text)
def test_the_setup_screen_probes_no_card_per_frame(self):
"""The view drew about ten frames a second and asked the card for
its games part on each, in the thread that reads the keys."""
state = fresh_state()
games = Path("/media/x/GAMES")
state.setups = [("amberelec", games, "AmberELEC")]
with mock.patch.object(install, "games_part", return_value=None):
state.setup_folders = install.setup_folders(state.setups)
with mock.patch.object(install, "games_part", side_effect=AssertionError):
for _frame in range(3):
text = "\n".join(install.tui_view(state, 80, 24))
self.assertIn(f"BIOS folder: {games}", text)
# The engine's own events (main, after the second audit).
def test_the_speed_is_the_network_bytes(self):
@@ -3964,6 +4004,7 @@ class ACardSetupIsOneDesign(unittest.TestCase):
share = Path("/userdata/bios")
state = fresh_state()
state.setups = [("knulli", share, "KNULLI")]
state.setup_folders = install.setup_folders(state.setups)
state.stack = ["setup", "platforms"]
state.focus["platforms"] = install._platform_focus(state, "knulli")
with mock.patch.dict(install._DETECTED_OS, {("knulli", share): "KNULLI"}), \
@@ -4648,6 +4689,7 @@ class AFolderThisUserCannotOpen(unittest.TestCase):
def test_chosen_from_the_setups(self):
state = fresh_state()
state.setups = [("retroarch", self.dest, "RetroArch")]
state.setup_folders = install.setup_folders(state.setups)
state.stack = ["setup"]
self.assertEqual(install.tui_update(state, Key("enter")), [])
self.assertEqual(state.screen, "folder")
@@ -6278,6 +6320,7 @@ class TheFolderScreenSaysWhatItOffers(unittest.TestCase):
state = fresh_state()
found = Path("/home/user/Games/bios")
state.setups = [("retroarch", found, "RetroArch")]
state.setup_folders = install.setup_folders(state.setups)
state.stack = ["setup", "platforms"]
install._activate(state, install.TuiRow("platform", "RetroArch", value="retroarch"))
self.assertEqual(state.folder_default, found)
@@ -8700,6 +8743,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
setups, _mounted = install.found_setups("linux")
state = install.TuiState(os_type="linux", home=HOME)
state.setups = setups
state.setup_folders = install.setup_folders(setups)
for index, (plat, path, label) in enumerate(setups):
state.focus["setup"] = index
screen = " ".join(install.tui_view(state, 120, 40))
@@ -10623,9 +10667,8 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase):
state = checked_state()
long_dest = Path("/home/user/" + "a-long-folder-name/" * 5 + "system")
state.dest = long_dest
with mock.patch.object(install, "_retroarch_config_at",
return_value=(HOME / ".config/retroarch/retroarch.cfg", HOME)):
lines = [str(line).strip() for line in install.tui_view(state, 80, 30)]
state.facts["config"] = (HOME / ".config/retroarch/retroarch.cfg", HOME)
lines = [str(line).strip() for line in install.tui_view(state, 80, 30)]
at = next(index for index, line in enumerate(lines) if line.startswith("BIOS folder:"))
tail = next(index for index, line in enumerate(lines) if line.startswith("Named by"))
self.assertNotIn("...", " ".join(lines[at:tail]))
@@ -11650,6 +11693,11 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase):
self.assertEqual(state.exit_code, 2)
self.assertTrue(install.tui_quit_chosen(state))
self.assertEqual(install.tui_farewell(state), ["RetroBIOS: quit. Nothing was installed."])
# A returning user's version note follows the quit line: still a
# chosen quit, so it goes to stderr where the launcher looks.
state.version = "List for RetroArch v2026.11.10, this is v2026.11.01."
self.assertTrue(install.tui_quit_chosen(state))
self.assertEqual(install.tui_farewell(state)[0], "RetroBIOS: quit. Nothing was installed.")
idle = fresh_state()
self.assertEqual(install.tui_idle_code(idle), 2)
@@ -11848,9 +11896,8 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase):
state = checked_state()
state.dest = self.root / "sys"
state.cli_systems = ["sony-playstation"]
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}), \
mock.patch.object(install, "_retroarch_config_at",
return_value=(str(cfg / "retroarch.cfg"), cfg)):
state.facts["config"] = (str(cfg / "retroarch.cfg"), cfg)
with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}):
lines = [str(line).strip() for line in install.tui_view(state, 120, 40)]
folder = next(i for i, line in enumerate(lines) if line.startswith("BIOS folder:"))
named = next(i for i, line in enumerate(lines) if line.startswith("Named by"))