Repository navigation
fix(import): unify import logic & change prioritization of MIME/extension - #22842
Conversation
* launches CSV importer for text * enqueues a message for *pkg Assisted-by: GPT-6 Assisted-by: GPT-6-Astra xhigh
apkg/csv now take the same route: `TEXT_IMPORT` => `FILE_IMPORT` This is prep for better import handling, we have been misidentifying `apkg` files as text based on a faulty MIME type, having a single place to accept a file, and determine its actual contents will resolve this. A `prepareImport` => `openImport` call chain is used for handling. Also allows us to move it to a background thread in a later commit. Prep for 21430 Assisted-by: GPT-6 Assisted-by: GPT-6-Astra xhigh
Rather then a separate CSV import. Assisted-by: GPT-6 Assisted-by: GPT-6-Astra xhigh
mikehardy
left a comment
There was a problem hiding this comment.
Assisted-by: composer-2.5
Thanks for the import unification work — the routing tests are a solid addition.
This act is from required CI only (no local prep on this tip). Head d6c00872.
The diff consolidates import handling in DeckPicker, IntentHandler, Import/ImportUtils, adds compat MIME helpers, and expands unit coverage (ImportRoutingTest, ImportUiThreadTest, and related deck-picker import tests).
Requesting changes: JUnit Tests (windows run 1) failed with four failures in ImportRoutingTest while ubuntu and macos unit jobs passed (run 40727503376):
package selected in the text picker keeps its confirmation on the current deck picker—BackendDbException/ SQLiteCannotOpen("unable to open database file") fromexportPackage(ImportRoutingTest.kt~196/479).specific collection MIME keeps replacement confirmation with a text or missing filename— same SQLite cannot-open duringexportPackage(~145).package picker ignores incorrect provider MIME—FileNotFoundExceptionfor Robolectric cachedeck.apkg(~208/220).dropped package retains its payload until preparation completes— missing cachedeck.apkg(~248/271).
Please address the Windows-only test/setup failures (likely temp cache path or export helper behavior under Robolectric on Windows) and get all three unit matrix legs green.
Assisted-by: GPT-6 Assisted-by: GPT-6-Astra xhigh Assisted-by: GPT-6.1-Sol xhigh
Assisted-by: GPT-6 Assisted-by: GPT-6-Astra xhigh
We have cases where `apkg` is `text/plain`, which was previously
imported as a failed CSV ('stream did not contain valid UTF-8').
Now, we check to see if a file has an apkg extension before falling
back to UTF-8
Fixes 21430
Assisted-by: GPT-6
Assisted-by: GPT-6-Astra xhigh
Assisted-by: GPT-6.1-Sol xhigh
A [a/col]pkg MIME type is a signal, whereas `text/plain` is more ambiguous. So treat *pkg MIME types as a stronger signal than filenames/MIME hints. Filenames are still used for deck vs collection detection. Part of 21430 Assisted-by: GPT-6-Astra xhigh
d6c0087 to
d0ed7c4
Compare
mikehardy
left a comment
There was a problem hiding this comment.
Assisted-by: grok-4.7
Thank you — the routing tests that import through the backend make the MIME priority fix credible for #21430.
Rebased seven commits onto main locally (clean replay; no push).
Ran lint (lintAll, ktlintCheck, lint-rules:test), unit (jacocoUnitTestReport), and emulator tests (TEST_RELEASE_BUILD=true on emulator-5556 / API35_GAPI); all passed.
ImportUtils.FileImporter.resolveImportInternal now orders collection filename, deck filename, specific package MIME (intent over provider), then text CSV/TSV/plain. DeckPicker and IntentHandler share onSelectedFileToImport / prepareImport on a background dispatcher with main-thread UI; package vs text still opens the right importer. Drag-and-drop drops the snackbar preflight and uses the same error dialog; API 31+ drop permissions follow the ContentInfo job via :compat. ImportRoutingTest serves a real package as text/plain and confirms backend import — the path that previously sent .apkg to the CSV reader.
some acceptable findings, no action required, just leaving for posterity: :compat adds a coroutines Job for the reachability fence; several refactor: commits also change behavior (removed TEXT_IMPORT, drag errors use the import dialog).
Note
Assisted-by: GPT-6-Astra xhigh
Purpose / Description
We had an issue where a file with
.apkgsent atext/plainintent, and was imported using the text file code.Fixes
Approach
Firstly: this unified all file import logic: files initially come in as
FILE_IMPORT, rather than TEXT/FILE_IMPORT.Secondly, if a file has a MIME
text/plainand an*pkgextension, prefer the*pkgextension, treating*pkgas an explicit intention.Finally, if a file has an
apkg/colpkgMIME, treat that as an explicit intent that we should try the package importer.There are a few import optimizations (background thread loading; ensuring we send the
Messageon a UI thread)How Has This Been Tested?
Extensively unit tested
Checklist