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
9 changes: 9 additions & 0 deletions .github/agent-policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ sensitive_paths:
# unreadable — never something to auto-merge. See testdata/vault-format/README.md.
- "testdata/vault-format/**"

# Screenshot baselines (docs/TEST_COVERAGE_PRD.md Phase 5). Exactly the same
# failure mode as the vault fixtures above, which is why they are gated the
# same way: re-recording a baseline makes a failing test pass WHILE RECORDING
# THE BREAK. The fix for a red screenshot test is almost always the UI, not
# the baseline, but `recordRoborazziDebug` is the easier keystroke — so an
# agent that hits a diff must never be able to bless it unattended. A human
# looks at the diff image under build/outputs/roborazzi first.
- "**/src/test/screenshots/**"

# Billing / payments (no core/licensing module anymore — no Pro tier
# for now, donation-only; these globs are for the still-live donation flow)
- "**/BtcPayClient*"
Expand Down
7 changes: 7 additions & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("libravault.android.library")
id("libravault.android.compose")
id("de.mannodermaus.android-junit5")
alias(libs.plugins.roborazzi)
}

android {
Expand Down Expand Up @@ -32,6 +33,12 @@ dependencies {
// ComponentActivity, for createAndroidComposeRule<ComponentActivity>() in
// LibravaultThemeTest — needs a real hosting Activity to assert against its Window.
testImplementation(libs.androidx.activity.compose)
// Screenshot baselines (docs/TEST_COVERAGE_PRD.md Phase 5). Attaches to the
// Robolectric Compose tests this module already runs — no emulator, no new
// test infrastructure, just captureRoboImage() on an existing tree.
testImplementation(libs.roborazzi)
testImplementation(libs.roborazzi.compose)
testImplementation(libs.roborazzi.junit.rule)
// Debug-only manifest declaring the ComponentActivity that Compose's
// createComposeRule() launches to host test content - picked up by unit
// tests too via testOptions.unitTests.isIncludeAndroidResources above.
Expand Down
137 changes: 137 additions & 0 deletions core/ui/src/test/kotlin/xyz/libravault/core/ui/ThemeScreenshotTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package xyz.libravault.core.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.unit.dp
import com.github.takahirom.roborazzi.captureRoboImage
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import xyz.libravault.core.ui.components.GeneratedCover
import xyz.libravault.core.ui.theme.LibravaultTheme
import xyz.libravault.core.ui.theme.ReadingTheme

/**
* Screenshot baselines for the three reading themes — Phase 5 of
* docs/TEST_COVERAGE_PRD.md.
*
* Runs on Robolectric with native graphics, so this is a plain JVM test in the
* existing `jvm-tests.yml` gate: no emulator, no separate CI job.
*
* ## What this is for, and what it is not for
*
* Everything else in Phase 5 asserts things the semantics tree can answer —
* contrast ratios (ColorSchemeContrastTest), accessible names
* (PlayerAccessibilityTest, ReaderTopBarAccessibilityTest). Those are precise
* and they are blind to anything about *pixels*: text clipped by a too-small
* container, controls overlapping, a divider that vanishes into its background,
* a theme that silently stops applying. Those are the regressions this catches.
*
* Deliberately a **small, stable set**: one sampler composable rendered in
* Dark, Light and Sepia. Baselines are a liability as well as an asset — every
* intentional UI change rewrites them, and a large set trains everyone to
* re-record without looking. Three images that are actually inspected beat
* thirty that are rubber-stamped.
*
* ## Re-recording is a deliberate act
*
* ```
* ./gradlew :core:ui:recordRoborazziDebug # rewrite baselines
* ./gradlew :core:ui:verifyRoborazziDebug # compare (what CI runs)
* ```
*
* The `src/test/screenshots` directory is in `.github/agent-policy.yml`
* sensitive_paths. Re-recording a baseline makes a failing test pass *while
* recording the break* — the same silent failure mode as
* `testdata/vault-format`, and the reason both are gated behind a human.
* **Look at the diff image under `build/outputs/roborazzi` before
* re-recording.**
*/
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(sdk = [34], qualifiers = "w411dp-h891dp-xhdpi")
class ThemeScreenshotTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun `dark theme sampler`() = captureSampler(ReadingTheme.DARK, darkTheme = true, name = "theme_dark")

@Test
fun `light theme sampler`() = captureSampler(ReadingTheme.LIGHT, darkTheme = false, name = "theme_light")

@Test
fun `sepia theme sampler`() = captureSampler(ReadingTheme.SEPIA, darkTheme = false, name = "theme_sepia")

private fun captureSampler(readingTheme: ReadingTheme, darkTheme: Boolean, name: String) {
composeTestRule.setContent {
LibravaultTheme(darkTheme = darkTheme, readingTheme = readingTheme) {
Sampler()
}
}
composeTestRule.onRoot().captureRoboImage("src/test/screenshots/$name.png")
}

/**
* A deliberately boring cross-section of the design system: body and
* secondary text, a filled and an outlined button, a divider, and the
* generated cover placeholder.
*
* Secondary text on `surfaceVariant` is here on purpose — that is the exact
* pairing that was below WCAG AA in sepia until it was fixed (see
* ColorSchemeContrastTest). The contrast test proves the numbers; this
* proves it still *looks* like readable text on a real surface.
*/
@Composable
private fun Sampler() {
Surface(color = MaterialTheme.colorScheme.background) {
Column(Modifier.fillMaxWidth().padding(16.dp)) {
Text("Love and Friendship", style = MaterialTheme.typography.titleLarge)
Text(
"Jane Austen",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Spacer(Modifier.size(12.dp))
HorizontalDivider()
Spacer(Modifier.size(12.dp))
Surface(color = MaterialTheme.colorScheme.surfaceVariant) {
Column(Modifier.fillMaxWidth().padding(12.dp)) {
Text("On a surface variant", style = MaterialTheme.typography.bodyLarge)
Text(
"Secondary text — the pairing that failed WCAG AA in sepia",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
Spacer(Modifier.size(12.dp))
Row {
Button(onClick = {}) { Text("Read") }
Spacer(Modifier.size(8.dp))
OutlinedButton(onClick = {}) { Text("Details") }
}
Spacer(Modifier.size(12.dp))
GeneratedCover(title = "Dune", modifier = Modifier.size(72.dp))
}
}
}
}
Binary file added core/ui/src/test/screenshots/theme_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/ui/src/test/screenshots/theme_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/ui/src/test/screenshots/theme_sepia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ android.useAndroidX=true
android.nonTransitiveRClass=true
android.enableJetifier=false
android.suppressUnsupportedCompileSdk=35

# Roborazzi screenshot baselines (docs/TEST_COVERAGE_PRD.md Phase 5).
# WITHOUT this, `captureRoboImage()` is a NO-OP in a normal test run: it neither
# records nor compares, so `./gradlew testDebugUnitTest` — which is exactly what
# jvm-tests.yml runs — passes even when the UI has visibly changed. Verified by
# mutating a theme colour and watching the suite stay green.
# Setting verify here makes comparison the default everywhere, locally and in
# CI. `recordRoborazziDebug` overrides it when baselines are updated on purpose.
roborazzi.test.verify=true
11 changes: 11 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ turbine = "1.1.0"
compose-test = "1.6.7"
bouncycastle = "1.84"
kover = "0.9.1" # JVM/Android line coverage — docs/TEST_COVERAGE_PRD.md Phase 1
roborazzi = "1.43.1" # JVM screenshot baselines — docs/TEST_COVERAGE_PRD.md Phase 5
kxml2 = "2.3.0"
webkit = "1.17.0"
zxing = "3.5.3"
Expand Down Expand Up @@ -133,6 +134,15 @@ androidx-test-ext-junit = { group = "androidx.test.ext", name =
compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4", version.ref = "compose-test" }
compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version.ref = "compose-test" }

# Testing — screenshot baselines. JVM/Robolectric, no emulator, so these run in
# the same jvm-tests.yml gate as everything else. Baselines live in
# <module>/src/test/screenshots/ and are covered by agent-policy.yml
# sensitive_paths: re-recording one makes a failing test pass while recording
# the break, the same silent failure mode as testdata/vault-format.
roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" }
roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" }
roborazzi-junit-rule = { group = "io.github.takahirom.roborazzi", name = "roborazzi-junit-rule", version.ref = "roborazzi" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
Expand All @@ -143,6 +153,7 @@ ksp = { id = "com.google.devtools.ksp", versio
hilt = { id = "com.google.dagger.hilt.android",version.ref = "hilt" }
android-junit5 = { id = "de.mannodermaus.android-junit5", version.ref = "junit5-android" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }

[bundles]
compose = ["compose-ui", "compose-ui-graphics", "compose-ui-tooling-preview", "compose-material3", "compose-icons-extended"]
Expand Down
Loading