Implement approval engine production readiness
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a05e2e-805b-7042-a750-71f473bceea2
This commit is contained in:
parent
ebce5abb27
commit
2bd2d19a98
30 changed files with 1679 additions and 53 deletions
55
tests/test_storage.py
Normal file
55
tests/test_storage.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from approval_engine.errors import Conflict, StoreUnavailable
|
||||
from approval_engine.store import Engine, LATEST_SCHEMA_VERSION
|
||||
from tests.conftest import FROZEN, approve
|
||||
|
||||
|
||||
def test_production_open_refuses_unmigrated_database(tmp_path):
|
||||
path = tmp_path / "approval.sqlite"
|
||||
sqlite3.connect(path).close()
|
||||
with pytest.raises(StoreUnavailable, match="run approval-engine migrate"):
|
||||
Engine(path, clock=lambda: FROZEN, auto_migrate=False)
|
||||
|
||||
|
||||
def test_migrate_then_open_without_auto_migrate(tmp_path):
|
||||
path = tmp_path / "approval.sqlite"
|
||||
migrated = Engine(path, clock=lambda: FROZEN)
|
||||
migrated.close()
|
||||
production = Engine(path, clock=lambda: FROZEN, auto_migrate=False)
|
||||
status = production.storage_status(integrity=True)
|
||||
assert status["schema_version"] == LATEST_SCHEMA_VERSION
|
||||
assert status["schema_current"] is True
|
||||
assert status["persistent"] is True
|
||||
assert status["ok"] is True
|
||||
production.close()
|
||||
|
||||
|
||||
def test_online_backup_is_mode_0600_and_restorable(tmp_path):
|
||||
source = tmp_path / "approval.sqlite"
|
||||
backup = tmp_path / "approval.backup.sqlite"
|
||||
engine = Engine(source, clock=lambda: FROZEN)
|
||||
obj = approve(engine)
|
||||
result = engine.backup(backup)
|
||||
assert result["integrity"] == "ok"
|
||||
assert os.stat(backup).st_mode & 0o777 == 0o600
|
||||
restored = Engine(backup, clock=lambda: FROZEN, auto_migrate=False)
|
||||
assert restored.get(obj.id).id == obj.id
|
||||
assert restored.storage_status(integrity=True)["ok"] is True
|
||||
restored.close()
|
||||
engine.close()
|
||||
|
||||
|
||||
def test_backup_refuses_overwrite(tmp_path):
|
||||
source = tmp_path / "approval.sqlite"
|
||||
target = tmp_path / "existing.sqlite"
|
||||
target.write_text("do not overwrite")
|
||||
engine = Engine(source, clock=lambda: FROZEN)
|
||||
with pytest.raises(Conflict, match="already exists"):
|
||||
engine.backup(target)
|
||||
assert target.read_text() == "do not overwrite"
|
||||
engine.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue