Compare commits

..

No commits in common. "d574be324d2152a68850744da2fe10c9499a523e" and "e594db5fd75a6d50bec5b19fd5465f063927e5f3" have entirely different histories.

8 changed files with 10 additions and 73 deletions

View File

@ -24,7 +24,7 @@ jobs:
run: echo "UTILS_ROOT=$GITHUB_WORKSPACE/.utils" >> "$GITHUB_ENV"
- uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version: "3.14.7"
- name: Install dependencies
run: pip install -r requirements.txt
- uses: pre-commit/action@v3.0.1

View File

@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version: "3.14.7"
- name: Install dependencies
run: pip install -r requirements.txt

View File

@ -4,7 +4,7 @@ version = "1.0.0"
description = "Enforce your Steam backlog: one game at a time, tracked with HowLongToBeat data"
# 3.11 floor: websockets 17 (and its successors) drop 3.10, and this repo
# tracks newest stable rather than the oldest interpreter still alive.
requires-python = ">=3.14"
requires-python = ">=3.11"
dependencies = [
"requests==2.34.2",
"howlongtobeatpy==1.0.23",

View File

@ -209,7 +209,7 @@ def do_enforce(config: Config, state: State, *, demo: bool = False) -> None:
_echo(" Press Ctrl+C to stop.\n")
# One session for the whole daemon: the engagement backdate needs to see
# the previous tick's verdict, so it cannot be rebuilt per iteration.
session = new_session(demo=demo)
session = new_session()
try:
while True:
# Reload state from disk so CLI changes (e.g. new game

View File

@ -36,7 +36,6 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__)
BUDGET_LOG_FILE: Final = Path("/var/log/steam-backlog-enforcer/budget.jsonl")
BUDGET_DEMO_LOG_FILE: Final = Path("/var/log/steam-backlog-enforcer/budget-demo.jsonl")
_MAX_BYTES: Final = 5 * 1024 * 1024
_BACKUP_COUNT: Final = 5
@ -48,38 +47,14 @@ EVENT_DETECTOR_FAILURE: Final = "detector_failure"
EVENT_MANUAL_ADJUSTMENT: Final = "manual_adjustment"
def budget_log_path(*, demo: bool) -> Path:
"""Return the audit log for a demo or production run.
Demo runs get their own file for the same reason they get their own state
file: this log is the record used to reconstruct real incidents, and a run
that carries no enforcement weight must not be able to plant records in it
that describe a budget nobody was ever charged. A 60-second demo billing
700 seconds is indistinguishable, after the fact, from the production
daemon having done something inexplicable.
Args:
demo: Whether this is a demo run.
Returns:
The destination JSONL file.
"""
return BUDGET_DEMO_LOG_FILE if demo else BUDGET_LOG_FILE
class BudgetLog:
"""Append-only JSONL sink, rotated by size."""
def __init__(self, *, path: Path) -> None:
def __init__(self, *, path: Path = BUDGET_LOG_FILE) -> None:
"""Prepare a sink; the file is opened on first write.
*path* is required on purpose. It used to default to the production
log, so a throwaway probe run as root — ``BudgetLog()`` in a scratch
script — wrote invented records straight into the trail this module
exists to keep trustworthy. Naming the destination is now unavoidable.
Args:
path: Destination JSONL file, from :func:`budget_log_path`.
path: Destination JSONL file.
"""
self._path = path
self._sink: logging.Logger | None = None

View File

@ -19,11 +19,7 @@ from typing import TYPE_CHECKING, Protocol
from steam_backlog_enforcer._desktop_env import desktop_uid, resolve_desktop_user
from steam_backlog_enforcer._playtime_engagement import EngagementTracker
from steam_backlog_enforcer._playtime_log import (
BudgetLog,
TickJournal,
budget_log_path,
)
from steam_backlog_enforcer._playtime_log import BudgetLog, TickJournal
if TYPE_CHECKING:
from steam_backlog_enforcer._engagement_types import EngagementVerdict
@ -74,19 +70,14 @@ class PlaytimeSession:
journal: TickRecorder
def new_session(*, demo: bool = False) -> PlaytimeSession:
def new_session() -> PlaytimeSession:
"""Build the session the enforce loop threads through every tick.
Args:
demo: Whether this is a short-budget demo run. Demo runs journal to
their own file, so they cannot plant records in the production
audit trail.
Returns:
A session bound to the desktop user's X display and runtime dir.
"""
uid = desktop_uid(resolve_desktop_user())
return PlaytimeSession(
tracker=EngagementTracker(uid=uid),
journal=TickJournal(BudgetLog(path=budget_log_path(demo=demo))),
journal=TickJournal(BudgetLog()),
)

View File

@ -21,14 +21,11 @@ from steam_backlog_enforcer._engagement_types import (
EngagementVerdict,
)
from steam_backlog_enforcer._playtime_log import (
BUDGET_DEMO_LOG_FILE,
BUDGET_LOG_FILE,
EVENT_DETECTOR_FAILURE,
EVENT_HEARTBEAT,
EVENT_VERDICT_CHANGE,
BudgetLog,
TickJournal,
budget_log_path,
)
from steam_backlog_enforcer._playtime_state import PlaytimeRules, PlaytimeState
@ -55,18 +52,6 @@ def _records(path: Path) -> list[dict]:
return [json.loads(line) for line in path.read_text().splitlines() if line]
class TestBudgetLogPath:
def test_production_run_journals_to_the_real_trail(self) -> None:
assert budget_log_path(demo=False) == BUDGET_LOG_FILE
def test_demo_run_cannot_reach_the_production_trail(self) -> None:
# A demo bills against a 60-second budget. Letting those records land
# in the production log makes the log unusable for the one job it has:
# reconstructing what the real budget actually did.
assert budget_log_path(demo=True) == BUDGET_DEMO_LOG_FILE
assert budget_log_path(demo=True) != BUDGET_LOG_FILE
class TestBudgetLog:
def test_creates_its_directory_on_first_write(self, tmp_path: Path) -> None:
target = tmp_path / "deep" / "nested" / "budget.jsonl"

View File

@ -5,11 +5,7 @@ from __future__ import annotations
from unittest.mock import patch
from steam_backlog_enforcer._playtime_engagement import EngagementTracker
from steam_backlog_enforcer._playtime_log import (
BUDGET_DEMO_LOG_FILE,
BUDGET_LOG_FILE,
TickJournal,
)
from steam_backlog_enforcer._playtime_log import TickJournal
from steam_backlog_enforcer._playtime_session import new_session
PS = "steam_backlog_enforcer._playtime_session"
@ -35,13 +31,3 @@ class TestNewSession:
):
session = new_session()
assert "/run/user/1000/" in str(session.tracker._holder_path)
def test_demo_journals_away_from_the_production_trail(self) -> None:
with (
patch(f"{PS}.resolve_desktop_user", return_value="kuhy"),
patch(f"{PS}.desktop_uid", return_value=1000),
):
live = new_session()
demo = new_session(demo=True)
assert demo.journal._log._path == BUDGET_DEMO_LOG_FILE
assert live.journal._log._path == BUDGET_LOG_FILE