Skip to content

Commit 1371067

Browse files
vdusekclaude
andcommitted
test: Add unit tests for _get_remaining_time() clamping
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 770ff04 commit 1371067

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/unit/actor/test_actor_helpers.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
import warnings
5-
from datetime import timedelta
5+
from datetime import datetime, timedelta, timezone
66
from typing import TYPE_CHECKING
77

88
import pytest
@@ -321,3 +321,26 @@ async def test_get_remaining_time_warns_when_not_at_home(caplog: pytest.LogCaptu
321321
result = Actor._get_remaining_time()
322322
assert result is None
323323
assert any('inherit' in msg or 'RemainingTime' in msg for msg in caplog.messages)
324+
325+
326+
async def test_get_remaining_time_clamps_negative_to_zero() -> None:
327+
"""Test that _get_remaining_time returns timedelta(0) instead of a negative value when timeout is in the past."""
328+
async with Actor:
329+
Actor.configuration.is_at_home = True
330+
Actor.configuration.timeout_at = datetime.now(tz=timezone.utc) - timedelta(minutes=5)
331+
332+
result = Actor._get_remaining_time()
333+
assert result is not None
334+
assert result == timedelta(0)
335+
336+
337+
async def test_get_remaining_time_returns_positive_when_timeout_in_future() -> None:
338+
"""Test that _get_remaining_time returns a positive timedelta when timeout is in the future."""
339+
async with Actor:
340+
Actor.configuration.is_at_home = True
341+
Actor.configuration.timeout_at = datetime.now(tz=timezone.utc) + timedelta(minutes=5)
342+
343+
result = Actor._get_remaining_time()
344+
assert result is not None
345+
assert result > timedelta(0)
346+
assert result <= timedelta(minutes=5)

0 commit comments

Comments
 (0)