diff options
| author | Adam Malczewski <[email protected]> | 2026-06-01 11:34:40 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-01 11:34:40 +0900 |
| commit | 1210d6257a60ab859425557274b58d8c9ec3f2fa (patch) | |
| tree | 25042e334a8d705ff308e9094dbf9556165932b5 /packaging/[email protected] | |
| parent | 64d2a8118535234212dd4b8dbb8b226fd5575607 (diff) | |
| download | dispatch-1210d6257a60ab859425557274b58d8c9ec3f2fa.tar.gz dispatch-1210d6257a60ab859425557274b58d8c9ec3f2fa.zip | |
fix(api): wake-schedule toggle requires explicit action: 'on' | 'off'
Round-2 Gemini review surfaced that the toggle endpoint derived add-vs-
remove from its own in-memory state, which combined catastrophically
with any UI desync: a user clicking to turn ON an hour the UI showed as
off, but the server had as on, would silently get the hour turned OFF.
The clicks felt 'inverted' and the only recovery was a full reload.
Fix: require an explicit `action` field on every /toggle request. The
client must declare its intent; the server is no longer allowed to guess.
Idempotency rules:
- action: 'off' on an already-off hour → 200, no-op success.
- action: 'on' on an already-on hour → 200, REPLACES timestamps (so a
recovering UI can re-assert the user's wall-clock intent without a
delete-then-add round trip).
- Missing or invalid action → 400.
The 'off' path no longer reads or requires `timestamps`. The 'on' path
still requires all four slot timestamps as finite Unix-ms numbers (the
skewed-toggle relaxation from round 1 is preserved).
Tests:
- toggle() helper auto-derives action from `timestamps` presence, so
the existing 12 tests stayed terse. One test that relied on the old
'empty body = add' behavior now passes `action: 'on'` explicitly.
- Added 4 new contract tests:
* rejects requests missing/with-invalid action
* action='off' on an already-off hour is idempotent
* action='on' on an already-on hour replaces timestamps (the
round-2 desync-recovery scenario)
* action='off' ignores stray timestamps payloads
29 / 29 routes tests pass; 431 / 431 across the workspace.
Diffstat (limited to 'packaging/[email protected]')
0 files changed, 0 insertions, 0 deletions
