fix(persistence): derive SCHEMA_VERSION from migrations; unbreak the red suite (#140)

* fix(persistence): derive SCHEMA_VERSION from the migrations directory

db.py hardcoded SCHEMA_VERSION = 26 while migrations/ had already reached
v29 (v27 dispatcher floor-drop counter, v28 mesh_observations, v29 IPAWS).
The migration runner globs the directory and applies every vN.sql it finds
regardless of the constant, so a fresh DB actually landed at 29 while the
constant claimed 26 -- a three-version drift that three tests were
correctly catching.

Derive it from the highest vN.sql present instead of bumping the literal,
so it cannot drift again the next time someone adds a migration. Falls back
to 0 if the directory is missing so import never fails; the migrations dir
sits alongside db.py and ships with the package (Dockerfile COPYs meshai/).

Adds a regression guard asserting the constant matches the highest
migration file, and updates three tests that hardcoded 26 as a literal.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(tle): make TLE fixtures time-relative so they cannot expire

The ISS fixtures hardcoded epochs of 2026-06-30/07-01/07-02. tle_handler
sets STALE_DAYS = 14 and get_tle_by_norad() filters on epoch >= now - 14d,
so the fixtures silently aged out on 2026-07-02 and the tests began
failing -- a time bomb, not a regression.

Compute epochs relative to wall-clock now (base = now - 2d, +/-1d for
newer/older) with correct TLE epoch-field encoding and mod-10 checksum.
STALE_DAYS is untouched -- widening it in product code would have changed
production behavior to paper over a test bug.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(fire-tracker): pin config + history db to tmp_path

load_config() defaults HistoryConfig.database to the relative path
"conversations.db", resolved against the process CWD, so every test calling
load_config() with no override shares one file for the whole session. The
conftest DB-isolation fixture only covers MESHAI_DB_PATH, not this.

Point both the config dir and the history database at the test's tmp_path.

NOTE: this does NOT resolve the order-dependent failure -- the test still
passes standalone and fails in a full run, so the polluting state lives
somewhere other than config/history. Left failing rather than weakened;
root cause still unidentified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
malice 2026-07-17 13:03:40 -06:00 committed by GitHub
commit 16f01b29d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 125 additions and 33 deletions

View file

@ -90,6 +90,23 @@ def test_schema_version_recorded(tmp_db):
assert int(row["value"]) == SCHEMA_VERSION
def test_schema_version_matches_highest_migration_file():
"""SCHEMA_VERSION is derived from migrations/ at import time (see
db._derive_schema_version); this test independently re-derives the
expected value straight off the filenames so a future regression
(e.g. someone re-hardcoding the constant) is caught even if the
derivation logic itself is what breaks."""
import re
versions = []
for p in persistence_db.MIGRATIONS_DIR.iterdir():
m = re.match(r"^v(\d+)", p.stem)
if p.suffix.lower() == ".sql" and m:
versions.append(int(m.group(1)))
assert versions, "no vN.sql migration files found"
assert SCHEMA_VERSION == max(versions)
def test_migration_idempotent_rerun(tmp_db):
init_db()
# Force a "second startup" by closing the connection and clearing the