rouse-context/.github/workflows/android-ci.yml
monkopedia-coder 76a927ecf5
build(test): make a failing test say what failed, and stop three green-but-empty runs (#645)
Four defects that share one shape -- the mechanism runs, reports success, and
its output has stopped being evidence -- and one ~35-line region of
app/build.gradle.kts, so they land together.

#641  testLogging.exceptionFormat was unset repo-wide, so Gradle's SHORT
      applied and every CI failure logged `AssertionError at File.kt:14` with
      no message. Set FULL on tasks.withType<Test> in every subproject: the
      one place that reaches AGP's testDebugUnitTest, the Kotlin plugin's
      jvmTest, AND the hand-registered integrationTest tasks.

#632  isFailOnNoMatchingTests = false on both :app filters meant `--tests`
      matching nothing printed BUILD SUCCESSFUL having run zero tests. Nothing
      ever depended on it (no workflow passes --tests; :core:tunnel never set
      it); flipped to Gradle's default.

#636  Goldens were not a declared input of the task that compares them, so a
      local verifyRoborazziDebug exited 0 on a corrupted PNG with
      testDebugUnitTest UP-TO-DATE. Declared app/screenshots,
      fastlane/.../phoneScreenshots and notifications/screenshots as inputs.

#640  Both distribution passes wrote the same test-results/ directory and
      Gradle clears it per run, so the FOSS results never reached the CI
      artifact. Each distribution now gets its own results/reports tree.

Closes #641
Closes #632
Closes #636
Closes #640


Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-30 02:19:13 -04:00

390 lines
21 KiB
YAML

name: Android CI
on:
push:
branches: [main]
paths-ignore: ['relay/**', 'docs/**', 'deploy/**']
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Debounce
run: sleep 60
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('**/*.gradle.kts', 'gradle/libs.versions.toml') }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo (relay integration-test binary)
uses: Swatinem/rust-cache@v2
with:
workspaces: relay
- name: Build relay binary (for :core:tunnel:integrationTest)
working-directory: relay
# `--features test-mode` compiles in the test-admin surface used by
# the `:core:tunnel:integrationTest` fixture (issue #249). The feature
# is compile-time excluded from release builds (deploy workflow runs
# `cargo build --release` WITHOUT this flag).
run: cargo build --features test-mode
- name: Generate debug keystore
run: |
mkdir -p .signing
keytool -genkeypair -v \
-keystore .signing/debug.keystore \
-storepass rousecontext -keypass rousecontext \
-keyalg RSA -keysize 2048 -validity 10000 \
-alias debug \
-dname "CN=Debug,O=Debug,L=Debug,S=Debug,C=US"
- name: Lint
# Distribution is a build flag, not a flavor (#467), so a single
# ktlintCheck only sees the selected (FOSS, default) `src` dir. Run a
# second pass with `-Pgoogle` so the Firebase distribution sources are
# linted too. (`:app` is the only module whose sources vary by flag.)
run: |
./gradlew ktlintCheck
./gradlew :app:ktlintCheck -Pgoogle
- name: Check for zombie screen files
run: bash scripts/check-zombie-screens.sh
- name: Check for manual-template JSON in production code
# Per #426: prevents reintroduction of the #417 bug class where
# """{"field":"$value"}""" string templates produce malformed JSON
# when interpolated values contain quotes, backslashes, or control
# characters. Production code must use @Serializable + encodeToString.
run: bash scripts/check-no-manual-json.sh
# A green gate is not evidence the gate works: #594 was a path allowlist,
# applied unanchored to grep's `file:line:content` output, that swallowed
# any violation merely mentioning the exempt file. This runs the gate
# against a throwaway repo and asserts the red cases actually go red.
- name: "Manual-JSON gate self-test (issue #594)"
run: bash scripts/tests/check-no-manual-json-test.sh
# Same reasoning applied to #628's positive control. That control compares
# a count of goldens on disk against Roborazzi's own tally, and an
# equality check has a vacuous solution: zero == zero passes. The first
# draft went green with the goldens deleted. Runs here — no JDK, under a
# second, long before the build — so a regression in the control reports
# in seconds rather than surviving because the thing it guards happened to
# be healthy that day (#597).
- name: "Roborazzi coverage-control self-test (issue #628)"
run: bash scripts/tests/check-roborazzi-coverage-test.sh
# Where the screenshot-verify step sits below is load-bearing and nothing
# fails if it moves: above "Upload test reports" it would overwrite
# app/build/reports/tests/ before that upload collects it, so the artifact
# would omit the reports for the tests that failed (#626, live). A comment
# is documentation; this is the gate.
- name: "Roborazzi step order is preserved (issue #628)"
run: bash scripts/check-roborazzi-step-order.sh
- name: "Roborazzi step-order gate self-test (issue #628)"
run: bash scripts/tests/check-roborazzi-step-order-test.sh
# Both distributions write the SAME `app/build/outputs/apk/debug/` path
# (distribution is a flag, not a flavor — #467), so each build is verified
# immediately after it runs, before the next one overwrites it.
- name: Build (Google distribution)
run: ./gradlew :app:assembleDebug -Pgoogle
- name: "Google APK really contains Firebase (issue #548)"
# The inverse of the purity gate, and not decoration: it is the live
# positive control. The FOSS check below can only be trusted if these
# patterns still match real Firebase code, and this proves they do on
# every run — so the gate cannot rot into one that matches nothing and
# passes everything (#579).
run: bash scripts/check-apk-distribution.sh --apk app/build/outputs/apk/debug/app-debug.apk --expect google
- name: Build (FOSS distribution, Firebase-free)
# Bare build (no `-Pgoogle`) is the FOSS distribution: it skips the
# Firebase Gradle plugins and proves it assembles without
# google-services. See #467.
run: ./gradlew :app:assembleDebug
- name: "FOSS APK contains no Google/Firebase code (issue #548)"
# Reads the artifact, not the build config: whatever flips the gate — a
# stray -P flag, a gradle.properties line, an ambient
# ORG_GRADLE_PROJECT_google — lands in the DEX and is caught here.
# `android-ci.yml` builds both distributions too (#585); without these
# the gate would live only in `ci.yml`, and deleting that job as a
# "duplicate build" would silently take the purity check with it.
run: bash scripts/check-apk-distribution.sh --apk app/build/outputs/apk/debug/app-debug.apk --expect foss
- name: Unit tests
timeout-minutes: 20
# Distribution is a build flag (#467), so `:app` unit tests run twice:
# bare = FOSS (ACRA / keypair seams), `-Pgoogle` = Firebase-backed. The
# library modules are distribution-agnostic and run once.
run: |
./gradlew \
:core:tunnel:jvmTest \
:core:mcp:jvmTest \
:core:bridge:jvmTest \
:api:testDebugUnitTest \
:notifications:testDebugUnitTest \
:work:testDebugUnitTest \
:integrations:testDebugUnitTest \
:app:testDebugUnitTest
./gradlew :app:testDebugUnitTest -Pgoogle
- name: Integration tests (relay)
if: success() || failure()
# Raised from 10 → 15 as the integration-scenario coverage grew
# through #247's batches. Both :core:tunnel:integrationTest and
# :app:integrationTest launch the real relay subprocess (Rust TLS
# handshake + Robolectric Android runtime), so each scenario costs
# several real seconds; the 10-min cap started truncating CI at
# ~120 tests (see the #285/#287 CI failures).
# Three serial integration suites (:core:tunnel + :app FOSS + :app
# Google) share the relay binary; 15 min was sized for two, and adding
# the second :app suite (#469) pushed the step over — bumped to 30.
timeout-minutes: 30
# `:app:integrationTest` boots the real AppModule Koin graph against the
# same `--test-mode` relay used by `:core:tunnel:integrationTest` (issue
# #250 scaffold; umbrella #247). With distribution as a build flag (#467)
# it runs once bare — FOSS, so the keypair device-identity round trip
# (register → provision → renew, zero Firebase) is covered (#469, part of
# #460) — and once with `-Pgoogle` for the Firebase-backed path. The
# FOSS pass (with :core:tunnel) runs first, then the Google pass; both
# reuse the relay binary built above. The Google pass runs last so the
# `koverHtmlReport` step (also `-Pgoogle`) reuses its results UP-TO-DATE.
run: |
./gradlew :core:tunnel:integrationTest :app:integrationTest
./gradlew :app:integrationTest -Pgoogle
- name: Coverage report (Kover)
# Runs after unit + integration tests. Kover would also trigger tests
# on its own, but the preceding steps already ran them — Gradle will
# reuse those results via `UP-TO-DATE`, so this step just aggregates.
# `-Pgoogle` so the `:app` coverage tracks the shipping Firebase
# distribution (matching the pre-#467 google-flavor-only coverage); its
# Google unit + integration runs above are reused UP-TO-DATE.
if: success() || failure()
timeout-minutes: 10
run: ./gradlew koverHtmlReport koverXmlReport -Pgoogle
- name: Per-module coverage summary
if: success() || failure()
run: |
set -euo pipefail
{
echo "## Coverage (line %)"
echo
echo "| Module | Covered | Missed | Line % |"
echo "|---|---:|---:|---:|"
modules=(api core/tunnel core/mcp core/bridge notifications work integrations app)
total_cov=0
total_mis=0
for m in "${modules[@]}"; do
f="$m/build/reports/kover/report.xml"
if [ ! -f "$f" ]; then
echo "| \`:$m\` | — | — | (no report) |"
continue
fi
# The last LINE counter in a Kover XML is the module total.
line=$(grep -E '<counter type="LINE"' "$f" | tail -1)
cov=$(echo "$line" | sed -n 's/.*covered="\([0-9]*\)".*/\1/p')
mis=$(echo "$line" | sed -n 's/.*missed="\([0-9]*\)".*/\1/p')
cov=${cov:-0}
mis=${mis:-0}
tot=$((cov + mis))
if [ "$tot" -eq 0 ]; then
pct="—"
else
pct=$(awk "BEGIN { printf \"%.1f%%\", ($cov * 100) / $tot }")
fi
echo "| \`:${m//\//:}\` | $cov | $mis | $pct |"
total_cov=$((total_cov + cov))
total_mis=$((total_mis + mis))
done
grand_tot=$((total_cov + total_mis))
if [ "$grand_tot" -gt 0 ]; then
grand_pct=$(awk "BEGIN { printf \"%.1f%%\", ($total_cov * 100) / $grand_tot }")
else
grand_pct="—"
fi
echo "| **Total** | **$total_cov** | **$total_mis** | **$grand_pct** |"
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage HTML
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: test-coverage
path: build/reports/kover/html/
# HTML is for a human reading a report in a browser; it is NOT where the
# failure text lives in a form anything can parse. Both uploads sit here,
# ABOVE the Roborazzi verify step, for the reason spelled out at that step:
# verify re-runs `:app`'s unit suite and overwrites both
# `app/build/reports/tests/` and `app/build/test-results/`.
# Deliberately NOT scoped to which step failed. `Integration tests (relay)`
# and `Coverage report (Kover)` both carry `if: success() || failure()`,
# so at least one test-running step executes in every non-cancelled run of
# this job — including one where `Lint` or a build step went red first.
# There is therefore always something to collect, and a step-scoped
# condition here would be a no-op dressed up as a gate.
#
# One case does reach `if-no-files-found: error` with nothing to upload: a
# compile failure in the test sources, where no task gets far enough to
# write a report. That adds a second red step to an already-red run, which
# is the right trade for never letting an empty artifact report as a clean
# upload.
- name: Upload test reports (HTML)
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: test-reports
if-no-files-found: error
path: "**/build/reports/tests/"
# The XML is the half of a test report that a tool can read: the failure
# message, the type, the full stack trace, and the captured stdout. Until
# #631 no workflow collected it — `Android CI` run 33135432024's
# `test-reports` artifact held 258 HTML files and zero XML.
#
# What this does NOT do, stated plainly because #631 originally claimed
# otherwise: it would not have recovered that run's `:app:integrationTest`
# failures. That task was killed by its own Gradle task timeout
# (`timeout.set(Duration.ofMinutes(10L))`, app/build.gradle.kts) --
# "Requesting stop of task ':app:integrationTest' as it has exceeded its
# configured timeout of 10m" -- and Gradle writes nothing at all for a
# Test task killed that way: no XML, no HTML, no binary results. Confirmed
# from the incident's own artifacts: `app/build/reports/tests/
# integrationTest` is ABSENT from the timed-out attempt and present in the
# green re-run, while `core/tunnel`'s appears in both. So this closes a
# real gap for every test task that COMPLETES -- which is most of them --
# and closes nothing for one that is killed.
#
# The bare `java.lang.AssertionError` with no message in that log is a
# separate defect: Gradle's `testLogging.exceptionFormat` defaults to
# SHORT and is unset repo-wide (#641). That fix matters more than this one
# for the same symptom, because the job log survives a task kill, the
# runner, and artifact expiry -- which no artifact does.
#
# Uploaded unconditionally, not `if: failure()`, for two reasons beyond
# size (the XML for a full run is a few hundred KB): a green run's XML is
# the only record of WHICH tests executed, and `BUILD SUCCESSFUL` prints
# identically for a full suite and for zero tests. Counting `<testcase>`
# elements in a green run's artifact is what distinguishes the two.
#
# Read that count per suite directory. `:app`'s two distribution passes
# now write SEPARATE trees (#640) --
#
# app/build/test-results/testDebugUnitTest/foss/ 76 files / 623 tests
# app/build/test-results/testDebugUnitTest/google/ 73 files / 614 tests
#
# -- so both survive to the upload. They did not before: both passes wrote
# `app/build/test-results/testDebugUnitTest/` and Gradle clears it per run,
# so green run 33228348111's artifact held the `-Pgoogle` pass only (73
# files / 614 tests) and the seven FOSS-only classes -- ACRA, UnifiedPush,
# the FOSS FGS selector -- ran, passed, and left no record anywhere.
#
# The counts differ legitimately: each distribution compiles its own
# `src/test{Foss,Google}` sources, so neither is a subset failure.
#
# A SEPARATE step, and a separate artifact name, on purpose:
# `if-no-files-found` is evaluated over a step's whole match set, so
# folding these two paths into one step would let the HTML satisfy the
# check while the XML path silently matched nothing — the exact defect
# this issue is about. And the names must differ: upload-artifact@v4
# documents that "artifact names must be unique since each created
# artifact is idempotent", and with the default `overwrite: false` a
# second upload under the same name fails the step rather than merging.
#
# `if-no-files-found: error` on both, rather than the default `warn`.
# `warn` leaves an annotation and a GREEN step, so an artifact containing
# nothing would be indistinguishable from one that worked. That is the
# same shape as #626 and this issue -- a collection step whose output
# nobody checks -- not the same cause.
- name: Upload test results (XML)
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: test-results-xml
if-no-files-found: error
path: "**/build/test-results/**/*.xml"
# Screenshot verification runs LAST, and that placement is load-bearing
# (issue #628).
#
# Until now no workflow ran any Roborazzi task at all: `testDebugUnitTest`
# executes the screenshot tests in Roborazzi's DEFAULT mode, which renders
# each composable and passes without ever comparing it to the committed
# PNG. #490 and #508 both shipped stale goldens fully green that way, for
# ~2 and ~9 weeks, and the drift surfaced only because an unrelated PR
# (#610) happened to run a record task. `verifyRoborazziDebug` is the mode
# that actually compares.
#
# Why last, rather than next to the "Unit tests" step it belongs beside:
#
# * Verify mode is a task INPUT, not a flag on the side. Measured: a
# plain `:app:testDebugUnitTest` immediately after a verify run
# re-EXECUTES (4 executed, 111 up-to-date) rather than reporting
# UP-TO-DATE, and vice versa. So a verify step placed anywhere above
# "Coverage report (Kover)" would leave `:app:testDebugUnitTest` out of
# date for Kover's `-Pgoogle` pass, falsifying that step's documented
# "Gradle will reuse those results via UP-TO-DATE" and adding a full
# ~1.5-min suite re-run inside its 10-minute cap. Below the Kover step,
# the inputs Kover sees are byte-identical to before this change.
#
# * The verify run re-runs `:app`'s whole unit suite and OVERWRITES both
# `app/build/reports/tests/` and `app/build/test-results/`. Above the
# two upload steps it would clobber a failing `-Pgoogle` run's report
# AND its XML with its own — producing precisely #626's
# artifact-that-omits-the-failure, and #631's
# artifact-without-the-assertion-message. Below them, both are already
# collected. `scripts/check-roborazzi-step-order.sh` pins this.
#
# `:notifications` carries 40 goldens of its own and had the identical
# hole, so it is verified in the same invocation. `--continue` so a
# mismatch in one module still reports the other's, instead of the first
# failure masking the rest.
- name: "Screenshot goldens match the committed PNGs (issue #628)"
id: roborazzi
if: success() || failure()
timeout-minutes: 20
# Bare (FOSS) distribution: the screenshot tests live in the shared
# `src/test` tree and the goldens are recorded with a bare
# `./gradlew :app:recordRoborazziDebug`, so this compares like for like.
run: ./gradlew :app:verifyRoborazziDebug :notifications:verifyRoborazziDebug --continue
# A green verify is NOT evidence that verification happened: Roborazzi
# prints BUILD SUCCESSFUL both when it compared 129 goldens and found no
# drift and when it compared zero. That second state is the one CI was
# already in, and the same rot #579/#594 describe for the grep gates. This
# reads the tally Roborazzi writes and asserts it equals the number of
# golden PNGs actually committed, so the gate cannot quietly stop covering
# them. Runs even when the verify above went red — the tally is written
# either way, and a mismatch changes what the red X means.
- name: "Roborazzi really compared every committed golden (issue #628)"
id: roborazzi_coverage
if: success() || failure()
run: bash scripts/check-roborazzi-coverage.sh
# `outputs/roborazzi/` is where Roborazzi writes `<name>_actual.png` and
# `<name>_compare.png` on a mismatch, and it is EMPTY on a clean run —
# confirmed by running the verify task against a deliberately perturbed
# golden and listing the tree. `reports/roborazzi/` holds the HTML index,
# whose <img> tags point at `../../../outputs/roborazzi/<name>_compare.png`
# — a repo-relative link, so both trees must be uploaded together and with
# their paths intact or the report renders as broken images. Uploading
# them as sibling paths makes upload-artifact root the archive at their
# common ancestor, which preserves that link. `test-results/roborazzi/`
# carries the JSON tallies the step above asserts on.
#
# `if-no-files-found: error` is deliberate: the HTML index is written on
# every verify run that reaches the comparison, so an empty artifact here
# means the paths have moved — the failure mode where an artifact is named
# for exactly the thing it omits (#626).
- name: Upload Roborazzi comparison images
if: failure() && (steps.roborazzi.outcome == 'failure' || steps.roborazzi_coverage.outcome == 'failure')
uses: actions/upload-artifact@v4
with:
name: roborazzi-screenshot-diffs
if-no-files-found: error
path: |
app/build/outputs/roborazzi/
app/build/reports/roborazzi/
app/build/test-results/roborazzi/
notifications/build/outputs/roborazzi/
notifications/build/reports/roborazzi/
notifications/build/test-results/roborazzi/