Make the gate one command, and add static analysis behind a baseline

Everything this repository promised was voluntary until now: 371 tests, lint and the generated code
map ran only if whoever changed the code remembered to run them. tools/verify.sh is that gate as one
command - the map check, detekt, the unit tests and lint, cheapest first so a stale document fails in
a second rather than after a release build - and --release adds the R8 build. The ordering is not
cosmetic: the two cheapest checks are also the two that catch drift nothing else can see.

The same script runs in three places: CI on every push and pull request, a nightly --release job (R8
is the one check nothing else performs, and it has hidden a real defect here once), and a pre-push
hook once the clone has been told to use .githooks. The nightly also uploads the R8 mapping, which is
what turns a release stack trace back into a line of Kotlin and is only worth keeping if it belongs
to the build that shipped.

Detekt is adopted with a baseline, which is the entire adoption strategy: everything it finds today
is frozen in config/detekt/baseline.xml, so the gate fails on a new finding rather than on a backlog
nobody is going to clear this week. Entries are keyed by rule, file and enclosing declaration, so a
new long function is still reported inside a file that already has one - proved by writing a TODO
into a file, watching the build fail on that exact line, and taking it out again. What it found
first agrees with the churn numbers from the last pass: ArchiveEngine 16 findings, BrowserViewModel
11, SelectionBar 9, 86 in total over 13 rules, the largest groups being the complexity ones this was
added for (cyclomatic complexity 10, nested block depth 7, too many functions 4, long methods 3, two
classes over 700 lines) plus 30 over-long lines.

Three findings were fixed rather than parked, because they were real: dead `menuOpen` state left in
BrowserScreen when the overflow menu moved into BrowserTopBar, a missing trailing newline, and two
`db` parameters that are the platform's signature rather than an oversight (suppressed with that
reason written next to them). Four rules were configured rather than obeyed: PackageNaming, because
the applicationId's underscore is an identity this app cannot change; FunctionNaming, for @Composable
(PascalCase by convention) and for backticked test names, which is the project's specification style;
MagicNumber, because sizes and limits are named constants here; and MatchingDeclarationName, because
a file is named after its concept rather than after a declaration inside it.

Two tooling facts cost real time and are in neither tool's documentation. Detekt runs through its CLI
rather than its Gradle plugin: the plugin performs the analysis inside the build's own JVM, and
detekt 1.23 cannot parse JDK 25's version string - it fails with "25.0.4.1" as the entire error
message - so the task drives detekt-cli on a 21 launcher, which is also the only way to pin the JVM
the analyser runs on. And a baseline has to exist before it can be read, which is why it starts as an
empty document rather than being generated into place.

Verified: the fast gate is green in 17 seconds, --release adds a 36-second R8 build, 371 JVM tests
still pass, lint is clean and the map is current. CHANGELOG, README, AGENTS.md, ROADMAP (the gate is
now a recorded decision) and the regenerated map carry it.
This commit is contained in:
2026-10-17 09:13:32 +02:00
parent 0743bda29e
commit b1bc805af0
16 changed files with 418 additions and 15 deletions
+21 -9
View File
@@ -22,17 +22,22 @@ feature name once you know what you are changing.
## Commands
```bash
./gradlew :app:testDebugUnitTest # the gate: 355 JVM tests
./gradlew :app:lintDebug # the gate: Android Lint
./gradlew :app:assembleDebug # then: adb install -r app/build/outputs/apk/debug/app-debug.apk
./gradlew :app:assembleRelease # R8 is on here, and it has hidden real bugs — see Traps
./tools/verify.sh # the gate: map check, detekt, tests, lint
./tools/verify.sh --release # ...and an R8 release build (what CI runs nightly)
GRADLE_FLAGS=--offline ./tools/verify.sh # when the network is unavailable
python3 tools/make-code-map.py # regenerate docs/CODE_MAP.md after touching source
python3 tools/make-code-map.py --check # fails when the map is stale
./gradlew :app:assembleDebug # then: adb install -r app/build/outputs/apk/debug/app-debug.apk
./gradlew :app:detektBaseline # re-freezes the findings that exist now — think before running it
python3 tools/make-code-map.py # regenerate docs/CODE_MAP.md after touching source
```
There is **no CI**: those two Gradle tasks are the gate, and whoever changes the code runs them.
Add `--offline` when the network is unavailable — the dependency cache is already warm.
CI (`.github/workflows/verify.yml`) runs the same script on every push and pull request, plus a nightly
`--release` build, because R8 is the one check nothing else performs and it has hidden a real defect
here before. `git config core.hooksPath .githooks` runs it before every push as well.
The detekt gap it leaves — the findings in `config/detekt/baseline.xml` — is a **ratchet**: new
findings fail the build, existing ones are parked until the file they live in is touched for another
reason. `tools/` holds the gate and the generators; `config/detekt/` holds the rules and that baseline.
## Where things live, and the one rule about direction
@@ -92,6 +97,13 @@ comment. `app/src/test/java/…/ProjectInvariantsTest.kt` holds the source-level
- **The debug build is a separate package** (`…filemanager.debug`), so it installs beside a release
build and the two can be compared directly.
- **detekt 1.23 cannot run on JDK 25.** It parses the version string of the JVM it runs on and
throws `25.0.4.1` as the entire error message, which is why `:app:detekt` drives the CLI on a 21
launcher. A bare version number as a build failure is this, not the code — and a **JDK 21 has to be
installed** for the toolchain to find: Gradle does not download one here.
- **A detekt baseline has to exist before it can be read.** It starts as an empty document on
purpose; `--create-baseline` cannot conjure the path it was told to consult.
## Documentation map — read on demand
| file | what it is for |
@@ -106,7 +118,7 @@ comment. `app/src/test/java/…/ProjectInvariantsTest.kt` holds the source-level
## Definition of done
1. `:app:testDebugUnitTest` and `:app:lintDebug` green.
1. `./tools/verify.sh` green — the map current, detekt, the unit tests and lint in one command.
2. `python3 tools/make-code-map.py` run, so that `--check` passes.
3. A `CHANGELOG.md` entry in the house voice: what changed, why, what was rejected, and what was
verified rather than assumed.