HormoneTrack/AGENTS.md

92 lines
5.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AGENTS.md
Android app (Kotlin + Jetpack Compose, single module `:app`), 100 % local HRT tracking.
Docs, comments and CHANGELOG are French-first; `README.md` (FR) ↔ `README.en.md` must stay in sync.
## Build & Test
- `./gradlew assembleDebug` — debug APK
- `./gradlew testDebugUnitTest` — 346 JVM tests (292 without local data)
- `./gradlew connectedDebugAndroidTest` — 16 Compose UI tests (emulator/device required)
- `./gradlew lint` — must be green before any release
- No CI: these gates run locally; every release commit needs `testDebugUnitTest` green.
- Needs `local.properties` (`sdk.dir=…`) or `ANDROID_HOME`; platform 37 auto-downloaded; JDK 17+.
## Command order (release)
`lint` → `testDebugUnitTest` → `connectedDebugAndroidTest` → `assembleRelease` →
emulator validation of the RELEASE APK (§16.ter) → tag → publish.
Release-APK validation before tagging is OBLIGATORY (checklist step 3.bis).
## Toolchain — pinned; bump only after reading docs/DEVELOPPEMENT.md §3
- AGP 9.4.0 / Kotlin compose plugin 2.3.21 / KSP 2.3.11 / Gradle 9.7.1 / Compose BOM 2026.08.00 — tested together.
- No version catalog, no ktlint/detekt. `app/lint.xml` downgrades two Compose checks to warnings;
`StringFormatMatches` stays a blocking error (it caught bugs #47/#48).
- Bump `versionCode` + `versionName` in `app/build.gradle.kts` BEFORE the release commit/tag
(v1.3.0–v1.3.2 shipped with a stale VERSION_NAME).
## Release
- Every release adds a `## [X.Y.Z]` section to `docs/CHANGELOG.md` (no "v" prefix) — the
`copyChangelog` task embeds it in the APK ("Nouveautés" dialog); missing section = empty dialog.
- Annotated tag `vX.Y.Z`, pushed to BOTH remotes: `origin` (gitea.cloudyfy.fr) and `farewell`
(gitea.farewell.dev, SSH; push-to-create disabled).
- Publish both APKs: `python3 scripts/publish-release.py cloudyfy|farewell vX.Y.Z`
(purge + upload + verify by download). Do NOT use `scripts/gitea-release.py` for APKs
(mono-APK; concurrent uploads overwrite each other — lesson #43).
- Gitea tokens come from the macOS keychain, scope `write:repository`. Never commit secrets;
`keystore.properties`/`*.keystore` are gitignored. Never compare tags as strings
(`v1.2.10` < `v1.2.5` lexicographically).
- Signing: `assembleRelease` uses the DEBUG key while `keystore.properties` is absent
(release installs over debug, no data loss). `scripts/make-release-keystore.sh` creates it —
signature then changes ⇒ on-device migration: export → uninstall → reinstall → import (§16.quater).
- Commits are layered with prefixes: `engine:` / `data:` / `reminders+ui:` / `scripts/docs:` / `release`.
## R8 / Gson traps (release-only bugs)
- `proguard-rules.pro` carries explicit `-keep` rules for Gson-reflected models
(`data.model.**`, `BackupData`, `TConfig`) and WorkManager classes.
- Two crashes happened ONLY in release (#64 class removed by R8, #72 `cycleEntries` null under
R8) — JVM tests never exercise R8; smoke-test backup export/import + charts on a release build.
## Emulator recipe (docs/DEVELOPPEMENT.md §16.ter)
- `scripts/seed-emulator.py <db> <backup.json>` injects real data (from `local-test-data/`) into
the debug app DB; extract the DB together with its `-wal` file after `force-stop` (WAL trap).
- ⚠️ `connectedDebugAndroidTest` UNINSTALLS the app (DB + DataStore wiped) — seed AFTER the last
instrumented run.
- Pan/pinch on the chart is NOT testable via `adb input swipe` headless (no intermediate moves).
## Tests
- Unit: `app/src/test/java/com/hormonetrack/` (pk, data, ui, util, reminder, settings);
UI: `app/src/androidTest/java/com/hormonetrack/`.
- Data-driven regressions load real exports from `local-test-data/` (gitignored) and SKIP when
absent — that's the 292 vs 346 delta. Regressions are numbered (e.g. #73 → `CycleEntrySliderTest`).
- `ui/ChartScreenSourceGuardTest.kt` reads `ChartScreen.kt` source and pins the gesture block
(+ its `rememberUpdatedState` alias) in that file — restructuring ChartScreen (~700 lines,
the #54–#70 hotspot) means rewriting this guard by design.
- No TODO/FIXME markers in code — remaining work lives in docs/DEVELOPPEMENT.md
§19 (limits), §20 (ideas), §21 (release manual checklist — NOT a TODO list).
## Architecture
- Packages in `app/src/main/java/com/hormonetrack/`: `pk/` pure PK engine (no Android deps,
time zones parameterized for deterministic tests), `data/` Room (hand-written migrations
v1→v4, `exportSchema=false`), `reminder/` (exact alarms, notification actions, boot),
`settings/` (DataStore), `ui/` (Compose; `screens/settings/` = cards).
- Assets: `mcmc_samples.json` (ESE MCMC cloud) in main; `pk_profiles.json` is test-only
(`src/test/assets/`) since v1.9.0 — Estrannaise is analytic at runtime.
- Backup JSON is versioned (`BackupData.version`); import rejects newer/unparsable backups
BEFORE wiping (transactional `db.withTransaction`); keep optional-field retrocompat when extending.
## Hard privacy constraints
- The repo must NEVER contain health data: `local-test-data/` and `TODO.md` are gitignored;
history was scrubbed before the first push (§8.bis).
- No `android.util.Log`, no `GlobalScope` in `app/src/main` — health logging goes through
`AppLog` (private `filesDir` buffer). `allowBackup=false`.
## Web port
- Separate repo `Siphonight/HormoneTrack-web` (same Gitea remotes), synced release-by-release;
Android-only features (Cycles, v1.14.0) are not ported yet. Engine/chart changes have JS
mirrors (`pk-engine.js`, `chart.js`) — flag sync needs in releases.
## Docs map
- `docs/DEVELOPPEMENT.md` — full dev doc: §3 versions, §14 numbered bugs, §16 release checklist,
§16.ter emulator, §16.quater keystore, §19–§21.
- `docs/CHANGELOG.md` (embedded in app), `docs/GUIDE_INSTALLATION.md` (user guide),
`docs/MONTRE-GADGETBRIDGE.md` (watch).