Progress (harness spec 3.4.0): one line for what a reply is doing
CI / check (push) Canceled after 0s

The `status` frame carries `progress` {phase, since, ...} beside its
text from spec 3.4.0 (progress.md). The app draws it as
`{{text}} · {{elapsed}}` -- the shared texts as string resources, the
elapsed time ticking each second, `retrying`'s `in` counted down, the
text alone for stopped and failed -- under the reply and in the
assistant's sheet, and falls back to the free `status` text for a server
that does not send it, a phase it does not know, or a required field
missing. Under inspection the clock stands still (65 s), so screenshots
are stable and nothing animates forever.

Coded to the spec while the server's frame is being added. ProgressTest
runs the spec's own conformance cases (conformance/progress.json, copied
from LLeMbas CLI 3.4.0 until the server vendors it) against the English
in res/values; fetch-contract.py pins the server's copy as
contract/harness_progress.json once it is there. gen-strings.py takes
the server's translations of the `{{field}}` texts (its catalogues key
them by the spec's English), numbering the fields and doubling a lone %.
Screenshots: 04-writing with a rate, 04-waiting-for-model at 360 dp and
1.5x type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 09:05:41 +00:00
1 parent afbe90442e
commit 23e3c5431a
23 files changed
+821 -15

No files matched your search

@@ -0,0 +1,98 @@
package eu.llembas.android
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Progress
import eu.llembas.android.api.ProgressWords
import eu.llembas.android.api.elapsed
import eu.llembas.android.api.progressLine
import eu.llembas.android.api.progressText
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.long
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import java.io.File
import java.util.Locale
/**
* The progress line (harness spec 3.4.0, `progress.md`): the spec's own conformance cases
* (`conformance/progress.json`, the file every client and the server test against), drawn with
* the app's English strings as `res/values/strings.xml` has them -- so a string that drifted
* from `loop.json`'s `progress.texts` fails here too.
*/
class ProgressTest {
/** The app's English, read from the generated resources, formatted as Android formats it. */
private val english: ProgressWords by lazy {
val xml = File("src/main/res/values/strings.xml").readText()
val strings = Regex("""<string name="progress_([a-z_]+)">(.*?)</string>""").findAll(xml)
.associate { it.groupValues[1] to it.groupValues[2].replace("\\'", "'").replace("&amp;", "&") }
val keys = mapOf("stopped_reason_person" to "stopped_person", "stopped_reason_steps" to "stopped_steps", "stopped_reason_budget" to "stopped_budget")
ProgressWords { key, args -> strings[keys[key] ?: key]?.let { String.format(Locale.ROOT, it, *args) } }
}
private val cases: List<JsonObject> by lazy {
// The server's pinned copy (`contract/harness_progress.json`) once it vendors spec 3.4.0;
// until then the spec's own file, copied from LLeMbas CLI 3.4.0 into the test resources.
val loader = javaClass.classLoader!!
val text = requireNotNull(loader.getResource("harness_progress.json") ?: loader.getResource("progress_conformance.json")).readText()
LembasJson.parseToJsonElement(text).jsonObject.getValue("cases").jsonArray.map { it.jsonObject }
}
@Test
fun everyConformanceCase() {
assertEquals(25, cases.size)
for (case in cases) {
val progress = LembasJson.decodeFromJsonElement(Progress.serializer(), case.getValue("progress"))
val now = case.getValue("now").jsonPrimitive.long
val expect = case.getValue("expect").jsonObject
val about = case["about"]?.jsonPrimitive?.content
assertEquals(about, expect.getValue("text").jsonPrimitive.content, progressText(progress, english, now, Locale.ROOT))
assertEquals(about, expect.getValue("line").jsonPrimitive.content, progressLine(progress, english, now, Locale.ROOT))
}
}
@Test
fun aClockWritesDurations() {
assertEquals("0s", elapsed(-1500))
assertEquals("59s", elapsed(59_999))
assertEquals("1m 00s", elapsed(60_000))
assertEquals("59m 59s", elapsed(3_599_000))
assertEquals("1h 00m", elapsed(3_600_000))
assertEquals("26h 03m", elapsed(93_780_000))
}
@Test
fun aRateInThePersonsNumberFormat() {
val writing = Progress(phase = "writing", since = 0, rate = 12.46)
assertEquals("Writing: 12,5 tok/s", progressText(writing, english, 0, Locale.forLanguageTag("sk")))
}
@Test
fun aPhaseThisAppDoesNotKnowFallsBackToStatus() {
assertNull(progressLine(Progress(phase = "dreaming", since = 0), english, 0))
// A required field missing: no half sentence, the status text instead.
assertNull(progressLine(Progress(phase = "running_tool", since = 0), english, 0))
assertNull(progressLine(Progress(phase = "waiting_for_model", since = 0, model = "coder"), english, 0))
}
@Test
fun theStatusFrameCarriesProgress() {
val frame = """{"text": "Running bake --slow", "progress": {"phase": "running_tool", "since": 1762790400000, "tool": "bash", "what": "bake --slow"}}"""
val live = LiveReply("m").apply("status", frame)
assertEquals("Running bake --slow", live.status)
assertEquals("bake --slow", live.progress?.what)
// An older server's frame: the text alone, no progress.
val old = live.apply("status", """{"text": "Thinking"}""")
assertEquals("Thinking", old.status)
assertNull(old.progress)
// Idle: progress null.
assertNull(live.apply("status", """{"text": "", "progress": null}""").progress)
// The reply ends: neither is kept.
val done = LembasJson.parseToJsonElement(File("../contract/event_done.json").readText()).toString()
assertNull(live.apply("done", done).progress)
}
}
@@ -14,6 +14,7 @@ import eu.llembas.android.api.LiveReply
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.RunError
import eu.llembas.android.api.RunModel
import eu.llembas.android.api.RunResult
@@ -183,10 +184,21 @@ object Fakes {
/** The last reply while it is being written: its tools done, its words coming in. */
val writing = transcript.copy(
messages = listOf(question, answer, packing, packingAnswer.copy(steps = emptyList(), complete = false)),
live = LiveReply(messageId = "m4", steps = packingSteps.take(2), tail = Tail(text = "Here is a list for **three days**, light enough")),
live = LiveReply(
messageId = "m4",
steps = packingSteps.take(2),
tail = Tail(text = "Here is a list for **three days**, light enough"),
status = "Writing",
progress = Progress(phase = "writing", since = 1762790400000, rate = 12.46),
),
summary = null,
)
/** Waiting for a model, the long reason: the progress line at its widest. */
val waitingForModel = writing.copy(
live = writing.live!!.copy(progress = Progress(phase = "waiting_for_model", since = 1762790400000, model = "Qwen 27B", reason = "busy")),
)
/** A chat on a model with effort levels, a team and a plan: the tune sheet with everything. */
val tuned = transcript.copy(
chat = chat.copy(model = "gpt-oss", effort = "high", mode = "plan", agents = AgentsSetting(1, 4)),
@@ -88,7 +88,11 @@ class ScreenShots {
}
@Test
fun writing() = shoot("04-writing") { ChatContent(Fakes.writing, NoChatActions, agent = false) }
fun writing() {
// The 3.4.0 progress line under the reply: `{{text}} · {{elapsed}}`, the clock still.
shoot("04-writing") { ChatContent(Fakes.writing, NoChatActions, agent = false) }
shoot("04-waiting-for-model", Phone.Small, fontScale = 1.5f) { ChatContent(Fakes.waitingForModel, NoChatActions, agent = false) }
}
@Test
fun drawer() {