Modern Apps git

← Modern-Apps.git

musicbrainz: stop promising a catalogue that cannot be built

Commit
364509840357d9593af7fb63fde83a8b50a18044
Author
vayun-mathur <[email protected]>
When
2026-08-20 22:36 UTC (3 months ago)
Parents
33894be

Diff

musicbrainz/src/main/java/com/vayunmathur/musicbrainz/ui/components/LoadFailureState.kt
diff --git a/musicbrainz/src/main/java/com/vayunmathur/musicbrainz/ui/components/LoadFailureState.kt b/musicbrainz/src/main/java/com/vayunmathur/musicbrainz/ui/components/LoadFailureState.ktindex 49715507cc..bfb47ce74c 100644--- a/musicbrainz/src/main/java/com/vayunmathur/musicbrainz/ui/components/LoadFailureState.kt+++ b/musicbrainz/src/main/java/com/vayunmathur/musicbrainz/ui/components/LoadFailureState.kt@@ -9,6 +9,32 @@ import com.vayunmathur.library.ui.ErrorState import com.vayunmathur.library.ui.Text import com.vayunmathur.musicbrainz.R +/**+ * The copy a not-ready screen uses, chosen solely by whether waiting could change the answer.+ *+ * Pulled out of the composable so the rule that matters can be asserted rather than reviewed:+ * a state that waiting cannot fix must never say "try again" and must never offer a button.+ */+internal data class NotReadyCopy(+    val title: Int,+    val fallbackMessage: Int,+    val showRetry: Boolean,+)++internal fun notReadyCopy(retryable: Boolean): NotReadyCopy = if (retryable) {+    NotReadyCopy(+        title = R.string.catalogue_not_ready,+        fallbackMessage = R.string.catalogue_not_ready_message,+        showRetry = true,+    )+} else {+    NotReadyCopy(+        title = R.string.catalogue_unavailable,+        fallbackMessage = R.string.catalogue_unavailable_message,+        showRetry = false,+    )+}+ /**  * The terminal state for a page that has nothing to show.  *@@ -17,12 +43,14 @@ import com.vayunmathur.musicbrainz.R  * end, and there is no fallback source to fall back to. Either way this is a settled state  * rather than a spinner, so the screen never sits there implying progress it is not making.  *- * [notReadyReason] is the server explaining why a catalogue is missing, shown in place of the- * default copy. [notReadyRetryable] is a SEPARATE question the server also answers: whether- * asking again could ever help. The two do not move together - a build that failed and is queued- * for the next check has a reason AND is worth retrying, while a host that cannot fit a build- * has a reason and never will be. So the button follows [notReadyRetryable] alone, and offering- * a retry that cannot work is the thing being avoided.+ * [notReadyRetryable] is the server answering one question - would waiting change the answer?+ * It is the ONLY thing the copy branches on, deliberately, because the state cannot answer it:+ * a catalogue can be absent and on its way, or absent and never coming.+ *+ * That honesty is structural rather than a consequence of the server always sending a+ * [notReadyReason]: each branch carries its own copy, so a missing reason degrades to a vaguer+ * TRUE message instead of a confident false one. The reason itself is displayed verbatim and+ * never parsed.  */ @Composable fun LoadFailureState(@@ -36,11 +64,21 @@ fun LoadFailureState(     onRetry: (() -> Unit)? = null, ) {     if (notReady) {+        val copy = notReadyCopy(notReadyRetryable)+        val reason = notReadyReason?.takeIf { it.isNotBlank() }+        // When waiting helps, the server's words replace the copy. When it does not, they are+        // shown ahead of it: the reason names the shortfall, the copy says where it has to be+        // dealt with, and the user cannot infer the second from the first.+        val message = when {+            reason == null -> stringResource(copy.fallbackMessage)+            copy.showRetry -> reason+            else -> reason + "\n\n" + stringResource(copy.fallbackMessage)+        }         EmptyState(-            title = stringResource(R.string.catalogue_not_ready),+            title = stringResource(copy.title),             modifier = modifier,-            message = notReadyReason ?: stringResource(R.string.catalogue_not_ready_message),-            action = if (notReadyRetryable && onRetry != null && retryLabel != null) {+            message = message,+            action = if (copy.showRetry && onRetry != null && retryLabel != null) {                 { Button(onClick = onRetry) { Text(retryLabel) } }             } else {                 null
musicbrainz/src/main/res/values/strings.xml
diff --git a/musicbrainz/src/main/res/values/strings.xml b/musicbrainz/src/main/res/values/strings.xmlindex 7ab9032ea0..ab34d9d0a7 100644--- a/musicbrainz/src/main/res/values/strings.xml+++ b/musicbrainz/src/main/res/values/strings.xml@@ -28,6 +28,10 @@     <string name="catalogue_not_ready">Catalogue not ready</string>     <!-- Body shown when the server has no music catalogue loaded yet, telling the user it is temporary. -->     <string name="catalogue_not_ready_message">The music catalogue is still being prepared on the server. Browsing will work once it is ready \u2014 try again in a few minutes.</string>+    <!-- Title shown when the server cannot build the music catalogue at all, so waiting will not help. -->+    <string name="catalogue_unavailable">Catalogue unavailable</string>+    <!-- Body shown when the server cannot build the music catalogue. Waiting will not help; the server itself needs attention. -->+    <string name="catalogue_unavailable_message">The server cannot build the music catalogue, so browsing is unavailable. Waiting will not help \u2014 this needs attention on the server.</string>     <!-- Button: retries a failed request. Verb. -->     <string name="retry">Retry</string> 
musicbrainz/src/test/java/com/vayunmathur/musicbrainz/network/api/MusicBrainzApiErrorTest.kt
diff --git a/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/network/api/MusicBrainzApiErrorTest.kt b/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/network/api/MusicBrainzApiErrorTest.ktindex 351f4fdc46..35cff8546f 100644--- a/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/network/api/MusicBrainzApiErrorTest.kt+++ b/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/network/api/MusicBrainzApiErrorTest.kt@@ -122,6 +122,47 @@ class MusicBrainzApiErrorTest {         assertTrue(building.retryable)     } +    /**+     * `progress` is ABSENT until it is known, not `0.0`. Decoding it as zero would report a build+     * that has not started as one that has started and made no headway - and if it were ever+     * shown as a percentage, a build about to finish could read 0% on the first poll.+     */+    @Test+    fun `absent progress is unknown rather than zero`() {+        val unknown = MusicBrainzApi.json.decodeFromString<NotReadyBody>(+            """{"error":"not_ready","state":"building","retryable":true}""",+        )+        assertNull(unknown.progress, "a missing progress must not decode as 0.0")++        val known = MusicBrainzApi.json.decodeFromString<NotReadyBody>(+            """{"error":"not_ready","state":"building","retryable":true,"progress":0.42}""",+        )+        assertEquals(0.42f, known.progress)++        // Zero sent explicitly is a real zero, and must stay distinguishable from absent.+        val zero = MusicBrainzApi.json.decodeFromString<NotReadyBody>(+            """{"error":"not_ready","state":"building","retryable":true,"progress":0.0}""",+        )+        assertEquals(0f, zero.progress)+    }++    /** `retryable` is always sent, so it decodes straight through in both directions. */+    @Test+    fun `retryable decodes from the status probe shape`() {+        assertEquals(+            true,+            MusicBrainzApi.json.decodeFromString<NotReadyBody>(+                """{"state":"absent","retryable":true}""",+            ).retryable,+        )+        assertEquals(+            false,+            MusicBrainzApi.json.decodeFromString<NotReadyBody>(+                """{"state":"absent","retryable":false}""",+            ).retryable,+        )+    }+     /** Mid-build answers 503 too, and reads the same to the user: come back shortly. */     @Test     fun `503 while building is also a wait`() {
musicbrainz/src/test/java/com/vayunmathur/musicbrainz/ui/components/NotReadyCopyTest.kt
diff --git a/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/ui/components/NotReadyCopyTest.kt b/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/ui/components/NotReadyCopyTest.ktnew file mode 100644index 0000000000..37a68bdafb--- /dev/null+++ b/musicbrainz/src/test/java/com/vayunmathur/musicbrainz/ui/components/NotReadyCopyTest.kt@@ -0,0 +1,70 @@+package com.vayunmathur.musicbrainz.ui.components++import com.vayunmathur.musicbrainz.R+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNotEquals+import kotlin.test.assertTrue++/**+ * Pins the one rule the not-ready screen must never break.+ *+ * The user's server has 5-7 GB free and a build currently needs 8 GB, so "the catalogue can never+ * be built here" is the REAL steady state on that hardware, not a corner case. Telling that user+ * to try again in a few minutes, forever, behind a button that cannot succeed, is the same+ * dishonesty as an endless spinner. So the copy is chosen only by whether waiting could change+ * the answer, and that choice is asserted here rather than left to review.+ */+class NotReadyCopyTest {++    @Test+    fun `waiting helps, so the wait copy and a retry are offered`() {+        val copy = notReadyCopy(retryable = true)+        assertEquals(R.string.catalogue_not_ready, copy.title)+        assertEquals(R.string.catalogue_not_ready_message, copy.fallbackMessage)+        assertTrue(copy.showRetry)+    }++    /**+     * The case that matters. No retry button, because pressing it can never work, and copy that+     * does not promise the catalogue is coming.+     */+    @Test+    fun `waiting cannot help, so no retry is offered`() {+        val copy = notReadyCopy(retryable = false)+        assertFalse(copy.showRetry, "a retry that cannot succeed must not be offered")+        assertEquals(R.string.catalogue_unavailable, copy.title)+        assertEquals(R.string.catalogue_unavailable_message, copy.fallbackMessage)+    }++    /**+     * The two branches must not share copy. If they ever collapse onto the same strings, the+     * non-retryable case silently starts telling the user to try again shortly - which is the+     * defect this whole split exists to prevent, and it would not fail any other test.+     */+    @Test+    fun `the two branches never share copy`() {+        val waiting = notReadyCopy(retryable = true)+        val terminal = notReadyCopy(retryable = false)+        assertNotEquals(waiting.title, terminal.title)+        assertNotEquals(+            waiting.fallbackMessage,+            terminal.fallbackMessage,+            "the terminal state must not reuse the 'try again in a few minutes' copy",+        )+        assertNotEquals(waiting.showRetry, terminal.showRetry)+    }++    /**+     * Retryability is the ONLY input. Nothing about the reason text, the state name or progress+     * may influence it - the server has already decided, and second-guessing it here is how the+     * two questions got conflated in the first place.+     */+    @Test+    fun `retryability is the only input`() {+        assertEquals(notReadyCopy(retryable = true), notReadyCopy(retryable = true))+        assertEquals(notReadyCopy(retryable = false), notReadyCopy(retryable = false))+        assertNotEquals(notReadyCopy(retryable = true), notReadyCopy(retryable = false))+    }+}