package com.cottondb.keysimport com.cottondb.keys.secrets.stuckRowimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.JsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNullimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.File/** * Secrets' changes that cannot be sent (UNSENT HEAL, assets/design/shared/UNSENT-HEAL.md), as `vault.settings`' sync * group carries them: one row saying how many, which opens their page with Send again and Let go (the unsent walk, * 26 Nov 2026: the acts stood on the row as small words beside its detail). */classSecretsUnsentTest {privateval repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile }privatefun src(name: String) = File(repo, "apps/android/app/src/keys/kotlin/com/cottondb/keys/secrets/$name").readText()privatefun j(text: String) = Json.parseToJsonElement(text) asJsonObjectprivateval settings = j("""{"groups":[{"id":"sync","title":"Sync","rows":[{"id":"sync","title":"Synced at 9:53"}, {"id":"stuck","title":"1 change can't be sent","detail":"It's saved on this phone, but Cotton can't take it. Send it again, or let it go.","tone":"attention", "acts":[{"id":"again","label":"Send again","method":"sync.stuck.again","request":{"ids":["op-1"]}}, {"id":"let_go","label":"Let go","method":"sync.stuck.letGo","request":{"ids":["op-1"]},"tone":"danger","confirm":{"title":"Let these changes go?","body":"b","yes":"Let go","no":"Keep them"}}]}]}]}""", ) @Testfun the_stuck_row_is_read_from_the_sync_group() { assertEquals("1 change can't be sent", stuckRow(settings)?.get("title").toString().trim('"')) assertNull(stuckRow(j("""{"groups":[{"id":"sync","rows":[{"id":"sync","title":"Synced at 9:53"}]}]}"""))) assertNull(stuckRow(null)) }/** The row opens the page; the page sends each act's own request through its confirm, and reads again even when refused. */ @Testfun the_row_opens_a_page_whose_acts_send_their_own_request_and_read_again() {val places = src("Places.kt") assertTrue(places.contains("state.stack.add(Screen.Unsent)")) assertTrue(places.contains("Tone.Go else Tone.Plain") && places.contains("state.stuckAct(act)")) assertTrue("the acts no longer stand on the row", !places.contains("\"rows\" to kotlinx.serialization.json.JsonArray(rest)")) assertTrue(src("SecretsApp.kt").contains("Screen.Unsent -> UnsentScreen(state)"))// Said once: with acts, the stuck row stands in place of the sync line; without, the sync line stays above it. assertTrue(places.contains("if (stuck == null || stuck.arr(\"acts\").isEmpty()) {")) assertTrue(places.substringAfter("if (stuck == null || stuck.arr(\"acts\").isEmpty()) {").substringBefore("} else PlainRow(stuck").contains("tag = \"secrets-you-sync\""))val act = src("SecretsState.kt").substringAfter("fun stuckAct(").substringBefore("/** An answer's") listOf("confirmed(act)", "act.obj(\"request\")", "say(refused.message)", "revision++").forEach { assertTrue(it, act.contains(it)) } assertTrue("revision is bumped after the catch, refused or not", act.indexOf("revision++") > act.indexOf("catch (refused")) }}