Add a single geometry token file and a test that enforces it

Introduce ui/theme/Dimens.kt as the one source of truth for app geometry,
alongside Typography.kt for type. It defines the 4dp spacing scale
(SPACING_XXS/XS/S/M/L/XL/XXL) and receives the geometry constants that
already existed, each with a comment tying it to what it is: PEEK_WIDTH_DP
(the collapsed strip), PEEK_BUDGET_DP, MIN_ACTIVE_PANE_WIDTH_DP and
MIN_COVERED_PANE_WIDTH_DP from SlidingPaneStack.kt, DESTINATION_PILL_RESERVE
from PipelinesApp.kt, and WIDE_RAIL_WIDTH_DP and DETAIL_MAX_WIDTH_DP from
DetailTabs.kt. Call sites now import the tokens; every value is unchanged,
so no layout changes.

Add ui/theme/DimensTest.kt, a JVM test that scans the app's Kotlin sources
for raw dp/sp literals and fails with file:line:literal unless the literal
is a token or an explicit, reasoned allow-list entry. The allow-list records
the 34 literals that predate the token file, each with a written reason, and
is expected to shrink as call sites migrate onto the tokens.

Document the change and its verification in android/README.md.
This commit is contained in:
2026-10-16 11:50:26 +01:00
parent d019213c5b
commit f6b9424894
7 changed files with 337 additions and 29 deletions
+73
View File
@@ -2248,3 +2248,76 @@ Not verified in this pass: a clean *settled* frame of the selected-row highlight
only a transient mid-fade frame was captured); resume-after-pause of an
in-flight animation on device (the pause is Compose's own recomposer behaviour,
not code here).
## One source of truth for app geometry, with an enforcement test (16 Oct 2026)
`android/` only. No layout changed: every moved value is identical, so the app
renders exactly as before. No new dependency, no server/Go/installer/Docker file
touched, no run started from the app.
- **`ui/theme/Dimens.kt`** is the single source of truth for app geometry,
alongside `Typography.kt` for type. It defines the 4dp **spacing scale**
(`SPACING_XXS`/`XS`/`S`/`M`/`L`/`XL`/`XXL`, each comment tied to that base
step) and moves the geometry constants that already existed:
`PEEK_WIDTH_DP` (the collapsed/peek strip), `PEEK_BUDGET_DP`,
`MIN_ACTIVE_PANE_WIDTH_DP`, `MIN_COVERED_PANE_WIDTH_DP` (from
`SlidingPaneStack.kt`), `DESTINATION_PILL_RESERVE` (from `PipelinesApp.kt`),
`WIDE_RAIL_WIDTH_DP` and `DETAIL_MAX_WIDTH_DP` (from `DetailTabs.kt`). The
removed `LIST_PANE_WIDTH`, `COLLAPSED_LIST_PANE_WIDTH` and
`COLLAPSED_RAIL_WIDTH_DP` no longer exist, so there was nothing to move for
the "list pane width" or the rail's collapsed width; the collapsed *strip*
that survives is `PEEK_WIDTH_DP`. Call sites import the tokens; their values
(`56/224/320/112/88/200/840`) are unchanged.
- **`ui/theme/DimensTest.kt`** scans the app's Kotlin sources
(`src/main/java`, excluding `Dimens.kt`) for raw `dp`/`sp` literals, masking
comment and string contents first so prose and URLs are not hits. It
allow-lists the 34 literals that predate the file, each with a written reason
(structural zeros/hairlines, the 4dp-scale members that are not yet migrated,
component glyph sizes, the workflow-graph's own pixel geometry, container
sizes and the `sp` typography values owned by `Typography.kt`). A literal that
is neither a token nor allow-listed fails with `file:line: literal`. The list
is expected to shrink as call sites move onto the tokens.
Evidence (macOS, JDK 17 from Homebrew `openjdk@17`,
`ANDROID_HOME=~/Library/Android/sdk`, Gradle 9.7.1, `--offline`):
- `gradle :app:assembleDebug :app:testDebugUnitTest --rerun-tasks --console=plain`
→ `BUILD SUCCESSFUL`; `--rerun-tasks` re-ran all 24 result XMLs to **188 tests,
0 failures, 0 errors, 0 skipped** (up from 186/23; the new `DimensTest` adds
`rawDimensionLiteralsAreTokensOrReasonedAllowListEntries` and
`everyAllowListEntryHasAWrittenReason`).
`app/build/outputs/apk/debug/app-debug.apk` is 17,929,473 bytes, sha256
`e52ceb25…`.
- **Enforcement proof.** Adding `private val PROBE_RAW_LITERAL = 123.dp` to
`ui/PipelinesApp.kt` made
`gradle :app:testDebugUnitTest --tests net.awan.pipelines.ui.theme.DimensTest`
`FAILED` with
`raw dimension literals outside net/awan/pipelines/ui/theme/Dimens.kt: [net/awan/pipelines/ui/PipelinesApp.kt:455: 123.dp]`
(file, line and literal); removing the line made the same task
`BUILD SUCCESSFUL`. The probe was reverted.
- **Before/after screenshots on `emulator-5554` only** (fold AVD, 2076x2152 /
390dpi; never the attached Pixel, never `emulator-5556`), against the live
server, each frame captured and validated with
`scripts/capture_png.sh -s emulator-5554`: the **before** APK was built from
HEAD `d019213` (android changes stashed, built, then restored) and the
**after** APK from the working tree, each installed with
`adb -s emulator-5554 install -r`, force-stopped and relaunched. Screen A is
the Pipelines list; screen B is the "Complete a Task" pipeline detail (the
wide rail plus the covered list peek, i.e. the moved rail/detail/pane
tokens). `captures/imgdiff.py` reports `([0.0, 0.0, 0.0], 0.0)` for both the
A and B pairs — pixel-identical before and after.
- `adb -s emulator-5554 logcat -d` held 0 `FATAL EXCEPTION` / 0
`E AndroidRuntime` lines; `animator_duration_scale` was left at 1; no run was
started from the app.
- **APK publish.** `app-debug.apk` copied to
`~/.local/share/pipelines/data/artifacts/116/1/pipelines-debug-wip-d019213.apk`
(`d019213` = `git rev-parse --short HEAD`; the working tree is uncommitted WIP
on top of it), sha256 `e52ceb25…`. `curl -I
http://10.0.0.249:8080/artifacts/116/1/pipelines-debug-wip-d019213.apk`
returned `HTTP/1.1 200 OK`, `Content-Type:
application/vnd.android.package-archive`, `Content-Length: 17929473`, and a
streamed `GET | shasum -a 256` returned the same `e52ceb25…`.
Not verified in this pass: whether `:app:lintDebug` stays at its two
pre-existing `NewApi` errors (it was not run).