study-screen: issues when custom scheduler callback takes too long
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
Research direction
The two proposed tests are in AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt, and the scenario depends on the custom scheduler set through col.config.cardStateCustomizer and on viewModel.onStateMutationCallback. Start by running the existing reviewer tests, then add the pause/stop/resume scenario for the queued Edit command and the typed-answer scenario. Done means both new tests pass against a real fix in the reviewer view model, and the work should be split because the typed-answer case predates the PR.
Written by the indexing model from the issue text.
Description
Assisted-by: GPT-6.1-Sol xhigh & GPT-6-Astra xhigh
Patches are ordered; the second builds on the first.
Queued Edit command lost while the reviewer is stopped
Subject: Queued Edit command lost while the reviewer is stopped
An Edit command queued behind custom scheduling disappears if scheduling completes while the reviewer is stopped.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
index 88b888816c..ebcdfc6629 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
@@ -18,7 +18,10 @@ import com.ichi2.anki.R
import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.cardviewer.Gesture
import com.ichi2.anki.cardviewer.TypeAnswerWebView
+import com.ichi2.anki.common.destinations.NoteEditorDestination
+import com.ichi2.anki.common.destinations.toIntent
import com.ichi2.anki.common.preferences.sharedPrefs
+import com.ichi2.anki.common.utils.ext.cardStateCustomizer
import com.ichi2.anki.dialogs.tags.TagsDialog
import com.ichi2.anki.preferences.reviewer.ViewerAction
import com.ichi2.anki.preferences.reviewer.WhiteboardAction
@@ -72,6 +75,31 @@ class ReviewerFragmentTest : RobolectricTest() {
}
}
+ @Test
+ fun `queued edit survives backgrounding before custom scheduler completes`() =
+ runTest {
+ val cardId = addBasicNote().firstCard().id
+ col.config.cardStateCustomizer = "await new Promise(resolve => setTimeout(resolve, 5000));"
+
+ withReviewer { controller ->
+ viewModel.onShowAnswer()
+ viewModel.executeAction(ViewerAction.EDIT)
+ advanceUntilIdle()
+ assertFalse(viewModel.showingAnswer.value)
+
+ controller.pause().stop()
+ advanceUntilIdle()
+ viewModel.onStateMutationCallback()
+ advanceUntilIdle()
+ controller.start().resume()
+ advanceUntilIdle()
+ advanceRobolectricLooper()
+
+ val intent = assertNotNull(shadowOf(controller.get()).nextStartedActivity, "The accepted Edit command must not be lost")
+ assertEquals(NoteEditorDestination.EditNoteFromPreviewer(cardId).toIntent().component, intent.component)
+ }
+ }
+
@Test
fun `recreated WebView retains keyboard support`() =
runTest {
[EXISTING] Typed answer discarded when the custom scheduler finishes in the background
Subject: [EXISTING] Typed answer discarded when the custom scheduler finishes in the background
Backgrounding after submitting a typed answer but before the custom scheduler completes discards the entered text and skips its comparison.
⚠️ This issue existed before the PR and should likely be split off into a separate issue.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
index ebcdfc6629..8a30f656fe 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragmentTest.kt
@@ -14,6 +14,7 @@ import androidx.core.content.getSystemService
import androidx.fragment.app.DialogFragment
import androidx.test.ext.junit.runners.AndroidJUnit4
import anki.scheduler.CardAnswer.Rating
+import app.cash.turbine.test
import com.ichi2.anki.R
import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.cardviewer.Gesture
@@ -41,6 +42,7 @@ import com.ichi2.anki.utils.ext.DIALOG_FRAGMENT_TAG
import com.ichi2.testutils.RecordingInputMethodManager
import com.ichi2.testutils.ext.addNoSuggestNote
import com.ichi2.testutils.ext.createInputConnection
+import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceUntilIdle
import org.junit.After
@@ -100,6 +102,31 @@ class ReviewerFragmentTest : RobolectricTest() {
}
}
+ @Test
+ fun `pending typed answer survives backgrounding before custom scheduler completes`() =
+ runTest {
+ targetContext.sharedPrefs().edit { putBoolean("useInputTag", false) }
+ addBasicWithTypingNote("front", "back")
+ col.config.cardStateCustomizer = "await new Promise(resolve => setTimeout(resolve, 5000));"
+
+ withReviewer { controller ->
+ binding.typeAnswerEditText.setText("back")
+ viewModel.onShowAnswer()
+ advanceUntilIdle()
+ assertFalse(viewModel.showingAnswer.value)
+
+ controller.pause().stop()
+ advanceUntilIdle()
+
+ viewModel.eval.filter { it.startsWith("_showAnswer(") }.test {
+ viewModel.onStateMutationCallback()
+ advanceUntilIdle()
+ assertContains(awaitItem(), "typeGood", message = "The submitted answer must retain the text entered before backgrounding")
+ cancelAndIgnoreRemainingEvents()
+ }
+ }
+ }
+
@Test
fun `recreated WebView retains keyboard support`() =
runTest {
The scheduler-completion callback was simulated in local lifecycle checks; this scenario was not exercised on an Android device.
The PR changed during review; findings apply to the version pinned at the start.
Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23281#pullrequestreview-5897114924
- Dominant language
- Kotlin
- Stars
- 12.3k
- Forks
- 3.1k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 383
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ankidroid/Anki-Android
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23392 ·
Maintainers usually reply within 1 day
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23390 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ankidroid/Anki-Android#23385 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ankidroid/Anki-Android#23374 ·
Maintainers usually reply within 1 day
-
Selected custom-study tags become unreadablePossibly taken @chesh-ire claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ankidroid/Anki-Android#23352 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in ankidroid/Anki-Android
Similar issues
-
Bug Domain changed
Difficulty 1/5 Under an hour Newbie friendliness 79/100
keiyoushi/extensions-source#21174 ·
Maintainers usually reply within 1 day
-
Unified account interface not translated into Simplified ChinesePossibly taken @xuenhua claimed this 3 days ago. Openunconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
thunderbird/thunderbird-android#11936 · 1 comment ·
Maintainers usually reply within 3 days
-
Update toast stylingOpendesign good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
scribe-org/Scribe-Android#778 ·
Maintainers usually reply within 1 day
-
AI Generated CI/CD ⚒️ Flaky-tests 🐦 go 🏃
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#7772 ·
Maintainers usually reply within 1 day
-
Error Handling Swift
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/wordpress-rs#1759 ·
Maintainers usually reply within 1 day