mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:22:18 +01:00
`./run.sh <anything>` is now the entry point. It installs its own dependencies (steamcmd via yay, DepotDownloader from the SteamRE release, a local .venv) and works out what the argument is: an appid, a Steam URL, an exact title, or part of a title. Every route is confirmed through steamcmd's own app_info before anything acts on it. Name search moves to steamcommunity.com/actions/SearchApps, which works, with the storefront API kept as a fallback -- it TLS-rejects scripted clients here, so search had been effectively dead. DNS on this box fails transiently about one lookup in three, so each backend is retried before giving up. An exact title now wins over Steam's own ranking, which puts "Portal 2" above "Portal"; an ambiguous name shows a picker, or exits 2 rather than guessing. Two problems found while building this, both now handled: Anonymous steamcmd has no licence for a paid app and does not say so. It transfers nothing, prints "Success! App '284160' fully installed.", exits 0, and writes StateFlags=4 with SizeOnDisk=0 and no depots. A running Steam client then reads that, decides the app is installed but stale, and downloads the whole game by itself. `ghost.py` detects that state -- validated read-only against all ten manifests in a real library, where the nine genuine installs are untouched and only the fabricated one matches -- and `--repair-ghosts` clears it away. Repair uses rmdir, never rmtree, so a non-empty directory survives a wrong diagnosis. And Steam's own in-progress downloads are no longer wasted. `takeover.py` hardlinks `steamapps/downloading/<appid>/` into the install directory before depotdownloader runs; depotdownloader hash-checks what is already on disk (ContentDownloader.cs skips a file when neededChunks is empty) and fetches only the remainder. Nothing is deleted up front -- the staging tree is cleared only after the install is verified -- so a failed run still leaves Steam able to resume. The trees share inodes, so an in-place chunk patch corrects both. cli.py drops from 311 to 244 lines, back under the repo's 250-line cap, by moving the install flow to flow.py and the manifest finish to finalize.py. install.sh had a latent bug: `pip install -e .[dev]` only warns about a missing extra and exits 0, so the `|| fallback` that installed pytest and coverage never ran. A fresh venv had no test tools at all; the existing one only worked because they had been installed by hand earlier. Now named outright and asserted. 246 tests, 100% statement and branch coverage. Verified live: all four input forms resolve to 284160, an exact "Portal" resolves to 400 and not 620, an ambiguous name exits 2, ghost detection flags nothing on nine real installs, and a from-scratch venv bootstraps and runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sgkb3wH6MU9fYquX328ovT
179 lines
5.9 KiB
Python
179 lines
5.9 KiB
Python
"""Turning one free-form argument into a confirmed Steam app.
|
|
|
|
Four shapes have to work -- an AppID, a Steam URL, an exact title and a
|
|
partial title -- and the ambiguous cases have to fail rather than guess.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from steam_installer import appinfo, resolve, target
|
|
|
|
|
|
def _metadata(appid):
|
|
return appinfo.AppMetadata(appid, "BeamNG.drive", "BeamNG.drive")
|
|
|
|
|
|
@pytest.fixture
|
|
def steam_knows_the_app(monkeypatch):
|
|
monkeypatch.setattr(appinfo, "get_metadata", _metadata)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("text", "expected"),
|
|
[
|
|
("284160", (284160, "appid")),
|
|
(" 284160 ", (284160, "appid")),
|
|
("https://steamcommunity.com/app/284160/guides/", (284160, "url")),
|
|
("https://store.steampowered.com/app/284160/BeamNGdrive/", (284160, "url")),
|
|
("https://store.steampowered.com/app/284160", (284160, "url")),
|
|
("https://store.steampowered.com/app/284160/?snr=1_7", (284160, "url")),
|
|
("steamcommunity.com/app/284160/", (284160, "url")),
|
|
("BeamNG.drive", None),
|
|
("BeamNG", None),
|
|
("0", None),
|
|
("https://steamcommunity.com/id/someone/", None),
|
|
],
|
|
)
|
|
def test_parse_literal_recognises_appids_and_urls(text, expected):
|
|
assert target.parse_literal(text) == expected
|
|
|
|
|
|
def test_an_appid_is_confirmed_through_steamcmd(steam_knows_the_app):
|
|
resolved = target.resolve_target("284160", None, interactive=False)
|
|
assert resolved.metadata.appid == 284160
|
|
assert resolved.source == "appid"
|
|
|
|
|
|
def test_the_appid_flag_skips_detection_entirely(steam_knows_the_app):
|
|
resolved = target.resolve_target("ignored name", 284160, interactive=False)
|
|
assert resolved.metadata.appid == 284160
|
|
assert resolved.source == "flag"
|
|
|
|
|
|
def test_a_url_resolves_without_searching(monkeypatch, steam_knows_the_app):
|
|
def no_search(name):
|
|
raise AssertionError("a URL must not trigger a search")
|
|
|
|
monkeypatch.setattr(resolve, "search", no_search)
|
|
resolved = target.resolve_target(
|
|
"https://steamcommunity.com/app/284160/guides/", None, interactive=False
|
|
)
|
|
assert resolved.source == "url"
|
|
|
|
|
|
def test_a_single_search_hit_is_taken(monkeypatch, steam_knows_the_app):
|
|
monkeypatch.setattr(
|
|
resolve, "search", lambda name: [resolve.SearchResult(284160, "BeamNG.drive")]
|
|
)
|
|
resolved = target.resolve_target("BeamNG", None, interactive=False)
|
|
assert resolved.metadata.appid == 284160
|
|
assert resolved.source == "only match"
|
|
|
|
|
|
def test_an_exact_title_wins_over_a_higher_ranked_sequel(monkeypatch):
|
|
"""Steam ranks Portal 2 first for "Portal"; typing the full name must not
|
|
install the sequel."""
|
|
monkeypatch.setattr(
|
|
resolve,
|
|
"search",
|
|
lambda name: [
|
|
resolve.SearchResult(620, "Portal 2"),
|
|
resolve.SearchResult(400, "Portal"),
|
|
],
|
|
)
|
|
monkeypatch.setattr(
|
|
appinfo, "get_metadata", lambda appid: appinfo.AppMetadata(appid, "Portal", "P")
|
|
)
|
|
|
|
resolved = target.resolve_target("Portal", None, interactive=False)
|
|
|
|
assert resolved.metadata.appid == 400
|
|
assert resolved.source == "exact"
|
|
|
|
|
|
def test_an_ambiguous_name_prompts_when_interactive(monkeypatch, steam_knows_the_app):
|
|
results = [resolve.SearchResult(1, "Witcher 3"), resolve.SearchResult(2, "Witcher")]
|
|
monkeypatch.setattr(resolve, "search", lambda name: results)
|
|
monkeypatch.setattr(resolve, "prompt_confirm", lambda r: r[1])
|
|
|
|
resolved = target.resolve_target("witch", None, interactive=True)
|
|
|
|
assert resolved.source == "picked"
|
|
|
|
|
|
def test_an_ambiguous_name_fails_closed_when_not_interactive(
|
|
monkeypatch, steam_knows_the_app, capsys
|
|
):
|
|
"""Guessing here is how the wrong 90 GB gets downloaded."""
|
|
monkeypatch.setattr(
|
|
resolve,
|
|
"search",
|
|
lambda name: [
|
|
resolve.SearchResult(1, "Witcher 3"),
|
|
resolve.SearchResult(2, "Witcher 2"),
|
|
],
|
|
)
|
|
|
|
with pytest.raises(target.TargetError, match="Ambiguous"):
|
|
target.resolve_target("witch", None, interactive=False)
|
|
|
|
err = capsys.readouterr().err
|
|
assert "Witcher 3" in err
|
|
assert "Witcher 2" in err
|
|
|
|
|
|
def test_no_matches_is_an_error_not_a_default_pick(monkeypatch):
|
|
monkeypatch.setattr(resolve, "search", lambda name: [])
|
|
with pytest.raises(target.TargetError, match="No Steam app matches"):
|
|
target.resolve_target("kwyjibo", None, interactive=False)
|
|
|
|
|
|
def test_search_being_unavailable_points_at_the_appid_workaround(monkeypatch):
|
|
def boom(name):
|
|
raise resolve.SearchUnavailable("tls blocked")
|
|
|
|
monkeypatch.setattr(resolve, "search", boom)
|
|
|
|
with pytest.raises(target.TargetError, match="numeric AppID"):
|
|
target.resolve_target("BeamNG", None, interactive=False)
|
|
|
|
|
|
def test_digits_that_are_not_an_appid_fall_through_to_a_name_search(monkeypatch):
|
|
"""A game literally called "2048" exists, so digits are not unambiguous."""
|
|
tried = []
|
|
|
|
def metadata(appid):
|
|
tried.append(appid)
|
|
if appid == 2048:
|
|
raise appinfo.AppInfoError("no such app")
|
|
return appinfo.AppMetadata(appid, "2048", "2048")
|
|
|
|
monkeypatch.setattr(appinfo, "get_metadata", metadata)
|
|
monkeypatch.setattr(
|
|
resolve, "search", lambda name: [resolve.SearchResult(999, "2048")]
|
|
)
|
|
|
|
resolved = target.resolve_target("2048", None, interactive=False)
|
|
|
|
assert resolved.metadata.appid == 999
|
|
assert tried == [2048, 999]
|
|
|
|
|
|
def test_an_unknown_appid_from_a_url_does_not_fall_through(monkeypatch):
|
|
"""A URL cannot also be a game's name, so there is nothing to fall back to."""
|
|
|
|
def boom(appid):
|
|
raise appinfo.AppInfoError("no such app")
|
|
|
|
monkeypatch.setattr(appinfo, "get_metadata", boom)
|
|
|
|
with pytest.raises(target.TargetError, match="not a known Steam app"):
|
|
target.resolve_target(
|
|
"https://store.steampowered.com/app/1/x/", None, interactive=False
|
|
)
|
|
|
|
|
|
def test_no_target_at_all_is_an_error():
|
|
with pytest.raises(target.TargetError, match="No target given"):
|
|
target.resolve_target(None, None, interactive=False)
|