steam-backlog-enforcer/steam_installer/tests/test_appinfo_cache_backed.py
Krzysztof kuhy Rudnicki a76e726e36 Merge steam-game-installer into the repo
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
2026-11-22 20:25:39 +01:00

97 lines
3.1 KiB
Python

"""get_metadata/get_build_id/get_dlc_plans answered from Steam's binary cache."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
import pytest
from steam_installer import appinfo
from steam_installer.tests._appinfo_blob import encode
if TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path
# The block steamcmd's app_info_print used to return for KCD2, now as Steam
# keeps it in its binary cache. The differential tests below pin that the
# cache gives the same answers the steamcmd text did.
KCD2: dict[str, Any] = {
"common": {
"name": "Kingdom Come: Deliverance II",
"installdir": "KingdomComeDeliverance2",
},
"depots": {
"1771303": {"config": {"oslist": "windows"}},
"branches": {"public": {"buildid": 23914554}},
},
}
@pytest.fixture(name="cache")
def _cache(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> Callable[[dict[int, Any]], None]:
"""Point appinfo at a fixture cache; returns a writer for its apps."""
path = tmp_path / "appinfo.vdf"
monkeypatch.setattr(appinfo.appinfo_cache, "default_path", lambda: path)
def write(apps: dict[int, Any]) -> None:
path.write_bytes(encode(apps))
return write
def test_metadata_comes_from_steams_cache(
cache: Callable[[dict[int, Any]], None],
) -> None:
"""Metadata comes from Steam's cache."""
cache({1771300: KCD2})
metadata = appinfo.get_metadata(1771300)
assert metadata.name == "Kingdom Come: Deliverance II"
assert metadata.installdir == "KingdomComeDeliverance2"
def test_get_build_id_through_the_real_parser(
cache: Callable[[dict[int, Any]], None],
) -> None:
# Stored as an int32 in the binary cache; still a string like steamcmd's.
"""Get build id through the real parser."""
cache({1771300: KCD2})
assert appinfo.get_build_id(1771300) == "23914554"
def test_app_missing_from_the_cache_fails_with_the_fix(
cache: Callable[[dict[int, Any]], None],
) -> None:
"""App missing from the cache fails with the fix."""
cache({1771300: KCD2})
with pytest.raises(
appinfo.AppInfoError, match="start Steam once, let it sync, rerun"
):
appinfo.get_metadata(999999999)
def test_unreadable_cache_fails_with_the_fix(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Unreadable cache fails with the fix."""
monkeypatch.setattr(
appinfo.appinfo_cache, "default_path", lambda: tmp_path / "missing.vdf"
)
with pytest.raises(appinfo.AppInfoError, match="start Steam once"):
appinfo.get_metadata(1)
def test_dlc_missing_from_the_cache_counts_as_not_owned(
cache: Callable[[dict[int, Any]], None],
) -> None:
"""Steam caches app info for what the account owns; on 2026-11-22 only 1828
of 7102 listed DLC ids were in the cache. Refusing on a missing one would
block installs that worked with steamcmd."""
game = {**KCD2, "extended": {"listofdlc": "500,600"}}
dlc = {"depots": {"501": {"manifests": {"public": {"gid": "9"}}}}}
cache({1771300: game, 500: dlc})
assert appinfo.get_dlc_plans(1771300) == {500: {"501": "9"}}