Skip to content

refactor(data): consolidate bundled-asset loading behind BundledAssetReader#5921

Merged
jamesarich merged 1 commit into
mainfrom
claude/beautiful-beaver-5930ca
Jun 23, 2026
Merged

refactor(data): consolidate bundled-asset loading behind BundledAssetReader#5921
jamesarich merged 1 commit into
mainfrom
claude/beautiful-beaver-5930ca

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

Why

Every bundled JSON asset in androidApp/src/main/assets/ needed three near-identical pieces: a 1-method commonMain *JsonDataSource interface, an androidMain impl that copy-pasted the same tolerant Json {} config + assets.open(...).decodeFromStream(...), and a desktop Koin stub returning empty. With 4 assets today (device_hardware, device_links, firmware_releases, device_bootloader_ota_quirks), the Json {} config was duplicated 4× and the desktop stub 4×, and each interface existed only so desktop could stub it.

This lands the DRY cleanup before wiring the upcoming event-firmware metadata API (a 5th consumer) so that work builds on the consolidated helper instead of adding a 5th copy.

🛠️ Changes

Replaces all of it with a single seam:

  • BundledAssetReader (commonMain) — fun interface { open(name): okio.Source? }; null = asset absent. Plus a generic inline fun <reified T> decode(name, json): T? via kotlinx-serialization-json-okio.
  • AndroidBundledAssetReader (androidMain, @Single) — serves assets/, returns null if the asset is missing.
  • Desktop/non-Android — one BundledAssetReader { null }, replacing the 4 per-asset stubs.
  • The 3 repositories now inject BundledAssetReader + the existing shared tolerant Json @Single (from core:network), instead of per-asset datasources — no new Json bean.
  • Added a BootloaderOtaQuirksResponse envelope to core:model (was a private wrapper in the deleted impl).

🧹 Cleanup

Deletes 4 *JsonDataSource interfaces + 4 androidMain impls + 4 desktop stubs + 3 redundant Json copies. +115 / −294 (net −179).

Behavior

Behavior-preserving: tolerant parsing (ignoreUnknownKeys/isLenient), repositories still seed Room from the bundled asset then stale-while-revalidate, desktop/non-Android still yields empty (no asset access), and the bootloader-quirks loader still swallows errors → empty.

Notes:

  • decode() uses explicit try/finally rather than .use {} — okio's Source doesn't extend AutoCloseable in commonMain (would break the iOS target).

🧪 Testing Performed

  • DeviceLinkRepositoryImplTest migrated to a fake BundledAssetReader that serializes through the real decode() path.
  • Full baseline green: spotlessApply spotlessCheck detekt assembleDebug test allTests kmpSmokeCompile — BUILD SUCCESSFUL.

🤖 Generated with Claude Code

…Reader

Each bundled JSON asset previously needed three near-identical pieces: a
1-method commonMain interface, an androidMain impl that copy-pasted the same
tolerant Json config + assets.open().decodeFromStream(), and a desktop Koin
stub returning empty. The Json {} config was duplicated 4x and the desktop
stub 4x.

Replace all of it with a single seam:
- BundledAssetReader { open(name): okio.Source? } + a generic reified
  decode<T>() extension (kotlinx-serialization-json-okio).
- AndroidBundledAssetReader serves assets/, returns null if absent.
- Desktop/non-Android gets one BundledAssetReader { null }.
- Repositories inject BundledAssetReader + the existing shared tolerant Json
  @single (core:network), instead of per-asset datasources.

Deletes 4 interfaces + 4 androidMain impls + 4 desktop stubs (and 3 redundant
Json copies). Behavior-preserving: tolerant parse, seed-then-SWR, desktop
yields empty, bootloader quirks still swallow errors to empty.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jamesarich jamesarich marked this pull request as ready for review June 23, 2026 21:48
@jamesarich jamesarich enabled auto-merge June 23, 2026 21:48
@github-actions github-actions Bot added the refactor no functional changes label Jun 23, 2026
@jamesarich jamesarich added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit 1194c75 Jun 23, 2026
22 checks passed
@jamesarich jamesarich deleted the claude/beautiful-beaver-5930ca branch June 23, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor no functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant