Reports, "notify when", report notifications, and a page as a card (spec 3.8.0)
CI / check (push) Canceled after 0s

Built against the provisional /api/v2 shapes of the round's brief; the
server's fixtures are pinned when its reports routes are on its dev.

- Reports in the drawer with an unread badge; routes reports and
  report/{id}. The list: unread first, title, the schedule's name, when,
  importance marked; pull to refresh; swipe to mark read or to delete (asks
  once). A report reads as a page (Markdown as the chat draws it) and is
  marked read on open; Share hands over its text; Reply asks the server for
  the report's chat and opens the ordinary chat screen entered from the
  report: "Report: <title>" in the bar, Back to the report, never added to
  the chats list.
- Scheduled: "Notify when" on the form -- Every run / When... (the default
  prefilled) / Never, each with its line; sent as notify and notify_when. A
  run shows its note and a row to its report; the run's chat stays openable.
- Push kind `report`: a Reports channel; unlocked the title and summary,
  on the lock screen only the app's name and "New report"; tap and Open go
  to the report, Mark read needs the phone unlocked. `schedule` and
  `schedule_failed` from an older server are handled as before.
- A page in an answer (an html-view fence, the server's "[page: Title]"
  line, or a `page` step) is one quiet card; no web view, never the source,
  in a chat and in a report. Copy and Share take the one-line projection.
- An id that may come as a string or as an object (a report's chat, a run's
  report) is read either way.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 09:38:58 +00:00
1 parent 118b2aa764
commit adc1c4fe3e
32 files changed
+1828 -46

No files matched your search

