Forward coding-agent id into test app for connectedAndroidTest verification#2726
Draft
ctufts wants to merge 1 commit into
Draft
Forward coding-agent id into test app for connectedAndroidTest verification#2726ctufts wants to merge 1 commit into
ctufts wants to merge 1 commit into
Conversation
Wires an optional `-Pmapbox.agent=<id>` Gradle property into `BuildConfig.MAPBOX_AGENT` on the sample/test app module, and forwards it into Common's process-wide MapboxAgentContext during app init, so outbound Mapbox requests made during a connectedAndroidTest run can be tagged with the coding agent that triggered them. Defaults to empty (no-op) so normal builds are unaffected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of changes
Part of a broader effort to measure how much SDK traffic comes from AI coding agents (Claude Code, Codex, Cursor, etc.) rather than human-run apps, the Mapbox Common SDK is adding a way to tag outbound requests with an agent identifier. On Android that identifier has to be resolved at compile time, since there's no OS environment variable to read the way there is on desktop platforms. So it has to come in through a Gradle property and get forwarded into the running process by the app itself.
This PR wires that forwarding path through the sample/test app (
appmodule) used forconnectedAndroidTest:app/build.gradle.ktsreads an optional-Pmapbox.agent=<id>Gradle property intoBuildConfig.MAPBOX_AGENT, following the sameproject.hasProperty(...)pattern already used forgitVersionCodeandAPP_KEYSTORE_PASSWORD. Defaults to an empty string when the property isn't supplied, and the value is escaped before being embedded in generated source.MapboxApplication.onCreate()forwardsBuildConfig.MAPBOX_AGENTinto Common'sMapboxAgentContextFactory.getInstance().setMapboxAgentId(...)via a small helper, guarded so it only fires when the value is non-empty.forwardAgentIdIfPresentinAgentTelemetryForwarding.kt) with a unit test covering: empty id -> no-op, non-empty id -> forwarded, forwarded exactly once.No agent detection or tagging logic lives in this repo, that all happens in Common. This change only forwards an already-resolved id into the running app process.
Blocked on Common: this depends on an unreleased Mapbox Common SDK change (mapbox-sdk PR #16363) that adds
com.mapbox.common.MapboxAgentContext/MapboxAgentContextFactory. Until a Common build with those classes is published and this repo's dependency is bumped,MapboxApplication.kt's import ofMapboxAgentContextFactorywon't resolve and theappmodule won't compile. That's why this PR is in draft; it can come out once the dependency lands.I also wasn't able to verify this end-to-end in my sandbox: building Common from source to work around the above needs the Android NDK and access to Mapbox's private Maven registry, and neither was available there. What I could confirm: the Gradle property to BuildConfig wiring matches this module's existing conventions by inspection, and the forwarding guard has a plain JUnit test with no dependency on the new Common API, so it'll run as soon as the module compiles again.
Verification once Common's change is available
./gradlew :app:testDebugUnitTest --tests "*AgentTelemetryForwardingTest*"for the guard logic (should already pass once the module compiles)../gradlew connectedAndroidTest -Pmapbox.agent=claude-codeon a device/emulator, confirming outbound Mapbox request User-Agents carryagent/claude-code.connectedAndroidTestwithout-Pmapbox.agent(or a normalassembleRelease) should show zero change in behavior.User impact (optional)
None. This only affects the sample/test app's instrumentation, not the published SDK's public API or behavior.
Pull request checklist:
@JvmOverloads,@file:JvmName, etc). -- N/A, internal to the sample app only.appmodule is excluded from API validation).make update-api-- N/A, no public API changes.skip changeloglabel since this only touches the internal sample/test app.Fixes: N/A -- implements one piece of a larger cross-SDK agent-traffic-measurement effort tracked internally.