Add API contract and idempotency-under-retry tests#250
Conversation
|
Warning Review limit reached
More reviews will be available in 49 minutes and 44 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds comprehensive contract tests and idempotency validation. It introduces recorded API response fixtures for GitHub and Slack, documents their refresh workflow, validates those fixtures parse correctly against Pydantic schemas, and verifies that service functions are idempotent under retry conditions. ChangesAPI Contract and Idempotency Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_idempotency_under_retry.py (1)
22-25: ⚡ Quick winLoad the newest matching fixture instead of the oldest.
sorted(...)[0]picks the oldest dated fixture when multiple recordings exist. This can keep tests on stale payloads and weaken contract drift coverage over time.Suggested diff
def _load_fixture(name: str) -> dict: matches = sorted(FIXTURES_DIR.glob(name)) assert matches, f"no fixture matching {name}" - return json.loads(matches[0].read_text(encoding="utf-8")) + return json.loads(matches[-1].read_text(encoding="utf-8"))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_idempotency_under_retry.py` around lines 22 - 25, The _load_fixture function currently picks the oldest matching file because it returns sorted(...)[0]; change it to select the newest matching fixture instead (e.g., choose the last element of a reverse sort or use max(..., key=lambda p: p.stat().st_mtime)) so tests use the most recent recording; update _load_fixture to load and return the newest match accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_api_contracts.py`:
- Around line 32-33: The helper _fixture_paths currently returns an empty list
silently; change it to validate the result and raise a clear error when no
fixtures are found so CI fails fast. Update _fixture_paths(prefix: str) to
collect and sort the glob results, then if the resulting list is empty raise an
AssertionError or ValueError with a message that includes the prefix (e.g., "no
fixtures found for prefix '{prefix}'") so any tests calling _fixture_paths (and
other callers) fail immediately when a fixture set is missing.
---
Nitpick comments:
In `@tests/test_idempotency_under_retry.py`:
- Around line 22-25: The _load_fixture function currently picks the oldest
matching file because it returns sorted(...)[0]; change it to select the newest
matching fixture instead (e.g., choose the last element of a reverse sort or use
max(..., key=lambda p: p.stat().st_mtime)) so tests use the most recent
recording; update _load_fixture to load and return the newest match accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d9b41b93-f732-440f-a705-672720bef123
📒 Files selected for processing (10)
tests/fixtures/api_contracts/README.mdtests/fixtures/api_contracts/github_commit_2026-05-28.jsontests/fixtures/api_contracts/github_issue_bundle_2026-05-28.jsontests/fixtures/api_contracts/github_pr_bundle_2026-05-28.jsontests/fixtures/api_contracts/slack_channel_2026-05-28.jsontests/fixtures/api_contracts/slack_message_2026-05-28.jsontests/fixtures/api_contracts/slack_team_2026-05-28.jsontests/fixtures/api_contracts/slack_user_2026-05-28.jsontests/test_api_contracts.pytests/test_idempotency_under_retry.py
Summary
Adds contract tests and idempotency-under-retry tests for GitHub and Slack ingestion boundaries (w4 issue 02 / eval B8).
tests/fixtures/api_contracts/are deserialized through the existing Pydantic boundary parsers (parse_issue_bundle,parse_pr_bundle,parse_commit,parse_team,parse_channel,parse_user,parse_message). Failures indicate API shape drift before production sync breaks.get_or_create_*service functions are called twice with identical inputs insidetransaction.atomic(), asserting no duplicate rows and the same returned object—matching Celery at-least-once delivery behavior.Changes
tests/fixtures/api_contracts/*_2026-05-28.json(7 fixtures)tests/fixtures/api_contracts/README.md(recording dates, refresh process, redaction)tests/test_api_contracts.pytests/test_idempotency_under_retry.pyIdempotency targets:
get_or_create_slack_teamget_or_create_slack_channelget_or_create_repositoryTest plan
testjob passes (uv run pytestpicks up roottests/automatically)uv run pytest tests/test_api_contracts.py tests/test_idempotency_under_retry.py -v(requires Postgres per README)Acceptance criteria (w4 #2)
get_or_create_*service functionsNotes
develop).*_2026-05-28.json); see README for refresh steps.pytest-recording/VCR added; recorded JSON only.Related issue
Summary by CodeRabbit
Tests
Documentation