Older once, a closed stream keeps its words, a locked phone's dictation stays on it
CI / check (push) Canceled after 0s

- Older: one read at a time, and a page is put above the transcript only
  while its anchor is still the first row, each row once (withOlder).
- A stream that closes without `done` reads the transcript again; where it
  cannot, the steps the stream had shown stay on the row (closedUnfinished).
- Edit, regenerate, continue and plan/execute declare `client`, as create
  and send do.
- The system recogniser sends nothing to the instance from a locked phone:
  the on-device recogniser where there is one, else ERROR_RECOGNIZER_BUSY;
  a phone that locks mid-recording sends nothing (recogniseWith).
- A thinking chip the person opened stays open when its step closes and at
  `done`: keyed by its place, one call site for the live and finished reply.
- The drawer's Reports badge follows the events route's `reports` frame.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-17 23:08:46 +00:00
1 parent 5689994037
commit c0dd0b5a50
12 files changed
+391 -20

No files matched your search

@@ -12,10 +12,12 @@ import eu.llembas.android.assist.AssistUiState
import eu.llembas.android.assist.Held
import eu.llembas.android.assist.LockedStart
import eu.llembas.android.assist.Opening
import eu.llembas.android.assist.Recognise
import eu.llembas.android.assist.Recorder
import eu.llembas.android.assist.SheetStop
import eu.llembas.android.assist.isStopPhrase
import eu.llembas.android.assist.lockedStart
import eu.llembas.android.assist.recogniseWith
import eu.llembas.android.assist.settle
import eu.llembas.android.assist.usePhoneRecognizer
import eu.llembas.android.auth.Prefs
@@ -213,4 +215,14 @@ class AssistTest {
assertTrue(NotificationReader.asksAbout("Anything urgent in My Notifications?", phrases))
assertFalse(NotificationReader.asksAbout("How do notifications work on Android?", phrases))
}
@Test
fun theSystemRecogniserSendsNothingToTheInstanceFromALockedPhone() {
// Unlocked: the instance writes it down, whatever else the phone has.
assertEquals(Recognise.Instance, recogniseWith(locked = false, onDevice = false))
assertEquals(Recognise.Instance, recogniseWith(locked = false, onDevice = true))
// Locked: the phone's own recogniser, or nobody -- never the instance.
assertEquals(Recognise.OnDevice, recogniseWith(locked = true, onDevice = true))
assertEquals(Recognise.Refuse, recogniseWith(locked = true, onDevice = false))
}
}
@@ -3,18 +3,25 @@ package eu.llembas.android
import eu.llembas.android.api.AgentSubagents
import eu.llembas.android.api.AgentsSetting
import eu.llembas.android.api.Chat
import eu.llembas.android.api.ChatDetail
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LinkedDevice
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Message
import eu.llembas.android.api.MessagePage
import eu.llembas.android.api.ModelList
import eu.llembas.android.api.Step
import eu.llembas.android.api.SubagentsOffer
import eu.llembas.android.ui.chat.ChatState
import eu.llembas.android.ui.chat.Draft
import eu.llembas.android.ui.chat.agents
import eu.llembas.android.ui.chat.closedUnfinished
import eu.llembas.android.ui.chat.compactContext
import eu.llembas.android.ui.chat.device
import eu.llembas.android.ui.chat.level
import eu.llembas.android.ui.chat.modelId
import eu.llembas.android.ui.chat.offersTeam
import eu.llembas.android.ui.chat.withOlder
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
@@ -84,4 +91,60 @@ class ChatStateTest {
assertEquals("8K", compactContext(8192))
assertEquals("1M", compactContext(1_000_000))
}
private fun said(id: String, role: String = "user") = Message(id = id, role = role)
@Test
fun anOlderPageIsPutAboveOnceHoweverOftenItArrives() {
val shown = ChatState(messages = listOf(said("m3"), said("m4")), more = true)
val page = MessagePage(messages = listOf(said("m1"), said("m2")), more = false)
val once = shown.withOlder("m3", page)
assertEquals(listOf("m1", "m2", "m3", "m4"), once.messages.map { it.id })
assertFalse(once.more)
// The same page a second time (two taps, two answers): m3 is no longer the first row.
assertEquals(once, once.withOlder("m3", page))
// A page that overlaps what is shown, or names a row twice, adds each row once.
val overlapping = MessagePage(messages = listOf(said("m2"), said("m2"), said("m3")), more = true)
assertEquals(listOf("m2", "m3", "m4"), shown.withOlder("m3", overlapping).messages.map { it.id })
// The transcript was read again meanwhile: the page belongs above another first row.
val moved = ChatState(messages = listOf(said("m7"), said("m8")), more = true)
assertEquals(moved, moved.withOlder("m3", page))
}
@Test
fun aStreamThatClosesWithoutDoneLeavesWhatWasWritten() {
val chat = Chat(id = "c")
val live = LiveReply("m2")
.apply("steps", """{"steps":[{"index":0,"kind":"thinking","text":"Flour first."}],"tail":{"thinking":"","text":"Mix the","label":""}}""")
.apply("status", """{"text":"Stopped","progress":{"phase":"stopped","reason":"person"}}""")
val writing = ChatState(chat = chat, messages = listOf(said("m1"), said("m2", "assistant")), live = live)
// Read again: the transcript is the server's, with the reply as it stored it.
val stored = said("m2", "assistant").copy(stopped = true, steps = listOf(Step(index = 0, kind = "text", markdown = "Mix the")))
val reread = writing.closedUnfinished("m2", ChatDetail(chat = chat.copy(title = "Waybread"), messages = listOf(said("m1"), stored), more = true))
assertNull(reread.live)
assertEquals(stored, reread.messages.last())
assertEquals("Waybread", reread.chat?.title)
assertTrue(reread.more)
// It could not be read: the steps the stream had shown stay on the row, closed, with
// the end the stream said.
val kept = writing.closedUnfinished("m2", null)
assertNull(kept.live)
assertEquals(listOf("thinking", "text"), kept.messages.last().steps.map { it.kind })
assertEquals("Mix the", kept.messages.last().steps.last().markdown)
assertTrue(kept.messages.last().steps.none { it.open })
assertEquals("stopped", kept.messages.last().progress?.phase)
assertEquals(said("m1"), kept.messages.first())
// Nothing had been written: nothing is invented, and nothing is live.
val empty = writing.copy(live = LiveReply("m2")).closedUnfinished("m2", null)
assertNull(empty.live)
assertEquals(writing.messages, empty.messages)
// Another reply is followed by now: this stream's end is not its business.
val next = writing.copy(live = LiveReply("m9"))
assertEquals(next, next.closedUnfinished("m2", null))
assertEquals(next, next.closedUnfinished("m2", ChatDetail(chat = chat)))
}
}
@@ -131,4 +131,36 @@ class ClientTest {
assertEquals("hi", api.fileContent("/home/frodo/a b.md").text)
assertEquals("/api/v2/files/content?path=%2Fhome%2Ffrodo%2Fa%20b.md", server.takeRequest().path)
}
@Test
fun everyRequestThatStartsAReplySaysWhatTheAppCanDo() = runTest {
val api = client()
val declared = "\"client\":[\"phone_actions\"]"
val answer = """{"chat":{"id":"c1"}}"""
repeat(6) { server.enqueue(MockResponse().setResponseCode(201).setBody(answer)) }
api.createChat("Hello")
api.sendMessage("c1", "And then?")
api.edit("c1", "m1", "Hello again")
api.regenerate("c1", "m2")
api.continueChat("c1")
api.executePlan("c1")
val paths = listOf(
"/api/v2/chats",
"/api/v2/chats/c1/messages",
"/api/v2/chats/c1/messages/m1/edit",
"/api/v2/chats/c1/messages/m2/regenerate",
"/api/v2/chats/c1/continue",
"/api/v2/chats/c1/plan/execute",
)
for (path in paths) {
val request = server.takeRequest()
assertEquals(path, request.path)
val body = request.body.readUtf8()
assertTrue("$path: $body", body.contains(declared))
}
// An edit still carries its words.
server.enqueue(MockResponse().setBody("{}"))
api.edit("c1", "m1", "Hello again")
assertTrue(server.takeRequest().body.readUtf8().contains("\"text\":\"Hello again\""))
}
}
@@ -13,6 +13,8 @@ import eu.llembas.android.api.shownMarkdown
import eu.llembas.android.push.ReportNotice
import eu.llembas.android.push.ScheduledNotice
import eu.llembas.android.ui.Segment
import eu.llembas.android.ui.home.ChatsState
import eu.llembas.android.ui.home.reported
import eu.llembas.android.ui.reports.shareText
import eu.llembas.android.ui.splitFences
import kotlinx.serialization.KSerializer
@@ -52,6 +54,18 @@ class ReportsContractTest {
assertEquals("2026-01-02T03:04:05+00:00", frame.latestCreated)
}
@Test
fun theEventsFrameMovesTheDrawersBadge() {
// The frame as the server writes it: its count is the badge, and such an instance has Reports.
val told = ChatsState(unreadReports = 4).reported(text("event_reports"))
assertEquals(1, told.unreadReports)
assertTrue(told.reports)
// Everything read: the badge goes.
assertEquals(0, told.reported("""{"unread":0,"newest":null,"latest_created":null}""").unreadReports)
// A frame that cannot be read changes nothing.
assertEquals(told, told.reported("not json"))
}
@Test
fun oneReportIsWrappedAndItsPageIsACard() {
// `GET /reports/{id}` answers `{report: …}`: read as ApiClient.report reads it.