Skip to content

ci(backend): adopt safe migrate-once database reset#186

Merged
abiorh-claw merged 15 commits into
mainfrom
codex/ws-ci-001-02a-safe-reset
Jul 22, 2026
Merged

ci(backend): adopt safe migrate-once database reset#186
abiorh-claw merged 15 commits into
mainfrom
codex/ws-ci-001-02a-safe-reset

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

PR Trust Bundle

Chunk

WS-CI-001-02A — Safe Migrate-Once Database Reset

Merge intent: .agent-loop/merge-intents/WS-CI-001-02A.json

Goal

Adopt Konan's migrate-once fixture work while proving that every destructive
reset is confined to an exact runner-owned database and reviewed schema.

What Changed

  • Migrated selected backend fixtures to one migration followed by transactional
    database resets.
  • Added live database and role custody checks before any destructive action.
  • Added exact protected/resettable inventories and a canonical full-schema
    fingerprint, including generic public namespace-object membership.
  • Added rollback, signal, repeated-reset, and adversarial schema-drift tests.
  • Preserved exact assertions, existing test collection, coverage thresholds,
    workflows, runner topology, product code, and migrations.

Scope and Attribution

The implementation stays within the signed 02A allowlist. The adopted source
work is preserved in commit 58125242 with Konan as author; subsequent commits
are bounded safety and review repairs. No workflow or product behavior changed.

Acceptance Evidence

  • Fresh isolated reset suite: 27 passed.
  • Exact collection: 1,915 tests, equal to 1,888 on trusted main plus 27 new
    reset tests; no existing node was lost.
  • Rerun, exception, cancellation, and SIGTERM paths preserve Alembic and actor
    migration state and leave all seven guarded triggers enabled.
  • Unexpected table, function, type, collation, column, and trigger drift fails
    before reset and remains present after rejection.
  • 95 agent gate tests and diff integrity passed.

CI Integrity

  • No workflow, shard, lane, runner, or coverage command changed
  • No test was skipped, deselected, removed, or weakened
  • Global 78 percent and all protected 90 percent floors remain blocking
  • Full GitHub Backend workflow passes the exact PR head
  • Hosted PostgreSQL reproduces the canonical schema fingerprint

Internal Review

Reviewed code SHA: 6bfd9fe

Reviewed at: 2026-07-22T13:36:15Z

Reviewer run IDs: eng006_senior_arch_docs, eng006_qa_ci_tests, eng006_security_ops_reuse

Senior/architecture and QA/CI/test-delta passed with only hosted evidence
conditions. Security/auth, product/ops, reuse/dedup, and documentation passed
without a code blocker. All valid internal findings were repaired.

Remaining Risk and Human Review Focus

The fingerprint intentionally binds PostgreSQL catalog definitions, so the
hosted PostgreSQL run is the portability proof. Review database/role custody,
schema fingerprint completeness, rollback restoration, exact test delta, and
Konan's preserved attribution.

Local duration is not used to claim performance success. Only the complete
GitHub Backend job and all coverage gates determine acceptance.

Follow-up

Do not start WS-CI-001-02B automatically. After this PR merges and signed
memory reconciles, it remains a same-initiative successor requiring explicit
start.

Human Merge Ownership

  • I can explain what changed.
  • I can explain why it changed.
  • I know what could break.
  • I accept the remaining risks.
  • The user explicitly approved this specific PR for merge.

Summary by CodeRabbit

  • New Features
    • Added safer, isolated PostgreSQL test database resets with ownership, schema, and protected-state checks.
    • Added schema-contract test coverage and explicit database reset validation.
  • Bug Fixes
    • Improved rollback behavior when resets fail or are interrupted, helping preserve database integrity.
  • Documentation
    • Added implementation review evidence, trust-bundle documentation, and updated initiative status tracking.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a schema-fingerprinted PostgreSQL reset harness, centralized database fixtures, reset safety tests, and migration-contract markers. Backend test modules now use pre-cleaned databases, while initiative metadata and review evidence document WS-CI-001-02A acceptance conditions.

Changes

Backend CI acceleration

