mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:22:18 +01:00
The installer ships as the steam_installer package beside steam_backlog_enforcer, with its tests, docs and Proton lock. The enforcer's fast install now starts the installer from this checkout. Both appinfo.vdf readers share one key-value decoder (steam_installer.appinfo_kv), and the duplicated test fixtures and helpers are folded into conftest and _cli_helpers so the whole-tree duplicate-code check is clean. check_requirements_sync treats sibling packages as first-party. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
"""The CLI and the Steam client: closed around an install, reopened after."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Never
|
|
|
|
import pytest
|
|
|
|
from steam_installer import appinfo, cli, depotdl, ghost, recognize
|
|
|
|
if TYPE_CHECKING:
|
|
import logging
|
|
|
|
|
|
def _installable(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setattr(
|
|
appinfo, "get_depot_plan", lambda a, language: appinfo.DepotPlan(set(), set())
|
|
)
|
|
monkeypatch.setattr(appinfo, "get_build_id", lambda a: "1")
|
|
monkeypatch.setattr(depotdl, "download", lambda *a, **kw: 1)
|
|
|
|
|
|
@pytest.mark.usefixtures("cli_steam")
|
|
def test_declining_the_shutdown_prompt_stops_the_run(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""Declining the shutdown prompt stops the run."""
|
|
monkeypatch.setattr(recognize, "steam_client_pids", lambda: [42])
|
|
monkeypatch.setattr(cli, "_is_interactive", lambda args: True)
|
|
monkeypatch.setattr(
|
|
"builtins.input", lambda *a: "n" if "Steam is running" in a[0] else "y"
|
|
)
|
|
monkeypatch.setattr(
|
|
depotdl, "download", lambda *a, **kw: pytest.fail("must not download")
|
|
)
|
|
|
|
assert cli.main(["284160", "--username", "u", "--language", "english"]) == 1
|
|
|
|
|
|
@pytest.mark.usefixtures("cli_steam")
|
|
def test_steam_is_closed_and_reopened_around_the_install(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""It was running before, so it is running after -- whatever the outcome."""
|
|
monkeypatch.setattr(recognize, "steam_client_pids", lambda: [42])
|
|
monkeypatch.setattr(ghost.recognize, "steam_client_pids", lambda: [42])
|
|
events = []
|
|
|
|
def stop(_logger: object) -> bool:
|
|
events.append("stop")
|
|
return True
|
|
|
|
monkeypatch.setattr(cli.flow.steamctl, "stop", stop)
|
|
monkeypatch.setattr(
|
|
cli.flow.steamctl, "start", lambda logger: events.append("start")
|
|
)
|
|
_installable(monkeypatch)
|
|
|
|
assert cli.main(["--yes", "284160", "--username", "u"]) == 1
|
|
assert events == ["stop", "start"]
|
|
|
|
|
|
@pytest.mark.usefixtures("cli_steam")
|
|
def test_a_steam_that_refuses_to_exit_aborts_the_run(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
capsys: pytest.CaptureFixture[str],
|
|
) -> None:
|
|
"""Never escalate to a signal: a hung client is the user's to deal with."""
|
|
monkeypatch.setattr(recognize, "steam_client_pids", lambda: [42])
|
|
|
|
def refuse(_logger: logging.Logger) -> Never:
|
|
msg = "Steam is still running after 60s"
|
|
raise cli.flow.steamctl.SteamStillRunningError(msg)
|
|
|
|
monkeypatch.setattr(cli.flow.steamctl, "stop", refuse)
|
|
monkeypatch.setattr(
|
|
depotdl, "download", lambda *a, **kw: pytest.fail("must not download")
|
|
)
|
|
|
|
assert cli.main(["--yes", "284160", "--username", "u"]) == 1
|
|
assert "still running" in capsys.readouterr().out
|
|
|
|
|
|
@pytest.mark.usefixtures("cli_steam")
|
|
def test_accepting_the_shutdown_prompt_closes_and_reopens_steam(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""The interactive path: asked, answered yes, Steam cycled around the run."""
|
|
monkeypatch.setattr(recognize, "steam_client_pids", lambda: [42])
|
|
monkeypatch.setattr(cli, "_is_interactive", lambda args: True)
|
|
monkeypatch.setattr("builtins.input", lambda *a: "y")
|
|
events = []
|
|
|
|
def stop(_logger: object) -> bool:
|
|
events.append("stop")
|
|
return True
|
|
|
|
monkeypatch.setattr(cli.flow.steamctl, "stop", stop)
|
|
monkeypatch.setattr(
|
|
cli.flow.steamctl, "start", lambda logger: events.append("start")
|
|
)
|
|
_installable(monkeypatch)
|
|
|
|
assert cli.main(["284160", "--username", "u", "--language", "english"]) == 1
|
|
assert events == ["stop", "start"]
|