Cotton code
73 lines · 4.0 KB · KotlinRaw
package com.cottondb.keysimport com.cottondb.shell.Groundimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.Fileclass KeysFlavourTest {    private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile }    private fun json(path: String) = JSONObject(File(repo, path).readText())    /**     * Cotton Secrets draws its own Plum ground (assets/design/keys/DECISIONS.md, owner 25 Nov 2026): no material under     * it, and its window and launch show the flavour's `flat.light`, the lilac-grey #F1EEF3, before its first frame.     */    @Test    fun secrets_window_and_launch_stand_on_plums_ground() {        assertEquals(Ground.blank, KeysParts().ground)        val window = json("apps/android/app/flavours.json").getJSONObject("keys").getString("windowGround")        assertEquals(json("apps/cotton/App/Flavours/keys/flavour.json").getJSONObject("flat").getString("light"), window)        assertEquals("#F1EEF3", window)    }    /** The flavour is the keys kit, opening on its passkeys; the registry's Android row is com.cottondb.keys, .dev beside it. */    @Test    fun keys_is_the_keys_kit_on_android() {        val flavour = json("apps/cotton/App/Flavours/keys/flavour.json")        assertEquals("keys", flavour.getString("kit"))        assertEquals("keys", flavour.getJSONObject("fan").getString("opens"))        val apps = json("apps/registry.json").getJSONArray("apps")        val row = (0 until apps.length()).map { apps.getJSONObject(it) }.first { it.getString("slug") == "keys" }        val android = row.getJSONObject("android")        assertEquals("com.cottondb.keys", android.getString("package"))        assertEquals("com.cottondb.keys.dev", android.getString("devPackage"))        val platforms = row.getJSONArray("platforms")        assertTrue((0 until platforms.length()).any { platforms.getString(it) == "android" })    }    /** The kit carries Passkeys (with Devices) and Passwords, the decks the iPhone shows. */    @Test    fun the_kit_has_passkeys_devices_and_passwords() {        val kit = json("crates/cotton-core/kits/keys/kit.json")        val tools = kit.getJSONArray("tools").let { a -> (0 until a.length()).map { a.getString(it) } }        assertEquals(listOf("personal/keys", "personal/passwords"), tools)        val views = json("crates/cotton-core/kits/personal/tools/keys/manifest.json").getJSONArray("views")        assertTrue((0 until views.length()).any { views.getJSONObject(it).getString("id") == "devices" })    }    /** The leather and the tool tiles are carried (apps/loom/materials.json), each one Loom's catalogue holds. */    @Test    fun the_leather_and_tiles_are_carried() {        val lists = json("apps/loom/materials.json")        fun names(a: org.json.JSONArray) = (0 until a.length()).map { a.getString(it) }        val materials = names(lists.getJSONArray("everyApp")) + names(lists.getJSONObject("apps").getJSONArray("keys"))        listOf("keys-teal", "tool-passwords", "tool-passwords-small").forEach { name ->            assertTrue("$name is not carried", name in materials)            assertTrue("$name is no Loom painting", File(repo, "apps/loom/Sources/CottonPaper/Media.xcassets/$name.imageset").isDirectory)        }    }    /** The provider is declared for passwords and passkeys, bound only by the system (Android 14's Credential Manager). */    @Test    fun the_credential_provider_is_declared() {        val manifest = File(repo, "apps/android/app/src/keys/AndroidManifest.xml").readText()        assertTrue(manifest.contains("android.permission.BIND_CREDENTIAL_PROVIDER_SERVICE"))        assertTrue(manifest.contains("android.service.credentials.CredentialProviderService"))        val provider = File(repo, "apps/android/app/src/keys/res/xml/credential_provider.xml").readText()        assertTrue(provider.contains("android.credentials.TYPE_PASSWORD_CREDENTIAL"))        assertTrue(provider.contains("androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL"))    }}