Files
FabledGrimoire/tests/test_routes_db_maintenance.py
T
bvandeusenandClaude Opus 5.5 1f5e963c35
CI & Build / Plugin hooks (push) Successful in 10s
CI & Build / Python lint (push) Successful in 1s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 1m42s
CI & Build / integration (push) Successful in 1m48s
CI & Build / Build & push image (push) Canceled after 22s
feat(6848): Settings restore rolls back, from the destination or a file, after a preview
The web restore no longer copies a backup in beside the live data.

- GET /api/admin/restore/sources lists the backups at the backup destination,
  newest first.
- POST /api/admin/restore/preview says what a restore would do, changing
  nothing: fresh or rollback, when the backup was taken, and counts now and
  after per kind. A backup that cannot apply here gets a 409 with the reason.
- POST /api/admin/restore?confirm=rollback runs backup_job.rollback_to_backup:
  safety backup, replace, then search rebuilt in the background.

Each takes ?source=<name> (a backup at the destination) or an upload. The
destination path exists because uploads are held to the request-size limit,
and a real instance's backup is far over it. backup_s3.get_file downloads
from a bucket. backup_destination.list_backups/open_backup only accept names
the scheduled backup writes, so a request cannot reach any other file.

Settings -> Data -> Restore from Backup opens RestoreBackupDialog. The dialog:
1. Pick a backup at the destination or a file.
2. Read the preview.
3. Type "roll back".
4. Run it. The dialog then says where the replaced state was saved, and sends
   the user to sign in again.

Closes #6840. Milestone 582, step 4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 20:06:07 -05:00

61 lines
2.0 KiB
Python

"""Structural tests for the DB-maintenance admin routes + scheduler surface."""
def test_admin_handlers_callable():
from grimoire.routes import admin as admin_routes
for name in (
"get_db_maintenance",
"update_db_maintenance",
"run_db_maintenance_now",
"get_db_maintenance_health",
):
assert callable(getattr(admin_routes, name))
def test_db_maintenance_routes_registered():
from grimoire.app import create_app
app = create_app()
rules = {r.rule for r in app.url_map.iter_rules()}
assert "/api/admin/db-maintenance" in rules
assert "/api/admin/db-maintenance/run" in rules
assert "/api/admin/db-maintenance/health" in rules
def test_scheduler_surface():
from grimoire.services import db_maintenance_scheduler as sched
for fn in (
"start_db_maintenance_scheduler",
"stop_db_maintenance_scheduler",
"reschedule_db_maintenance",
"get_maintenance_hour",
"is_maintenance_enabled",
):
assert callable(getattr(sched, fn)), f"scheduler missing {fn}"
def test_service_surface_and_allowlist():
from grimoire.services.db_maintenance import (
MAINTENANCE_TABLES,
get_last_run,
get_table_health,
run_maintenance,
)
assert callable(run_maintenance) and callable(get_last_run) and callable(get_table_health)
# The allowlist is a closed tuple covering exactly the high-churn tables.
assert isinstance(MAINTENANCE_TABLES, tuple)
assert set(MAINTENANCE_TABLES) == {
"app_logs", "notifications", "password_reset_tokens",
"invitation_tokens", "notes", "note_versions",
}
def test_set_admin_setting_exists():
from grimoire.services.settings import set_admin_setting
assert callable(set_admin_setting)
def test_restore_routes_registered():
from grimoire.app import create_app
rules = {r.rule for r in create_app().url_map.iter_rules()}
assert {"/api/admin/restore", "/api/admin/restore/preview", "/api/admin/restore/sources"} <= rules