Buried card remains active after a missed timebox prompt

Open
#23,393 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
android, kotlin
Domain
mobile, testing

Research direction

The issue says work is deferred for an architectural fix and links PR #23384, so first read that pull request and its review discussion. The regression scenario is captured in AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerTimeboxBackgroundTest.kt; use it to understand the missed timebox prompt after backgrounding. The issue gives no implementation entry point, and the work is explicitly deferred.

Written by the indexing model from the issue text.

Description

Blocked by dependency Needs reviewer reply

Assisted-by: GPT-6.1-Sol xhigh & GPT-6.2-Astra xhigh & GPT-6.2-Sol xhigh

Subject: Buried card remains active after a missed timebox prompt

Burying a card as the timebox expires, then backgrounding before completion, can leave that card actionable when the reviewer resumes.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerTimeboxBackgroundTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerTimeboxBackgroundTest.kt
new file mode 100644
index 0000000000..4ba8665739
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerTimeboxBackgroundTest.kt
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.ui.windows.reviewer
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.RobolectricTest
+import com.ichi2.anki.ioDispatcher
+import com.ichi2.anki.preferences.reviewer.ViewerAction
+import com.ichi2.anki.previewer.CardViewerActivity
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.advanceUntilIdle
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Robolectric
+import org.robolectric.shadows.ShadowDialog
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+@RunWith(AndroidJUnit4::class)
+class ReviewerTimeboxBackgroundTest : RobolectricTest() {
+    override fun getCollectionStorageMode() = CollectionStorageMode.IN_MEMORY_WITH_MEDIA
+
+    @Test
+    fun `backgrounding at a timebox boundary cannot leave a buried card actionable`() =
+        runTest {
+            updateDeckConfig(col.decks.selected()) { autoplay = false }
+            val firstCard = addBasicNote("first", "1").firstCard()
+            val secondCard = addBasicNote("second", "2").firstCard()
+            col.config.set("timeLim", 60)
+
+            val intent = ReviewerFragment.getIntent(targetContext)
+            Robolectric.buildActivity(CardViewerActivity::class.java, intent).use { controller ->
+                controller.setup().windowFocusChanged(true)
+                advanceUntilIdle()
+                val viewModel = (controller.get().fragment as ReviewerFragment).viewModel
+                viewModel.onPageFinished(false)
+                advanceUntilIdle()
+                assertEquals(firstCard.id, viewModel.getCardId())
+
+                collectionTime.addM(2)
+                // Keep the accepted action queued until the view's collectors have stopped.
+                ioDispatcher = StandardTestDispatcher(testScheduler)
+                viewModel.executeAction(ViewerAction.BURY_CARD)
+                controller.pause().stop()
+                advanceUntilIdle()
+                controller.start().resume()
+                advanceUntilIdle()
+                advanceRobolectricLooper()
+
+                val promptIsVisible = ShadowDialog.getLatestDialog()?.isShowing == true
+                assertTrue(
+                    promptIsVisible || viewModel.getCardId() == secondCard.id,
+                    "Returning must show the timebox prompt or the next card, not leave the buried card actionable",
+                )
+            }
+        }
+}

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23384#pullrequestreview-5947688994

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.