steam-backlog-enforcer/steam_backlog_enforcer/tests/_isolate_shadow.py
Krzysztof kuhy Rudnicki e82ddd9a4b playtime: shadow leisure billing (C4); /proc scan from leisure_watch
The enforcer now imports the Steam/launcher/counted-process scan from
leisure_watch.procscan (v0.1.0, shared with the leisure watcher) and drops
its own copies (_playtime_procs, _counted_procs, _total_block_launchers and
enforcer's two scanners). Every counted-process read passes
config.CONFIG_FILE explicitly, as before.

Each tick also bills a shadow leisure budget beside the enforced one, from
the same incoming stamp and delta clamp, before accumulate: paused (held
gatelock grab or i3lock) -> shadow_paused_seconds; else a qualifying game,
a "leisure" now.json, or an untrusted/missing now.json (fail closed) bills
shadow_seconds once, split over shadow_per_source. shadow_budget_seconds is
earned_time.resolve(leisure=True) from the same answers, held as a same-day
high-water mark. Not billed under a total block. Shadow verdict changes go
to budget.jsonl as shadow_change (the live game view skips them); /api/budget
and MCP get_gaming_time carry a "shadow" block. Enforced fields, cutoff,
warnings and existing log records are unchanged.

Also fixes two tests that assumed earned_time < 0.14 internals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dsh4Znwh2KnC7q6vbGpX1N
2026-10-19 12:37:01 +02:00

35 lines
1.2 KiB
Python

"""Autouse isolation of the shared /proc scan and the shadow leisure inputs.
The scanners moved to ``leisure_watch.procscan`` read ``/proc`` through their
own module constants, and the shadow tick reads the desktop user's gatelock
claims, i3lock and the watcher's signed ``now.json``. Unpatched, a test would
see the developer's live games, lockers and browser.
Default: nothing paused and no trusted watcher fact (the fail-closed reading).
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from unittest.mock import patch
import pytest
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path
@pytest.fixture(autouse=True)
def _isolate_shadow(tmp_path: Path) -> Iterator[None]:
"""Point the scan at an empty /proc and the shadow inputs at nothing."""
fake_proc = tmp_path / "procscan_proc"
fake_proc.mkdir(exist_ok=True)
with (
patch("leisure_watch.procscan._steam._PROC", fake_proc),
patch("leisure_watch.procscan._cmdline._PROC", fake_proc),
patch("steam_backlog_enforcer._shadow.paused_by", return_value=None),
patch("steam_backlog_enforcer._shadow.read_now", return_value=None),
):
yield