steam-backlog-enforcer/steam_installer/tests/test_ghost_repair.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

88 lines
2.9 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.
"""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
import pytest
from steam_installer import ghost
from steam_installer.tests._acf_helpers import GHOST_ACF, _real_install, _write
if TYPE_CHECKING:
from steam_installer.library import SteamLibrary
LOGGER = logging.getLogger("test-ghost-repair")
def test_repair_moves_the_manifest_aside_and_removes_the_empty_directory(
library: SteamLibrary,
) -> None:
"""Repair moves the manifest aside and removes the empty directory."""
_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: SteamLibrary, caplog: pytest.LogCaptureFixture
) -> None:
"""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: SteamLibrary) -> None:
"""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: SteamLibrary) -> None:
"""Repair refuses anything that is not a ghost."""
_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: SteamLibrary) -> None:
"""Repair defaults its timestamp to now."""
_write(library, 284160, GHOST_ACF)
touched = ghost.repair(ghost.inspect(library, 284160), LOGGER)
assert touched[0].name.startswith("appmanifest_284160.acf.ghost-")