steam-backlog-enforcer/steam_backlog_enforcer/tests/_research_fixtures.py
Krzysztof kuhy Rudnicki 5d5aa3e773
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
Add Librarian-only research window to total block
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
2026-11-11 14:29:58 +01:00

81 lines
2.6 KiB
Python

"""Fixtures for the daemon-pass tests: every effect of one pass is a mock."""
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch
import pytest
from steam_backlog_enforcer._research_tick import total_block_pass
from steam_backlog_enforcer.config import Config
from steam_backlog_enforcer.tests._research_helpers import NOW, lock
if TYPE_CHECKING:
from collections.abc import Iterator
from steam_backlog_enforcer.tests._total_block_paths import Paths
PKG = "steam_backlog_enforcer._research_tick"
BLOCK = "steam_backlog_enforcer._total_block"
NOW_PATCH = "steam_backlog_enforcer._research_window.now"
@dataclass
class Mocks:
"""The collaborators of one pass, all stand-ins."""
block_tick: MagicMock
reconcile: MagicMock
launchers: MagicMock
counted: MagicMock
steam_installed: MagicMock
enforce: MagicMock
guard: MagicMock
notify: MagicMock
restore_store: MagicMock
steam_kill: MagicMock
steam_uninstall: MagicMock
steam_purge: MagicMock
@pytest.fixture
def tm(total_block_paths: Paths) -> Iterator[Mocks]:
"""An active total block with every effect replaced by a mock."""
lock(total_block_paths)
with (
patch(f"{PKG}.enforce_total_block_tick") as block_tick,
patch(f"{PKG}.reconcile_open_window") as reconcile,
patch(f"{PKG}.kill_and_uninstall_launchers", return_value=[]) as launchers,
patch(f"{PKG}.kill_processes_by_name", return_value=[]) as counted,
patch(f"{PKG}.steam_is_installed", return_value=True) as installed,
patch(f"{PKG}.enforce_allowed_game", return_value=[]) as enforce,
patch(f"{PKG}.guard_installed_games", return_value=0) as guard,
patch(f"{PKG}.send_notification") as notify,
patch(f"{PKG}.restore_store_block", return_value=True) as restore_store,
patch(f"{BLOCK}.kill_steam_and_launchers") as steam_kill,
patch(f"{BLOCK}.uninstall_steam_package") as steam_uninstall,
patch(f"{BLOCK}.purge_steam_and_proton") as steam_purge,
):
yield Mocks(
block_tick,
reconcile,
launchers,
counted,
installed,
enforce,
guard,
notify,
restore_store,
steam_kill,
steam_uninstall,
steam_purge,
)
def run_pass(now: float = NOW, *, block_store: bool = True) -> None:
"""Run one total-block pass with the clock at *now*."""
with patch(NOW_PATCH, return_value=now):
total_block_pass(Config(block_store=block_store))