feat(runtime): implement single-article consolidation runtime and modularize codebase
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Unit tests for SQLite WAL state persistence and native backup/restore."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from src.runtime.storage.sqlite_store import SQLiteStore
|
||||
|
||||
|
||||
def test_sqlite_claim_and_transitions(tmp_path: Path):
|
||||
db_file = tmp_path / "test.db"
|
||||
store = SQLiteStore(db_file)
|
||||
|
||||
fp = "e" * 64
|
||||
is_new, rec = store.claim_or_get_execution(fp, "https://example.com", "trafilatura", "1.0.0")
|
||||
assert is_new is True
|
||||
assert rec["current_status"] == "received"
|
||||
|
||||
# Transition to validated
|
||||
store.record_transition(fp, "validated", reason="Passed pre-call checks")
|
||||
updated = store.get_execution(fp)
|
||||
assert updated is not None
|
||||
assert updated["current_status"] == "validated"
|
||||
|
||||
|
||||
def test_sqlite_native_backup_and_restore(tmp_path: Path):
|
||||
db_file = tmp_path / "main.db"
|
||||
backup_file = tmp_path / "backup.db"
|
||||
|
||||
store = SQLiteStore(db_file)
|
||||
fp = "b" * 64
|
||||
store.claim_or_get_execution(fp, "https://example.com/backup", "trafilatura", "1.0.0")
|
||||
|
||||
# Native backup
|
||||
store.backup_db(backup_file)
|
||||
assert backup_file.exists()
|
||||
|
||||
# Create new store from restored db
|
||||
restore_target = tmp_path / "restored.db"
|
||||
new_store = SQLiteStore(restore_target)
|
||||
new_store.restore_db(backup_file)
|
||||
|
||||
rec = new_store.get_execution(fp)
|
||||
assert rec is not None
|
||||
assert rec["source_url"] == "https://example.com/backup"
|
||||
Reference in New Issue
Block a user