@@ -0,0 +1,60 @@
package eu.llembas.android
import android.app.Application
import android.app.Notification
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.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
/**
* A report's notification, both of its faces: unlocked, the report's title and summary; on the
* lock screen the app's fixed words and nothing from the account (rule 5).
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [35], qualifiers = "en")
class ReportNotificationTest {
private val app: Application get() = RuntimeEnvironment.getApplication()
private val notice = ReportNotice("rep1", "Two tenders opened", "Storage bids are due in May.", high = false)
private fun Notification.words() = listOf(Notification.EXTRA_TITLE, Notification.EXTRA_TEXT, Notification.EXTRA_BIG_TEXT).map {
extras.getCharSequence(it)?.toString().orEmpty()
}
@Test
fun unlockedItSaysTheReportLockedOnlyThatThereIsOne() {
val shown = Notifications.reportNotification(app, "home", notice)
assertEquals(LembasApp.CHANNEL_REPORTS, shown.channelId)
assertEquals("Two tenders opened", shown.words()[0])
assertEquals("Storage bids are due in May.", shown.words()[1])
// Private: Android shows the public version on a locked screen.
assertEquals(Notification.VISIBILITY_PRIVATE, shown.visibility)
val locked = shown.publicVersion
assertNotNull(locked)
assertEquals(listOf("LLeMbas", "New report", ""), locked.words())
// Nothing of the report anywhere in what the lock screen gets.
val all = locked.words().joinToString(" ") + locked.extras.keySet().joinToString(" ") { locked.extras.get(it)?.toString().orEmpty() }
assertFalse(all.contains("tenders"))
assertFalse(all.contains("Storage"))
}
@Test
fun itOffersOpenAndMarkReadAndTheSecondNeedsThePhoneUnlocked() {
val shown = Notifications.reportNotification(app, "home", notice)
assertEquals(listOf("Open", "Mark read"), shown.actions.map { it.title.toString() })
assertFalse(shown.actions[0].isAuthenticationRequired)
assertTrue(shown.actions[1].isAuthenticationRequired)
assertNotNull(shown.contentIntent)
assertEquals(Notification.FLAG_AUTO_CANCEL, shown.flags and Notification.FLAG_AUTO_CANCEL)
// 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])
}
}
@@ -0,0 +1,168 @@
package eu.llembas.android
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.PushPayload
import eu.llembas.android.api.Report
import eu.llembas.android.api.ReportList
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.sortedReports
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.splitFences
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Reports (harness spec 3.8.0, `reports.md`) and pages in an answer (`pages.md`), as far as they
* need no phone: the shapes, the list's order, "notify when", the push, and a page's place in
* the text. The shapes here are written out in the test; `ReportsContractTest` reads the server's
* own fixtures once they are pinned.
*/
class ReportsTest {
private val list = """
{"reports": [
{"id": "rep1", "title": "Two tenders opened", "summary": "Storage bids are due in May.", "importance": "high",
"schedule": {"id": "s1", "title": "Morning news"}, "created": "2026-03-10T07:31:00+00:00", "unread": true},
{"id": "rep2", "title": "Nothing new on the bridge", "summary": "", "importance": "normal",
"schedule": {"id": "s2", "title": "Bridge watch"}, "created": "2026-03-11T07:31:00+00:00", "unread": false},
{"id": "rep3", "title": "Flour is back in stock", "created": "2026-03-09T07:31:00+00:00", "unread": true}
]}
""".trimIndent()
@Test
fun theListAndItsOrder() {
val reports = LembasJson.decodeFromString(ReportList.serializer(), list).reports
assertEquals("Morning news", reports[0].schedule?.title)
assertTrue(reports[0].high)
assertFalse(reports[2].high)
assertNull(reports[2].schedule)
// The unread first, the newest first within each half.
assertEquals(listOf("rep1", "rep3", "rep2"), sortedReports(reports).map { it.id })
// A server that says nothing has none.
assertTrue(LembasJson.decodeFromString(ReportList.serializer(), "{}").reports.isEmpty())
}
@Test
fun oneReportItsBodyAndTheChatAReplyContinuesIn() {
val alone = LembasJson.decodeFromString(
Report.serializer(),
"""{"id":"rep1","title":"Two tenders opened","body":"**Two** tenders.","chat":null,"unread":true,"created_at":"2026-03-10T07:31:00+00:00"}""",
)
assertEquals("**Two** tenders.", alone.body)
assertNull(alone.chatId)
// `created` under either name.
assertEquals("2026-03-10T07:31:00+00:00", alone.created)
// The chat as an id, or as an object carrying one: both are the chat.
val replied = LembasJson.decodeFromString(Report.serializer(), """{"id":"rep1","chat":"chat9"}""")
assertEquals("chat9", replied.chatId)
assertEquals("chat9", LembasJson.decodeFromString(Report.serializer(), """{"id":"rep1","chat":{"id":"chat9"}}""").chatId)
assertEquals("chat9", LembasJson.decodeFromString(ReportReply.serializer(), """{"chat":"chat9"}""").chatId)
assertNull(LembasJson.decodeFromString(ReportReply.serializer(), """{"chat":""}""").chatId)
}
@Test
fun aRunLeavesANoteAndMaybeAReport() {
val filed = LembasJson.decodeFromString(ScheduleRun.serializer(), """{"id":"r1","status":"ok","note":"Two tenders; report filed.","report":"rep1"}""")
assertEquals("Two tenders; report filed.", filed.note)
assertEquals("rep1", filed.reportId)
val quiet = LembasJson.decodeFromString(ScheduleRun.serializer(), """{"id":"r2","status":"ok","note":"Nothing changed since Monday.","report":null}""")
assertNull(quiet.reportId)
// A server before 3.8.0 says neither.
val old = LembasJson.decodeFromString(ScheduleRun.serializer(), """{"id":"r3","status":"silent"}""")
assertEquals("", old.note)
assertNull(old.reportId)
}
@Test
fun notifyWhenIsOneOfThree() {
assertEquals("always", notifyChoice("always"))
assertEquals("never", notifyChoice("never"))
assertEquals("when", notifyChoice("when"))
// What a server before 3.8.0 called "when it matters", and a schedule that says nothing: the default.
assertEquals("when", notifyChoice("matters"))
assertEquals("when", notifyChoice(""))
val schedule = LembasJson.decodeFromString(Schedule.serializer(), """{"id":"s1","notify":"when","notify_when":"the price drops below 100"}""")
assertEquals("the price drops below 100", schedule.notifyWhen)
assertEquals("", LembasJson.decodeFromString(Schedule.serializer(), """{"id":"s1","notify":"matters"}""").notifyWhen)
}
@Test
fun aReportsPushOpensTheReport() {
val payload = LembasJson.decodeFromString(
PushPayload.serializer(),
"""{"kind":"report","title":"Two tenders opened","body":"Storage bids are due in May.","url":"/reports/rep1"}""",
)
val notice = ReportNotice.from(payload)!!
assertEquals("rep1", notice.reportId)
assertEquals("Two tenders opened", notice.title)
assertEquals("Storage bids are due in May.", notice.summary)
assertFalse(notice.high)
// The id named outright wins over the address, and importance may make it urgent.
val named = payload.copy(reportId = "rep7", importance = "high")
assertEquals("rep7", ReportNotice.from(named)!!.reportId)
assertTrue(ReportNotice.from(named)!!.high)
// One notification per report.
assertEquals(notice.id, ReportNotice.from(payload)!!.id)
// Not a report: nothing; and a report is not a scheduled result.
assertNull(ReportNotice.from(payload.copy(kind = "reply")))
assertNull(ReportNotice.from(payload.copy(url = "/chat/c1")))
assertNull(ScheduledNotice.from(payload))
}
@Test
fun anOlderServersScheduledPushStillWorks() {
// 2.0.0-beta.11 and before: a run's result is its own push, which opens the run.
val result = LembasJson.decodeFromString(
PushPayload.serializer(),
"""{"kind":"schedule","title":"Morning news","body":"Little happened.","url":"/scheduled/s1?run=r1","schedule_id":"s1","run_id":"r1"}""",
)
assertNull(ReportNotice.from(result))
val notice = ScheduledNotice.from(result)!!
assertEquals("s1", notice.scheduleId)
assertEquals("r1", notice.runId)
assertFalse(notice.failed)
// A failed run keeps its failure notification under 3.8.0 too.
assertTrue(ScheduledNotice.from(result.copy(kind = "schedule_failed"))!!.failed)
}
@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."
val split = splitFences(reply)
assertEquals(listOf(Segment.Prose("Sales by month:"), Segment.Page("Monthly sales"), Segment.Prose("That is all.")), split)
// The word is exact: these are ordinary code blocks.
assertEquals(listOf(Segment.Code("html", "<p>")), splitFences("```html\n<p>\n```"))
assertEquals(listOf(Segment.Code("html-views", "<p>")), splitFences("```html-views\n<p>\n```"))
// Tildes, no title, and one still being written.
assertEquals(listOf(Segment.Page("")), splitFences("~~~html-view\n<html></html>\n~~~"))
assertEquals(listOf(Segment.Page("Chart", closed = false)), splitFences("```html-view Chart\n<html>"))
// Backticks inside a page do not end it unless a line is the closing fence.
assertEquals(listOf(Segment.Page("T")), splitFences("````html-view T\nconst a = `x`\n```\nstill the page\n````"))
// The server's own line in a page's place.
assertEquals(
listOf(Segment.Prose("Before."), Segment.Page("Monthly sales"), Segment.Prose("After.")),
splitFences("Before.\n\n[page: Monthly sales]\n\nAfter."),
)
assertEquals(listOf(Segment.Prose("See [page: x] inline.")), splitFences("See [page: x] inline."))
}
@Test
fun whatIsCopiedOrSharedSaysThereIsAPage() {
val reply = "Sales:\n\n```html-view Monthly sales\n<html>secret markup</html>\n```\n\n```sh\nmake\n```"
val text = pageProjection(reply, untitled = "Page")
assertEquals("Sales:\n\n[page: Monthly sales]\n\n```sh\nmake\n```", text)
assertFalse(text.contains("secret markup"))
assertEquals("[page: Page]", pageProjection("```html-view\n<html></html>\n```", untitled = "Page"))
val report = Report(id = "rep1", title = "Two tenders opened", body = "Bids are due.\n\n```html-view Chart\n<svg></svg>\n```")
assertEquals("Two tenders opened\n\nBids are due.\n\n[page: Chart]", shareText(report))
}
}
@@ -19,6 +19,8 @@ import eu.llembas.android.api.Message
import eu.llembas.android.api.Metrics
import eu.llembas.android.api.ModelList
import eu.llembas.android.api.Progress
import eu.llembas.android.api.Report
import eu.llembas.android.api.ReportSchedule
import eu.llembas.android.api.RunError
import eu.llembas.android.api.RunModel
import eu.llembas.android.api.RunResult
@@ -50,6 +52,8 @@ import eu.llembas.android.ui.chat.ChatState
import eu.llembas.android.ui.chat.Draft
import eu.llembas.android.ui.home.ChatsState
import eu.llembas.android.ui.memory.MemoryState
import eu.llembas.android.ui.reports.ReportState
import eu.llembas.android.ui.reports.ReportsState
import eu.llembas.android.ui.scheduled.EditState
import eu.llembas.android.ui.scheduled.ModelsState
import eu.llembas.android.ui.scheduled.RunState
@@ -59,6 +63,7 @@ import eu.llembas.android.ui.settings.SettingsState
import eu.llembas.android.ui.settings.WakeTestShown
import eu.llembas.android.wake.WakeFailure
import eu.llembas.android.wake.WakeState
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonObject
import java.time.LocalDate
@@ -645,6 +650,68 @@ object Fakes {
),
)
/** Reports: two unread (one marked important), one read; a long title and a long task name. */
val reports = ReportsState(
reports = listOf(
Report(
id = "rep1",
title = "Two storage tenders opened, and one of them closes before the next run",
summary = "Austria asks for 200 MW of grid storage, bids due in May. A second, smaller one closes on Friday.",
importance = "high",
schedule = ReportSchedule("s1", "Morning news on renewables"),
created = "2026-03-10T07:31:00+00:00",
unread = true,
),
Report(
id = "rep2",
title = "Flour is back in stock",
summary = "The mill lists the stone-ground flour again.",
schedule = ReportSchedule("s2", "The mill's price list, watched every hour of every working day"),
created = "2026-03-09T16:00:00+00:00",
unread = true,
),
Report(
id = "rep3",
title = "Nothing new on the bridge",
summary = "The council has not published the minutes yet.",
schedule = ReportSchedule("s3", "Bridge watch"),
created = "2026-03-08T07:31:00+00:00",
),
),
)
/** One report read as a page: Markdown, a code block, and a page a phone does not draw. */
val report = ReportState(
loading = false,
report = reports.reports[0].copy(
unread = false,
body = """
|Two tenders for grid storage opened this week.
|
|1. **Austria**: 200 MW, bids due on 15 May.
|2. **A smaller one** closes on Friday; see the [notice](https://example.org/notice).
|
|```html-view Storage tenders by month
|<!doctype html><html><body><svg></svg></body></html>
|```
|
|```text
|storage tender: 200 MW, deadline 2026-05-15
|```
""".trimMargin(),
),
)
/** A task's history under spec 3.8.0: a run that filed a report, one that says why it did not, one unchanged. */
val scheduleWithReports = ScheduleState(
schedule = schedules[0].copy(notify = "when", notifyWhen = "a tender for storage opens or closes"),
runs = listOf(
ok.copy(id = "r-10", note = "Two tenders opened; the report says which.", report = JsonPrimitive("rep1"), preview = ""),
ok.copy(id = "r-11", note = "No tender opened or closed since yesterday, so there is nothing to report.", preview = ""),
ScheduleRun(id = "r-12", scheduleId = "s1", dueAt = "2026-03-06T07:30:00+00:00", status = "unchanged", note = "The page did not change."),
),
)
val schedulingModels = ModelsState(
models = SchedulingModels(
models = listOf(
@@ -657,6 +724,9 @@ object Fakes {
),
)
/** The form with "When…" chosen and the person's own words in it. */
val editingNotify: EditState get() = editing.copy(notify = "when", notifyWhen = "a tender for storage opens or closes")
val editing = EditState(
words = "Every weekday at 7:30, sum up the news about renewable energy in five points",
compiled = ScheduleCompiled(
@@ -54,6 +54,10 @@ import eu.llembas.android.ui.home.DrawerContent
import eu.llembas.android.ui.memory.MemoryActions
import eu.llembas.android.ui.memory.MemoryContent
import eu.llembas.android.ui.memory.MemoryState
import eu.llembas.android.ui.reports.ReportContent
import eu.llembas.android.ui.reports.ReportsActions
import eu.llembas.android.ui.reports.ReportsContent
import eu.llembas.android.ui.reports.ReportsState
import eu.llembas.android.ui.scheduled.RunContent
import eu.llembas.android.ui.scheduled.ScheduleContent
import eu.llembas.android.ui.scheduled.ScheduleEditContent
@@ -88,6 +92,8 @@ private object NoActivityActions : ActivityActions
private object NoSettingsActions : SettingsActions
private object NoReportsActions : ReportsActions
private object NoAssistActions : AssistActions
private object NoShareActions : ShareActions
@@ -137,7 +143,7 @@ class ScreenShots {
drawerState = rememberDrawerState(DrawerValue.Open),
drawerContent = {
DrawerContent(
Fakes.chats,
Fakes.chats.copy(unreadReports = 2),
current = "c1",
account = "Home · frodo@example.org",
actions = NoDrawerActions,
@@ -247,7 +253,26 @@ class ScreenShots {
}
@Test
fun scheduleEdit() = shoot("11-schedule-edit") { ScheduleEditContent(Fakes.editing, editing = false) }
fun scheduleEdit() {
shoot("11-schedule-edit", Phone.Scroll) { ScheduleEditContent(Fakes.editing, editing = false) }
// "Notify when": the three choices, and "When…" with the person's words.
shoot("11-schedule-edit-notify", Phone.Scroll) { ScheduleEditContent(Fakes.editingNotify, editing = true) }
shoot("11-schedule-edit-notify", Phone.SmallScroll, fontScale = 1.5f) { ScheduleEditContent(Fakes.editingNotify, editing = true) }
}
@Test
fun reports() {
shoot("40-reports") { ReportsContent(Fakes.reports, NoReportsActions) }
shoot("40-reports", Phone.Small, fontScale = 1.5f) { ReportsContent(Fakes.reports, NoReportsActions) }
shoot("40-reports-none") { ReportsContent(ReportsState(), NoReportsActions) }
shoot("40-reports-older-instance") { ReportsContent(ReportsState(unsupported = true), NoReportsActions) }
// One report as a page; the page in it is a card, not a page and not its source.
shoot("41-report", Phone.Scroll) { ReportContent(Fakes.report) }
shoot("41-report", Phone.Small, fontScale = 1.5f) { ReportContent(Fakes.report) }
// A task's runs: the note, the way to a report, an unchanged look.
shoot("42-schedule-runs-reports", Phone.Scroll) { ScheduleContent(Fakes.scheduleWithReports) }
shoot("42-schedule-runs-reports", Phone.SmallScroll, fontScale = 1.5f) { ScheduleContent(Fakes.scheduleWithReports) }
}
@Test
fun scheduleRun() {