fix: reject contradictory running break sessions
This commit is contained in:
parent
c5b466f281
commit
dfd33aee1c
|
|
@ -596,6 +596,12 @@ class TodaySessionUpdate(BaseModel):
|
||||||
running: bool
|
running: bool
|
||||||
break_deadline_at: int | None = Field(default=None, ge=0, le=10_000_000_000_000)
|
break_deadline_at: int | None = Field(default=None, ge=0, le=10_000_000_000_000)
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
def validate_break_is_paused(self):
|
||||||
|
if self.running and self.break_deadline_at is not None:
|
||||||
|
raise ValueError("break must remain paused")
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class TodayRecapTimeLog(TodayRecap):
|
class TodayRecapTimeLog(TodayRecap):
|
||||||
log_identities: list[str] = Field(min_length=1, max_length=20)
|
log_identities: list[str] = Field(min_length=1, max_length=20)
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,14 @@ async def test_active_session_api_persists_a_bounded_break_deadline(monkeypatch,
|
||||||
assert (await main.get_today_session()) == saved
|
assert (await main.get_today_session()) == saved
|
||||||
|
|
||||||
|
|
||||||
|
def test_active_session_api_rejects_a_running_break():
|
||||||
|
with pytest.raises(ValueError, match="break must remain paused"):
|
||||||
|
main.TodaySessionUpdate(
|
||||||
|
base_revision=0, device_id="phone-a", identity="issue:r:1:",
|
||||||
|
elapsed_ms=5_000, running=True, break_deadline_at=1_800_000,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_active_session_api_returns_current_state_on_claim_conflict(monkeypatch, tmp_path):
|
async def test_active_session_api_returns_current_state_on_claim_conflict(monkeypatch, tmp_path):
|
||||||
async def user():
|
async def user():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user