|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to coding agents when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Android client library for tracking user events (Nosara/Tracks), A/B testing (ExPlat), and crash logging (Sentry). Published to Automattic's S3 Maven repository. Used internally by Automattic mobile apps. Includes a `sampletracksapp` app module that can be used for manual testing. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +./gradlew assembleDebug # Build all modules |
| 13 | +./gradlew testDebugUnitTest # Run all unit tests |
| 14 | +./gradlew lintDebug # Run lint checks |
| 15 | +./gradlew ktlint # Check Kotlin code style (custom task from ktlint.gradle) |
| 16 | +./gradlew ktlintFormat # Fix Kotlin code style deviations (custom task from ktlint.gradle) |
| 17 | +./gradlew ciktlint # Same as ktlint but with checkstyle XML output for CI (custom task from ktlint.gradle) |
| 18 | +./gradlew buildHealth # Dependency analysis |
| 19 | +./gradlew :experimentation:apiCheck # Binary compatibility check (`experimentation` module only) |
| 20 | +./gradlew :benchmark:assembleDebugAndroidTest # Build benchmark instrumented tests |
| 21 | +./gradlew :benchmark:connectedDebugAndroidTest # Run benchmark instrumented tests on a connected device |
| 22 | +``` |
| 23 | + |
| 24 | +To run a single test class: |
| 25 | + |
| 26 | +```bash |
| 27 | +./gradlew :experimentation:testDebugUnitTest --tests "com.automattic.android.experimentation.ExPlatTest" |
| 28 | +./gradlew :crashlogging:testDebugUnitTest --tests "com.automattic.android.tracks.crashlogging.SentryCrashLoggingTest" |
| 29 | +``` |
| 30 | + |
| 31 | +**Note:** `gradle.properties` is gitignored. CI copies `gradle.properties-example` before building. Locally, copy it manually if needed: `cp gradle.properties-example gradle.properties`. |
| 32 | + |
| 33 | +## Architecture |
| 34 | + |
| 35 | +Three independently published library modules plus a sample app and benchmark module: |
| 36 | + |
| 37 | +| Module | Artifact | Language | Description | |
| 38 | +|--------|----------|----------|-------------| |
| 39 | +| `AutomatticTracks` | `com.automattic:Automattic-Tracks-Android` | Java + Kotlin | Core event tracking with SQLite storage and background network transmission | |
| 40 | +| `experimentation` | `com.automattic.tracks:experimentation` | Kotlin | ExPlat A/B testing SDK with file-based caching and OkHttp REST client | |
| 41 | +| `crashlogging` | `com.automattic.tracks:crashlogging` | Kotlin | Sentry-based crash logging, performance monitoring, and error tracking | |
| 42 | +| `sampletracksapp` | — | Kotlin | Sample app demonstrating library usage | |
| 43 | +| `benchmark` | — | Kotlin | Performance benchmarking via `androidTest` instrumented tests using `androidx.benchmark` | |
| 44 | + |
| 45 | +### Key architectural details |
| 46 | + |
| 47 | +- **AutomatticTracks** uses a queue-based architecture with background threads for event buffering, DB-to-network transfer, and network transmission. Events expire after 14 days. |
| 48 | +- **experimentation** has `explicitApi()` enabled and uses binary compatibility validation (`apiCheck`). Public API surface is tracked in `experimentation/api/experimentation.api`. |
| 49 | +- **crashlogging** wraps Sentry SDK via `SentryErrorTrackerWrapper` and exposes a `CrashLoggingDataProvider` interface for host apps to supply user/app context. |
| 50 | +- Modules publish independently to S3. No product flavors or build variants. |
| 51 | + |
| 52 | +## Testing Conventions |
| 53 | + |
| 54 | +- **Frameworks:** JUnit 4, AssertJ, Mockito-Kotlin, kotlinx-coroutines-test, MockWebServer |
| 55 | +- **Assertions:** Use AssertJ (`assertThat`), not kotlin.test assertions |
| 56 | +- **Naming:** Backtick-quoted names: `` `given ..., when ..., then ...` `` |
| 57 | +- **Coroutines:** Use `runTest` from `kotlinx.coroutines.test` |
| 58 | + |
| 59 | +## Important Gotchas |
| 60 | + |
| 61 | +- Build files use **Groovy** (`build.gradle`, `settings.gradle`), not Kotlin DSL — except `benchmark/build.gradle.kts` which uses Kotlin DSL |
| 62 | +- Dependency versions are defined as `ext` properties in root `build.gradle`, not a version catalog |
| 63 | + |
| 64 | +## Publishing |
| 65 | + |
| 66 | +CI publishes on every PR commit and trunk merge: |
| 67 | +- PR: `{pr-number}-{commit-full-sha1}` |
| 68 | +- Trunk merge: `trunk-{commit-full-sha1}` |
| 69 | +- Tag: `{tag-name}` |
0 commit comments