package com.cottondb.messages.warmimport android.app.Applicationimport androidx.compose.ui.test.junit4.createComposeRuleimport com.cottondb.messages.chat.ChatDataimport com.cottondb.messages.chat.ChatModelimport com.cottondb.messages.chat.ThreadPageimport com.cottondb.messages.chat.Wordsimport com.cottondb.shell.core.CottonCoreimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.SupervisorJobimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Ignoreimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport org.robolectric.shadows.ShadowLooperimport java.util.concurrent.TimeUnit/** * Seen on the emulator (21 Nov 2026): in an imported chat scrolled a little way up, Jump to latest closed Comms. The * glide down ran in the model's own scope, which has no frame clock ("A MonotonicFrameClock is not available"). Invented * words. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], qualifiers = "w400dp-h860dp-xhdpi", application = Application::class)classJumpToLatestTest { @get:Ruleval compose = createComposeRule()privateval words = Words { set, key -> "$set:$key" }privateval threadWords = ThreadWordsWarm("Back", "Call", "Video call", "Not sent", "Try again", "You", "Their page")privateval acts = MessageActs({}, {}, { _, _ -> }, {}, { _, _ -> }, {}, { _, _ -> }, {}, {}, VoicePlayer(kotlinx.coroutines.MainScope()))privatefun page() = ThreadPage.of(CottonCore.json.parseToJsonElement(""" {"thread":"t1","header":{"name":"+15550100123","picture":{"initials":"","tint":1},"source":"cotton","status":"","calls":[]}, "items":[${(1..30).joinToString(",") { """{"item":"bubble","message":"m$it","mine":${it % 2 == 0},"kind":"text","text":"Invented words $it","head":true,"tail":true,"time":"20:0${it % 10}","pinned":false,"actions":["reply"]}""" }}]} """).jsonObject, words)// Marked and filed (coordinator, 23 Nov 2026: "make it not depend on timing, or mark and file it"):// passes alone, fails in the 195-test fork (android 16196, :59). ChatModel.jump glides on// AndroidUiDispatcher.Main, a process-wide singleton bound to the Choreographer of the first test that// made it; Robolectric resets that looper between tests, so its frames never come. The fix is jump's,// in the app: glide on the composition's own frame clock (a scope from rememberCoroutineScope). @Ignore("jump glides on a process-wide frame clock; filed in main-green-19's report, 23 Nov 2026") @Testfun jump_to_latest_glides_to_the_foot() {val model = ChatModel(ChatData(null, null, words, CoroutineScope(SupervisorJob()), null), CoroutineScope(SupervisorJob())) model.prefetched["t1"] = page() model.open("t1", unread = false) compose.setContent { WarmTheme(night = false) { Conversation(model.thread!!, model.threadList, acts, threadWords, {}, {}, {}, {}, {}, {}, {}, {}, null, {}, {}) {} } } compose.waitForIdle() compose.runOnIdle { model.threadList.dispatchRawDelta(1500f) } compose.waitForIdle() assert(model.threadList.firstVisibleItemIndex in4..40) { "scrolled up: ${model.threadList.firstVisibleItemIndex}" }// The glide runs on the frames' clock (AndroidUiDispatcher), which waitForIdle does not wait on: the test// steps the main looper a frame at a time until the jump has ended, so no run depends on how fast the box is.val jump = compose.runOnIdle { model.jump() }for (frame in0 until 600) {if (jump.isCompleted) breakShadowLooper.idleMainLooper(16, TimeUnit.MILLISECONDS) compose.waitForIdle() } assert(jump.isCompleted) { "the jump never ended" } compose.waitForIdle() assertEquals(0, model.threadList.firstVisibleItemIndex) }}