Skip to content

refactor(testing): name the lease-token guard; fill contract coverage#144

Merged
lesnik512 merged 1 commit into
mainfrom
refactor/name-lease-token-guard
Jul 17, 2026
Merged

refactor(testing): name the lease-token guard; fill contract coverage#144
lesnik512 merged 1 commit into
mainfrom
refactor/name-lease-token-guard

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Candidate #4 from the architecture review, scoped by research.

Research finding: the report framed the SQL-vs-Python "twins" (the fetch eligibility predicate and the lease-token guard) as "duplicated prose-in-two-languages, held in sync only by comments." On investigation, tests/test_client_contract.py already co-verifies both twins across both adapters, branch by branch (unleased/future/expired/fresh eligibility; token match/mismatch/unleased guard) — which is the "co-verify, don't share" pattern the report recommended as the fix. So the residual is small.

Changes

  • _lease_token_matches(row_token, claim_token) — the NULL=NULL guard (token is not None and row_token == token) was written inline three times. delete_with_lease and mark_pending_with_lease now share the helper; delete_batch_with_lease keeps its set-based form (O(1) lookup) with a comment naming the same rule. The helper docstring notes parity is pinned by the contract suite, not by mirror comments.
  • Contract coverage — add test_mark_pending_noop_on_unleased_row (the NULL=NULL guard on the retry path — the delete path already had its twin, mark_pending didn't) and test_fetch_empty_queues_returns_empty. Both run against the fake and real Postgres.

The lease-cutoff stays deliberately divergent (server-side make_interval vs Python timedelta — the clock-skew invariant) and is untouched. The exactly-now boundary is intentionally not added: equal timestamps can't be manufactured deterministically across both substrates, so such a test would be flaky.

Verification

  • just test603 passed (+4: two scenarios × two adapters), coverage 100.00%
  • just lint — ruff + ty clean

🤖 Generated with Claude Code

Candidate #4 from the architecture review, scoped by research: the SQL-vs-Python
"twins" (eligibility predicate + lease-token guard) are already co-verified across
both adapters by tests/test_client_contract.py -- the co-verify pattern the review
recommended already exists. So the residual is small:

- Extract _lease_token_matches(row_token, claim_token) for the NULL=NULL guard,
  triplicated inline across delete_with_lease / mark_pending (now share it) and
  delete_batch (set-based; comment names the same rule). The guard's parity with
  the real client's SQL is pinned by the contract suite, not by mirror comments.
- Contract suite: add the missing mark_pending unleased-row (NULL=NULL) scenario
  that the delete path already had, plus an empty-queues symmetry check. Both run
  against the fake and real Postgres.

The lease-cutoff stays deliberately divergent (server-side make_interval vs Python
timedelta) -- the clock-skew invariant -- and is not touched.

Behavior-preserving. Full suite green (603 passed, coverage 100%), lint + ty clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512
lesnik512 merged commit 7442058 into main Jul 17, 2026
7 checks passed
@lesnik512
lesnik512 deleted the refactor/name-lease-token-guard branch July 17, 2026 10:52
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