A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Android Widgets: guards for the state palette and the plan-usage palette
Claude0eef35d626c4
diff --git a/android/README.md b/android/README.mdindex 0e55cb15..7ed95932 100644--- a/android/README.md+++ b/android/README.md@@ -58,11 +58,11 @@ The desktop side is in `windows/src-tauri/src/phone_link`; the protocol is `docs- **Away from home Wi-Fi** (optional): through your own Cloudflare relay, end-to-end encrypted; the direct link is always tried first.- **Keeping the link alive with the screen off**: an alarm every few minutes checks that the computer still answers and reconnects if not (Doze allows nothing more); Home says when and why the link was lost; Settings > Computer > *Can't connect?* checks the network, address, discovery, certificate, pairing code and relay; a calm hint suggests the battery setting ("Unrestricted", with the Samsung steps) only if it would help. Details and limits: `docs/ANDROID_LINK.md`, "Keeping the link alive".- **Widget, quick-settings tile, ongoing notification**: agent names and state words only. Updated when something changes, never on a timer.-- **Widgets**: nine to pick from on the home screen, all on one card (24dp corners, a thin border, dark by default and light when the system is in day mode) with a gradient and a glow in the colour of the state: orange while something waits for you, blue while an agent works, green when it is done, muted when nothing runs or the computer is not there. In the Widget picker each one shows a large, realistic preview with sample data (Android 12 and later; Android 11 shows a still picture of the card with Mochi), its name and a one-line description. The previews are static: vector Mochi faces in `res/drawable/preview_*`, layouts in `res/layout/widget_preview_*`.+- **Widgets**: nine to pick from on the home screen, all on one card (24dp corners, a thin border, dark by default and light when the system is in day mode) with a gradient, a 1dp border and a glow in the colour of the state, the same palette for every Widget (`WidgetTone` in `core/WidgetData.kt`, `res/values/colors.xml`): green when an agent has finished, blue while it works, orange while something waits for you, soft grey when all is calm, and a muted grey with the "not connected" icon when the computer is not there. With several agents the most urgent one sets the colour (waiting, then working, then happy, then idle). Plan usage has a palette of its own so it never looks like a state: teal, yellow from 75% and red from 90% (`PlanUsageLook`); only from 90% is the percentage big and bold, with "Near limit" and when it resets. In the Widget picker each one shows a large, realistic preview with sample data (Android 12 and later; Android 11 shows a still picture of the card with Mochi), its name and a one-line description. The previews are static: vector Mochi faces in `res/drawable/preview_*`, layouts in `res/layout/widget_preview_*`.- *Agents summary* (3x2, the first Widget, same receiver as before): its text and counts are unchanged, now on the shared card with a small Mochi in the state of your most urgent agent, a headline with a badge for what waits for you and up to three short lines with a state dot each. A tap anywhere opens the app; it has no buttons.- *Mochi at a glance* (Solo, 2x2): Mochi in the state of your most urgent agent, its name and a state word.- *All your agents* (List, 4x3): one row of at least 48dp per agent (Mochi's face, name, state word, dot), up to five, with a badge for what waits for you; with no agent, a centred empty state ("Waiting for your computer" / "No agents running").- - *Mochi, big* (4x4): no speech bubble any more. On the left Mochi with his glow and badge, then the agent's name and state word; on the right your plan usage (Claude and Codex, each with a big percentage and a thin bar that is green, orange above 75% and red above 90%), or "Plan usage is off" (a tap opens Settings) or "Not connected". Under them rounded buttons: two rows of three (Home, Chat, Settings, Recent, Top agent, Pair again; tinted orange while something waits), one row of four when medium, none when small.+ - *Mochi, big* (4x4): no speech bubble any more. On the left Mochi with his glow and badge, then the agent's name and state word; on the right your plan usage (Claude and Codex, each with a thin bar that is teal, yellow from 75% and red from 90%, and a small percentage that becomes big and bold with "Near limit" from 90%), or "Plan usage is off" (a tap opens Settings) or "Not connected". Under them rounded buttons: two rows of three (Home, Chat, Settings, Recent, Top agent, Pair again; tinted orange while something waits), one row of four when medium, none when small.- *One-line status* (Status Pill, 4x1): one slim line with a dot, the agent's name and its state word, and four round buttons that open Home, Chat, Settings and Recent decisions. Narrower, the state word goes first, then the name; the text never runs under the buttons.- *Approvals waiting* (Waiting Alert, 2x2): calm when nothing waits, a bright orange "N waiting" when something does. A tap opens the app and the sheet rises by itself.- *Plan usage* (Usage Ring, 2x2): a ring for your Claude or Codex plan usage; "Turn on plan usage in the app" when it is off.diff --git a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.ktindex 58775c94..81bea6bc 100644--- a/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt+++ b/android/app/src/main/kotlin/com/coucou/android/core/WidgetData.kt@@ -194,7 +194,7 @@ data class WidgetContent(/*** The look of the whole widget. Not connected: muted. Something waits for you: orange. Otherwise the most urgent agent's tone, and- * the tiles are already in the order of [GlanceBuilder.rank] (waiting, then trouble, working, happy, idle): the top one decides.+ * the tiles are already in the order of [GlanceBuilder.rank] (waiting, then trouble, working, happy, idle): the top one sets the look.* Connected with nothing to list: idle grey.*/val look: WidgetTone get() = when {diff --git a/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.kt b/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.ktnew file mode 100644index 00000000..7e05da9c--- /dev/null+++ b/android/app/src/test/kotlin/com/coucou/android/PlanUsageLookTest.kt@@ -0,0 +1,123 @@+package com.coucou.android++import com.coucou.android.core.PlanUsageLook+import com.coucou.android.core.UsageRing+import com.coucou.android.core.UsageTone+import java.io.File+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertNull+import org.junit.Assert.assertTrue+import org.junit.Test++/** One function decides how plan usage looks: its colour, whether it is shown prominently, and the "Near limit" line. */+class PlanUsageLookTest {+ private val now = 10_000_000L+ private fun inMinutes(m: Long) = now + m * 60_000++ @Test fun theThresholdsAreNamedConstants() {+ assertEquals(75, PlanUsageLook.CLOSE_FROM)+ assertEquals(90, PlanUsageLook.LIMIT_FROM)+ val src = File("src/main/kotlin/com/coucou/android/core/WidgetData.kt").readText()+ assertTrue(src.contains("const val CLOSE_FROM = 75") && src.contains("const val LIMIT_FROM = 90"))+ }++ @Test fun tealUnderSeventyFiveYellowFromSeventyFiveRedFromNinety() {+ for (p in listOf(0, 1, 50, 73, 74)) assertEquals("$p%", UsageTone.CALM, PlanUsageLook.tone(p))+ for (p in listOf(75, 76, 80, 89)) assertEquals("$p%", UsageTone.CLOSE, PlanUsageLook.tone(p))+ for (p in listOf(90, 91, 95, 100)) assertEquals("$p%", UsageTone.LIMIT, PlanUsageLook.tone(p))+ }++ @Test fun theExactBoundariesOfTheBrief() {+ assertEquals(UsageTone.CALM, PlanUsageLook.tone(74))+ assertEquals(UsageTone.CLOSE, PlanUsageLook.tone(75))+ assertEquals(UsageTone.CLOSE, PlanUsageLook.tone(89))+ assertEquals(UsageTone.LIMIT, PlanUsageLook.tone(90))+ assertEquals(UsageTone.LIMIT, PlanUsageLook.tone(100))+ }++ @Test fun valuesOutsideZeroToHundredAreClamped() {+ assertEquals(100, PlanUsageLook.clamp(140))+ assertEquals(100, PlanUsageLook.clamp(101))+ assertEquals(100, PlanUsageLook.clamp(Int.MAX_VALUE))+ assertEquals(0, PlanUsageLook.clamp(-1))+ assertEquals(0, PlanUsageLook.clamp(Int.MIN_VALUE))+ assertEquals(UsageTone.LIMIT, PlanUsageLook.tone(250))+ assertEquals(UsageTone.CALM, PlanUsageLook.tone(-40))+ val over = UsageRing("Claude", "5 h", 140)+ assertEquals(100, over.shown)+ assertEquals(1f, over.fraction, 0f)+ assertEquals(UsageTone.LIMIT, over.tone)+ }++ @Test fun onlyFromTheRedLineTheRateIsProminent() {+ for (p in listOf(0, 50, 74, 75, 89)) assertFalse("$p%", PlanUsageLook.nearLimit(p))+ for (p in listOf(90, 91, 100, 140)) assertTrue("$p%", PlanUsageLook.nearLimit(p))+ assertFalse(UsageRing("Claude", "5 h", 89).nearLimit)+ assertTrue(UsageRing("Claude", "5 h", 90).nearLimit)+ }++ @Test fun belowTheRedLineThereIsNoWarningLine() {+ for (p in listOf(0, 42, 74, 75, 89)) assertNull("$p%", PlanUsageLook.note(p, inMinutes(120), now))+ }++ @Test fun fromTheRedLineItSaysNearLimitAndWhenItResets() {+ assertEquals("Near limit · resets in 2 h", PlanUsageLook.note(90, inMinutes(120), now))+ assertEquals("Near limit · resets in 2 h", PlanUsageLook.note(100, inMinutes(125), now))+ assertEquals("Near limit · resets in 40 min", PlanUsageLook.note(95, inMinutes(40), now))+ assertEquals("Near limit · resets in 3 d", PlanUsageLook.note(93, inMinutes(3 * 24 * 60), now))+ }++ @Test fun withoutAResetTimeItJustSaysNearLimit() {+ assertEquals("Near limit", PlanUsageLook.note(95, 0L, now))+ assertEquals("a reset time in the past is no reset time", "Near limit", PlanUsageLook.note(95, now - 1, now))+ }++ @Test fun theResetLineReadsInTheRightUnit() {+ assertEquals("resets in 1 min", PlanUsageLook.resetLine(now + 1_000, now))+ assertEquals("resets in 59 min", PlanUsageLook.resetLine(inMinutes(59), now))+ assertEquals("resets in 1 h", PlanUsageLook.resetLine(inMinutes(60), now))+ assertEquals("resets in 47 h", PlanUsageLook.resetLine(inMinutes(47 * 60 + 59), now))+ assertEquals("resets in 2 d", PlanUsageLook.resetLine(inMinutes(48 * 60), now))+ assertNull(PlanUsageLook.resetLine(0L, now))+ assertNull(PlanUsageLook.resetLine(now, now))+ }++ @Test fun theRingAndTheTextComeFromTheSameFunction() {+ for (p in listOf(0, 74, 75, 89, 90, 100, 140)) {+ val row = UsageRing("Claude", "5 h", p, PlanUsageLook.note(p, inMinutes(120), now))+ assertEquals(PlanUsageLook.tone(p), row.tone)+ assertEquals(PlanUsageLook.nearLimit(p), row.nearLimit)+ assertEquals("a note exactly when it is near the limit: $p%", row.nearLimit, row.note != null)+ }+ }++ // ── Its own palette ─────────────────────────────────────────────────────────────────────────────++ private val dark = Regex("""<color name="(\w+)">#([0-9A-Fa-f]{8})</color>""").findAll(File("src/main/res/values/colors.xml").readText()).associate { it.groupValues[1] to it.groupValues[2] }+ private fun hex(t: UsageTone) = t.argb.toUInt().toString(16).uppercase().padStart(8, '0')++ @Test fun theResourcesCarryTheSameUsagePalette() {+ for (t in UsageTone.values()) {+ val k = t.name.lowercase()+ assertEquals(k, hex(t), dark.getValue("widget_usage_$k").uppercase())+ assertEquals("tint $k", hex(t).substring(2), dark.getValue("widget_tint_usage_$k").substring(2).uppercase())+ assertEquals("border $k", "99" + hex(t).substring(2), dark.getValue("widget_border_usage_$k").uppercase())+ assertTrue("a card and a tint for $k", File("src/main/res/drawable/widget_card_usage_$k.xml").exists() && File("src/main/res/drawable/widget_tint_usage_$k.xml").exists())+ }+ }++ @Test fun theUsagePaletteNeverLooksLikeAState() {+ fun rgb(argb: Int) = intArrayOf((argb shr 16) and 255, (argb shr 8) and 255, argb and 255)+ fun dist(a: IntArray, b: IntArray) = Math.sqrt(a.indices.sumOf { ((a[it] - b[it]) * (a[it] - b[it])).toDouble() })+ for (u in UsageTone.values()) {+ for (s in com.coucou.android.core.WidgetTone.values()) {+ val d = dist(rgb(u.argb), rgb(s.argb))+ assertTrue("${u.name} is only ${d.toInt()} from ${s.name}", d >= 40.0)+ }+ }+ // And the three of them are clearly apart from each other, and the yellow is not the waiting orange.+ for (a in UsageTone.values()) for (b in UsageTone.values()) if (a != b) assertTrue("$a $b", dist(rgb(a.argb), rgb(b.argb)) >= 80.0)+ assertTrue(dist(rgb(UsageTone.CLOSE.argb), rgb(com.coucou.android.core.WidgetTone.ATTENTION.argb)) >= 40.0)+ }+}diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.ktindex 10ac6ee1..9ecc6c04 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt@@ -154,7 +154,7 @@ class WidgetButtonsTest {assertEquals(listOf("@+id/big_left", "@+id/big_right"), sides.map { it.getAttribute("android:id") })assertEquals("Mochi's side is about 45% of the width", listOf("45", "55"), sides.map { it.getAttribute("android:layout_weight") })val left = byId(root, "big_left").descendants().mapNotNull { it.getAttribute("android:id").takeIf { id -> id.isNotEmpty() } }- assertEquals(listOf("@+id/big_mochi", "@+id/big_row", "@+id/big_dot", "@+id/big_name", "@+id/big_state"), left)+ assertEquals(listOf("@+id/big_mochi", "@+id/big_row", "@+id/big_offline", "@+id/big_dot", "@+id/big_name", "@+id/big_state"), left)assertEquals("the badge stays in the top-right corner", "top|end", byId(root, "big_badge").getAttribute("android:layout_gravity"))}@@ -163,20 +163,30 @@ class WidgetButtonsTest {for (k in listOf("a", "b")) {val label = byId(root, "big_usage_${k}_label")val pct = byId(root, "big_usage_${k}_pct")+ val big = byId(root, "big_usage_${k}_pct_big")+ val note = byId(root, "big_usage_${k}_note")val bar = byId(root, "big_usage_${k}_bar")assertEquals("12sp label", "@dimen/widget_text_secondary", label.getAttribute("android:textSize"))- assertEquals("28sp bold percentage", "@dimen/widget_text_big", pct.getAttribute("android:textSize"))- assertEquals("bold", pct.getAttribute("android:textStyle"))+ // Under the red line: small and normal, no warning line. From the red line: big and bold, with the line under it.+ assertEquals("@dimen/widget_text_pct", pct.getAttribute("android:textSize"))+ assertTrue("the small percentage is not bold", pct.getAttribute("android:textStyle").isEmpty())+ assertEquals("@dimen/widget_text_pct_big", big.getAttribute("android:textSize"))+ assertEquals("bold", big.getAttribute("android:textStyle"))+ assertEquals("gone", big.getAttribute("android:visibility"))+ assertEquals("gone", note.getAttribute("android:visibility"))assertEquals("ImageView", bar.tagName)assertEquals("6dp", bar.getAttribute("android:layout_height"))}- assertEquals(28.0, dimens.getValue("widget_text_big"), 0.0)+ assertEquals(18.0, dimens.getValue("widget_text_pct"), 0.0)+ assertEquals(32.0, dimens.getValue("widget_text_pct_big"), 0.0)assertEquals(12.0, dimens.getValue("widget_text_secondary"), 0.0)+ assertFalse("the old 28sp bold percentage is gone", dimens.containsKey("widget_text_big"))// The code puts the percentage and a bar bitmap in each row, and Claude and Codex are the two rows.- assertTrue(bigSource.contains("""v.setTextViewText(pct, "${'$'}{row.pct}%")"""))+ assertTrue(bigSource.contains("""v.setTextViewText(if (near) r.pctBig else r.pct, "${'$'}{row.shown}%")"""))+ assertTrue(bigSource.contains("val near = row.nearLimit"))assertTrue(bigSource.contains("BarBitmap.of(row,"))assertTrue(bigSource.contains("R.id.big_usage_a_bar") && bigSource.contains("R.id.big_usage_b_bar"))- assertTrue(File(main + "app/BarBitmap.kt").readText().contains("row.barTone"))+ assertTrue(File(main + "app/BarBitmap.kt").readText().contains("row.tone"))}@Test fun thePlanUsageIsOffAndNotConnectedStatesExist() {diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.ktindex 8b2952ab..4b4fbf75 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetDataTest.kt@@ -123,7 +123,7 @@ class WidgetDataTest {assertEquals("3 waiting", build(listOf(s("agent_codex", BotState.QUESTION)), approvals = 2).alertLine)assertEquals("Not connected", build(emptyList(), link = LinkState.DISCONNECTED).alertLine)assertEquals(WidgetTone.ATTENTION, build(listOf(s("agent_codex", BotState.APPROVAL)), approvals = 1).look)- assertEquals(WidgetTone.MUTED, build(emptyList()).look)+ assertEquals("connected with nothing to list is calm", WidgetTone.IDLE, build(emptyList()).look)}private val now = 1_000_000L@@ -138,7 +138,7 @@ class WidgetDataTest {@Test fun theRingPrefersClaudesFiveHoursThenItsWeekThenCodex() {assertEquals(UsageRing("Claude", "5 h", 42), built(usage(claude5 = 42, claudeWeek = 10, codex5 = 90)).ring)assertEquals(UsageRing("Claude", "week", 10), built(usage(claudeWeek = 10, codex5 = 90)).ring)- assertEquals(UsageRing("Codex", "5 h", 90), built(usage(codex5 = 90)).ring)+ assertEquals(UsageRing("Codex", "5 h", 90, "Near limit · resets in 1 h"), built(usage(codex5 = 90)).ring)assertNull(built(usage()).ring)assertNull("the switch is off", built(null).ring)}@@ -148,13 +148,15 @@ class WidgetDataTest {assertNull(built(usage(claude5 = 42), LinkState.DISCONNECTED).ring)}- @Test fun theRingIsGreenThenOrangeThenRedLikeHome() {- assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 49).tone)- assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 50).tone)- assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 79).tone)- assertEquals(WidgetTone.TROUBLE, UsageRing("Claude", "5 h", 80).tone)+ @Test fun theRingIsTealThenYellowThenRedInItsOwnPalette() {+ assertEquals(com.coucou.android.core.UsageTone.CALM, UsageRing("Claude", "5 h", 49).tone)+ assertEquals(com.coucou.android.core.UsageTone.CALM, UsageRing("Claude", "5 h", 74).tone)+ assertEquals(com.coucou.android.core.UsageTone.CLOSE, UsageRing("Claude", "5 h", 75).tone)+ assertEquals(com.coucou.android.core.UsageTone.LIMIT, UsageRing("Claude", "5 h", 90).tone)assertEquals(0.42f, UsageRing("Claude", "5 h", 42).fraction, 0.0001f)assertEquals(1f, UsageRing("Claude", "5 h", 140).fraction, 0f)+ assertEquals(100, UsageRing("Claude", "5 h", 140).shown)+ assertEquals(0, UsageRing("Claude", "5 h", -3).shown)assertEquals(0f, UsageRing("Claude", "5 h", -3).fraction, 0f)assertEquals("Claude · 5 h", UsageRing("Claude", "5 h", 1).label)}diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetPaletteTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetPaletteTest.ktnew file mode 100644index 00000000..9c2b9095--- /dev/null+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetPaletteTest.kt@@ -0,0 +1,236 @@+package com.coucou.android++import com.coucou.android.core.GlanceBuilder+import com.coucou.android.core.UsageTone+import com.coucou.android.core.WidgetData+import com.coucou.android.core.WidgetTone+import com.coucou.android.link.LinkState+import com.coucou.android.link.SessionInfo+import com.coucou.android.mochi.BotState+import java.io.File+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++/** One palette for every Widget: the same state gives the same colour everywhere, nothing picks a colour of its own, and text stays readable. */+class WidgetPaletteTest {+ private val res = "src/main/res/"+ private val main = "src/main/kotlin/com/coucou/android/"+ private fun read(p: String) = File(p).readText()++ // ── One state, one colour, the most urgent agent wins ───────────────────────────────────────────++ private fun s(id: String, state: BotState) = SessionInfo(id, "", state, "", 0, 0, 0L)+ private fun look(link: LinkState, vararg states: BotState): WidgetTone {+ val sessions = states.mapIndexed { i, st -> s("p$i", st) }+ val g = GlanceBuilder.build(true, link, "PC", sessions, 0) { "x" }+ return WidgetData.build(g, sessions, { "x" }).look+ }++ @Test fun everyStateHasItsOneColour() {+ val expected = mapOf(+ BotState.FINISHED to WidgetTone.DONE,+ BotState.WORKING to WidgetTone.WORKING, BotState.THINKING to WidgetTone.WORKING, BotState.SEARCHING to WidgetTone.WORKING,+ BotState.APPROVAL to WidgetTone.ATTENTION, BotState.QUESTION to WidgetTone.ATTENTION,+ BotState.IDLE to WidgetTone.IDLE, BotState.SLEEPING to WidgetTone.IDLE,+ BotState.ERROR to WidgetTone.TROUBLE, BotState.RATELIMIT to WidgetTone.TROUBLE, BotState.DIZZY to WidgetTone.TROUBLE,+ )+ assertEquals("every state is mapped", BotState.values().toSet(), expected.keys)+ for ((st, tone) in expected) assertEquals(st.name, tone, WidgetTone.of(st))+ }++ @Test fun greenBlueOrangeGreyAndNotConnected() {+ assertEquals(WidgetTone.DONE, look(LinkState.CONNECTED, BotState.FINISHED))+ assertEquals(WidgetTone.WORKING, look(LinkState.CONNECTED, BotState.WORKING))+ assertEquals(WidgetTone.ATTENTION, look(LinkState.CONNECTED, BotState.APPROVAL))+ assertEquals(WidgetTone.ATTENTION, look(LinkState.CONNECTED, BotState.QUESTION))+ assertEquals("calm: soft grey", WidgetTone.IDLE, look(LinkState.CONNECTED))+ assertEquals(WidgetTone.IDLE, look(LinkState.CONNECTED, BotState.IDLE, BotState.SLEEPING))+ assertEquals("not connected: muted grey, whatever the agents were", WidgetTone.MUTED, look(LinkState.DISCONNECTED, BotState.WORKING))+ assertEquals(WidgetTone.MUTED, look(LinkState.CONNECTING))+ assertTrue("two different greys", WidgetTone.IDLE.argb != WidgetTone.MUTED.argb)+ }++ @Test fun theMostUrgentAgentSetsTheCard() {+ assertEquals(WidgetTone.ATTENTION, look(LinkState.CONNECTED, BotState.IDLE, BotState.FINISHED, BotState.WORKING, BotState.APPROVAL))+ assertEquals(WidgetTone.ATTENTION, look(LinkState.CONNECTED, BotState.WORKING, BotState.QUESTION))+ assertEquals(WidgetTone.WORKING, look(LinkState.CONNECTED, BotState.IDLE, BotState.FINISHED, BotState.WORKING))+ assertEquals(WidgetTone.WORKING, look(LinkState.CONNECTED, BotState.FINISHED, BotState.THINKING, BotState.IDLE))+ assertEquals(WidgetTone.DONE, look(LinkState.CONNECTED, BotState.IDLE, BotState.FINISHED))+ assertEquals(WidgetTone.IDLE, look(LinkState.CONNECTED, BotState.SLEEPING, BotState.IDLE))+ // A stopped agent (red) ranks above working in the existing order of core/Glance.kt, below something waiting.+ assertEquals(WidgetTone.TROUBLE, look(LinkState.CONNECTED, BotState.WORKING, BotState.ERROR))+ assertEquals(WidgetTone.ATTENTION, look(LinkState.CONNECTED, BotState.ERROR, BotState.APPROVAL))+ }++ @Test fun theOrderIsTheOneOfTheGlance() {+ val order = listOf(+ BotState.APPROVAL, BotState.QUESTION, BotState.ERROR, BotState.RATELIMIT, BotState.DIZZY,+ BotState.WORKING, BotState.SEARCHING, BotState.THINKING, BotState.FINISHED, BotState.SLEEPING, BotState.IDLE,+ )+ assertEquals(order, BotState.values().sortedBy { GlanceBuilder.rank(it) })+ val sessions = order.reversed().mapIndexed { i, st -> s("p$i", st) }+ val g = GlanceBuilder.build(true, LinkState.CONNECTED, "PC", sessions, 0) { "x" }+ val tiles = WidgetData.build(g, sessions, { "x" }).tiles+ assertEquals("the tiles come most urgent first", tiles.map { GlanceBuilder.rank(it.state) }, tiles.map { GlanceBuilder.rank(it.state) }.sorted())+ }++ @Test fun theTodayWidgetIsGreenOnceSomethingFinishedAndSoftGreyBefore() {+ val g = GlanceBuilder.build(true, LinkState.CONNECTED, "PC", emptyList(), 0) { "x" }+ assertEquals(WidgetTone.IDLE, WidgetData.build(g, emptyList(), { "x" }, today = 0).todayLook)+ assertEquals(WidgetTone.DONE, WidgetData.build(g, emptyList(), { "x" }, today = 1).todayLook)+ }++ // ── The palette in the resources ────────────────────────────────────────────────────────────────++ private fun colours(path: String) = Regex("""<color name="(\w+)">#([0-9A-Fa-f]{8})</color>""").findAll(read(path)).associate { it.groupValues[1] to it.groupValues[2].uppercase() }+ private val dark get() = colours(res + "values/colors.xml")+ private val light get() = dark + colours(res + "values-notnight/colors.xml")++ @Test fun everyToneHasItsColourItsTintItsBorderAndItsCard() {+ for (t in WidgetTone.values()) {+ val k = t.name.lowercase()+ val hex = t.argb.toUInt().toString(16).uppercase().padStart(8, '0')+ assertEquals(k, hex, dark.getValue("widget_tone_$k"))+ assertEquals("the border is the tone at 60%: $k", "99" + hex.substring(2), dark.getValue("widget_border_$k"))+ assertEquals("the tint is the tone: $k", hex.substring(2), dark.getValue("widget_tint_$k").substring(2))+ assertTrue("a card for $k", File("${res}drawable/widget_card_$k.xml").exists())+ assertTrue("a tint for $k", File("${res}drawable/widget_tint_$k.xml").exists())+ val card = read("${res}drawable/widget_card_$k.xml")+ assertTrue("$k: a 1dp border in the state's colour", card.contains("@dimen/widget_border_width") && card.contains("@color/widget_border_$k"))+ }+ assertTrue(read(res + "values/dimens.xml").contains("""<dimen name="widget_border_width">1dp</dimen>"""))+ }++ // ── Nothing picks a colour of its own ───────────────────────────────────────────────────────────++ @Test fun noWidgetLayoutHardCodesAColour() {+ for (f in File(res + "layout").listFiles()!!.filter { it.name.startsWith("widget_") }) {+ val hits = Regex(""""#[0-9A-Fa-f]{3,8}"""").findAll(f.readText()).map { it.value }.toList()+ assertTrue("${f.name} hard-codes $hits", hits.isEmpty())+ }+ }++ @Test fun noWidgetDrawableHardCodesAStateColour() {+ // A white base that code tints, and the transparent end of a gradient: nothing else.+ val allowed = setOf("#FFFFFFFF", "#00000000")+ for (f in File(res + "drawable").listFiles()!!.filter { (it.name.startsWith("widget_") || it.name.startsWith("ic_widget_")) && !it.name.startsWith("widget_preview_image_") }) {+ val hits = Regex("""#[0-9A-Fa-f]{6,8}""").findAll(f.readText()).map { it.value.uppercase() }.filter { it !in allowed }.toList()+ assertTrue("${f.name} hard-codes $hits", hits.isEmpty())+ }+ assertTrue(read(res + "drawable/widget_badge_bg.xml").contains("@color/widget_tone_attention"))+ }++ private val widgetSources = listOf(+ "SoloWidget", "ListWidget", "MochiBigWidget", "StatusPillWidget", "WaitingAlertWidget", "UsageRingWidget", "TodayWidget", "MoodWidget", "GlanceWidget",+ ).associateWith { read("${main}app/$it.kt") }++ @Test fun noWidgetSourceHardCodesAColour() {+ for ((name, src) in widgetSources + mapOf("WidgetHub" to read(main + "app/WidgetHub.kt"))) {+ assertFalse("$name has a hex colour", Regex("""0x[0-9A-Fa-f]{6,8}""").containsMatchIn(src))+ for (call in listOf("Color(", "Color.", "parseColor", "setTextColor(", "argb(")) assertFalse("$name uses $call", src.contains(call))+ }+ // The pictures keep only their neutral track and glow strength, named.+ for (f in listOf("BarBitmap", "RingBitmap", "MochiBitmap")) {+ for (line in read("${main}app/$f.kt").lines().filter { Regex("""0x[0-9A-Fa-f]{6,8}""").containsMatchIn(it) }) assertTrue("$f: $line", line.contains("TRACK"))+ }+ }++ @Test fun everyWidgetPaintsThroughTheHubAndNeverSetsItsOwnCard() {+ for ((name, src) in widgetSources) {+ assertTrue("$name does not paint through the hub", src.contains("WidgetHub.paint(") || src.contains("WidgetHub.paintUsage("))+ if (name != "MochiBigWidget") assertFalse("$name sets a background itself", src.contains("setBackgroundResource"))+ }+ // The plan-usage card uses the usage palette, and a Widget with no usage never borrows the orange.+ assertTrue(widgetSources.getValue("UsageRingWidget").contains("WidgetHub.paintUsage(v, R.id.ring_root, R.id.ring_tint, ring.tone)"))+ assertTrue(widgetSources.getValue("UsageRingWidget").contains("if (c.connected) WidgetTone.IDLE else WidgetTone.MUTED"))+ }++ @Test fun mochisGlowAlwaysFollowsTheCardsTone() {+ for ((name, src) in widgetSources) {+ for (line in src.lines().filter { it.contains("MochiBitmap.of(") && it.contains("glow = true") }) assertTrue("$name: $line", line.contains("tone ="))+ }+ val bitmap = read(main + "app/MochiBitmap.kt")+ assertTrue(bitmap.contains("tone: WidgetTone = WidgetTone.of(state)"))+ assertTrue(bitmap.contains("val tone: WidgetTone)"))+ }++ @Test fun theNotConnectedIconIsOnEveryWidgetThatShowsAStatus() {+ for ((name, layout) in listOf("SoloWidget" to "widget_solo", "ListWidget" to "widget_list", "MochiBigWidget" to "widget_big", "WaitingAlertWidget" to "widget_alert", "MoodWidget" to "widget_mood", "GlanceWidget" to "widget_glance")) {+ // In the layout, or set from code when the computer is not there (the List swaps its dot for it).+ assertTrue("$layout has no not-connected icon", read("${res}layout/$layout.xml").contains("@drawable/ic_widget_offline") || widgetSources.getValue(name).contains("R.drawable.ic_widget_offline"))+ assertTrue("$name never shows it", widgetSources.getValue(name).contains("connected"))+ }+ assertTrue(widgetSources.getValue("StatusPillWidget").contains("R.drawable.ic_widget_offline"))+ for (id in listOf("big_offline" to "MochiBigWidget", "alert_offline" to "WaitingAlertWidget", "mood_offline" to "MoodWidget", "glance_offline" to "GlanceWidget")) {+ assertTrue(id.first, widgetSources.getValue(id.second).contains("R.id.${id.first}"))+ }+ }++ @Test fun theButtonTilesAreOrangeOnlyWhileSomethingWaits() {+ val big = widgetSources.getValue("MochiBigWidget")+ assertTrue(big.contains("if (c.look == WidgetTone.ATTENTION) R.drawable.widget_tile_bg_attention else R.drawable.widget_tile_bg"))+ assertFalse("the pill's round buttons never turn orange", widgetSources.getValue("StatusPillWidget").contains("tile_bg"))+ assertTrue(read(res + "drawable/widget_tile_bg.xml").contains("@color/widget_button"))+ assertTrue(read(res + "drawable/widget_tile_bg_attention.xml").contains("@color/widget_tone_attention"))+ }++ // ── The picker previews keep their sample's colour ──────────────────────────────────────────────++ @Test fun eachPreviewKeepsItsSampleStateColour() {+ val sample = mapOf(+ "solo" to "attention", "list" to "attention", "big" to "working", "pill" to "working", "alert" to "attention",+ "today" to "done", "mood" to "done", "glance" to "working", "ring" to "usage_calm",+ )+ for ((n, tone) in sample) {+ val xml = read("${res}layout/widget_preview_$n.xml")+ assertTrue("$n card", xml.contains("""android:background="@drawable/widget_card_$tone""""))+ assertTrue("$n tint", xml.contains("""android:background="@drawable/widget_tint_$tone""""))+ val image = read("${res}drawable/widget_preview_image_$n.xml")+ assertTrue("$n Android 11 picture", image.contains("@drawable/widget_card_$tone") && image.contains("@drawable/widget_tint_$tone"))+ }+ }++ // ── Readable on every tinted card, in light and dark ────────────────────────────────────────────++ private fun argb(hex: String) = intArrayOf(hex.substring(0, 2).toInt(16), hex.substring(2, 4).toInt(16), hex.substring(4, 6).toInt(16), hex.substring(6, 8).toInt(16))+ private fun over(fg: IntArray, bg: IntArray): IntArray {+ val a = fg[0] / 255.0+ return intArrayOf(255, (fg[1] * a + bg[1] * (1 - a)).toInt(), (fg[2] * a + bg[2] * (1 - a)).toInt(), (fg[3] * a + bg[3] * (1 - a)).toInt())+ }+ private fun lum(c: IntArray): Double {+ fun f(v: Int): Double { val s = v / 255.0; return if (s <= 0.03928) s / 12.92 else Math.pow((s + 0.055) / 1.055, 2.4) }+ return 0.2126 * f(c[1]) + 0.7152 * f(c[2]) + 0.0722 * f(c[3])+ }+ private fun ratio(a: IntArray, b: IntArray): Double { val x = lum(a); val y = lum(b); return (maxOf(x, y) + 0.05) / (minOf(x, y) + 0.05) }++ @Test fun textIsReadableOnEveryTintedCardInLightAndDark() {+ val tints = WidgetTone.values().map { "widget_tint_${it.name.lowercase()}" } + UsageTone.values().map { "widget_tint_usage_${it.name.lowercase()}" }+ for ((mode, c) in listOf("dark" to dark, "light" to light)) {+ val card = argb(c.getValue("widget_card"))+ for (tint in tints) {+ // The gradient is strongest in its corner: take that, the worst case.+ val bg = over(argb(c.getValue(tint)), card)+ for ((name, need) in listOf("widget_text" to 7.0, "widget_text_soft" to 4.5, "widget_text_secondary" to 4.5)) {+ val fg = over(argb(c.getValue(name)), bg)+ val r = ratio(fg, bg)+ assertTrue("$mode $name on $tint: ${"%.1f".format(r)}:1", r >= need)+ }+ }+ }+ }++ @Test fun theOrangeAlertCountIsReadableInLightAndDark() {+ for ((mode, c) in listOf("dark" to dark, "light" to light)) {+ val card = argb(c.getValue("widget_card"))+ val bg = over(argb(c.getValue("widget_tint_attention")), card)+ // 20sp bold is large text: 3:1 is the bar.+ val r = ratio(argb(c.getValue("widget_tone_attention_text")), bg)+ assertTrue("$mode: ${"%.1f".format(r)}:1", r >= 3.0)+ }+ // The badge: the dark text on the orange.+ val badge = ratio(argb(dark.getValue("widget_on_tone")), argb(dark.getValue("widget_tone_attention")))+ assertTrue("badge ${"%.1f".format(badge)}:1", badge >= 4.5)+ }+}diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.ktindex e5e4f9d6..bd30c671 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt@@ -144,7 +144,7 @@ class WidgetPreviewTest {// The pill shows its four buttons: home, chat, settings and recent, in that order.assertEquals(listOf("ic_widget_home", "ic_widget_chat", "ic_widget_settings", "ic_widget_recent"), Regex("""@drawable/(ic_widget_\w+)""").findAll(preview("pill")).map { it.groupValues[1] }.toList())assertEquals(listOf("2 waiting", "Claude Code"), text("alert"))- assertEquals(listOf("70%", "Claude · 5 h"), text("ring"))+ assertEquals(listOf("68%", "Claude · 5 h"), text("ring"))assertTrue(text("today").containsAll(listOf("5", "done today")))assertTrue("the Mood preview shows only a face", text("mood").isEmpty())// The tones of the samples: waiting orange, working blue, finished green.@@ -153,18 +153,19 @@ class WidgetPreviewTest {assertTrue(preview("alert").contains("widget_card_attention"))assertTrue(preview("big").contains("preview_mochi_working") && preview("big").contains("widget_tint_working"))assertEquals("six tiles", 6, Regex("""@drawable/widget_tile_bg"""").findAll(preview("big")).count())- assertEquals("two thin bars", 2, Regex("""@drawable/preview_bar_done"""").findAll(preview("big")).count())+ assertEquals("two thin bars", 2, Regex("""@drawable/preview_bar_calm"""").findAll(preview("big")).count())assertFalse("no speech bubble", preview("big").contains("bubble", ignoreCase = true))assertTrue(preview("glance").contains("preview_mochi_working") && preview("glance").contains("widget_tint_working"))assertTrue(preview("mood").contains("preview_mochi_done") && preview("today").contains("preview_mochi_done"))assertTrue(preview("list").let { it.contains("preview_face_waiting") && it.contains("preview_face_working") && it.contains("preview_face_done") })- assertTrue(preview("ring").contains("preview_ring_70"))+ assertTrue(preview("ring").contains("preview_ring_68"))}@Test fun theBadgeAndTheAlertAreOrange() {for (n in listOf("solo", "list")) assertTrue(n, preview(n).contains("@drawable/widget_badge_bg"))- assertTrue(File(res + "drawable/widget_badge_bg.xml").readText().contains("#FFFF9F0A"))- assertTrue(preview("alert").contains("""android:textColor="@color/widget_tone_attention""""))+ // The badge is the waiting tone from the shared palette, not a literal of its own.+ assertTrue(File(res + "drawable/widget_badge_bg.xml").readText().contains("@color/widget_tone_attention"))+ assertTrue(preview("alert").contains("""android:textColor="@color/widget_tone_attention_text""""))}// ── The vector Mochi ───────────────────────────────────────────────────────────────────────────@@ -199,16 +200,25 @@ class WidgetPreviewTest {assertFalse("calm: no badge", read(res + "drawable/preview_face_idle.xml").contains("""android:fillColor="#000000""""))}- @Test fun theRingIsAnArcAtSeventyPercentInTheMediumTone() {- val ring = read(res + "drawable/preview_ring_70.xml")+ @Test fun theRingIsANormalTealArcAtSixtyEightPercent() {+ val ring = read(res + "drawable/preview_ring_68.xml")+ assertFalse(File(res + "drawable/preview_ring_70.xml").exists())assertTrue(ring.contains("""android:strokeLineCap="round""""))- assertTrue(ring.contains("#" + hex(WidgetTone.ATTENTION)))- // 70 % of the circle from the top, clockwise: it ends at 252 degrees (x = 50 + 44 sin, y = 50 - 44 cos).+ // Plan usage has its own palette: teal under 75%, never a state colour.+ assertTrue(ring.contains("#" + usageHex(com.coucou.android.core.UsageTone.CALM)))+ assertFalse(ring.contains("#" + hex(WidgetTone.ATTENTION)))+ // 68 % of the circle from the top, clockwise: it ends at 244.8 degrees (x = 50 + 44 sin, y = 50 - 44 cos).val end = Regex("""M50,6 A44,44 0 1 1 (?!50,)([\d.]+),([\d.]+)""").find(ring)!!.groupValues- assertEquals(50 + 44 * Math.sin(Math.toRadians(252.0)), end[1].toDouble(), 0.1)- assertEquals(50 - 44 * Math.cos(Math.toRadians(252.0)), end[2].toDouble(), 0.1)+ val deg = 0.68 * 360+ assertEquals(50 + 44 * Math.sin(Math.toRadians(deg)), end[1].toDouble(), 0.1)+ assertEquals(50 - 44 * Math.cos(Math.toRadians(deg)), end[2].toDouble(), 0.1)+ // A normal look under the red line: the ring's percentage is small and not bold.+ val layout = preview("ring")+ assertTrue(layout.contains("@dimen/widget_text_pct") && !layout.contains("android:textStyle=\"bold\""))}+ private fun usageHex(t: com.coucou.android.core.UsageTone) = t.argb.toUInt().toString(16).uppercase().padStart(8, '0').substring(2)+@Test fun nothingInThePreviewsIsABitmap() {for (dir in File(res).listFiles()!!.filter { it.name.startsWith("drawable") || it.name.startsWith("mipmap") }) {for (f in dir.listFiles()!!.filter { it.name.startsWith("preview_") || it.name.startsWith("widget_preview_") }) {diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.ktindex af87e31c..76cf71f7 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSampleTest.kt@@ -46,7 +46,7 @@ class WidgetSampleTest {assertEquals(0, c.waiting)assertEquals("Claude", c.ring!!.plan)assertEquals(42, c.ring!!.pct)- assertEquals(WidgetTone.DONE, c.ring!!.tone)+ assertEquals(com.coucou.android.core.UsageTone.CALM, c.ring!!.tone)assertEquals(3, c.today)}@@ -58,7 +58,7 @@ class WidgetSampleTest {assertEquals("Claude Code", c.alertSub)assertEquals(BotState.APPROVAL, c.mood)assertEquals("a request on top, then the others by urgency", listOf("Claude Code", "Codex", "Gemini CLI"), c.tiles.map { it.name })- assertEquals(WidgetTone.TROUBLE, c.ring!!.tone)+ assertEquals(com.coucou.android.core.UsageTone.CLOSE, c.ring!!.tone)}@Test fun done() {@@ -80,7 +80,7 @@ class WidgetSampleTest {assertTrue(c.tiles.size <= WidgetData.MAX_ROWS)}// The four tones that matter are all on show somewhere.- assertEquals(setOf(WidgetTone.MUTED, WidgetTone.WORKING, WidgetTone.ATTENTION, WidgetTone.DONE), all.map { it.look }.toSet())+ assertEquals(setOf(WidgetTone.MUTED, WidgetTone.IDLE, WidgetTone.WORKING, WidgetTone.ATTENTION, WidgetTone.DONE), all.map { it.look }.toSet())}@Test fun theSamePreviewTwiceIsTheSameContentSoAPushCanBeSkipped() {diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.ktindex c1d80274..bb4e00ae 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt@@ -127,7 +127,8 @@ class WidgetSurfacesTest {for (word in listOf("openScreen", "openSession", "LaunchScreen")) assertFalse(word, src.contains(word))val layout = read("src/main/res/layout/widget_glance.xml")assertFalse(layout.contains("<Button"))- assertFalse("no icon button in the summary", layout.contains("ic_widget_"))+ assertFalse("no icon button in the summary", Regex("ic_widget_(home|chat|settings|recent|session|pair)").containsMatchIn(layout))+ assertTrue("it shows the not-connected icon", layout.contains("@drawable/ic_widget_offline"))}@Test fun theListRowsAreAtLeastFortyEightDpAndTheEmptyStateFillsTheCard() {diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.ktindex cc350b03..775c62e7 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetToneTest.kt@@ -3,6 +3,7 @@ package com.coucou.androidimport com.coucou.android.core.Glanceimport com.coucou.android.core.GlanceToneimport com.coucou.android.core.GlanceLine+import com.coucou.android.core.lookimport com.coucou.android.core.moodimport com.coucou.android.core.WidgetContentimport com.coucou.android.core.WidgetTile@@ -33,7 +34,7 @@ class WidgetToneTest {for (s in listOf(BotState.WORKING, BotState.THINKING, BotState.SEARCHING)) assertEquals(WidgetTone.WORKING, WidgetTone.of(s))assertEquals(WidgetTone.DONE, WidgetTone.of(BotState.FINISHED))for (s in listOf(BotState.ERROR, BotState.RATELIMIT, BotState.DIZZY)) assertEquals(WidgetTone.TROUBLE, WidgetTone.of(s))- for (s in listOf(BotState.IDLE, BotState.SLEEPING)) assertEquals(WidgetTone.MUTED, WidgetTone.of(s))+ for (s in listOf(BotState.IDLE, BotState.SLEEPING)) assertEquals("calm is soft grey, not the muted grey of 'not connected'", WidgetTone.IDLE, WidgetTone.of(s))}@Test fun aComputerThatIsNotConnectedIsAlwaysMuted() {@@ -46,6 +47,7 @@ class WidgetToneTest {assertEquals(0xFF34D499.toInt(), WidgetTone.DONE.argb)assertEquals(0xFFF4505E.toInt(), WidgetTone.TROUBLE.argb)assertEquals(0xFF94A2B8.toInt(), WidgetTone.MUTED.argb)+ assertEquals(0xFFB8BDC7.toInt(), WidgetTone.IDLE.argb)}@Test fun theResourcesCarryTheSamePalette() {@@ -98,23 +100,26 @@ class WidgetToneTest {assertEquals(WidgetTone.ATTENTION, content(waiting = 1, states = arrayOf(BotState.WORKING)).look)assertEquals(WidgetTone.WORKING, content(states = arrayOf(BotState.WORKING, BotState.IDLE)).look)assertEquals(WidgetTone.DONE, content(states = arrayOf(BotState.FINISHED)).look)- assertEquals(WidgetTone.MUTED, content().look)+ assertEquals("connected with nothing to list is calm", WidgetTone.IDLE, content().look)}// ── The summary widget: the existing Glance, in the shared look ──────────────────────────────────- @Test fun theFiveToneOfTheGlanceBecomeTheFiveToneOfTheWidgets() {- assertEquals(WidgetTone.MUTED, WidgetTone.of(GlanceTone.CALM))- assertEquals(WidgetTone.DONE, WidgetTone.of(GlanceTone.OK))- assertEquals(WidgetTone.WORKING, WidgetTone.of(GlanceTone.BUSY))- assertEquals(WidgetTone.ATTENTION, WidgetTone.of(GlanceTone.ATTENTION))- assertEquals(WidgetTone.TROUBLE, WidgetTone.of(GlanceTone.TROUBLE))- for (t in GlanceTone.values()) WidgetTone.of(t)- }-private fun glance(connected: Boolean, vararg states: BotState) =Glance("h", "d", GlanceTone.CALM, connected, states.map { GlanceLine("A", "t", it) }, 0)+ @Test fun theSummaryLooksLikeEveryOtherWidgetForTheSameAgents() {+ assertEquals(WidgetTone.MUTED, glance(false, BotState.WORKING).look())+ assertEquals(WidgetTone.IDLE, glance(true).look())+ assertEquals(WidgetTone.IDLE, glance(true, BotState.IDLE, BotState.SLEEPING).look())+ assertEquals(WidgetTone.DONE, glance(true, BotState.FINISHED, BotState.IDLE).look())+ assertEquals(WidgetTone.WORKING, glance(true, BotState.WORKING, BotState.FINISHED).look())+ assertEquals(WidgetTone.ATTENTION, glance(true, BotState.APPROVAL, BotState.WORKING).look())+ assertEquals(WidgetTone.TROUBLE, glance(true, BotState.ERROR, BotState.WORKING).look())+ // Something waiting wins even when its session is not the first line.+ assertEquals(WidgetTone.ATTENTION, Glance("h", "d", GlanceTone.ATTENTION, true, listOf(GlanceLine("A", "t", BotState.WORKING)), 1).look())+ }+@Test fun mochiOnTheSummaryFollowsTheMostUrgentLine() {assertEquals(BotState.APPROVAL, glance(true, BotState.APPROVAL, BotState.WORKING).mood())assertEquals(BotState.WORKING, glance(true, BotState.WORKING).mood())diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.ktindex 99c1d5bd..5ede875b 100644--- a/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt@@ -2,7 +2,9 @@ package com.coucou.androidimport com.coucou.android.core.Glanceimport com.coucou.android.core.GlanceBuilder+import com.coucou.android.core.PlanUsageLookimport com.coucou.android.core.UsageRing+import com.coucou.android.core.UsageToneimport com.coucou.android.core.UsageSideimport com.coucou.android.core.WidgetDataimport com.coucou.android.core.WidgetSample@@ -25,26 +27,13 @@ class WidgetUsageSideTest {private fun glance(link: LinkState = LinkState.CONNECTED): Glance = GlanceBuilder.build(true, link, "PC", emptyList(), 0) { "x" }private fun build(u: UsageSnapshot?, link: LinkState = LinkState.CONNECTED) = WidgetData.build(glance(link), emptyList(), { "x" }, u, today = 0, nowMs = now)- // ── The colour: green, then orange above 75%, then red above 90% ────────────────────────────────+ // ── The colour comes from one function (PlanUsageLook, tested at its boundaries in PlanUsageLookTest) ──- @Test fun theThresholdsAre75And90() {- assertEquals(75, WidgetData.BAR_ORANGE_ABOVE)- assertEquals(90, WidgetData.BAR_RED_ABOVE)- }-- @Test fun greenUpToSeventyFiveThenOrangeThenRed() {- for (p in listOf(-5, 0, 1, 50, 74, 75)) assertEquals("$p%", WidgetTone.DONE, WidgetData.barTone(p))- for (p in listOf(76, 80, 89, 90)) assertEquals("$p%", WidgetTone.ATTENTION, WidgetData.barTone(p))- for (p in listOf(91, 95, 100, 140)) assertEquals("$p%", WidgetTone.TROUBLE, WidgetData.barTone(p))- }-- @Test fun theBarOfARowUsesIt() {- assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 75).barTone)- assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 76).barTone)- assertEquals(WidgetTone.TROUBLE, UsageRing("Codex", "week", 91).barTone)- // The Usage Ring widget keeps its own rule (Home's 50% and 80%); only Mochi Big's bar changes.- assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 60).tone)- assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 60).barTone)+ @Test fun theBarAndTheRingUseThePlanUsagePalette() {+ assertEquals(UsageTone.CALM, UsageRing("Claude", "5 h", 74).tone)+ assertEquals(UsageTone.CLOSE, UsageRing("Claude", "5 h", 75).tone)+ assertEquals(UsageTone.LIMIT, UsageRing("Codex", "week", 90).tone)+ assertEquals(PlanUsageLook.tone(60), UsageRing("Claude", "5 h", 60).tone)}// ── The rows ────────────────────────────────────────────────────────────────────────────────────@@ -123,9 +112,12 @@ class WidgetUsageSideTest {val working = WidgetData.sample(WidgetSample.WORKING, now)assertEquals(UsageSide.ROWS, working.usageSide)assertEquals(listOf("Claude · 5 h" to 42, "Codex · week" to 41), working.usageRows.map { it.label to it.pct })- assertEquals(listOf(WidgetTone.DONE, WidgetTone.DONE), working.usageRows.map { it.barTone })+ assertEquals(listOf(UsageTone.CALM, UsageTone.CALM), working.usageRows.map { it.tone })val waiting = WidgetData.sample(WidgetSample.WAITING, now)- assertEquals(listOf(WidgetTone.ATTENTION, WidgetTone.TROUBLE), waiting.usageRows.map { it.barTone })+ assertEquals(listOf(UsageTone.CLOSE, UsageTone.LIMIT), waiting.usageRows.map { it.tone })+ // The second row is at the limit: it says so, and when it resets.+ assertEquals("Near limit · resets in 3 d", waiting.usageRows[1].note)+ assertEquals("no warning below the red line", null, waiting.usageRows[0].note)assertEquals(UsageSide.ROWS, WidgetData.sample(WidgetSample.DONE, now).usageSide)assertEquals(1, WidgetData.sample(WidgetSample.DONE, now).usageRows.size)assertEquals(UsageSide.OFF, WidgetData.sample(WidgetSample.EMPTY, now).usageSide)