Review: a report's conversation, ids from outside, the form's notify, the drawer, the channels
CI / check (push) Canceled after 0s

Contract at server dev 40813d1 (84 files): a chat's `controls` and `report`,
a text step's `pages` and `text`, a report's `schedule_title`.

- B1 (must): a `user` row the server wrote (`machine`) is never the person's
  bubble -- a quiet note; in a report's conversation the first such line is
  left out. A report chat's bar takes its title from the chat's own `report`
  (so it survives the app being closed), and its menu offers only what
  `controls` allows.
- A1: ids from a push payload or an intent extra pass `safeId`
  (^[A-Za-z0-9_-]{1,64}$) before they become a route: chat, schedule, run,
  report.
- C1-C3: an empty "When..." is sent empty (the server's default) and the
  field shows the default as a placeholder; editing sends `notify` only once
  the schedule was read or the person chose, and a failed read says so and
  disables Save.
- B2: Reports is in the drawer only where the instance has the route.
- A text step with pages is drawn from the server's `text`; a report from
  its `text`. A fence with a space before `html-view` is a code block, as
  the spec has it.
- A push of a kind the app does not know shows nothing. An important report
  uses a channel of high importance. A report read or deleted in the app
  cancels its notification.
- stop() and compact() post an empty body again: a search-and-replace in
  adc1c4f had changed them to "{}" by mistake.

One commit: the model, the screens and the push share these files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 11:38:14 +00:00
1 parent 24669b7cd6
commit af290cd7d5
46 files changed
+519 -68

No files matched your search

@@ -1,6 +1,7 @@
package eu.llembas.android
import eu.llembas.android.api.CardItem
import eu.llembas.android.api.Drawn
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Message
@@ -8,6 +9,7 @@ import eu.llembas.android.api.Progress
import eu.llembas.android.api.ProgressWords
import eu.llembas.android.api.ToolCall
import eu.llembas.android.api.callDuration
import eu.llembas.android.api.drawn
import eu.llembas.android.api.ending
import eu.llembas.android.api.localeNumber
import eu.llembas.android.api.progressLine
@@ -181,4 +183,20 @@ class DisplayTest {
}
}
}
@Test
fun aLineTheServerWroteIsNeverThePersonsBubble() {
val person = Message(id = "m1", role = "user", text = "How many are left?")
val machine = Message(id = "m0", role = "user", machine = true, text = "[report] This conversation continues a report.")
val reply = Message(id = "m2", role = "assistant")
assertEquals(Drawn.Person, drawn(person, first = true, reportChat = false))
assertEquals(Drawn.Reply, drawn(reply, first = false, reportChat = true))
// In any chat: a quiet note.
assertEquals(Drawn.Note, drawn(machine, first = true, reportChat = false))
assertEquals(Drawn.Note, drawn(machine, first = false, reportChat = true))
// In a report's conversation the line that opens it is left out: the report is one tap back.
assertEquals(Drawn.Hidden, drawn(machine, first = true, reportChat = true))
// What the person wrote first in such a chat is still theirs.
assertEquals(Drawn.Person, drawn(person, first = true, reportChat = true))
}
}
@@ -2,16 +2,19 @@ package eu.llembas.android
import android.app.Application
import android.app.Notification
import android.app.NotificationManager
import eu.llembas.android.push.Notifications
import eu.llembas.android.push.ReportNotice
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
/**
@@ -57,4 +60,23 @@ class ReportNotificationTest {
// A report without a title still says something that is the app's own.
assertEquals("New report", Notifications.reportNotification(app, "home", notice.copy(title = "")).words()[0])
}
@Test
fun anImportantReportHasAChannelThatComesUp() {
assertEquals(LembasApp.CHANNEL_REPORTS_HIGH, Notifications.reportNotification(app, "home", notice.copy(high = true)).channelId)
val manager = app.getSystemService(NotificationManager::class.java)
assertEquals(NotificationManager.IMPORTANCE_HIGH, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS_HIGH).importance)
assertEquals(NotificationManager.IMPORTANCE_DEFAULT, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS).importance)
// Both stay private on the lock screen.
assertEquals(Notification.VISIBILITY_PRIVATE, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS_HIGH).lockscreenVisibility)
}
@Test
fun readingTheReportInTheAppTakesItsNotificationAway() {
val manager = app.getSystemService(NotificationManager::class.java)
manager.notify(notice.id, Notifications.reportNotification(app, "home", notice))
assertNotNull(shadowOf(manager).getNotification(notice.id))
Notifications.reportSeen(app, "rep1")
assertNull(shadowOf(manager).getNotification(notice.id))
}
}
@@ -1,5 +1,6 @@
package eu.llembas.android
import eu.llembas.android.api.Chat
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.PushPayload
import eu.llembas.android.api.Report
@@ -7,6 +8,8 @@ import eu.llembas.android.api.ReportList
import eu.llembas.android.api.ReportReply
import eu.llembas.android.api.ReportsFrame
import eu.llembas.android.api.RunResult
import eu.llembas.android.api.Step
import eu.llembas.android.api.shownMarkdown
import eu.llembas.android.push.ReportNotice
import eu.llembas.android.push.ScheduledNotice
import eu.llembas.android.ui.Segment
@@ -79,4 +82,38 @@ class ReportsContractTest {
// And the run that filed it says which report.
assertEquals("rep1", read("schedule_run", RunResult.serializer()).run.reportId)
}
@Test
fun aReportsConversationSaysWhichReportAndWhatMayBeDoneToIt() {
val chat = read("chat_report", Chat.serializer())
assertEquals("report", chat.kind)
assertEquals("rep1", chat.report?.id)
assertEquals("Two cakes are unwrapped", chat.report?.title)
// Rename and delete; not archive, pin or a folder.
assertTrue(chat.allows("rename") && chat.allows("delete"))
assertFalse(chat.allows("archive") || chat.allows("pin") || chat.allows("folder"))
// An ordinary chat allows all of them, and so does a server that does not say.
assertTrue(read("chat", Chat.serializer()).allows("archive"))
assertNull(read("chat", Chat.serializer()).report)
assertTrue(LembasJson.decodeFromString(Chat.serializer(), """{"id":"c1"}""").allows("archive"))
}
@Test
fun aReportWhoseScheduleIsGoneKeepsItsName() {
val orphan = LembasJson.decodeFromJsonElement(Report.serializer(), LembasJson.parseToJsonElement(text("report_orphan")).jsonObject.getValue("report"))
assertNull(orphan.schedule)
assertEquals("Waybread check", orphan.from)
assertEquals("Waybread check", read("reports", ReportList.serializer()).reports.single().from)
}
@Test
fun aStepWithAPageIsShownByItsText() {
val step = read("step_text_page", Step.serializer())
assertEquals("Cakes", step.pages.single().title)
// The server's own text, where the page is its one line -- which the phone draws as a card.
assertEquals("Two are unwrapped.\n\n[page: Cakes]\n", step.shownMarkdown)
assertEquals(listOf(Segment.Prose("Two are unwrapped."), Segment.Page("Cakes")), splitFences(step.shownMarkdown))
// A step without pages is its markdown.
assertEquals("plain", Step(kind = "text", markdown = "plain", text = "other").shownMarkdown)
}
}
@@ -8,12 +8,16 @@ import eu.llembas.android.api.ReportReply
import eu.llembas.android.api.Schedule
import eu.llembas.android.api.ScheduleRun
import eu.llembas.android.api.notifyChoice
import eu.llembas.android.api.safeId
import eu.llembas.android.api.sortedReports
import eu.llembas.android.push.Notifications
import eu.llembas.android.push.ReportNotice
import eu.llembas.android.push.ScheduledNotice
import eu.llembas.android.ui.Segment
import eu.llembas.android.ui.pageProjection
import eu.llembas.android.ui.reports.shareText
import eu.llembas.android.ui.scheduled.EditState
import eu.llembas.android.ui.scheduled.notifyToSend
import eu.llembas.android.ui.splitFences
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -148,6 +152,52 @@ class ReportsTest {
assertTrue(ScheduledNotice.from(result.copy(kind = "schedule_failed"))!!.failed)
}
@Test
fun onlyWhatLooksLikeAnIdBecomesARoute() {
assertEquals("rep1", safeId("rep1"))
assertEquals("a-b_C9", safeId("a-b_C9"))
// A slash, a query, a dot, nothing, too much: none of these is an id.
for (bad in listOf("a/b", "rep1?x=1", "..", "", "rep 1", "x".repeat(65))) assertNull(bad, safeId(bad))
assertNull(safeId(null))
// A push whose id is no id shows nothing rather than open somewhere else.
val push = PushPayload(kind = "report", reportId = "rep1/../../chat/c1", url = "/reports/rep1")
assertNull(ReportNotice.from(push))
assertNull(ReportNotice.from(PushPayload(kind = "report", url = "/reports/a%2Fb")))
assertNull(ScheduledNotice.from(PushPayload(kind = "schedule", scheduleId = "s1/x")))
// The run's id alone being bad drops the run, not the notification.
assertNull(ScheduledNotice.from(PushPayload(kind = "schedule", scheduleId = "s1", runId = "r/1"))!!.runId)
}
@Test
fun aPushOfAKindThisAppDoesNotKnowIsNotAChat() {
assertTrue(Notifications.chatKind(""))
assertTrue(Notifications.chatKind("reply"))
assertTrue(Notifications.chatKind("ask"))
assertFalse(Notifications.chatKind("digest"))
assertFalse(Notifications.chatKind("report"))
}
@Test
fun theFormSendsNotifyOnlyWhenItKnowsWhatItSends() {
val fresh = EditState(reports = true)
// A new schedule: what the form shows is what is meant.
assertEquals("when", notifyToSend(fresh, editing = false))
// An instance without Reports is sent nothing new.
assertNull(notifyToSend(EditState(reports = false, notify = "never", notifyTouched = true), editing = false))
// Editing before the schedule was read (or when reading it failed): the default is not written over it...
assertNull(notifyToSend(fresh, editing = true))
assertNull(notifyToSend(fresh.copy(loadFailed = true), editing = true))
// ...unless the person chose, or it was read.
assertEquals("never", notifyToSend(fresh.copy(notify = "never", notifyTouched = true), editing = true))
assertEquals("always", notifyToSend(fresh.copy(notify = "always", loaded = true), editing = true))
}
@Test
fun aSpaceBeforeTheWordIsNotAPage() {
// The spec: `html-view` stands straight after the fence. With a space it is a code block, here as on the server.
assertEquals(listOf(Segment.Code("html-view", "<p>x</p>")), splitFences("``` html-view Cakes\n<p>x</p>\n```"))
}
@Test
fun aPageInAnAnswerIsNeverItsSource() {
val reply = "Sales by month:\n\n```html-view Monthly sales\n<!doctype html>\n<html><script>alert(1)</script></html>\n```\n\nThat is all."
@@ -143,7 +143,7 @@ class ScreenShots {
drawerState = rememberDrawerState(DrawerValue.Open),
drawerContent = {
DrawerContent(
Fakes.chats.copy(unreadReports = 2),
Fakes.chats.copy(reports = true, unreadReports = 2),
current = "c1",
account = "Home · frodo@example.org",
actions = NoDrawerActions,