field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

SearchAdmissionTests.kt (3118B)


      1 package tera.smoke
      2 
      3 import kotlin.test.Test
      4 import kotlin.test.assertEquals
      5 import kotlin.test.assertFailsWith
      6 import kotlin.test.assertFalse
      7 import kotlin.test.assertTrue
      8 import kotlinx.coroutines.runBlocking
      9 import uniffi.tera_core.FfiLocalNetworkRecord
     10 import uniffi.tera_core.FfiTodayProjectionUpdate
     11 import uniffi.tera_core.TeraAppException
     12 
     13 class SearchAdmissionTests {
     14     @Test
     15     fun installedSearchPreservesTypedByteAdmissionAndClosedPrecedence(): Unit = runBlocking {
     16         SmokeFixture().use { fixture ->
     17             val runtime = fixture.runtime()
     18             val context = FfiLocalNetworkRecord(1u, "nearby", "Nearby", listOf("wss://relay.example"), null, emptyList(), 1uL)
     19             try {
     20                 val authors = (0 until 4096).map { it.toString(16).padStart(64, '0') }
     21                 val maximum = context.copy(followedAuthors = authors)
     22                 assertEquals(authors, runtime.phase1LocalNetwork(maximum).followedAuthors)
     23                 for (invalidAuthors in listOf(
     24                     authors + 4096.toString(16).padStart(64, '0'),
     25                     listOf("a".repeat(64), "a".repeat(64)),
     26                     listOf("A".repeat(64)), listOf("x".repeat(262_145)),
     27                 )) {
     28                     val failure = assertFailsWith<TeraAppException.Failure> {
     29                         runtime.phase1Search(context.copy(followedAuthors = invalidAuthors), "carrot", 20u, UNIX_S, "UTC")
     30                     }
     31                     assertEquals("invalid_local_network", failure.report.code)
     32                     assertFalse(failure.report.retryable)
     33                     assertEquals(listOf("correct_input"), failure.report.recoveryActions)
     34                 }
     35                 runtime.phase1RefreshToday(context, UNIX_S, FfiTodayProjectionUpdate.REBUILD)
     36                 for (query in listOf(
     37                     "x".repeat(257), "é".repeat(128) + "a",
     38                     " ".repeat(1_048_576) + "carrots", "x".repeat(1_048_576),
     39                     "   ", "\ncarrots", "carrots\u0000", "İ".repeat(86),
     40                 )) {
     41                     val failure = assertFailsWith<TeraAppException.Failure> {
     42                         runtime.phase1Search(context, query, 20u, UNIX_S, "UTC")
     43                     }
     44                     assertEquals("today_invalid_request", failure.report.code)
     45                     assertFalse(failure.report.retryable)
     46                     assertEquals(listOf("correct_input"), failure.report.recoveryActions)
     47                 }
     48                 for (query in listOf("x".repeat(256), "é".repeat(128), "İ".repeat(85) + "a", "  CARROT  ")) {
     49                     assertTrue(runtime.phase1Search(context, query, 20u, UNIX_S, "UTC").isEmpty())
     50                 }
     51                 runtime.shutdown()
     52                 val failure = assertFailsWith<TeraAppException.Failure> {
     53                     runtime.phase1Search(context, "x".repeat(257), 20u, UNIX_S, "UTC")
     54                 }
     55                 assertEquals("client_closed", failure.report.code)
     56             } finally {
     57                 runtime.shutdown()
     58                 runtime.close()
     59             }
     60         }
     61     }
     62 }