A report's push: its words are in the payload's notification
CI / check (push) Canceled after 0s

The payload's top says only the app's name and "New report"; the title,
the summary and the importance are read from its notification, and from
the top only where there is none.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-13 09:56:15 +00:00
1 parent adc1c4fe3e
commit dcd5adf491
3 files changed
+26 -1

No files matched your search

@@ -215,6 +215,8 @@ data class RunNotification(
val actions: List<String> = emptyList(),
val labels: Map<String, String> = emptyMap(),
val ask: String = "",
/** A report's notification: `normal` or `high`. */
val importance: String = "",
)
/**
@@ -19,7 +19,16 @@ data class ReportNotice(val reportId: String, val title: String, val summary: St
fun from(payload: PushPayload): ReportNotice? {
if (payload.kind != KIND) return null
val id = payload.reportId?.takeIf { it.isNotBlank() } ?: fromUrl(payload.url) ?: return null
return ReportNotice(id, payload.title, payload.body, high = payload.importance == "high")
// The report's own words are in the payload's `notification` (the payload's top is
// what an older client would show: the app's name and "New report"). A payload
// without one is read by its top.
val words = payload.notification
return ReportNotice(
reportId = id,
title = words?.title ?: payload.title,
summary = words?.body ?: payload.body,
high = (words?.importance?.ifBlank { null } ?: payload.importance) == "high",
)
}
/** `/reports/{id}` → the id; null for anything else. */
@@ -118,6 +118,20 @@ class ReportsTest {
assertNull(ScheduledNotice.from(payload))
}
@Test
fun theReportsWordsComeFromThePayloadsNotification() {
// The payload's top is for a client that knows nothing of reports; the words are inside.
val payload = LembasJson.decodeFromString(
PushPayload.serializer(),
"""{"kind":"report","report_id":"rep1","title":"LLeMbas","body":"New report","url":"/reports/rep1",
"notification":{"title":"Two tenders opened","body":"Storage bids are due in May.","public":{"title":"New report","body":""},"importance":"high"}}""",
)
val notice = ReportNotice.from(payload)!!
assertEquals("Two tenders opened", notice.title)
assertEquals("Storage bids are due in May.", notice.summary)
assertTrue(notice.high)
}
@Test
fun anOlderServersScheduledPushStillWorks() {
// 2.0.0-beta.11 and before: a run's result is its own push, which opens the run.