Layer / File(s) Summary
Implementation metadata and review evidence
.agent-loop/initiatives/..., .agent-loop/merge-intents/...
Updates WS-CI-001 status, merge metadata, internal review evidence, trust-bundle acceptance details, and hosted CI conditions.
Schema contract and reset harness
backend/pyproject.toml, backend/tests/conftest.py
Adds the postgres_schema_contract marker, custody validation, canonical schema fingerprinting, guarded transactional resets, schema rebuilds, and the clean_postgres_database fixture.
Reset safety and migration validation
backend/tests/test_database_reset.py, backend/tests/test_alembic.py
Tests unsafe targets, custody mismatches, schema drift, repeated resets, rollback and signal recovery, trigger restoration, and migration schema expectations.
Backend fixture migration
backend/tests/test_actors.py, backend/tests/test_auth.py, backend/tests/test_authorization.py, backend/tests/test_checkers.py, backend/tests/test_tasks.py, backend/tests/test_projects.py, backend/tests/test_audit.py, backend/tests/test_outbox.py, backend/tests/test_artifact_*.py, backend/tests/test_api_rate_controls.py
Replaces per-module Alembic setup and reset orchestration with centralized clean or isolated database fixtures.
Test assertion and typing updates
backend/tests/test_*.py
Refines assertions, helper signatures, concurrency task-name handling, SQLAlchemy query grouping, migration test setup, and type-checking annotations.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adopting a safe migrate-once database reset for backend CI.
Description check ✅ Passed The description covers the key required sections, including chunk, goal, changes, evidence, risks, and human ownership.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ws-ci-001-02a-safe-reset

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
backend/tests/conftest.py (1)

250-257: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused include_canonical_actors flag

_reset_test_database_state() ignores this parameter, and there are no callers passing it. Dropping it (and tightening TestDatabaseReset if needed) keeps the fixture contract aligned with behavior.

🤖 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 `@backend/tests/conftest.py` around lines 250 - 257, Remove the unused
include_canonical_actors parameter and its del statement from
_reset_test_database_state. Update the TestDatabaseReset contract or related
type definitions if they still expose this flag, while preserving the existing
database reset and after_disable behavior.
🤖 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.

Nitpick comments:
In `@backend/tests/conftest.py`:
- Around line 250-257: Remove the unused include_canonical_actors parameter and
its del statement from _reset_test_database_state. Update the TestDatabaseReset
contract or related type definitions if they still expose this flag, while
preserving the existing database reset and after_disable behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8df6b7fe-eefb-4a95-8116-4668a4c56b97

📥 Commits

Reviewing files that changed from the base of the PR and between 196e7f6 and 37ec214.

📒 Files selected for processing (19)
  • .agent-loop/initiatives/WS-CI-001-backend-ci-acceleration/STATUS.md
  • .agent-loop/initiatives/WS-CI-001-backend-ci-acceleration/reviews/WS-CI-001-02A-internal-review-evidence.md
  • .agent-loop/initiatives/WS-CI-001-backend-ci-acceleration/reviews/WS-CI-001-02A-pr-trust-bundle.md
  • .agent-loop/merge-intents/WS-CI-001-02A.json
  • backend/pyproject.toml
  • backend/tests/conftest.py
  • backend/tests/test_actors.py
  • backend/tests/test_alembic.py
  • backend/tests/test_api_rate_controls.py
  • backend/tests/test_artifact_admission.py
  • backend/tests/test_artifact_recovery.py
  • backend/tests/test_audit.py
  • backend/tests/test_auth.py
  • backend/tests/test_authorization.py
  • backend/tests/test_checkers.py
  • backend/tests/test_database_reset.py
  • backend/tests/test_outbox.py
  • backend/tests/test_projects.py
  • backend/tests/test_tasks.py

@abiorh-claw
abiorh-claw self-requested a review July 22, 2026 14:30
@abiorh-claw
abiorh-claw merged commit 9033a97 into main Jul 22, 2026
14 checks passed
github-actions Bot pushed a commit that referenced this pull request Jul 22, 2026
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.

3 participants