logicgate: merge sandbox groups that differ only by case
- Commit
161db0fa88e10650fb5462edd9cbcfee73447cd7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 01:03 UTC (4 days ago)
- Parents
ce307a7
Symptom: with one component filed under "Adders" and another under "adders", only one of them appeared in the sandbox list. The other still existed in the catalog but could not be opened or deleted from the list until renamed from somewhere else. Root cause: SandboxUiState.groups grouped case-sensitively and then poured the result into a map sorted with String.CASE_INSENSITIVE_ORDER. That comparator treats the two group names as the same key, so the second component list silently replaced the first. Fix: group by the lowercased group name so case variants merge into one displayed group (keeping the first-seen casing as the header), then sort the merged groups case-insensitively as before. Verified: new LogicViewModelTest case failed before the fix (one component dropped) and passes after; full :games:logicgate:testDevUnitTest, :games:logicgate:lint and :games:logicgate:lintVitalRelease all pass.
Diff
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.ktindex 124bc37481..ea8a5e66a3 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/platform/LogicUiContract.kt@@ -59,7 +59,14 @@ data class SandboxUiState( val components: List<ComponentCard> = emptyList(), ) { val groups: List<Pair<String, List<ComponentCard>>>- get() = components.groupBy { it.group }.toSortedMap(String.CASE_INSENSITIVE_ORDER).toList()+ get() = components+ // Group names are free text, so "Adders" and "adders" are the+ // same filing group: keying the sort map case-insensitively+ // while grouping case-sensitively made the second list+ // silently replace the first, dropping its components.+ .groupBy { it.group.lowercase() }+ .values.map { cards -> cards.first().group to cards }+ .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.first }) } /** What the editor is editing. */
games/logicgate/src/test/java/com/vayunmathur/games/logicgate/platform/LogicViewModelTest.kt
diff --git a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/platform/LogicViewModelTest.kt b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/platform/LogicViewModelTest.ktindex 7f80b99fe9..5f8ea86dbd 100644--- a/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/platform/LogicViewModelTest.kt+++ b/games/logicgate/src/test/java/com/vayunmathur/games/logicgate/platform/LogicViewModelTest.kt@@ -154,4 +154,16 @@ class LogicViewModelTest { .cost, ) }++ @Test fun `sandbox groups differing only by case keep every component`() {+ val first = ComponentCard("a", "alpha", "Adders", 1, 1, 1)+ val second = ComponentCard("b", "beta", "adders", 1, 1, 1)+ val groups = SandboxUiState(listOf(first, second)).groups+ assertEquals(+ listOf(first, second),+ groups.single().second,+ "two groups that differ only by case must merge, not let one " ++ "silently replace the other in the sandbox list",+ )+ } }