feat(phase-1/m2.3): import dedupe — importing the same file twice adds nothing

Phase 1 M2 task 3 (tools/DESKTOP_PHASE_PLAN.md §4). Logic lives in
BackupBridge so both platforms get it through the one bridge:

- BackupBridge.import gains skipExisting (default true) and returns
  ImportSummary(imported, skipped). A note is skipped when the library
  already holds the key (createdAt, updatedAt, sha256(content)) — the
  triple the export preserves verbatim, trustworthy only since the M2
  import-timestamp fix. Keys are snapshotted BEFORE importing, so two
  genuinely identical notes inside one file still both import into a
  fresh library; only a second import of the same file is a no-op.
  Snapshotted keys include trashed notes. skipExisting=false restores
  the old additive behaviour (the documented override).
- Android: BackupManager.import passes the flag and returns the summary
  (signature-identical call for SettingsViewModel); its snackbar now
  reports the skip count. Screen layouts untouched — exit criterion
  "Android backup screens unchanged" holds.
- Desktop: the import confirm dialog swaps its "duplicates persist"
  warning for a working "Skip notes that are already here" checkbox
  (default ON); scripted path prints the re-import outcome.
- Format unchanged: formatVersion stays 1 (streaming/dedupe-at-format
  level stays a Phase-2 formatVersion=2 idea).

Verification passed: :core:data-jvm:backupSmoke (new step — re-import
skipped=27, override added 27, store=54; RESULT M2 round-trip PASS on
the real export) + :desktopApp:run --args="--data-dir /tmp/incido-m2t3
--backup-import <export> --backup-export … --exit-after 8" (imported=27
skipped=0 → exported=27 → reimport imported=0 skipped=27, clean exit) +
assembleDebug + :core:data-jvm:smoke + :desktopApp:run --self-test —
all green; output recorded in DESKTOP_FEASIBILITY.md.

Known limitation (by design): attachments are not in the key.
This commit is contained in:
Incido Developer committed 2026-10-05 19:33:07 +13:00
1 parent cf0e74b68d
commit 031d8570b4
7 files changed
+138 -21

No files matched your search

+32
View File
@@ -370,5 +370,37 @@ list already has an exit-time AWT/`exitProcess` quirk).
Full suite green after the change: `assembleDebug`, `:core:data-jvm:smoke`,
`backupSmoke`, `:desktopApp:run --self-test`.
**M2 task 3 — import dedupe: DONE.** `BackupBridge.import` now skips notes
whose `(createdAt, updatedAt, sha256(content))` key already exists in the
library (default ON, `skipExisting = false` overrides), and returns
`ImportSummary(imported, skipped)` instead of a bare count. The existing
keys are snapshotted BEFORE the import, so two genuinely identical notes
inside one file still import into a fresh library — only a second import
of the same file adds nothing (matches the §4 wording exactly). Keys
include trashed notes, so restoring around the trash can't duplicate.
`BackupManager.import` (Android shim) passes the flag through and returns
the summary; `SettingsViewModel`'s snackbar gained the skip count (one
line — the screen layouts are untouched). The desktop confirm dialog
replaced its "duplicates persist" warning with a working
"Skip notes that are already here" checkbox (default ON); the export
format did not change (`formatVersion` stays 1).
```
backupSmoke new step: re-import skipped=27; override added 27 (store=54) PASS
:desktopApp:run --backup-import <real export> --backup-export … --exit-after 8
BACKUP imported=27 skipped=0 → exported=27 → reimport imported=0 skipped=27
```
Known limitation (by design, per plan): attachments are not part of the
key — two notes with identical text AND timestamps but different
attachments dedupe as one. Phone side: second import now says
"Imported 0 note(s), skipped 27 already imported." — device smoke still
pending with the rest of task 4.
Full suite green: `backupSmoke` (9 steps incl. dedupe), `assembleDebug`,
`:core:data-jvm:smoke`, scripted desktop run (clean exit),
`:desktopApp:run --self-test`.