Serve no history for demo budget runs
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 (push) Waiting to run
Tests / test (push) Waiting to run

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-08-29 07:26:51 +02:00
parent f0f14ebf49
commit 9062fa8c10
2 changed files with 17 additions and 2 deletions

View File

@ -197,7 +197,13 @@ def build_budget_snapshot(*, demo: bool = False) -> dict[str, Any]:
{"pid": game.pid, "name": game.name} for game in session.games
],
},
"history": [
# Demo runs have no history by design — HistoryWriter skips them, for
# the same reason they get their own state file and log. Serving the
# production days here would plot real 8-hour days against the demo's
# 60-second budget line, painting every one of them over-budget.
"history": []
if demo
else [
{"day": day.day, "seconds": round(day.seconds, 1)}
for day in load_history(_HISTORY_DAYS)
],

View File

@ -123,7 +123,7 @@ class TestBuildBudgetSnapshot:
patch.object(view, "last_verdict", return_value=kwargs["session"]),
patch.object(view, "mounted_targets", return_value=set()),
):
return build_budget_snapshot()
return build_budget_snapshot(demo=bool(kwargs.get("demo", False)))
def test_reports_a_readable_day(self) -> None:
snapshot = self._snapshot()
@ -180,6 +180,15 @@ class TestBuildBudgetSnapshot:
snapshot = self._snapshot()
assert snapshot["history"] == [{"day": "2026-08-27", "seconds": 1.5}]
def test_demo_runs_serve_no_history(self) -> None:
"""Production days must not be plotted against the 60-second budget."""
day = HistoryDay(day="2026-08-28", seconds=28800.0)
with patch.object(view, "load_history", return_value=[day]) as load:
snapshot = self._snapshot(demo=True)
assert snapshot["history"] == []
assert snapshot["rules"]["demo"] is True
load.assert_not_called()
def test_leaks_no_secret(self) -> None:
"""The API key must never cross the HTTP boundary."""
with patch.object(Config, "load", return_value=Config(steam_api_key="SEKRET")):