Stage A of review fixes: single read snapshot, redacted /health, batched diff

/addresses reads the cursor and data in one session and one snapshot,
/health exposes only time and backup file name of the last restore,
get_changes checks presence in batches instead of per value (6.8 s -> 88 ms
on a 12k-entry journal). Adds the plan for review fixes 5-10.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5 committed 2026-09-21 10:06:31 +03:00
1 parent 0155fd3f38
commit d6b69d0842
6 files changed
+103 -33

No files matched your search

+11
View File
@@ -83,6 +83,17 @@ def test_change_journal(files):
assert db.get_changes(conn, {"asn"}, cursor=c3 + 1) is None
assert db.get_changes(conn, {"asn"}, cursor=c3) == (set(), set(), c3)
# Пакет больше порции проверки наличия (PRESENCE_BATCH): результат полный и точный
head = db.journal_head(conn)
bulk = {f"10.{i // 250}.{i % 250}.0/24" for i in range(2 * db.PRESENCE_BATCH + 200)}
with db.transaction(conn):
db.merge_source(conn, "asn", "3", bulk, now, 90)
assert db.get_changes(conn, {"asn"}, cursor=head)[:2] == (bulk, set())
head = db.journal_head(conn)
with db.transaction(conn):
db.purge_source(conn, "asn", "3")
assert db.get_changes(conn, {"asn"}, cursor=head)[:2] == (set(), bulk)
def test_backup_rotation_and_integrity(files):
now = datetime.datetime.now()
+13
View File
@@ -132,3 +132,16 @@ def test_recreated_database_is_withheld(env):
db.settle_recreated(conn)
assert env.get("/addresses").json() == ["1.0.0.0/24"]
assert env.get("/health").json()["db_recreated"] is None
def test_health_hides_internal_paths(env):
save_json_atomic(cc.RESTORE_FILE, {"at": "2026-09-21T10:00:00", "backup": "/data/backups/ripe-20260921T100000Z.db",
"quarantine": "/data/ripe.db.corrupt-1", "error": "file is not a database"})
# Наружу - время и имя файла копии, без каталогов, карантина и текста ошибки
assert env.get("/health").json()["last_restore"] == {"at": "2026-09-21T10:00:00",
"backup": "ripe-20260921T100000Z.db"}
assert json_dump_has_no_paths(env.get("/health").text)
def json_dump_has_no_paths(text):
return "/data" not in text and "corrupt" not in text and "not a database" not in text