fix(sfm): a download never downgrades a stored event -- an existing row is returned, nothing written

THOR's watcher (and Blastware's ACH) store every event through
/db/import/idf_file and /db/import/blastware_file, with the paired report.
Storing a download of the same event afterwards overwrote that richer copy:
on Series 4 the file, .h5 and sidecar were rewritten (extensions dropped);
on Series 3 the row lost PVS, project strings and ZC frequencies and was
repointed at a second, review-less file set.

persist_download now looks up (serial, timestamp) first.  A row there is
returned as it stands -- inserted false, detail.already_stored true -- with
no store call, no insert_events and no sidecar write.  Never merge.

- DownloadedEvent gains `timestamp` (the unit's own event time) and
  `record` (Series 4's 0x0C fields); both adapters set them.
- The Series-3 `event is None` guard now runs before backfill/save, with a
  message that is true there ("nothing was stored").
- Tests build the watcher's state exactly as the import endpoints do and
  prove the row dict, the sidecar bytes and the file mtimes are unchanged.

No schema change, no migration, no codec change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-21 17:35:23 -04:00
1 parent ddb22d9624
commit ef096e3082
9 files changed
+178 -22

No files matched your search

+2 -1
View File
@@ -212,10 +212,11 @@ def test_download_stores_the_event_and_says_where(da, sdm):
assert db.get_event(out["db_event_id"])["serial"] == "UM20147"
def test_downloading_it_again_refreshes_the_same_row(da, sdm):
def test_downloading_it_again_returns_the_stored_row_rather_than_rewriting_it(da, sdm):
first = srv.device_events_download(serial="UM20147", event_id=W_ID, **EV)
again = srv.device_events_download(serial="UM20147", event_id=W_ID, **EV)
assert again["inserted"] is False and again["db_event_id"] == first["db_event_id"]
assert again["detail"]["already_stored"] is True
@pytest.mark.parametrize("event_id,status", [