From 4a1a58524a03d53baecfc5e48df505a43f926944 Mon Sep 17 00:00:00 2001 From: leather147 Date: Sun, 27 Sep 2026 01:04:11 +0300 Subject: [PATCH 1/6] Give the project its first instrumented tests, of the tab bar's arranging gesture on a device There was no androidTest source set anywhere, so the one thing a hand notices about the arranging gesture could not be asked: whether half a slot, at a device's real density and with its real long-press timeout, is where a tab changes place. The JVM tests drag ten thousand pixels to land on an answer Robolectric's densities cannot move. ToolbarOnDeviceTest, in :core:designsystem, holds a tab and drags it 0.7 and 0.4 of a slot in one touch: the first moves it exactly one place and is not taken for a tap, the second puts it back. A third taps the page with the mode open and checks the dismiss layer closes it and passes nothing through. All three pass on the API 37 emulator in 14 seconds, with `./gradlew :core:designsystem:connectedDebugAndroidTest`. The Compose BOM's ui-test-junit4 brings Espresso 3.5.0, which reaches for InputManager.getInstance by reflection; API 34 removed it and every test failed at its first onIdle. Espresso 3.7.0 and runner 1.7.0 are pinned in the catalog, read from Google Maven's metadata, where each is the current release. Not in CI, on purpose: CI has no device. CLAUDE.md, docs/build.md, the README and docs/architecture.md say how to run it and that it is the only test that touches a device. Closes #110 --- CLAUDE.md | 3 + README.md | 9 +- android/core/designsystem/build.gradle.kts | 13 ++ .../component/ToolbarOnDeviceTest.kt | 176 ++++++++++++++++++ android/gradle/libs.versions.toml | 11 ++ docs/architecture.md | 6 +- docs/build.md | 15 ++ 7 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 android/core/designsystem/src/androidTest/kotlin/com/lumenpearson/lessons/core/designsystem/component/ToolbarOnDeviceTest.kt diff --git a/CLAUDE.md b/CLAUDE.md index 41058693..c2ddd6b5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -73,6 +73,9 @@ Android, from `android/`: - **`./gradlew assembleDebug`** and **`./gradlew assembleRelease`** — CI builds both on every push, because R8 and resource shrinking are where "worked in debug" stops being true - `./gradlew lint` runs the AGP Android lint; CI does not, so do not report it as a gate +- `./gradlew :core:designsystem:connectedDebugAndroidTest` — the one instrumented source set + (#110), on a running emulator or a connected phone. Not a CI gate: CI has no device, and a + gate that cannot run is worse than none The app is set in **two** bundled faces, both under `core/designsystem/src/main/res/font/` and both carrying one axis, `wght`: diff --git a/README.md b/README.md index ecd72bea..8493403f 100644 --- a/README.md +++ b/README.md @@ -233,8 +233,11 @@ on the emulator, which the owner was using at the same time, only the one-touch the pill's round end were seen. What it could not give is written in `HANDOVER.md`: a thumb, haptics, a real GPU, Doze on a school morning, TalkBack, a real diary account. -**What nothing checks automatically.** There is no `androidTest` directory in this project: -not one test runs on a device or an emulator. About two dozen of the app's screens, sheets and rows — +**What nothing checks automatically.** One test source set runs on a device, and only on +demand: `ToolbarOnDeviceTest` in `:core:designsystem` (#110), three tests of the tab bar's +arranging gesture at the device's own density, run with `connectedDebugAndroidTest` on an +emulator or a phone and never in CI, which has no device. Everything else is the JVM. About +two dozen of the app's screens, sheets and rows — the class list, the join mode, the connection errors, the first-run reveal and the terms line under its button, the diary home, the crash-report sheet, the calendar's header, its two sheets, its year picker and its day list, and the rest — are @@ -431,7 +434,7 @@ thread. The details and the reasons are in [docs/design.md](docs/design.md#what-of-this-list-is-already-fixed). None of the five has been checked on a screen. All of them are about what the eye sees, -and there is no `androidTest` in this project, so what is proved here is only that the size +and no test in this project looks at a screen, so what is proved here is only that the size ladder's logic became monotonic over real sizes rather than over rungs. **The app crashed wherever a line of text was drawn, and had done since the marquee diff --git a/android/core/designsystem/build.gradle.kts b/android/core/designsystem/build.gradle.kts index 78347652..69f2aad6 100644 --- a/android/core/designsystem/build.gradle.kts +++ b/android/core/designsystem/build.gradle.kts @@ -21,6 +21,11 @@ android { defaultConfig { minSdk = 26 + // The project's first instrumented tests (#110), which run only on a + // device: `./gradlew :core:designsystem:connectedDebugAndroidTest`. Not + // a CI gate, because CI has no device, and a gate that cannot run is + // worse than none. + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildFeatures { @@ -90,4 +95,12 @@ dependencies { testImplementation(composeBom) testImplementation(libs.androidx.compose.ui.test.junit4) debugImplementation(libs.androidx.compose.ui.test.manifest) + + // The same Compose test library the JVM tests use, from the same BOM. It + // brings the runner and Espresso too, at versions from before API 34; + // the two below lift them to ones that run on it (see the catalog). + androidTestImplementation(composeBom) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + androidTestImplementation(libs.androidx.test.espresso.core) + androidTestImplementation(libs.androidx.test.runner) } diff --git a/android/core/designsystem/src/androidTest/kotlin/com/lumenpearson/lessons/core/designsystem/component/ToolbarOnDeviceTest.kt b/android/core/designsystem/src/androidTest/kotlin/com/lumenpearson/lessons/core/designsystem/component/ToolbarOnDeviceTest.kt new file mode 100644 index 00000000..1f103417 --- /dev/null +++ b/android/core/designsystem/src/androidTest/kotlin/com/lumenpearson/lessons/core/designsystem/component/ToolbarOnDeviceTest.kt @@ -0,0 +1,176 @@ +package com.lumenpearson.lessons.core.designsystem.component + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Settings +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.Snapshot +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.click +import androidx.compose.ui.test.down +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.moveBy +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performTouchInput +import androidx.compose.ui.test.up +import androidx.compose.ui.unit.dp +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.lumenpearson.lessons.core.designsystem.theme.LessonsTheme +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/** + * The tab bar's arranging gesture on a device: the project's first instrumented + * tests (#110). + * + * The JVM tests drive the same gesture under Robolectric, whose densities and + * `ViewConfiguration` are its own, so they drag ten thousand pixels to land on + * an answer that holds under any of them. What they could not ask is the one + * thing a hand notices: whether half a slot, at the device's real density and + * with its real long-press timeout and touch slop, is where a tab changes + * place. That is what these drags measure — a fraction of one slot's pitch, in + * the device's own pixels. + * + * The clock is held, as in the JVM tests, and for the same reason: the jiggle + * and the labels' marquee run for ever, so a clock left to advance on its own + * would never find the composition idle. + */ +@RunWith(AndroidJUnit4::class) +class ToolbarOnDeviceTest { + + @get:Rule + val compose = createComposeRule() + + @Before + fun holdTheClock() { + compose.mainClock.autoAdvance = false + } + + private val labels = listOf("Сегодня", "Календарь", "Задания") + + private var reordering by mutableStateOf(false) + private var reported: List? = null + private var tapped = false + private var dismissed = 0 + private var pageTapped = false + + @Test + fun a_long_press_carried_past_half_a_slot_moves_the_tab_one_place() { + showBar() + + compose.holdAndDrag(labels[0], slots = 0.7f) + + assertTrue("the long press did not open the mode", reordering) + assertEquals("the same touch did not carry the tab one place", listOf(1, 0, 2), reported) + assertFalse("the lift that ended the drag was taken for a tap", tapped) + } + + @Test + fun a_long_press_carried_short_of_half_a_slot_puts_the_tab_back() { + showBar() + + compose.holdAndDrag(labels[0], slots = 0.4f) + + assertTrue("the long press did not open the mode", reordering) + assertNull("a drag short of half a slot reported a new order", reported) + } + + @Test + fun a_tap_on_the_page_closes_the_mode_and_reaches_nothing() { + showBar() + compose.holdAndDrag(labels[0], slots = 0f) + assertTrue("the long press did not open the mode", reordering) + + compose.onNodeWithTag(Page).performTouchInput { click(Offset(40f, 40f)) } + compose.settle() + + assertEquals("the tap outside the bar did not close the mode", 1, dismissed) + assertFalse("the tap reached the page under the layer", pageTapped) + } + + private fun showBar() { + compose.setContent { + LessonsTheme { + Box(Modifier.fillMaxSize()) { + Box( + Modifier + .fillMaxSize() + .testTag(Page) + .clickable { pageTapped = true }, + ) + if (reordering) { + ArrangingDismissLayer(onDismiss = { + dismissed++ + reordering = false + }) + } + LessonsFloatingToolbar( + modifier = Modifier.align(Alignment.BottomCenter), + items = labels.map { label -> + ToolbarItem(icon = Icons.Rounded.Settings, label = label) { tapped = true } + }, + selectedIndex = 0, + reorderable = true, + reordering = reordering, + onReorderingChange = { reordering = it }, + onReorder = { reported = it }, + ) + } + } + } + compose.settle() + } + + /** + * Down, a wait past the long-press timeout on the composition's clock, and + * a move of [slots] times the row's pitch in the device's own pixels, in + * ten steps, then the lift — one touch throughout. + */ + private fun ComposeContentTestRule.holdAndDrag(label: String, slots: Float) { + val pitch = with(density) { SlotPitch.toPx() } + onNodeWithContentDescription(label).performTouchInput { down(center) } + settle() + mainClock.advanceTimeBy(LongPressWaitMillis) + settle() + repeat(Steps) { + onNodeWithContentDescription(label).performTouchInput { + moveBy(Offset(pitch * slots / Steps, 0f)) + } + settle(frames = 2) + } + onNodeWithContentDescription(label).performTouchInput { up() } + settle(frames = 60) + } + + /** Frames by hand; see the JVM tests' `settle` for why the notification comes first. */ + private fun ComposeContentTestRule.settle(frames: Int = 6) { + Snapshot.sendApplyNotifications() + repeat(frames) { mainClock.advanceTimeByFrame() } + } + + private companion object { + const val Page = "page" + const val Steps = 10 + + /** Past any platform's long-press timeout, which is 400–500 ms. */ + const val LongPressWaitMillis = 1_000L + + /** One tab and the gap after it, as `ToolbarItems` counts a slot. */ + val SlotPitch = 56.dp + } +} diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index b3181f03..f10f361c 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -12,6 +12,13 @@ # okhttp at the same version; it rides `version.ref = "okhttp"` so the # two can never be bumped apart. # +# espresso-core, androidx.test runner -> Google Maven's maven-metadata.xml, +# read on 27 September 2026, where each is the . Instrumented +# tests only (#110). The Compose BOM's ui-test-junit4 brings espresso +# 3.5.0 and runner 1.5.0, and espresso 3.5.0 reaches for +# InputManager.getInstance by reflection, which API 34 removed: every +# test failed at its first Espresso.onIdle on the API 37 emulator. +# # The first CI run failed on invented versions (room 2.9.2, navigation 2.9.6, # okhttp 5.2.0, kotlinx-serialization-json 1.9.1) that do not exist in any # repository. Verify a version against its repository before adding it here. @@ -42,6 +49,8 @@ coroutines = "1.11.0" junit = "4.13.2" robolectric = "4.17" +espresso = "3.7.0" +androidxTestRunner = "1.7.0" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } @@ -81,6 +90,8 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor junit = { group = "junit", name = "junit", version.ref = "junit" } robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } +androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso" } +androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTestRunner" } androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } diff --git a/docs/architecture.md b/docs/architecture.md index 079a3810..01a8aa7c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -762,8 +762,10 @@ The table below is the load-bearing part of that rather than the whole of it: | `android/app/.../RootGateTest.kt`, `SyncArmingTest.kt` | which home each mode opens on, and that the class sync is armed in a class only | JVM JUnit | | `android/app/.../ui/onboarding/OnboardingFlowTest.kt`, `OnboardingViewModelTest.kt` | the first run's routes, dots and resume, and that the saved state never carries a credential | JVM JUnit | -What nothing covers is a device: there is no `androidTest` directory, so not one test has -run on hardware or an emulator. About two dozen of the app's screens, sheets and rows are +A device is covered by one source set, on demand: `ToolbarOnDeviceTest`, the project's +only `androidTest` (#110), drags the tab bar's arranging gesture by fractions of a slot at +the device's own density with `connectedDebugAndroidTest`, on an emulator or a phone. CI has +no device and does not run it. About two dozen of the app's screens, sheets and rows are composed under Robolectric with a Russian locale and a phone's width — among them the class list, the join mode, the connection errors, the first-run reveal and its legal line, the diary home, the crash-report sheet, the two sheets the calendar reopens after a rotation, its diff --git a/docs/build.md b/docs/build.md index 5f2921f4..62ade838 100644 --- a/docs/build.md +++ b/docs/build.md @@ -778,6 +778,21 @@ behaves with the server gone, remove the tunnel instead (`adb reverse --remove t On Windows the server needs one package Linux does not: the time-zone database. It is declared in `pyproject.toml` for Windows only (#170), so `pip install -e ".[dev]"` brings it. +### Instrumented tests + +One source set runs on a device rather than the JVM: `:core:designsystem`'s `androidTest` +(#110). With an emulator running or a phone connected: + +```bash +./gradlew :core:designsystem:connectedDebugAndroidTest +``` + +It installs a test APK of its own and does not touch the installed app. It is not in CI and +must not be: CI has no device. Its two test libraries are pinned in the catalog above what +the Compose BOM brings, because the BOM's Espresso 3.5.0 reaches for +`InputManager.getInstance` by reflection, which API 34 removed, and every test failed at its +first `onIdle` on the API 37 emulator. + ### Why HTTP and not HTTPS Since Android 9 the system blocks `http://` by default. The app allows it through From 7108c93fee8cdb9efc1e47940c0532660bb3e531 Mon Sep 17 00:00:00 2001 From: leather147 Date: Sun, 27 Sep 2026 01:09:14 +0300 Subject: [PATCH 2/6] Say where the password goes once on the sign-in forms, not twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both forms that take a diary password showed the sentence naming the diary's host beside the general notice, and the notice opened by saying it again: «по HTTPS, прямо в дневник», one paragraph under the other. With a host known, the sentence that names it now also says the password goes nowhere else, and the second paragraph is only what happens to the session. Without one, the general notice stands alone as before. One function decides the paragraphs for both forms, so they cannot drift apart again. PasswordPrivacyTest counts «HTTPS» across what is drawn, in both languages, and fails on the old pair. Closes #175 --- .../lessons/ui/diary/DiarySignInScreen.kt | 17 +++--- .../lessons/ui/diary/PasswordPrivacy.kt | 27 ++++++++ .../lessons/ui/onboarding/SignInPage.kt | 8 +-- .../src/main/res/values-en/strings_diary.xml | 3 +- .../app/src/main/res/values/strings_diary.xml | 7 ++- .../lessons/ui/diary/PasswordPrivacyTest.kt | 61 +++++++++++++++++++ 6 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/PasswordPrivacy.kt create mode 100644 android/app/src/test/kotlin/com/lumenpearson/lessons/ui/diary/PasswordPrivacyTest.kt diff --git a/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/DiarySignInScreen.kt b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/DiarySignInScreen.kt index a33b87d2..8c78840c 100644 --- a/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/DiarySignInScreen.kt +++ b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/DiarySignInScreen.kt @@ -155,18 +155,19 @@ fun DiarySignInScreen( modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp), ) { - place?.host?.let { host -> + passwordPrivacyParagraphs(place?.host).forEachIndexed { index, paragraph -> Text( - text = correctedString(R.string.diary_password_destination, host), + text = paragraph, style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurface, + // The sentence naming the host first and brightest: + // it is the one fact on this card a reader can check. + color = if (index == 0 && place?.host != null) { + MaterialTheme.colorScheme.onSurface + } else { + MaterialTheme.colorScheme.onSurfaceVariant + }, ) } - Text( - text = correctedString(R.string.diary_password_notice), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) } } } diff --git a/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/PasswordPrivacy.kt b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/PasswordPrivacy.kt new file mode 100644 index 00000000..551675c5 --- /dev/null +++ b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/diary/PasswordPrivacy.kt @@ -0,0 +1,27 @@ +package com.lumenpearson.lessons.ui.diary + +import androidx.compose.runtime.Composable +import com.lumenpearson.lessons.R +import com.lumenpearson.lessons.core.designsystem.text.correctedString + +/** + * What a sign-in form says about where the password goes, in the order it is + * said, for both forms that take one — the diary's own and the first run's. + * + * With the diary's host known, the sentence that names it also says it goes + * nowhere else, and the rest is only what happens to the session. The two + * forms used to show that sentence beside the general notice, which opened by + * saying it all again: «по HTTPS, прямо в дневник» twice, one paragraph after + * the other (#175). Without a host, which a region handed off to its own site + * never reaches this far to have, the general notice stands alone. + */ +@Composable +internal fun passwordPrivacyParagraphs(host: String?): List = + if (host != null) { + listOf( + correctedString(R.string.diary_password_destination, host), + correctedString(R.string.diary_password_session), + ) + } else { + listOf(correctedString(R.string.diary_password_notice)) + } diff --git a/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/onboarding/SignInPage.kt b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/onboarding/SignInPage.kt index c886bc65..3298e4a7 100644 --- a/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/onboarding/SignInPage.kt +++ b/android/app/src/main/kotlin/com/lumenpearson/lessons/ui/onboarding/SignInPage.kt @@ -43,6 +43,7 @@ import com.lumenpearson.lessons.ui.common.ServerUrlSheet import com.lumenpearson.lessons.ui.common.openInBrowser import com.lumenpearson.lessons.ui.diary.DiaryCredentialFields import com.lumenpearson.lessons.ui.diary.asText +import com.lumenpearson.lessons.ui.diary.passwordPrivacyParagraphs import com.lumenpearson.lessons.ui.diary.regionName import com.lumenpearson.lessons.ui.diary.systemName @@ -150,12 +151,7 @@ internal fun SignInPage( Column(modifier = Modifier.fillMaxWidth()) { SectionHeader(title = correctedString(R.string.onboarding_sign_in_privacy_title)) - NoteCard( - listOfNotNull( - current.place.host?.let { correctedString(R.string.diary_password_destination, it) }, - correctedString(R.string.diary_password_notice), - ).joinToString("\n\n"), - ) + NoteCard(passwordPrivacyParagraphs(current.place.host).joinToString("\n\n")) } if (isInsecure(baseUrl)) NoteCard(correctedString(R.string.diary_insecure_server)) diff --git a/android/app/src/main/res/values-en/strings_diary.xml b/android/app/src/main/res/values-en/strings_diary.xml index 45248097..1e86a60e 100644 --- a/android/app/src/main/res/values-en/strings_diary.xml +++ b/android/app/src/main/res/values-en/strings_diary.xml @@ -109,7 +109,8 @@ ⚠️ The server address starts with http://. That does not touch the password - it goes straight to the diary over HTTPS. But the session the diary issues, and the key to it, travel to the server in the clear: anyone on the same Wi-Fi can pick them up and open your diary. Set up https:// on the server if you can. - The password goes only to %1$s - over HTTPS, straight to the diary. + The password goes only to %1$s - over HTTPS, straight to the diary, and nowhere else: not to our server and not to this phone\'s storage. + The server is handed only the session the diary issued. When that ends, the app will ask for the password again. Diary: %1$s diff --git a/android/app/src/main/res/values/strings_diary.xml b/android/app/src/main/res/values/strings_diary.xml index 5d74befd..aa5ede5a 100644 --- a/android/app/src/main/res/values/strings_diary.xml +++ b/android/app/src/main/res/values/strings_diary.xml @@ -112,8 +112,11 @@ - Пароль уйдёт только на %1$s — по HTTPS, прямо в дневник. + allowed to send to. With a host, these two stand in for + diary_password_notice rather than beside it: the notice said the first + half again (#175). --> + Пароль уйдёт только на %1$s — по HTTPS, прямо в дневник, и больше никуда: ни на наш сервер, ни на диск телефона. + Серверу телефон передаёт только сессию, которую выдал дневник. Когда она закончится, приложение спросит пароль ещё раз. Дневник: %1$s