Files
FabledGrimoire/tests/test_integration_db_maintenance.py
bvandeusenandClaude Opus 5.5 0f5ef0be63
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 56s
CI & Build / integration (push) Successful in 1m4s
CI & Build / Python tests (push) Successful in 1m55s
CI & Build / Build & push image (push) Successful in 44s
rename(547): the server is grimoire — package, image, DB defaults, backups
Step 2 of the Scribe -> Grimoire rename.

- src/scribe -> src/grimoire, and every import, patch target, module path,
  hypercorn entry point and `python -m grimoire.restore` with it; pyproject,
  uv.lock and the frontend package are named grimoire.
- Image git.fabledsword.com/bvandeusen/fabledgrimoire; CI's Postgres service
  runs as grimoire / grimoire_test.
- Compose files default the DB user, database and (prod) volume to grimoire,
  each overridable from .env, so an install created as Scribe keeps its data
  by setting POSTGRES_USER, POSTGRES_DB and PGDATA_VOLUME.
- Backups are written as grimoire-<ts>.tar with format grimoire-backup-tar.
  Archives named scribe-* with the scribe-backup-tar manifest still restore
  and are still counted at the destination (folder and S3), with tests.
- Exports, the MCP auth realm, the ASGI scope key and the persistent logger
  carry the new name.

Kept on purpose: the secret-sealing key label stays "scribe.secrets.v1",
because every stored secret was derived under it.

Plugin identity (plugin name, hooks, env vars, .scribe marker, skills) is
step 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:50:45 -04:00

42 lines
1.6 KiB
Python

"""Real-Postgres integration tests for DB maintenance + health.
These run only in the CI integration lane (a real Postgres service + schema
built by `alembic upgrade head`). They exercise the actual async SQLAlchemy
connection path that unit mocks cannot: the un-awaited
`AsyncConnection.execution_options` regression (which made every VACUUM raise
AttributeError, reporting 0/6) passes the unit suite but fails here.
"""
import pytest
from grimoire.services.db_maintenance import (
MAINTENANCE_TABLES,
get_table_health,
run_maintenance,
)
pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine")]
@pytest.mark.asyncio
async def test_run_maintenance_vacuums_real_tables():
summary = await run_maintenance()
assert summary["tables"], "no tables were vacuumed"
# Every allowlisted table exists after `alembic upgrade head`, so every
# VACUUM (ANALYZE) must succeed. With the un-awaited execution_options bug
# they would ALL fail with AttributeError — this is the guard.
failed = [t for t in summary["tables"] if not t["ok"]]
assert not failed, f"VACUUM failed for: {failed}"
assert {t["table"] for t in summary["tables"]} <= set(MAINTENANCE_TABLES)
@pytest.mark.asyncio
async def test_table_health_reports_real_stats():
health = await get_table_health()
assert health["db_bytes"] > 0
names = {t["table"] for t in health["tables"]}
# Core table built by migrations must show up in pg_stat_user_tables.
assert "notes" in names
for t in health["tables"]:
assert t["dead_pct"] >= 0
assert t["total_bytes"] >= 0