diet-guard/diet_guard
Krzysztof kuhy Rudnicki af461d3157 Split _state.py and _tk_fakes.py; make the food-log redirect fail closed
Eighth batch of the 250-line sweep (over-cap count 28 -> 25).

  _state.py       366 -> 197  (+ _state_today.py, _state_sync.py)
  test_state.py   400 -> 221  (+ test_state_today.py, test_state_sync.py)
  _tk_fakes.py    368 -> 167  (+ _tk_fakes_containers.py, _tk_fakes_canvas.py)

_state.py is the file conftest patches FOOD_LOG_FILE on, so the split is
constrained rather than free: `FOOD_LOG_FILE` and the two functions that open
it stay put, and the derived read model (_state_today) and the sync/undo
helpers (_state_sync) reach the file only through _state's private
_read_raw_log/_write_log. Callers were rewired to import from the new modules
directly rather than via a circular re-export.

That constraint is now enforced instead of merely documented. Moving a reader
of FOOD_LOG_FILE into a sibling would leave conftest's patch pointing at a
name nothing reads: check_patch_targets.py still exits 0 (the path resolves)
and the runtime is unchanged (a file write, not a network call), so the suite
would go green while writing to the real ~/.local/share/diet_guard and the
next sync tick would publish it. test_state_redirect.py asserts both halves --
only _constants and _state may name the constant, and the redirect
demonstrably moves a real write off the live path. Verified it fails closed by
adding a FOOD_LOG_FILE reader to _state_today: it named that module exactly.

_tk_fakes.py keeps _FAKE_TK/_FAKE_TTK and gains an explicit __all__, since the
re-exports are load-bearing and ruff would otherwise strip them as unused. The
identity canary from the previous commit covers the split: breaking one entry
in the assembly (Canvas=object) fails 8 gate tests loudly rather than silently
building real widgets.

Verified: 706 Python tests / 100% branch coverage, check_patch_targets 0,
pre-commit clean, ~/.local/share/diet_guard byte-identical.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RA9ynjqXPnexRQnR5oAuCC
2026-08-15 20:21:26 +02:00
..
sync_merge Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
tests Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
__init__.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
__main__.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_averages.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_budget_history.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_budget.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_calendar_view.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_cli_args.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_cli_averages.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_cli_gate.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_cli_init.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_cli_log.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_cli_sync.py Make the phone publish on every tick, and fail closed on Firebase errors 2026-08-10 14:35:37 +02:00
_cli.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_coerce.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_constants.py Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
_daystatus.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_device.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_estimator.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_foodbank_manual.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_foodbank.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_fuzzy.py feat(diet_guard): add meal-logging screen-lock gate with trigger fix 2026-06-10 22:32:39 +02:00
_gate.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_gatelock_budgetedit.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_calendar_types.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_calendar_ui.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_calendar_widgets.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_calendar.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_core.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_dashboard.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_gatelock_fields.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_groups.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_layout.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_lockfile.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_mealflow.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_nutrition.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_gatelock_spacing.py Migrate diet_guard to gatelock v0.2.0 per-output locking 2026-07-25 16:56:13 +02:00
_gatelock_support.py feat: split oversized modules for 500-line limit, fix kasa coverage gap 2026-06-14 07:19:37 +02:00
_gatelock_typography.py Make the meal gate usable without a pointer on a 1366x768 screen 2026-07-30 16:21:27 +02:00
_gatelock_ui_types.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_ui.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock_widgetgroups.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_gatelock.py Split the six Python gate files; guard the fake-tk patch set 2026-08-15 20:08:03 +02:00
_mcp_read.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_mcp_server.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_mcp.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_portions.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_resolve.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_slots.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_state_sync.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_state_today.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_state.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_sync_banks.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync_client.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync_errors.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync_events.py Make PC sync event-driven; retire the 15-min timer 2026-08-15 19:21:30 +02:00
_sync_paths.py Split _sync.py and its tests; extract the gate fixtures from conftest 2026-08-15 18:51:18 +02:00
_sync.py Split _state.py and _tk_fakes.py; make the food-log redirect fail closed 2026-08-15 20:21:26 +02:00
_test_guard.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00