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

@@ -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