Skip to content

refactor(client): route cancel_timer/fetch_unprocessed through the client seam#141

Merged
lesnik512 merged 1 commit into
mainfrom
refactor/table-ops-behind-client-seam
Jul 17, 2026
Merged

refactor(client): route cancel_timer/fetch_unprocessed through the client seam#141
lesnik512 merged 1 commit into
mainfrom
refactor/table-ops-behind-client-seam

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Moves cancel_timer and fetch_unprocessed off the broker's inline SQL and onto the AbstractOutboxClient seam, so the client is the single owner of outbox-table SQL. The broker methods become thin delegations.

From the architecture-deepening review (candidate #3). Previously table/column knowledge was split three ways — producer (insert+NOTIFY), client (lease/DLQ), and broker-inline (delete(t) / select(*t.c) on self._outbox_table). Now it lives behind one seam.

Changes

  • client.py — two new methods on AbstractOutboxClient + OutboxClient impls (SQL + both input guards moved verbatim). fetch_unprocessed co-locates with _row_to_message.
  • Guards in the client adapters (design decision) — the broker delegation is a pure passthrough, matching how publish validates. Real client raises TypeError/ValueError; fake ignores session (del session) and mirrors the limit guard. A directly-constructed OutboxClient now enforces the contract itself.
  • broker.py — both methods reduced to return await self.client.<method>(...); drops the delete/select/_row_to_message imports.
  • testing.pyFakeOutboxClient gains fetch_unprocessed and an aligned cancel_timer; the _build_fake_cancel_timer/_build_fake_fetch_unprocessed builders + their two mock.patch.object lines are deleted — the test broker already swaps in the fake as broker.client, so delegation reaches it. (publish/publish_batch stay patched — they drive sync dispatch.)

Behavior change (deliberate)

The test broker's session arg goes from runtime-optional (the deleted patch defaulted it to None) to required-but-ignored, matching the client signature. This aligns runtime with what was always true at the type level (old test calls carried # ty: ignore[missing-argument]) and with the documented public signature (docs/usage/timers.md). No documented usage omitted session.

Promotion

architecture/test-broker.md + docs/usage/testing.md updated (the two methods delegate through the swapped fake client; session required). Lightweight change file added.

Verification

  • just test599 passed, Postgres 17, coverage 100.00%
  • just lint — ruff + ty clean
  • just check-planning — OK
  • mkdocs build --strict — clean

🤖 Generated with Claude Code

…ient seam

Both broker methods built delete()/select() inline on self._outbox_table,
bypassing the OutboxClient seam that already owns the table -- so table/column
knowledge was split across producer, client, and broker-inline. Move them onto
AbstractOutboxClient (real + fake) so the client is the single owner of that SQL;
the broker methods become thin delegations.

- guards live in the client adapters (matches how publish validates): the real
  client raises TypeError/ValueError, the fake ignores session and mirrors the
  limit guard; the broker delegation is a pure passthrough
- fetch_unprocessed co-locates with _row_to_message, so broker.py drops the
  delete/select/_row_to_message imports
- delete the test-broker patch machinery for both: the test broker already swaps
  in the fake as broker.client, so delegation reaches it (publish/publish_batch
  stay patched -- they drive sync dispatch)

Behavior change (deliberate): the test broker's session arg goes from
runtime-optional to required-but-ignored, aligning runtime with the always-
required type and the documented public signature. No documented usage omitted it.

Truth-home promotion in architecture/test-broker.md + docs/usage/testing.md.

Full suite green (599 passed, coverage 100%), just lint + ty + check-planning
+ mkdocs --strict clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512
lesnik512 merged commit f2e96fa into main Jul 17, 2026
7 checks passed
@lesnik512
lesnik512 deleted the refactor/table-ops-behind-client-seam branch July 17, 2026 08:00
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.

1 participant