test(m2): backupSmoke — round-trip a real Android export through :core:backup, + import-timestamp fix

Phase 1 M2 verification probe, driven by a real phone export (27 notes,
1 attachment, 14 orphan tags; the file is user data and stays out of the
repo):

- :core:data-jvm:backupSmoke --args="<export.incido.json> [libDir]" —
  preview, import into a fresh JVM library, re-export + field-by-field
  compare, encrypted envelope export (wrong passphrase rejected),
  encrypted import into a 2nd library with attachment-byte equality.

The probe caught a PRE-EXISTING Android bug the phone also has: upsert /
saveNoteWithHashtags stamped createdAt+updatedAt to now on every insert,
so backup import rewrote every note's history — and would defeat the
(createdAt, updatedAt, sha256(content)) dedupe key M2 task 3 depends on.
Justified behavior change (invariant 1: not silent): non-zero caller
timestamps are now honoured, 0 still means now. The Android editor
passes its own stamps (verified at both Note(...) sites), so only the
import path changes. addAttachment gains createdAt: Long = 0L;
importSnapshot passes the phone value through.

Verification passed: :core:data-jvm:backupSmoke (RESULT: M2 round-trip
PASS on the real export) + assembleDebug + :core:data-jvm:smoke (after a
forced codegen regen: "ID model file unchanged") + :desktopApp:run
--self-test + :spike:data-jvm:run — all green; output recorded in
DESKTOP_FEASIBILITY.md.

Known pre-existing gap left open (documented): importSnapshot never
recreates orphaned hashtag rows.
This commit is contained in:
Incido Developer committed 2026-10-05 19:03:31 +13:00
1 parent 7cc4eda90d
commit 8facbe718b
6 files changed
+278 -3

No files matched your search

@@ -250,6 +250,7 @@ class NoteRepositoryImpl(
bytes: ByteArray,
mimeType: String,
displayName: String,
createdAt: Long,
): Long {
// v0.3.1.2 — honour the EXIF Orientation tag on inbound images
// (camera intent usually writes landscape pixels + an EXIF
@@ -265,7 +266,9 @@ class NoteRepositoryImpl(
noteId = noteId,
mimeType = mimeType,
displayName = displayName,
createdAt = System.currentTimeMillis(),
// IMPORT FIX (Phase 1, M2): backup import supplies the phone's
// original timestamp; 0 keeps the old "now" behaviour.
createdAt = createdAt.takeIf { it != 0L } ?: System.currentTimeMillis(),
sizeBytes = storedBytes.size.toLong(),
bytes = storedBytes,
)
@@ -443,7 +446,15 @@ class NoteRepositoryImpl(
override suspend fun upsert(note: Note): Note {
val now = System.currentTimeMillis()
val toPersist = if (note.id == 0L) {
note.copy(createdAt = now, updatedAt = now).toEntity()
// IMPORT FIX (Phase 1, M2): a caller that supplies a real
// createdAt/updatedAt (backup import must — they are the dedupe
// key and the user's own history) is honoured; 0 still means
// "now". The Android editor already stamps both fields itself,
// so this only changes the import path.
note.copy(
createdAt = note.createdAt.takeIf { it != 0L } ?: now,
updatedAt = note.updatedAt.takeIf { it != 0L } ?: now,
).toEntity()
} else {
note.copy(updatedAt = now).toEntity()
}
@@ -546,7 +557,12 @@ class NoteRepositoryImpl(
): Note {
val now = System.currentTimeMillis()
val toPersist = if (note.id == 0L) {
note.copy(createdAt = now, updatedAt = now).toEntity()
// IMPORT FIX (Phase 1, M2): honour caller-supplied timestamps
// (backup import) — see the matching change in upsert().
note.copy(
createdAt = note.createdAt.takeIf { it != 0L } ?: now,
updatedAt = note.updatedAt.takeIf { it != 0L } ?: now,
).toEntity()
} else {
note.copy(updatedAt = now).toEntity()
}