Skip to content

Share poll-delay logic between search and preview, and test it offline - #35

Merged
jm-mailosaur merged 4 commits into
mainfrom
claude/poll-delay-spec-python
Dec 4, 2026
Merged

jm-mailosaur merged 4 commits into
mainfrom
claude/poll-delay-spec-python

Conversation

@jm-mailosaur

@jm-mailosaur jm-mailosaur commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

messages.search and files.get_preview each parse the x-ms-delay header themselves, and a value that isn't a whole number makes int() raise ValueError. Neither polling loop has tests that run without the live API.

Changes

  1. Add a private _poll_delay(header, poll_count) in mailosaur/operations/_polling.py, used by both loops: no header, an empty entry or anything but ASCII digits waits 1000 ms; poll n uses entry n, and the last entry repeats.
  2. Treat a delay above a signed 64-bit integer as 1000 ms, because Python ints are unbounded and a huge value would overflow the timeout check.
  3. Add tests/polling_test.py with the 9 tests (5 search, 4 preview) of the shared poll-delay spec, using a fake session and a fake clock, so they run offline without secrets. CI's pytest picks them up too.
  4. The fake session fails the test after 20 requests, so a loop that never stops fails instead of hanging.
  5. No change to the public API, error types or messages, and no new dependency.

Search and preview polling now read x-ms-delay through one private
_poll_delay function. Entries are trimmed, and an empty entry or one that
isn't a whole number counts as 1000 ms instead of raising ValueError.

tests/polling_test.py covers both loops with a fake session and a fake
clock, so it runs in milliseconds with no network or API key.
Treat a delay past a signed 64-bit integer as 1000 ms, and cap the fake
session at 20 requests so a loop that never stops fails instead of
hanging. Add tests for millisecond elapsed time and for reading the delay
from the latest response, and cover signed values in the not-a-number
test.
The search helper always passed error_on_timeout, so the timeout error test
never ran with the client's own default. Pass it only when a test sets it.
Parsing is shared, so preview keeps only the tests of its own loop. The
sub-second and over-one-second cases are covered by the latest-response
tests, and the timeout tests now also check that elapsed time is measured
in milliseconds.
@jm-mailosaur
jm-mailosaur merged commit 09174dd into main Dec 4, 2026
5 checks passed
@jm-mailosaur
jm-mailosaur deleted the claude/poll-delay-spec-python branch December 4, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants