Skip to content

m12-pr16: partition rotation health invariants (tests/db/test_partition_health.py)#34

Open
BalaShankar9 wants to merge 1 commit into
m12-pr15-test-dlqfrom
m12-pr16-test-partition-health
Open

m12-pr16: partition rotation health invariants (tests/db/test_partition_health.py)#34
BalaShankar9 wants to merge 1 commit into
m12-pr15-test-dlqfrom
m12-pr16-test-partition-health

Conversation

@BalaShankar9

Copy link
Copy Markdown
Owner

m12-pr16: partition rotation health invariants (tests/db/test_partition_health.py)

Adds 15 unit tests pinning health invariants for the events_outbox
partition rotation introduced in m7-pr27a (ADR-0037). Complements the
existing tests/integration/test_outbox_partitions.py (migration regex

  • opt-in live-DB) by covering gaps that integration test does not:

Time-math (5 tests, pure helper mirroring SQL date_trunc + i months)

  • YYYY_MM zero-pad
  • current month + N (count = N+1)
  • year roll at December
  • 25-month span at max lookahead, monotonic, no dups
  • day-of-month invariance

Cross-file contract (8 tests against migration / runbook / ADR)

  • bootstrap and cron use identical months_ahead (=4)
  • p_months_ahead bounds 0..24 RAISE present
  • EXCEPTION WHEN OTHERS still inserts audit row with err_msg
  • audit columns pinned (table_name text, ran_at timestamptz, etc.)
  • cron command body is bare function call (no error-swallowing wrapper)
  • daily 00:01 UTC schedule literal
  • runbook 36h alert window contract (24h cadence + 12h grace)
  • ADR-0037 status remains Accepted
  • SAFETY header references ADR-0037

Sanity (1 test): helper count vs constant.

Why "health" vs existing rotation tests: the migration tests pin
WHAT was deployed; these pin the INVARIANTS the daily job and alert
depend on. If someone changes cron to twice-daily but forgets to
update the runbook alert window, or renames an audit column the
Prometheus query reads, that drift now fails CI.

Files

  • backend/tests/db/init.py (new, empty)
  • backend/tests/db/test_partition_health.py (new, 15 tests)
  • context/TESTING_CONTEXT.md (moved from Planned to Shipped m12-pr16)
  • context/CHANGELOG_INTELLIGENCE.md (m12-pr16 row)

Validation

  • pytest tests/db/test_partition_health.py -v -> 15 passed in 0.03s
  • No other tests touched; no production code touched.

Stacked on PR #33 (m12-pr15). Base branch: m12-pr15-test-dlq.

…on_health.py)

Adds 15 unit tests pinning health invariants for the events_outbox
partition rotation introduced in m7-pr27a (ADR-0037). Complements the
existing tests/integration/test_outbox_partitions.py (migration regex
+ opt-in live-DB) by covering gaps that integration test does not:

Time-math (5 tests, pure helper mirroring SQL date_trunc + i months)
- YYYY_MM zero-pad
- current month + N (count = N+1)
- year roll at December
- 25-month span at max lookahead, monotonic, no dups
- day-of-month invariance

Cross-file contract (8 tests against migration / runbook / ADR)
- bootstrap and cron use identical months_ahead (=4)
- p_months_ahead bounds 0..24 RAISE present
- EXCEPTION WHEN OTHERS still inserts audit row with err_msg
- audit columns pinned (table_name text, ran_at timestamptz, etc.)
- cron command body is bare function call (no error-swallowing wrapper)
- daily 00:01 UTC schedule literal
- runbook 36h alert window contract (24h cadence + 12h grace)
- ADR-0037 status remains Accepted
- SAFETY header references ADR-0037

Sanity (1 test): helper count vs constant.

Why "health" vs existing rotation tests: the migration tests pin
WHAT was deployed; these pin the INVARIANTS the daily job and alert
depend on. If someone changes cron to twice-daily but forgets to
update the runbook alert window, or renames an audit column the
Prometheus query reads, that drift now fails CI.

Files
- backend/tests/db/__init__.py (new, empty)
- backend/tests/db/test_partition_health.py (new, 15 tests)
- context/TESTING_CONTEXT.md (moved from Planned to Shipped m12-pr16)
- context/CHANGELOG_INTELLIGENCE.md (m12-pr16 row)

Validation
- pytest tests/db/test_partition_health.py -v -> 15 passed in 0.03s
- No other tests touched; no production code touched.

Stacked on PR #33 (m12-pr15). Base branch: m12-pr15-test-dlq.
Copilot AI review requested due to automatic review settings May 9, 2026 04:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “health invariants” unit test suite that statically pins the cross-file contract for events_outbox partition rotation (migration ↔ cron schedule ↔ runbook ↔ ADR), complementing the existing integration coverage.

Changes:

  • Added 15 unit tests (backend/tests/db/test_partition_health.py) that verify time-math invariants and contract invariants across the rotation migration, runbook, and ADR.
  • Added backend/tests/db/__init__.py to establish the tests/db package.
  • Updated context docs to mark this test suite as shipped and to add the m12-pr16 changelog ledger row.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
context/TESTING_CONTEXT.md Moves the partition health tests entry from “Planned” to “Shipped (m12-pr16)”.
context/CHANGELOG_INTELLIGENCE.md Adds the m12-pr16 ledger row and links m12-pr15 to PR #33.
backend/tests/db/test_partition_health.py New unit tests that pin partition rotation invariants across migration/runbook/ADR plus pure time-math helper checks.
backend/tests/db/init.py New (empty) package marker for backend/tests/db.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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