mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 18:33:57 +01:00
manual:2026-09-13T14:30 -- the synced copy of the football that this
morning's day-key rekey let back in under a second id -- made every
workout-sync tick log "Manual-workout budget exhausted -- not ingested".
Tombstoning it once did not stick: sync_log pulls only the OTHER devices'
logs and _manual_push re-derives the PC's log from log.json each tick, so
the next push overwrote the tombstone ("tombstoned", then "LIVE" five
seconds later). Deletion is monotonic only for records still in the merge.
- New _sync_tombstones: {id: {deleted_hlc, reason, tombstoned_at}} in
screen_locker/sync_tombstones.json (gitignored with its siblings). The
HLC is minted once and stored so re-pushing does not churn the store.
The ledger path is resolved at call time, not as a default argument, so
the test suite's redirect actually applies -- verified by hashing the
real ledger before and after the run.
- _manual_push.records_from_workout_log merges the ledger over the live
derivation, so every push carries the tombstones.
- scripts/tombstone_sync_record.py <id> [--apply --reason ...]: dry run
reports live/tombstoned; --apply writes the ledger, runs one tick and
reports what the store holds afterwards. Rerunnable.
- tests/_isolated_state.py redirects SYNC_TOMBSTONES_FILE (both bindings).
Verified: --apply -> "tombstoned"; a second ordinary tick -> "already
tombstoned" with the same HLC; workout-sync.service now logs "Sync record
manual:2026-09-13T14:30 is tombstoned -- skipping it" and the budget line
for that id is gone. log.json untouched (the local entry stays; it shares
the original's credit per duplicate_credits.json).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C7vgacLhb4WJjxuVj2QLEP
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
"""On-disk state paths every test must redirect away from the real files.
|
|
|
|
Split out of ``conftest.py`` (250-line cap) -- the *fixture* itself has to
|
|
stay in ``conftest.py`` (pytest only applies autouse fixtures declared
|
|
there), but this static table has no such constraint.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
# Each on-disk state path, and every module that bound it by value at import
|
|
# time. All of them need patching, not just the _constants source -- a missed
|
|
# binding lets a test write to the real file.
|
|
ISOLATED_STATE: tuple[tuple[str, tuple[str, ...]], ...] = (
|
|
(
|
|
"sick_history.json",
|
|
("_sick_tracker.SICK_HISTORY_FILE", "_constants.SICK_HISTORY_FILE"),
|
|
),
|
|
(
|
|
"early_bird_pending.json",
|
|
(
|
|
"_early_bird.EARLY_BIRD_PENDING_FILE",
|
|
"_constants.EARLY_BIRD_PENDING_FILE",
|
|
),
|
|
),
|
|
(
|
|
"extra_benefits_state.json",
|
|
(
|
|
"_constants.EXTRA_BENEFITS_FILE",
|
|
"_startup_checks.EXTRA_BENEFITS_FILE",
|
|
"_sync_mixin.EXTRA_BENEFITS_FILE",
|
|
"_early_bird.EXTRA_BENEFITS_FILE",
|
|
"_status.EXTRA_BENEFITS_FILE",
|
|
),
|
|
),
|
|
# Pushed to the shared sync store on every tick; a test that wrote here
|
|
# would tombstone a real workout on the phone.
|
|
(
|
|
"sync_tombstones.json",
|
|
(
|
|
"_constants.SYNC_TOMBSTONES_FILE",
|
|
"_sync_tombstones.SYNC_TOMBSTONES_FILE",
|
|
),
|
|
),
|
|
(
|
|
"sick_day_state.json",
|
|
(
|
|
"_constants.SICK_DAY_STATE_FILE",
|
|
"_startup_checks.SICK_DAY_STATE_FILE",
|
|
"_shutdown_sick_state.SICK_DAY_STATE_FILE",
|
|
),
|
|
),
|
|
# The durable lock-decision trail. Written on EVERY locker run, so without
|
|
# this the suite would append test decisions to the user's real
|
|
# enforcement history in ~/.local/share/screen_locker/.
|
|
# BOTH bindings: _decision_trail owns the writer and reads its own
|
|
# module global, so patching only _decision_log would silently let
|
|
# the suite write into the real enforcement history.
|
|
(
|
|
"decisions.jsonl",
|
|
(
|
|
"_decision_log.DECISION_LOG_FILE",
|
|
"_decision_trail.DECISION_LOG_FILE",
|
|
),
|
|
),
|
|
# Written whenever a locker run waits in gatelock's queue.
|
|
(
|
|
"queue_state.json",
|
|
("_constants.QUEUE_STATE_FILE", "_queue_state.QUEUE_STATE_FILE"),
|
|
),
|
|
# Real $XDG_RUNTIME_DIR/gatelock file; unisolated, only the first test in
|
|
# the whole suite would win it, since it is shared across all of them.
|
|
(
|
|
"instance.lock",
|
|
("_constants.INSTANCE_LOCK_FILE", "screen_lock.INSTANCE_LOCK_FILE"),
|
|
),
|
|
)
|