Contract at server dev ee74edc: the reports routes, pinned
CI / check (push) Canceled after 0s

79 files; the provisional shapes held, with these taken from the fixtures:

- GET /reports carries `unread`, the count the drawer's badge shows
  (ApiClient.unreadReports); GET /reports/{id} answers {report: ...} with
  `text` (the body with each page as its one line), which Share uses.
- A schedule carries `notify_default`, the default condition in the
  account's language: what "When..." starts from and what the task's page
  says while the person wrote none.
- The events' `reports` frame (unread, newest) has its model; nothing
  follows it yet.
- push_schedule.json is gone (a finished run sends a report's push now);
  the test of an older server's payload keeps it written out.
- ReportsContractTest reads reports, report, report_reply, push_report and
  event_reports; ScheduleContractTest follows the new values (notify
  "when", the run's note and report, the frame's version).

Tokens and strings are unchanged at this ref.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 10:10:02 +00:00
1 parent ca1ace2987
commit 613eba4154
22 files changed
+318 -104

No files matched your search

@@ -398,6 +398,9 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
return get<ReportList>(if (asked.isEmpty()) "/reports" else "/reports?" + asked).reports
}
/** How many reports are unread: the drawer's badge. */
suspend fun unreadReports(): Int = get<ReportList>("/reports?unread=1").unreadCount
/** One report with its body. Read as the report itself, or as `{report: …}` around it. */
suspend fun report(id: String): Report {
val answer = get<JsonObject>("/reports/${segment(id)}")
@@ -38,6 +38,9 @@ data class Report(
@JsonNames("created_at") val created: String? = null,
val unread: Boolean = false,
val body: String? = null,
/** The body as text: every page in it replaced by its one line, `[page: Title]`. */
val text: String? = null,
val model: String? = null,
val chat: JsonElement? = null,
) {
val high: Boolean get() = importance == "high"
@@ -47,7 +50,14 @@ data class Report(
}
@Serializable
data class ReportList(val reports: List<Report> = emptyList(), val more: Boolean = false)
data class ReportList(val reports: List<Report> = emptyList(), val unread: Int? = null) {
/** How many reports are unread: the server's count, else as many as it listed unread. */
val unreadCount: Int get() = unread ?: reports.count { it.unread }
}
/** `GET /events`, frame `reports`: the count of the unread, and the newest report. */
@Serializable
data class ReportsFrame(val unread: Int = 0, val newest: Report? = null)
/** `POST /reports/{id}/reply`: the chat the conversation about the report is in. */
@Serializable
@@ -99,6 +99,8 @@ data class Schedule(
val mode: String = "",
val notify: String = "",
@SerialName("notify_when") val notifyWhen: String = "",
/** What "When…" means while [notifyWhen] is empty, in the account's language. */
@SerialName("notify_default") val notifyDefault: String = "",
@SerialName("catch_up") val catchUp: String = "",
@SerialName("grace_minutes") val graceMinutes: Int? = null,
val model: String? = null,
@@ -139,7 +139,7 @@ class ChatsViewModel(app: Application) : AndroidViewModel(app) {
// Folders are a side dish: the chats show without them if they cannot be read.
val folders = runCatching { api.folders() }.getOrDefault(_state.value.folders)
// So is the count of unread reports: an instance before Reports simply has none.
val unread = runCatching { api.reports(unread = true).size }.getOrDefault(0)
val unread = runCatching { api.unreadReports() }.getOrDefault(0)
_state.value = ChatsState(chats = page.chats, more = page.more, folders = folders, unreadReports = unread)
} catch (e: Exception) {
_state.update { it.copy(loading = false, error = getApplication<Application>().explain(e)) }
@@ -357,8 +357,11 @@ fun ReportScreen(id: String, onBack: () -> Unit, onReply: (chat: String, title:
}
/** What Share hands over: the title, then the report as text -- a page in it as its one line, never its source. */
fun shareText(report: Report): String =
listOf(report.title, pageProjection(report.body.orEmpty(), untitled = "Page")).filter { it.isNotBlank() }.joinToString("\n\n")
fun shareText(report: Report): String {
// The server's own text of the body where it sends one; else the same made here.
val text = report.text?.trim()?.ifBlank { null } ?: pageProjection(report.body.orEmpty(), untitled = "Page")
return listOf(report.title, text).filter { it.isNotBlank() }.joinToString("\n\n")
}
/**
* A report, read as a page: its title, where it came from and when, then the body -- Markdown a
@@ -614,7 +614,12 @@ private fun notifyWords(schedule: Schedule): String? = when (schedule.notify) {
"always" -> stringResource(R.string.notify_always)
// "When…" with the person's own words (spec 3.8.0); a server before it said "matters".
"when" -> stringResource(R.string.notify_when_words, schedule.notifyWhen.ifBlank { stringResource(R.string.notify_when_default) })
"when" -> stringResource(
R.string.notify_when_words,
schedule.notifyWhen.ifBlank {
schedule.notifyDefault.ifBlank { stringResource(R.string.notify_when_default) }
},
)
"matters" -> stringResource(R.string.notify_matters)
@@ -797,6 +802,8 @@ data class EditState(
val notifyWhen: String = "",
/** Whether the instance has Reports (LLeMbas 2.0.0-beta.12): an older one is neither shown nor sent "notify when". */
val reports: Boolean = false,
/** The server's default condition in the account's language, when it said one. */
val notifyDefault: String = "",
)
class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
@@ -819,7 +826,16 @@ class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
if (id == null) return
viewModelScope.launch {
runCatching { getApplication<Application>().api().schedule(id) }.onSuccess { s ->
_state.update { it.copy(words = s.request.ifBlank { s.instruction }, notify = notifyChoice(s.notify), notifyWhen = s.notifyWhen) }
_state.update {
it.copy(
words = s.request.ifBlank {
s.instruction
},
notify = notifyChoice(s.notify),
notifyWhen = s.notifyWhen,
notifyDefault = s.notifyDefault,
)
}
}
}
}
@@ -947,7 +963,7 @@ fun ScheduleEditContent(
if (state.unsupported) Text(stringResource(R.string.scheduled_unsupported), color = palette.inkMuted)
state.error?.let { Text(it, color = palette.danger, style = MaterialTheme.typography.bodyMedium) }
state.compiled?.let { Understood(it) }
if (state.reports) NotifyWhen(state.notify, state.notifyWhen, onNotify, onNotifyWhen)
if (state.reports) NotifyWhen(state.notify, state.notifyWhen, state.notifyDefault, onNotify, onNotifyWhen)
Spacer(Modifier.height(24.dp))
}
}
@@ -959,7 +975,7 @@ fun ScheduleEditContent(
* task's history. "When…" opens a field with the default already in it.
*/
@Composable
private fun NotifyWhen(notify: String, words: String, onNotify: (String) -> Unit, onWords: (String) -> Unit) {
private fun NotifyWhen(notify: String, words: String, default: String, onNotify: (String) -> Unit, onWords: (String) -> Unit) {
val palette = LocalPalette.current
val choices = listOf(
Triple("always", R.string.notify_every_run, R.string.notify_every_run_line),
@@ -986,7 +1002,7 @@ private fun NotifyWhen(notify: String, words: String, onNotify: (String) -> Unit
}
}
if (value == "when" && notify == "when") {
val usual = stringResource(R.string.notify_when_default)
val usual = default.ifBlank { stringResource(R.string.notify_when_default) }
OutlinedTextField(
value = words.ifEmpty { usual },
onValueChange = onWords,
@@ -0,0 +1,82 @@
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.ReportsFrame
import eu.llembas.android.api.RunResult
import eu.llembas.android.push.ReportNotice
import eu.llembas.android.push.ScheduledNotice
import eu.llembas.android.ui.Segment
import eu.llembas.android.ui.reports.shareText
import eu.llembas.android.ui.splitFences
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.jsonObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The server's reports contract (`contract/report*.json`, `push_report.json`,
* `event_reports.json`, written by its own serialisers): every file read with the app's models,
* and what the app makes of each.
*/
class ReportsContractTest {
private fun text(name: String): String = requireNotNull(javaClass.classLoader!!.getResource("$name.json")) { "contract/$name.json is missing" }.readText()
private fun <T> read(name: String, serializer: KSerializer<T>): T = LembasJson.decodeFromString(serializer, text(name))
@Test
fun theListAndTheCountOfTheUnread() {
val list = read("reports", ReportList.serializer())
val report = list.reports.single()
assertEquals("rep1", report.id)
assertEquals("Two cakes are unwrapped", report.title)
assertEquals("Two of the twelve cakes have lost their leaves.", report.summary)
assertTrue(report.high)
assertTrue(report.unread)
assertEquals("Waybread check", report.schedule?.title)
assertEquals("2026-01-02T03:04:05+00:00", report.created)
assertEquals(1, list.unreadCount)
// The same for the events frame, which carries the newest one too.
val frame = read("event_reports", ReportsFrame.serializer())
assertEquals(1, frame.unread)
assertEquals("rep1", frame.newest?.id)
}
@Test
fun oneReportIsWrappedAndItsPageIsACard() {
// `GET /reports/{id}` answers `{report: …}`: read as ApiClient.report reads it.
val report = LembasJson.decodeFromJsonElement(Report.serializer(), LembasJson.parseToJsonElement(text("report")).jsonObject.getValue("report"))
assertEquals("chat9", report.chatId)
assertEquals("gpt-oss", report.model)
// The body carries the page's source; the phone draws a card in its place, never the source.
val drawn = splitFences(report.body!!)
assertEquals(Segment.Page("Cakes"), drawn.last())
assertFalse(drawn.any { it is Segment.Code })
// Share takes the server's own text, where the page is its one line.
assertEquals("Two cakes are unwrapped\n\n## What\n\nTwo of the twelve cakes have lost their leaves.\n\n[page: Cakes]", shareText(report))
assertFalse(shareText(report).contains("10 wrapped"))
assertEquals("chat9", read("report_reply", ReportReply.serializer()).chatId)
}
@Test
fun theReportsPush() {
val payload = read("push_report", PushPayload.serializer())
val notice = ReportNotice.from(payload)!!
assertEquals("rep1", notice.reportId)
// The words are the notification's; the payload's top is the app's name and "New report".
assertEquals("Two cakes are unwrapped", notice.title)
assertEquals("Two of the twelve cakes have lost their leaves.", notice.summary)
assertTrue(notice.high)
assertEquals("LLeMbas", payload.title)
// It is not a scheduled result, though it names the schedule and the run.
assertNull(ScheduledNotice.from(payload))
// And the run that filed it says which report.
assertEquals("rep1", read("schedule_run", RunResult.serializer()).run.reportId)
}
}
@@ -51,7 +51,10 @@ class ScheduleContractTest {
assertEquals("2026-01-12T07:30:00+00:00", s.nextRun)
assertEquals(5, s.nextRuns.size)
assertEquals("fresh", s.mode)
assertEquals("matters", s.notify)
// Spec 3.8.0: when the person's own words hold -- none here, so the server's default.
assertEquals("when", s.notify)
assertEquals("", s.notifyWhen)
assertEquals("something needs my attention", s.notifyDefault)
assertEquals("one", s.catchUp)
assertNull(s.graceMinutes)
assertEquals("qwen", s.model)
@@ -80,6 +83,9 @@ class ScheduleContractTest {
assertEquals("msg2", run.messageId)
assertEquals("All the waybread is wrapped.", run.preview)
assertTrue(run.notified)
// The run filed a report, and left its line for the history.
assertEquals("rep1", run.reportId)
assertEquals("Filed a report: two cakes are unwrapped.", run.note)
}
@Test
@@ -87,7 +93,7 @@ class ScheduleContractTest {
assertWaybread(read("schedules", ScheduleList.serializer()).schedules.single())
assertWaybread(read("schedule", ScheduleEnvelope.serializer()).schedule)
val frame = read("event_schedules", SchedulesFrame.serializer())
assertEquals("8bee85746004dc19", frame.version)
assertEquals("d55e588277f6c90b", frame.version)
assertWaybread(frame.schedules.single())
}
@@ -226,9 +232,20 @@ class ScheduleContractTest {
@Test
fun theServersNotificationWordsAndRunAgain() {
// `push_schedule.json`: the task's name and first lines unlocked, Finished on the lock
// screen, Open and Run again with the owner's labels.
val done = ScheduledNotice.from(read("push_schedule", PushPayload.serializer()))!!
// What a server before 3.8.0 sent for a finished run (it sends a report's push now):
// the task's name and first lines unlocked, Finished on the lock screen, Open and Run
// again with the owner's labels. Such an instance is still talked to.
val done = ScheduledNotice.from(
LembasJson.decodeFromString(
PushPayload.serializer(),
"""{"schedule_id":"sched1","run_id":"run1","chat_id":"chat1","status":"ok","visibility":"private",
"actions":["open","run_again"],"ask":"",
"notification":{"title":"Waybread check","body":"All the waybread is wrapped.",
"public":{"title":"Waybread check","body":"Finished"},"actions":["open","run_again"],
"labels":{"open":"Open","run_again":"Run again"},"ask":""},
"title":"LLeMbas","body":"A scheduled task has finished.","url":"/scheduled/sched1?run=run1","kind":"schedule"}""",
),
)!!
assertEquals("Waybread check", done.title)
assertEquals("All the waybread is wrapped.", done.body)
assertEquals("Waybread check", done.publicTitle)
@@ -248,9 +265,10 @@ class ScheduleContractTest {
assertEquals("Failed", failed.publicBody)
assertEquals("run3", failed.runId)
// The run's own copy (the schedules frame) says the same.
// The run's own copy of its notification is the report's now: Open alone.
val run = read("schedule_run", RunResult.serializer()).run
assertEquals(listOf("open", "run_again"), run.notification!!.actions)
assertEquals(listOf("open"), run.notification!!.actions)
assertEquals("high", run.notification!!.importance)
}
@Test
+15
View File
@@ -0,0 +1,15 @@
{
"unread": 1,
"newest": {
"id": "rep1",
"title": "Two cakes are unwrapped",
"summary": "Two of the twelve cakes have lost their leaves.",
"importance": "high",
"schedule": {
"id": "sched1",
"title": "Waybread check"
},
"created": "2026-01-02T03:04:05+00:00",
"unread": true
}
}
+15 -11
View File
@@ -1,5 +1,5 @@
{
"version": "8bee85746004dc19",
"version": "d55e588277f6c90b",
"schedules": [
{
"id": "sched1",
@@ -32,7 +32,10 @@
],
"target": "chat",
"mode": "fresh",
"notify": "matters",
"notify": "when",
"notify_when": "",
"notify_default": "something needs my attention",
"save_file": false,
"catch_up": "one",
"grace_minutes": null,
"model": "qwen",
@@ -81,25 +84,26 @@
"chat_id": "chat1",
"message_id": "msg2",
"report_path": null,
"report": "rep1",
"note": "Filed a report: two cakes are unwrapped.",
"preview": "All the waybread is wrapped.",
"error": null,
"notified": true,
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "Waybread check",
"body": "Finished"
"title": "New report",
"body": ""
},
"actions": [
"open",
"run_again"
"open"
],
"labels": {
"open": "Open",
"run_again": "Run again"
"open": "Open"
},
"ask": ""
"ask": "",
"importance": "high"
},
"watch": null
},
+3 -3
View File
@@ -1,5 +1,5 @@
{
"ref": "v2.0.0-beta.11",
"commit": "cd9795363195e30232c70409d1cb21e100f94edc",
"sha256": "da264d17c7c4a11ef5774482df5e1eaab9c608078b8c2a151ab026d3d14a7298"
"ref": "ee74edc9f3bf81f50c5c6b14e448211ee502cfdc",
"commit": "ee74edc9f3bf81f50c5c6b14e448211ee502cfdc",
"sha256": "d19ab4ed34614c065bbd360fc88a59844292a9f791c3bdf97d2b59f6127f8770"
}
+29
View File
@@ -0,0 +1,29 @@
{
"report_id": "rep1",
"schedule_id": "sched1",
"run_id": "run1",
"visibility": "private",
"actions": [
"open"
],
"notification": {
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "New report",
"body": ""
},
"actions": [
"open"
],
"labels": {
"open": "Open"
},
"ask": "",
"importance": "high"
},
"title": "LLeMbas",
"body": "New report",
"url": "/reports/rep1",
"kind": "report"
}
-34
View File
@@ -1,34 +0,0 @@
{
"schedule_id": "sched1",
"run_id": "run1",
"chat_id": "chat1",
"status": "ok",
"visibility": "private",
"actions": [
"open",
"run_again"
],
"ask": "",
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"public": {
"title": "Waybread check",
"body": "Finished"
},
"actions": [
"open",
"run_again"
],
"labels": {
"open": "Open",
"run_again": "Run again"
},
"ask": ""
},
"pause_label": "Pause",
"title": "LLeMbas",
"body": "A scheduled task has finished.",
"url": "/scheduled/sched1?run=run1",
"kind": "schedule"
}
+24
View File
@@ -0,0 +1,24 @@
{
"report": {
"id": "rep1",
"title": "Two cakes are unwrapped",
"summary": "Two of the twelve cakes have lost their leaves.",
"importance": "high",
"schedule": {
"id": "sched1",
"title": "Waybread check"
},
"created": "2026-01-02T03:04:05+00:00",
"unread": true,
"body": "## What\n\nTwo of the twelve cakes have lost their leaves.\n\n```html-view Cakes\n<p>10 wrapped, 2 not</p>\n```\n",
"text": "## What\n\nTwo of the twelve cakes have lost their leaves.\n\n[page: Cakes]\n",
"pages": [
{
"title": "Cakes",
"digest": "526b3a6b58f09769d9f81f628942cc7f"
}
],
"model": "gpt-oss",
"chat": "chat9"
}
}
+3
View File
@@ -0,0 +1,3 @@
{
"chat": "chat9"
}
+17
View File
@@ -0,0 +1,17 @@
{
"reports": [
{
"id": "rep1",
"title": "Two cakes are unwrapped",
"summary": "Two of the twelve cakes have lost their leaves.",
"importance": "high",
"schedule": {
"id": "sched1",
"title": "Waybread check"
},
"created": "2026-01-02T03:04:05+00:00",
"unread": true
}
],
"unread": 1
}
+14 -10
View File
@@ -30,7 +30,10 @@
],
"target": "chat",
"mode": "fresh",
"notify": "matters",
"notify": "when",
"notify_when": "",
"notify_default": "something needs my attention",
"save_file": false,
"catch_up": "one",
"grace_minutes": null,
"model": "qwen",
@@ -79,25 +82,26 @@
"chat_id": "chat1",
"message_id": "msg2",
"report_path": null,
"report": "rep1",
"note": "Filed a report: two cakes are unwrapped.",
"preview": "All the waybread is wrapped.",
"error": null,
"notified": true,
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "Waybread check",
"body": "Finished"
"title": "New report",
"body": ""
},
"actions": [
"open",
"run_again"
"open"
],
"labels": {
"open": "Open",
"run_again": "Run again"
"open": "Open"
},
"ask": ""
"ask": "",
"importance": "high"
},
"watch": null
},
+6 -1
View File
@@ -16,7 +16,10 @@
"next_runs": [],
"target": "chat",
"mode": "fresh",
"notify": "matters",
"notify": "when",
"notify_when": "",
"notify_default": "something needs my attention",
"save_file": false,
"catch_up": "one",
"grace_minutes": null,
"model": null,
@@ -83,6 +86,8 @@
"chat_id": null,
"message_id": null,
"report_path": null,
"report": null,
"note": "",
"preview": "",
"error": {
"class": "device_away",
+10 -9
View File
@@ -26,25 +26,26 @@
"chat_id": "chat1",
"message_id": "msg2",
"report_path": null,
"report": "rep1",
"note": "Filed a report: two cakes are unwrapped.",
"preview": "All the waybread is wrapped.",
"error": null,
"notified": true,
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "Waybread check",
"body": "Finished"
"title": "New report",
"body": ""
},
"actions": [
"open",
"run_again"
"open"
],
"labels": {
"open": "Open",
"run_again": "Run again"
"open": "Open"
},
"ask": ""
"ask": "",
"importance": "high"
},
"watch": null
},
+12 -9
View File
@@ -32,6 +32,8 @@
"chat_id": null,
"message_id": null,
"report_path": null,
"report": null,
"note": "",
"preview": "",
"error": {
"class": "no_model",
@@ -68,25 +70,26 @@
"chat_id": "chat1",
"message_id": "msg2",
"report_path": null,
"report": "rep1",
"note": "Filed a report: two cakes are unwrapped.",
"preview": "All the waybread is wrapped.",
"error": null,
"notified": true,
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "Waybread check",
"body": "Finished"
"title": "New report",
"body": ""
},
"actions": [
"open",
"run_again"
"open"
],
"labels": {
"open": "Open",
"run_again": "Run again"
"open": "Open"
},
"ask": ""
"ask": "",
"importance": "high"
},
"watch": null
}
+6 -1
View File
@@ -16,7 +16,10 @@
"next_runs": [],
"target": "chat",
"mode": "fresh",
"notify": "matters",
"notify": "when",
"notify_when": "",
"notify_default": "something needs my attention",
"save_file": false,
"catch_up": "one",
"grace_minutes": null,
"model": null,
@@ -70,6 +73,8 @@
"chat_id": null,
"message_id": null,
"report_path": null,
"report": null,
"note": "",
"preview": "",
"error": null,
"notified": false,
+14 -10
View File
@@ -31,7 +31,10 @@
],
"target": "chat",
"mode": "fresh",
"notify": "matters",
"notify": "when",
"notify_when": "",
"notify_default": "something needs my attention",
"save_file": false,
"catch_up": "one",
"grace_minutes": null,
"model": "qwen",
@@ -80,25 +83,26 @@
"chat_id": "chat1",
"message_id": "msg2",
"report_path": null,
"report": "rep1",
"note": "Filed a report: two cakes are unwrapped.",
"preview": "All the waybread is wrapped.",
"error": null,
"notified": true,
"notification": {
"title": "Waybread check",
"body": "All the waybread is wrapped.",
"title": "Two cakes are unwrapped",
"body": "Two of the twelve cakes have lost their leaves.",
"public": {
"title": "Waybread check",
"body": "Finished"
"title": "New report",
"body": ""
},
"actions": [
"open",
"run_again"
"open"
],
"labels": {
"open": "Open",
"run_again": "Run again"
"open": "Open"
},
"ask": ""
"ask": "",
"importance": "high"
},
"watch": null
},