From 877c995b472a6c67f6e1ce70023cf76dd2e11c65 Mon Sep 17 00:00:00 2001 From: timmy Date: Sun, 23 Aug 2026 19:26:02 +0000 Subject: [PATCH] fix: preserve active break during session adoption (Closes #1315) --- frontend/today-timer.js | 2 +- tests/test_today_break.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/frontend/today-timer.js b/frontend/today-timer.js index 47b734d..d1200c3 100644 --- a/frontend/today-timer.js +++ b/frontend/today-timer.js @@ -126,7 +126,7 @@ function createTodayTimer({ storage, getLogin, now = () => Date.now(), onChange state.attention_interruption = null; state.search_interruption = null; state.detour_interruption = null; - state.timed_break = null; + if(running || validBreak(state)?.identity !== identity) state.timed_break=null; return write(state); }, activate(identity) { diff --git a/tests/test_today_break.py b/tests/test_today_break.py index f705b1a..e53bb83 100644 --- a/tests/test_today_break.py +++ b/tests/test_today_break.py @@ -93,6 +93,35 @@ process.stdout.write(JSON.stringify({reopened,snapshot:timer.snapshot(),pending: } +def test_adopting_paused_state_for_same_item_preserves_valid_local_break(): + script = TIMER.read_text() + r""" +const values = new Map(); +const storage = {getItem:key=>values.get(key)||null,setItem:(key,value)=>values.set(key,value)}; +const timer = createTodayTimer({storage,getLogin:()=> 'timmy',now:()=>100000}); +timer.activate('issue:r:42:'); +timer.startBreak(5); +const adopted = timer.adopt('issue:r:42:', 12000, false, [ + {identity:'issue:r:42:',elapsed_ms:12000}, +]); +process.stdout.write(JSON.stringify({adopted,snapshot:timer.snapshot(),pending:timer.breakSnapshot()})); +""" + + assert run_node(script) == { + "adopted": True, + "snapshot": { + "identity": "issue:r:42:", + "elapsed_ms": 12000, + "running": False, + "break_deadline_at": 400_000, + }, + "pending": { + "identity": "issue:r:42:", + "deadline_at": 400_000, + "expired": False, + }, + } + + def test_break_expiry_never_restarts_time_and_resume_is_explicit_and_idempotent(): script = TIMER.read_text() + r""" const values = new Map();