mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-23 15:46:18 +01:00
earned_time 0.24 progress rows: the reset and sick floor pass
progress_map to resolve (workout left out, WorkoutCreditMixin owns
it); the live pass pays max(0, pay_now - applied) and stamps
<name>_bonus_minutes. A legacy <name>_bonus_date of today still
means the full bonus, so a mid-day deploy never pays twice. The
reset stamps minutes, never the date, so a partial stays open.
No progress row pays exactly as before; a credit pays in full.
Lands 5b6ac0b from the progress stack as this commit; its parent
4ed64b4 was already on main. Pins earned_time to the new tag
earned-time-v0.24.0 (utils c06f2da), in the manifests and the
pylint hook envs.
The preview keeps both sides: earners come from the day's registry
(main) and are priced through term_for with a progress row (stack).
_preview_sim.ROWS is the one row source for the live add and the
derivation; a new test pins a 1-of-2 review row on 2026-11-24 and
checks the preview pays term_for's share (10), not the flat 20.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""Signed progress rows and a state file for the partial-bonus tests.
|
|
|
|
A progress row is the fact a gate signs, "done N of M for day D"
|
|
(``earned_time`` 0.24.0, DOCS-progress.md), written to the gate's own ledger
|
|
next to its credits. Like every ledger helper here it signs with
|
|
``_earned_fixtures.KEY`` and lands where screen-locker reads it, so the
|
|
tests read real signed ledgers, never a mock of the reader.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any, Final
|
|
|
|
import earned_time
|
|
|
|
from screen_locker._day import today_str
|
|
from screen_locker.tests._earned_fixtures import _any_credit, signed, write_ledger
|
|
|
|
if TYPE_CHECKING:
|
|
from unittest.mock import MagicMock
|
|
|
|
# A flat earner whose rung does not divide by 3 or 2, so a share rounds down.
|
|
ODD: Final = earned_time.Earner(
|
|
name="odd",
|
|
label="Odd",
|
|
gaming_minutes=50,
|
|
shutdown_minutes=50,
|
|
ledger=".local/share/odd_guard/ledger.json",
|
|
match=_any_credit,
|
|
progress_source="odd",
|
|
)
|
|
|
|
|
|
def progress_row(
|
|
earner: earned_time.Earner,
|
|
done: int,
|
|
target: int,
|
|
day: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""A signed progress row for ``earner``'s source (default today)."""
|
|
for_day = day or today_str()
|
|
return signed(
|
|
{
|
|
"kind": "progress",
|
|
"entry_id": f"progress:{for_day}:{done}:{target}",
|
|
"day": for_day,
|
|
"amount": 0,
|
|
"device": "test",
|
|
"created_at": f"{for_day}T12:00:00+00:00",
|
|
"detail": {
|
|
"source": earner.progress_source,
|
|
"for_day": for_day,
|
|
"done": str(done),
|
|
"target": str(target),
|
|
},
|
|
}
|
|
)
|
|
|
|
|
|
def put_progress(earner: earned_time.Earner, rows: list[tuple[int, int]]) -> None:
|
|
"""Replace ``earner``'s ledger with one progress row per (done, target)."""
|
|
write_ledger(earner, [progress_row(earner, d, t) for d, t in rows])
|
|
|
|
|
|
def paid(mixin: MagicMock) -> list[int]:
|
|
"""The minutes each ``_adjust_shutdown_time_by`` call pushed, in order."""
|
|
return [c.args[0] for c in mixin._adjust_shutdown_time_by.call_args_list]
|