mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-20 22:32:32 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
kuhy 2026-11-11: game-design research needs Librarian (app 4197610) actually played during the 6-day total block. New root command total-block-research --until T opens ONE window per lock: <= 48 h, never past the lock end, a rerun never extends it. The command only validates and records (/var/lib/steam-backlog- enforcer, root 0700; lock id + deadline + two latches). The daemon opens and closes everything: Steam hosts names, the store block, the total-block chain (IP cache kept) and the steam package, reinstalled with only guard-lib's package-block hook masked for that one pacman call (--hookdir, proved in a guest). Lock file, hook and end date are never touched. Browser-game sites stay null-routed. Only Librarian may run: loop-local allowed set, strict mode (no whitelist exceptions, no zero-achievement games), launchers and counted games killed; state.json is never read or written. Expiry latches the record, then the ordinary tick re-applies hosts (now reconciled each tick), chain, uninstall and purge; the normal store block is restored once, unconditionally. Failure modes: missing/corrupt/unparseable record = no window and a corrupt one also refuses a new window (fail closed); a clock set back cannot reopen a latched window. Checked: 3290 tests at 100% coverage; whole-tree pylint 10/10 run in three parts (the hook exceeds the 60 s cap, so SKIP=pylint here); vmbox guest with real guardctl package-block and the real unit, window opened, Librarian-only enforced, clock moved past the deadline and the full block re-applied. Not verified on the host. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWWzuCEg1m87jpKyRrw
125 lines
4.1 KiB
Python
125 lines
4.1 KiB
Python
"""Strict mode: during research only runtimes survive besides the allowed game."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import ClassVar
|
|
from unittest.mock import patch
|
|
|
|
from steam_backlog_enforcer._enforce_guards import guard_installed_games
|
|
from steam_backlog_enforcer.enforcer import enforce_allowed_game
|
|
from steam_backlog_enforcer.game_uninstall import (
|
|
is_infrastructure_app,
|
|
is_protected_app,
|
|
)
|
|
|
|
UNI = "steam_backlog_enforcer.game_uninstall"
|
|
LIBRARIAN = 4197610
|
|
EXCEPTION = 880940 # an approved whitelist exception
|
|
ZERO_ACH = 555 # an owned game with no achievements
|
|
PROTON = 1493710 # Proton Experimental, a runtime
|
|
OTHER = 111
|
|
|
|
|
|
def _world() -> tuple[object, object]:
|
|
"""Patch the two exemption sources: approved exceptions and zero-ach games."""
|
|
return (
|
|
patch(f"{UNI}.get_approved_exception_ids", return_value={EXCEPTION}),
|
|
patch(f"{UNI}.zero_achievement_ids", return_value={ZERO_ACH}),
|
|
)
|
|
|
|
|
|
class TestPredicates:
|
|
"""Infrastructure is the strict subset of protected."""
|
|
|
|
def test_runtime_is_infrastructure(self) -> None:
|
|
"""Test that Proton is protected in both modes."""
|
|
assert is_infrastructure_app(PROTON)
|
|
assert is_protected_app(PROTON)
|
|
|
|
def test_exceptions_are_protected_but_not_infrastructure(self) -> None:
|
|
"""Test that the whitelist does not reach strict mode."""
|
|
exc, zero = _world()
|
|
with exc, zero:
|
|
assert is_protected_app(EXCEPTION)
|
|
assert is_protected_app(ZERO_ACH)
|
|
assert not is_infrastructure_app(EXCEPTION)
|
|
assert not is_infrastructure_app(ZERO_ACH)
|
|
|
|
|
|
class TestKill:
|
|
"""enforce_allowed_game with and without strict."""
|
|
|
|
RUNNING: ClassVar[dict[int, int]] = {
|
|
10: LIBRARIAN,
|
|
11: EXCEPTION,
|
|
12: ZERO_ACH,
|
|
13: PROTON,
|
|
14: 0,
|
|
15: OTHER,
|
|
}
|
|
|
|
def _violations(self, *, strict: bool) -> list[tuple[int, int]]:
|
|
exc, zero = _world()
|
|
with (
|
|
exc,
|
|
zero,
|
|
patch(
|
|
"steam_backlog_enforcer.enforcer.get_running_steam_game_pids",
|
|
return_value=self.RUNNING,
|
|
),
|
|
patch("steam_backlog_enforcer.enforcer.kill_process"),
|
|
):
|
|
return enforce_allowed_game(
|
|
{LIBRARIAN}, kill_unauthorized=True, strict=strict
|
|
)
|
|
|
|
def test_default_spares_exceptions(self) -> None:
|
|
"""Test that normal enforcement is unchanged."""
|
|
assert self._violations(strict=False) == [(15, OTHER)]
|
|
|
|
def test_strict_kills_exceptions_and_zero_achievement_games(self) -> None:
|
|
"""Test that only Librarian, runtimes and app 0 survive strict mode."""
|
|
assert self._violations(strict=True) == [
|
|
(11, EXCEPTION),
|
|
(12, ZERO_ACH),
|
|
(15, OTHER),
|
|
]
|
|
|
|
|
|
class TestUninstall:
|
|
"""guard_installed_games with and without strict."""
|
|
|
|
INSTALLED: ClassVar[list[tuple[int, str]]] = [
|
|
(LIBRARIAN, "Librarian"),
|
|
(EXCEPTION, "Party game"),
|
|
(ZERO_ACH, "No achievements"),
|
|
(PROTON, "Proton Experimental"),
|
|
(OTHER, "Other"),
|
|
]
|
|
|
|
def _removed(self, *, strict: bool) -> list[int]:
|
|
exc, zero = _world()
|
|
with (
|
|
exc,
|
|
zero,
|
|
patch(
|
|
"steam_backlog_enforcer._enforce_guards.get_installed_games",
|
|
return_value=self.INSTALLED,
|
|
),
|
|
patch(
|
|
"steam_backlog_enforcer._enforce_guards.uninstall_game",
|
|
return_value=True,
|
|
) as uninstall,
|
|
patch("steam_backlog_enforcer._enforce_guards.send_notification"),
|
|
):
|
|
guard_installed_games({LIBRARIAN}, strict=strict)
|
|
return [call.args[0] for call in uninstall.call_args_list]
|
|
|
|
def test_default_spares_exceptions(self) -> None:
|
|
"""Test that normal enforcement is unchanged."""
|
|
assert self._removed(strict=False) == [OTHER]
|
|
|
|
def test_strict_removes_everything_but_librarian_and_runtimes(self) -> None:
|
|
"""Test that exceptions and zero-achievement games go in strict mode."""
|
|
assert self._removed(strict=True) == [EXCEPTION, ZERO_ACH, OTHER]
|