Contract at server dev 9ab0818: spec 3.7.0 from the server -- end, ms, always, the builds
CI / check (push) Canceled after 0s

- Pinned: 75 files, with the spec's display.json (DisplayTest runs its
  duration and end cases) and progress.json's budget stop.
- Not additive: a call's chips no longer carry "exit 0", and an edit's are
  one "+N -M" (the app draws chips only, so nothing is said twice);
  block.title follows the spec's key order.
- A message's `end {phase, reason, text}` is what a stopped or failed reply
  is drawn from, so a reloaded one says "Stopped: by you" too; the app
  writes the line in its own language from the phase and the reason.
- A call's time is block.duration (the server's), else made from `ms`;
  its state is block.state; a call without a title shows block.label.
- "Always allow" only when every item of the approval has `always`.
- The notifications build's updater takes its file from latest.json, else
  from GET /apps' `notifications {url, sha256}` of the same version.
- ApiClient.mentions and attachFrom with their models and fixtures; the
  composer does not use them yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-12 12:33:47 +00:00
1 parent d30b74e1a4
commit 694e7f46d7
38 files changed
+1343 -48

No files matched your search

@@ -3,6 +3,8 @@ package eu.llembas.android
import eu.llembas.android.api.APP_API
import eu.llembas.android.api.AgentSubagents
import eu.llembas.android.api.AskFrame
import eu.llembas.android.api.AttachmentEnvelope
import eu.llembas.android.api.CardItem
import eu.llembas.android.api.CardSubagent
import eu.llembas.android.api.Chat
import eu.llembas.android.api.ChatPage
@@ -17,10 +19,12 @@ import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Me
import eu.llembas.android.api.MemoryEnvelope
import eu.llembas.android.api.MemoryList
import eu.llembas.android.api.Mentions
import eu.llembas.android.api.Message
import eu.llembas.android.api.Metrics
import eu.llembas.android.api.ModelList
import eu.llembas.android.api.Plan
import eu.llembas.android.api.ProgressWords
import eu.llembas.android.api.SearchResults
import eu.llembas.android.api.StatusFrame
import eu.llembas.android.api.SteeredFrame
@@ -31,8 +35,14 @@ import eu.llembas.android.api.TitleFrame
import eu.llembas.android.api.ToolCall
import eu.llembas.android.api.TreeFrame
import eu.llembas.android.api.TreeView
import eu.llembas.android.api.callDuration
import eu.llembas.android.api.ending
import eu.llembas.android.api.progressText
import eu.llembas.android.api.state
import eu.llembas.android.api.took
import eu.llembas.android.ui.chat.ChatState
import eu.llembas.android.ui.chat.approvalTexts
import eu.llembas.android.ui.chat.offersAlways
import eu.llembas.android.ui.chat.offersTeam
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
@@ -43,6 +53,7 @@ import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.Locale
/**
* The server's contract, as pinned in `contract/` by `scripts/fetch-contract.py`: every shape
@@ -190,7 +201,18 @@ class ContractTest {
val call = reply.steps[2].calls.single()
assertEquals("shell", call.block.kind)
assertEquals("bake --slow", call.block.title)
assertEquals(listOf("exit 0"), call.block.chips)
// Spec 3.7.0: an exit code is a fact only when it is not 0; the call says its state, how
// long it took and what its tool is called.
assertTrue(call.block.chips.isEmpty())
assertEquals("done", call.block.state)
assertEquals("done", call.state())
assertEquals(2412L, call.ms)
assertEquals("2.4s", call.block.duration)
assertEquals("2.4s", call.took())
assertEquals("2.4s", callDuration("done", call.ms))
assertEquals("Bash", call.block.label)
assertNull(reply.end)
assertNull(reply.ending())
assertEquals("and add honey", reply.steps[3].messages.single().text)
assertEquals(40, reply.metrics!!.completionTokens)
}
@@ -316,6 +338,47 @@ class ContractTest {
assertEquals("Waybread", read("event_done", DoneFrame.serializer()).chat.title)
}
@Test
fun aStoredReplySaysHowItEnded() {
val words = ProgressWords { key, args ->
mapOf("stopped_reason" to "Stopped: %s", "stopped_reason_person" to "by you", "failed" to "Failed: %s")[key]?.format(*args)
}
val stopped = read("message_stopped", Message.serializer())
assertEquals("person", stopped.end!!.reason)
// The app's own words, from the phase and the reason, say what the server's line says.
assertEquals(stopped.end!!.text, progressText(stopped.ending()!!, words, 0, Locale.ROOT))
val failed = read("message_failed", Message.serializer())
assertEquals("failed", failed.ending()!!.phase)
assertEquals(failed.end!!.text, progressText(failed.ending()!!, words, 0, Locale.ROOT))
}
@Test
fun alwaysAllowIsOfferedOnlyWhereTheRequestOffersIt() {
val cards = read("event_ask", AskFrame.serializer()).cards
val approvals = cards.filter { it.kind == "approval" }
assertEquals(listOf(true, true), approvals.map { offersAlways(it) })
val once = approvals[0].copy(items = approvals[0].items.map { it.copy(always = false) })
assertFalse(offersAlways(once))
// An older server says nothing of it, and offered it always.
assertTrue(LembasJson.decodeFromString(CardItem.serializer(), """{"key":"0","kind":"approval"}""").always)
}
@Test
fun whatAtOffersAndWhatAttachingItGives() {
val items = read("mentions", Mentions.serializer()).items
assertEquals(listOf("file", "attachment"), items.map { it.kind })
assertEquals("/home/frodo/bread.md", items[0].path)
assertEquals("att1", items[1].id)
assertEquals("https://example.org/waybread", read("mentions_url", Mentions.serializer()).items.single().url)
assertEquals("bread.md", read("attachment_from", AttachmentEnvelope.serializer()).attachment.name)
}
@Test
fun aRunningCallComesWithTheTail() {
// The tail's `calls` are not drawn yet (the steps are); the frame must still parse.
assertEquals("Done. *Wrap", read("event_tail", Tail.serializer()).text)
}
@Test
fun doneIsTheEndAndTheChatsNameMayFollow() {
// A new chat's first reply: saved and done at once, under the name made from the prompt.
@@ -8,7 +8,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.end
import eu.llembas.android.api.ending
import eu.llembas.android.api.localeNumber
import eu.llembas.android.api.progressLine
import eu.llembas.android.api.progressText
@@ -84,7 +84,7 @@ class DisplayTest {
private fun reply(stopped: Boolean = false, error: String? = null, progress: Progress? = null) =
Message(id = "m", role = "assistant", stopped = stopped, error = error, progress = progress)
private fun line(message: Message): String? = message.end()?.let { progressText(it, english, 0, Locale.ROOT) }
private fun line(message: Message): String? = message.ending()?.let { progressText(it, english, 0, Locale.ROOT) }
@Test
fun aReplyThatDidNotFinishKeepsItsLine() {
@@ -96,9 +96,9 @@ class DisplayTest {
// An error: its first line is the reason, and the line is the spec's, not the raw text.
assertEquals("Failed: 502 Bad Gateway", line(reply(error = "502 Bad Gateway\n at upstream")))
// A reply that finished shows nothing; nor does a user's message, or one that is only queued.
assertNull(reply().end())
assertNull(Message(id = "u", role = "user", stopped = true).end())
assertNull(reply(progress = Progress(phase = "queued", ahead = 1)).end())
assertNull(reply().ending())
assertNull(Message(id = "u", role = "user", stopped = true).ending())
assertNull(reply(progress = Progress(phase = "queued", ahead = 1)).ending())
}
@Test
@@ -115,7 +115,7 @@ class DisplayTest {
assertNull(ended.progress)
assertEquals("Stopped: by you", line(ended.finished!!))
// A reply that finished after all keeps nothing of an earlier stop.
assertNull(live.apply("done", doneWith { }).finished!!.end())
assertNull(live.apply("done", doneWith { }).finished!!.ending())
// The phase moved on before the end (a retry that then worked): no end is remembered.
val moved = live.apply("status", """{"text": "Writing", "progress": {"phase": "writing", "since": 1}}""")
assertNull(moved.end)
@@ -176,7 +176,7 @@ class DisplayTest {
val progress = case.getValue("progress").let { if (it is JsonNull) null else LembasJson.decodeFromJsonElement(Progress.serializer(), it) }
val want = expect.getValue("line").let { if (it is JsonNull) null else it.jsonPrimitive.content }
val message = Message(id = "m", role = "assistant", progress = progress)
assertEquals(about, want, message.end()?.let { progressLine(it, english, case.getValue("now").jsonPrimitive.long, Locale.ROOT) })
assertEquals(about, want, message.ending()?.let { progressLine(it, english, case.getValue("now").jsonPrimitive.long, Locale.ROOT) })
}
}
}
@@ -46,7 +46,7 @@ class ProgressTest {
@Test
fun everyConformanceCase() {
assertEquals(25, cases.size)
assertEquals(26, cases.size)
for (case in cases) {
val progress = LembasJson.decodeFromJsonElement(Progress.serializer(), case.getValue("progress"))
val now = case.getValue("now").jsonPrimitive.long
@@ -1,5 +1,8 @@
package eu.llembas.android
import eu.llembas.android.api.AppBuild
import eu.llembas.android.api.AppRelease
import eu.llembas.android.api.AppsInfo
import eu.llembas.android.api.LembasJson
import eu.llembas.android.assist.AssistController
import eu.llembas.android.assist.Recorder
@@ -35,6 +38,26 @@ class SmallThingsTest {
assertEquals(LatestFile("https://example.org/a.apk", "aa"), both.fileFor(notificationsBuild = false))
}
@Test
fun theInstanceMayNameTheNotificationsBuildOfTheSameRelease() {
val plain = Latest(version = "1.0.0", url = "https://example.org/a.apk", sha256 = "aa")
val build = AppBuild("https://example.org/a-notifications.apk", "bb")
val same = AppRelease(version = "1.0.0", notifications = build)
assertEquals(LatestFile(build.url, build.sha256), plain.fileFor(notificationsBuild = true, recommended = same))
// Another version, no address worth trusting, or nothing known: it installs nothing itself.
assertNull(plain.fileFor(notificationsBuild = true, recommended = same.copy(version = "1.0.1")))
assertNull(plain.fileFor(notificationsBuild = true, recommended = same.copy(notifications = build.copy(url = "http://example.org/a.apk"))))
assertNull(plain.fileFor(notificationsBuild = true, recommended = null))
// The standard build never takes it.
assertEquals(LatestFile("https://example.org/a.apk", "aa"), plain.fileFor(notificationsBuild = false, recommended = same))
val apps = LembasJson.decodeFromString(
AppsInfo.serializer(),
"""{"apps":{"android":{"version":"1.0.0","notifications":{"url":"https://example.org/n.apk","sha256":"cc"},"fdroid":{"url":"https://example.org/f.apk","sha256":"dd"}}}}""",
)
assertEquals("cc", apps.android!!.notifications!!.sha256)
assertEquals("dd", apps.android!!.fdroid!!.sha256)
}
@Test
fun aVoiceReadsNoMarkup() {
val said = AssistController.plain("**Bake** it.\n\n```sh\nbake\n```\nSee [the recipe](https://example.org).")