Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
225 changes: 168 additions & 57 deletions HANDOVER.md

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ Read this before planning a release.
| `ruff check app tests scripts migrations` | clean |
| `python -m mypy` | clean, 100 modules — asks whether anything reaches for an attribute that does not exist |
| `pytest -q -n auto` | 2024 tests, green, about four minutes — the command CI runs |
| `./gradlew test` | 1438 tests, green, all five modules |
| `./gradlew test` | 1446 tests, green, all five modules |
| `./gradlew assembleDebug` | the APK builds |
| `./gradlew assembleRelease` | the APK builds; R8 and resource shrinking pass |
| `./gradlew :core:designsystem:connectedDebugAndroidTest` | 3 tests, green on an API 37 emulator — on demand only, never in CI, which has no device |

The release build is checked in the same run as the debug one: R8 and resource shrinking
are the classic source of "it worked in debug and broke in the APK", and catching that on
Expand All @@ -233,8 +234,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
Expand Down Expand Up @@ -431,7 +435,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> =
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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -185,21 +186,34 @@ class JoinViewModel(

private val code = MutableStateFlow("")
private val submitting = MutableStateFlow(false)
private val error = MutableStateFlow<JoinError?>(null)
private val error = MutableStateFlow<ShownError?>(null)
private val joined = MutableStateFlow<JoinedClass?>(null)

/**
* An error, and the server address it was an answer from — `null` for one
* that is about the code rather than about any server.
*
* A refusal is a fact about the address that gave it. The screen used to
* keep it after the address was changed, until the next keystroke or the
* next press, so it showed a connection error about an address it no
* longer used (#176). The address can change from this screen's own link
* or from the settings, so the error is matched against the address rather
* than cleared by the one path that knows about it.
*/
private data class ShownError(val error: JoinError, val baseUrl: String?)

val uiState: StateFlow<JoinUiState> = combine(
code,
submitting,
error,
joined,
settingsRepository.settings.map { it.baseUrl },
) { code, isSubmitting, error, joined, baseUrl ->
) { code, isSubmitting, shown, joined, baseUrl ->
JoinUiState(
code = code,
baseUrl = baseUrl,
isSubmitting = isSubmitting,
error = error,
error = shown?.takeIf { it.baseUrl == null || it.baseUrl == baseUrl }?.error,
joined = joined,
)
}.stateIn(
Expand Down Expand Up @@ -239,7 +253,7 @@ class JoinViewModel(
fun submit(): String? {
val value = code.value
if (value.length !in ClassCodeLengths) {
error.value = JoinError.InvalidCode
error.value = ShownError(JoinError.InvalidCode, baseUrl = null)
return null
}
if (submitting.value) return null
Expand All @@ -250,11 +264,12 @@ class JoinViewModel(
viewModelScope.launch {
submitting.value = true
error.value = null
val address = settingsRepository.settings.first().baseUrl
val result = sessionRepository.join(value, deviceName)
val failure = result.exceptionOrNull()
if (failure != null) {
submitting.value = false
error.value = JoinError.of(failure)
error.value = ShownError(JoinError.of(failure), address)
return@launch
}
// Pull the timetable straight away. Joining only stores a token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/values-en/strings_diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
<string name="diary_insecure_server">⚠️ 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.</string>

<!-- Where the password goes, said on the form that takes it. -->
<string name="diary_password_destination">The password goes only to %1$s - over HTTPS, straight to the diary.</string>
<string name="diary_password_destination">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.</string>
<string name="diary_password_session">The server is handed only the session the diary issued. When that ends, the app will ask for the password again.</string>
<string name="diary_sign_in_where">Diary: %1$s</string>

<!-- Every way a sign-in or a read can fail; %1$s is the diary server's host. -->
Expand Down
7 changes: 5 additions & 2 deletions android/app/src/main/res/values/strings_diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@

<!-- Where the password goes, said on the form that takes it. The host comes
from the catalog bundled with the app, the same list the sign-in is
allowed to send to. -->
<string name="diary_password_destination">Пароль уйдёт только на %1$s — по HTTPS, прямо в дневник.</string>
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). -->
<string name="diary_password_destination">Пароль уйдёт только на %1$s — по HTTPS, прямо в дневник, и больше никуда: ни на наш сервер, ни на диск телефона.</string>
<string name="diary_password_session">Серверу телефон передаёт только сессию, которую выдал дневник. Когда она закончится, приложение спросит пароль ещё раз.</string>
<string name="diary_sign_in_where">Дневник: %1$s</string>

<!-- Every way a sign-in or a read can fail, one sentence each
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.lumenpearson.lessons.ui.diary

import androidx.compose.ui.test.junit4.createComposeRule
import com.lumenpearson.lessons.core.designsystem.theme.LessonsTheme
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

/**
* What the sign-in forms say about the password, read as a reader reads it:
* every paragraph, one after the other (#175).
*
* The forms showed the sentence naming the diary's host beside the general
* notice, and the notice opened by saying the same thing: «по HTTPS, прямо в
* дневник» twice, one paragraph under the other. Counting the protocol across
* what is actually drawn is the check that cannot be satisfied by a paragraph
* that merely looks different.
*/
@RunWith(RobolectricTestRunner::class)
class PasswordPrivacyTest {

@get:Rule
val compose = createComposeRule()

private fun paragraphs(host: String?): List<String> {
var drawn = emptyList<String>()
compose.setContent { LessonsTheme { drawn = passwordPrivacyParagraphs(host) } }
compose.waitForIdle()
return drawn
}

@Test
@Config(qualifiers = "ru")
fun `with a host, the Russian card says where the password goes once`() {
val text = paragraphs("region.obramur.ru").joinToString("\n")

assertEquals(text, 1, Regex("HTTPS").findAll(text).count())
assertEquals(text, 1, Regex("прямо в дневник").findAll(text).count())
assertEquals(text, 1, Regex("region\\.obramur\\.ru").findAll(text).count())
}

@Test
@Config(qualifiers = "en")
fun `with a host, the English card says where the password goes once`() {
val text = paragraphs("region.obramur.ru").joinToString("\n")

assertEquals(text, 1, Regex("HTTPS").findAll(text).count())
assertEquals(text, 1, Regex("straight to the diary").findAll(text).count())
}

@Test
@Config(qualifiers = "ru")
fun `without a host, the general notice stands alone and still says it`() {
val text = paragraphs(null).joinToString("\n")

assertEquals(text, 1, Regex("HTTPS").findAll(text).count())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.lumenpearson.lessons.ui.join

import java.io.IOException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test

/**
* A join's error is an answer from one server address, and is shown only while
* that is still the address (#176).
*
* The screen kept a connection error after the address under the button had
* been changed to a working one, so it reported a refusal about an address it
* no longer used until somebody typed or pressed again.
*/
@OptIn(ExperimentalCoroutinesApi::class)
class JoinErrorAddressTest {

@Before
fun main() = Dispatchers.setMain(UnconfinedTestDispatcher())

@After
fun reset() = Dispatchers.resetMain()

@Test
fun `a connection error goes when the address it came from is changed`() = runTest {
val rig = JoinRig().apply {
failWith = IOException("failed to connect")
settings.stored.value = settings.stored.value.copy(baseUrl = "http://10.0.2.2:8000")
}
val model = rig.model()
val watching = launch(UnconfinedTestDispatcher(testScheduler)) { model.uiState.collect {} }

model.onCodeChange("ABCD1234")
model.submit()
assertEquals(JoinError.Rejected(null), model.uiState.first { it.error != null }.error)

model.onServerUrlChange("http://127.0.0.1:8000")

assertNull(
"the old address's refusal is still under the field",
model.uiState.first { it.baseUrl == "http://127.0.0.1:8000" }.error,
)
watching.cancel()
}

@Test
fun `a wrong-length code is shown whatever the address`() = runTest {
val rig = JoinRig()
val model = rig.model()
val watching = launch(UnconfinedTestDispatcher(testScheduler)) { model.uiState.collect {} }

model.onCodeChange("ABC")
model.submit()
model.onServerUrlChange("http://127.0.0.1:8000")

assertEquals(
JoinError.InvalidCode,
model.uiState.first { it.baseUrl == "http://127.0.0.1:8000" }.error,
)
watching.cancel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ internal class JoinRig {
var syncGate: CompletableDeferred<Unit>? = null
val codes = mutableListOf<String>()

/** When set, every join fails with it, as an unreachable server does. */
var failWith: Throwable? = null
val settings = FakeSettings()

private val sessionRepository = object : SessionRepository {
override val session: Flow<Session?> = joined.map { it.lastOrNull() }
override val sessions: Flow<List<Session>> = joined
Expand All @@ -33,6 +37,7 @@ internal class JoinRig {
override suspend fun currentAll(): List<Session> = joined.value
override suspend fun join(code: String, deviceName: String?): Result<Session> {
codes += code
failWith?.let { return Result.failure(it) }
val session = Session(classId = 10L + codes.size, className = "9А", school = null, token = "t")
joined.value = joined.value + session
return Result.success(session)
Expand All @@ -56,7 +61,7 @@ internal class JoinRig {
override suspend fun forgetClassesOtherThan(keep: Set<Long>) = Unit
}

fun model() = JoinViewModel(sessionRepository, timetables, FakeSettings(), deviceName = null)
fun model() = JoinViewModel(sessionRepository, timetables, settings, deviceName = null)

/** Hands [model] to `viewModel(factory = …)`, the way the app's own factory would. */
fun factory(model: JoinViewModel = model()) = object : ViewModelProvider.Factory {
Expand Down
Loading
Loading