mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-23 22:46:17 +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
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
"""Clearing a ghost away, and every case where it must refuse to.
|
|
|
|
Split from test_ghost.py to keep both files under the repo's 250-line cap.
|
|
"""
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from steam_installer import ghost
|
|
from tests.conftest import GHOST_ACF, _real_install, _write
|
|
|
|
LOGGER = logging.getLogger("test-ghost-repair")
|
|
|
|
|
|
def test_repair_moves_the_manifest_aside_and_removes_the_empty_directory(library):
|
|
_write(library, 284160, GHOST_ACF)
|
|
content = library.common / "BeamNG.drive"
|
|
content.mkdir()
|
|
report = ghost.inspect(library, 284160)
|
|
|
|
touched = ghost.repair(report, LOGGER, now_unix=1757000000)
|
|
|
|
assert not report.manifest_path.exists()
|
|
backup = library.steamapps / "appmanifest_284160.acf.ghost-1757000000"
|
|
assert backup.read_text() == GHOST_ACF
|
|
assert not content.exists()
|
|
assert touched == [backup, content]
|
|
|
|
|
|
def test_repair_refuses_to_delete_a_non_empty_directory(library, caplog):
|
|
"""rmdir, never rmtree: the kernel itself is the last line of defence."""
|
|
_write(library, 284160, GHOST_ACF)
|
|
content = library.common / "BeamNG.drive"
|
|
content.mkdir()
|
|
report = ghost.inspect(library, 284160)
|
|
# Content appears between the check and the repair.
|
|
(content / "surprise.pak").write_bytes(b"x")
|
|
|
|
with caplog.at_level(logging.WARNING):
|
|
touched = ghost.repair(report, LOGGER, now_unix=1)
|
|
|
|
assert content.exists()
|
|
assert (content / "surprise.pak").exists()
|
|
assert content not in touched
|
|
|
|
|
|
def test_repair_refuses_a_warm_ghost(library):
|
|
"""Staged bytes are a real partial download, not a lie to clean up."""
|
|
_write(library, 284160, GHOST_ACF)
|
|
staged = library.steamapps / "downloading" / "284160"
|
|
staged.mkdir(parents=True)
|
|
(staged / "part.pak").write_bytes(b"x" * 3000)
|
|
report = ghost.inspect(library, 284160)
|
|
|
|
with pytest.raises(ValueError, match="partial download"):
|
|
ghost.repair(report, LOGGER)
|
|
|
|
assert report.manifest_path.exists()
|
|
assert (staged / "part.pak").exists()
|
|
|
|
|
|
def test_repair_refuses_anything_that_is_not_a_ghost(library):
|
|
_real_install(library)
|
|
report = ghost.inspect(library, 475150)
|
|
|
|
with pytest.raises(ValueError, match="not a ghost"):
|
|
ghost.repair(report, LOGGER)
|
|
|
|
|
|
def test_repair_defaults_its_timestamp_to_now(library):
|
|
_write(library, 284160, GHOST_ACF)
|
|
touched = ghost.repair(ghost.inspect(library, 284160), LOGGER)
|
|
assert touched[0].name.startswith("appmanifest_284160.acf.ghost-")
|