chessbaseLinux/docs/qa/android-embedded-release-notes-functional/30-commit-failure-source.diff

33 lines
2 KiB
Diff
Raw Permalink Normal View History

--- /tmp/opencode/chesspenguin-openspec/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/AndroidReleaseNotes.kt 2026-12-04 03:44:10.969856585 +0300
+++ /tmp/opencode/qa-android-release-notes/tree/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/AndroidReleaseNotes.kt 2026-12-04 03:58:15.511138257 +0300
@@ -126,7 +126,7 @@
val active = _state.value.activePresentation ?: return
if (_state.value.presentedThisLaunch) return
val attempted = markPresented(durablePrefs, active.currentCode)
- val committed = withContext(Dispatchers.IO) { writePrefs(prefs, attempted) }
+ val committed = withContext(Dispatchers.IO) { writePrefs(prefs, attempted, failCommitForQA = true) }
durablePrefs = releaseNotesPrefsAfterCommit(durablePrefs, attempted, committed)
if (!committed) Log.w(TAG, "Could not save Android release-notes presentation")
_state.value = _state.value.copy(
@@ -160,12 +160,18 @@
return ReleaseNotesPrefs(launched, decodePendingCodes(pending), presented)
}
-private fun writePrefs(prefs: SharedPreferences, state: ReleaseNotesPrefs): Boolean = runCatching {
+private fun writePrefs(prefs: SharedPreferences, state: ReleaseNotesPrefs, failCommitForQA: Boolean = false): Boolean = runCatching {
val editor = prefs.edit()
if (state.lastLaunchedCode == null) editor.remove(LAST_LAUNCHED) else editor.putLong(LAST_LAUNCHED, state.lastLaunchedCode)
editor.putStringSet(PENDING, encodePendingCodes(state.pendingCodes).toSet())
editor.putLong(LAST_PRESENTED, state.lastPresentedCode)
- editor.commit()
+ if (failCommitForQA) {
+ // QA only: model a failed presentation commit without changing durable or in-memory prefs.
+ Log.w("AndroidReleaseNotes", "QA forced presentation commit=false; editor was not committed")
+ false
+ } else {
+ editor.commit()
+ }
}.getOrDefault(false)
private fun Long.validStoredCode() = this in 1..Int.MAX_VALUE.toLong()