Repository navigation
ADFA-7115: Carry test source sets and test compile graphs in the Android model - #2251
hal-eisen-adfa wants to merge 2 commits into
Conversation
…oid model The Android proto model had no unit test or android test source providers and no test dependency graphs, so nothing downstream could give test sources a scope. - SourceSetContainer gains unitTestSourceProvider and androidTestSourceProvider. - VariantDependencies gains unitTestArtifact and androidTestArtifact. - The serializer reads them through AGP's deprecated single-artifact getters. They exist from AGP 7.3 (our minimum), and AGP 9.3 implements them over the host/device test maps, so one path covers every supported version. - SYNC_META_VERSION 2 -> 3, so cached models re-sync instead of reading the new fields as unset. The model builder already requests test compile graphs (only test runtime classpaths are off).
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Sources that kapt, KSP and the like generate for tests (Hilt in instrumented tests, for one) live under the unit test and android test artifacts' generated source folders, which the model dropped. AndroidVariant now carries them per scope, read through the same deprecated single-artifact getters as the test source providers. Raised by CodeRabbit on #2252.
hal-eisen-adfa
left a comment
There was a problem hiding this comment.
Claude Code /pr-review (high) of #2251, layer 1 of 4 (base stage; above it: #2252, #2253, #2254) of the ADFA-7115 stack. Claims were verified against the stack tip 8b39c5dd29 (#2254's head); anchors are on this PR's head.
MINOR
- TestArtifactsSerializationTest.kt:93 - no test for a Variant with null test artifacts
- ProjectSyncHelper.kt:54 - SYNC_META_VERSION KDoc says bump only on incompatible changes
- PR body: Verification section stale
- PR body: model-builder runtime-classpath claim is false on AGP 9
NITPICK - 4 inline, not listed
Findings without a diff anchor
MINOR: The PR body's Verification section is stale. It says TestArtifactsSerializationTest (4 tests) and that nulling "the four new fields" fails "the two positive tests", but the file has five tests and the serializer sets six new fields; the same body also mentions "a fifth case". Update it to five tests and six fields, and state the revert result for the generated-folder case.
MINOR: The PR body says the model builder "only turns off test runtime classpaths", but on AGP 9 it builds the unit-test runtime classpath. AGP 9.3.1 ModelBuilder.buildVariantDependenciesModel reads dontBuildHostTestRuntimeClasspath for host tests and ignores the deprecated dontBuildUnitTestRuntimeClasspath; AndroidProjectModelBuilder.kt:86 (pre-existing, not in this diff) passes emptyMap(). Fix the claim, or set mapOf("UnitTest" to true) in a follow-up.
Verdict
Computed: COMMENT. Rule: REVIEW.md plus CLAUDE.md (QA needs no critical, high or medium findings), with the skill's default table. Submitted as COMMENT because GitHub refuses approve/request-changes on your own PR.
| } | ||
|
|
||
| @Test | ||
| fun `serializes each test artifact's generated source folders`() { |
There was a problem hiding this comment.
MINOR: No test covers a Variant whose unitTestArtifact or androidTestArtifact is null.
That is the path a release-variant sync takes, since androidTest exists only for testBuildType. If a refactor turns ?. into !! or drops .orEmpty(), all five tests still pass and the first release-variant sync throws inside Variant.asProtoModel.
Add a case with both artifacts null that asserts both generated-folder lists are empty.
| * produced and consumed only by the IDE and hold no user data, so discarding them is safe. | ||
| */ | ||
| const val SYNC_META_VERSION = "2" | ||
| const val SYNC_META_VERSION = "3" |
There was a problem hiding this comment.
MINOR: The SYNC_META_VERSION KDoc (line 49) says to bump only when a schema changes incompatibly, but this bump is for a purely additive change.
The next developer who adds optional fields follows the KDoc and skips the bump. Cached projects then read the new fields as unset until a manual re-sync, which is the stale-cache bug this bump exists to prevent.
Reword it: bump whenever a persisted proto schema changes, including added fields that consumers rely on.
| map<string, Library> libraries = 3; | ||
|
|
||
| // The dependencies for the variant's unit test artifact, if it has one. | ||
| ArtifactDependencies unitTestArtifact = 4; |
There was a problem hiding this comment.
NITPICK: The proto copies AGP's deprecated singular test shape rather than the hostTestArtifacts / deviceTestArtifacts maps.
Screenshot tests and AGP 9 test suites cannot be represented, so supporting them needs another schema change and another SYNC_META_VERSION bump.
Consider map<string, ArtifactDependencies> keyed by artifact name, or list it under Limitations.
| name = this.name, | ||
| mainArtifact = this.mainArtifact.asProtoModel(), | ||
| librariesMap = this.libraries.mapValues { entry -> entry.value.asProtoModel() }, | ||
| unitTestArtifact = this.unitTestArtifact?.asProtoModel(), |
There was a problem hiding this comment.
NITPICK: Each test artifact runs its own DependencyGraphBuilder, so each test graph re-emits nearly every key string from the main graph.
testImplementation extends implementation, and the sample has 54 and 53 nodes against main's 52, so persisted graph keys per module roughly triple.
If the size matters, share one key table across the three artifacts of a VariantDependencies.
| ) | ||
|
|
||
| // See VariantDependencies.asProtoModel for why the deprecated test getters are used. | ||
| @Suppress("DEPRECATION") |
There was a problem hiding this comment.
NITPICK: @Suppress("DEPRECATION") covers whole functions (here, and at lines 84 and 215), not just the four deprecated test getters.
If AGP later deprecates another member these functions read (mainArtifact, name, libraries), the build stays silent and the removal surfaces as an UnsupportedMethodException during sync instead of a compile warning.
Scope the suppression to each test-getter expression or a small helper.
| ), | ||
| variantSourceProvidersList = | ||
| basicAndroidProject.variantSourceProviders(this.name).map { provider -> provider.asProtoModel() }, | ||
| unitTestGeneratedSourceFolderPathsList = |
There was a problem hiding this comment.
NITPICK: The ?.generatedSourceFolders?.map { it.absolutePath }.orEmpty() block is copied for each test artifact.
Each future per-artifact field will need another copy.
Extract an AbstractArtifact?.generatedSourcePaths() helper.
ADFA-7115
PR 1 of 4. Code features don't work in
src/test/src/androidTestbecause nothing in the Android project model describes them. This PR adds that data and changes no behavior. The stack:getTestSourceDirectories(scope)/getTestCompileClasspaths(scope), kept out of the transitivegetCompileSourceDirectories().KtSourceModules, each friend of main.Changes
android.proto:SourceSetContainergainsunitTestSourceProviderandandroidTestSourceProvider.VariantDependenciesgainsunitTestArtifactandandroidTestArtifact.AndroidProjectExts.ktserializes them through AGP's deprecated single-artifact getters. They exist in AGP 7.3, our minimum (checked the 7.3.0builder-modeljar). AGP 9.3.1 implements them overhostTestSourceProviders/deviceTestSourceProvidersandhostTestArtifacts/deviceTestArtifacts(checked theSourceSetContainerImpl/VariantDependenciesImplbytecode), so one path covers every supported version.AndroidVariantgainsunitTestGeneratedSourceFolderPathsandandroidTestGeneratedSourceFolderPaths: sources kapt, KSP and the like generate for tests (e.g. Hilt in instrumented tests). Added after CodeRabbit's review of ADFA-7115: Add per-scope test source and classpath getters #2252; covered by a fifthTestArtifactsSerializationTestcase, which fails with the fields serialized empty.SYNC_META_VERSION2 -> 3. Without the bump, cached projects would read the new fields as unset until a manual re-sync.Verification
TestArtifactsSerializationTest(4 tests) plus the existing serializer tests pass. With the four new fields set tonullin the serializer, the two positive tests fail.src/testandsrc/androidTestplustestImplementation(slidingpanelayout)andandroidTestImplementation(localbroadcastmanager). Decoded.cg/gradle-sync/project.pbwithprotoc:unitTestSourceProvider.javaDirs=app/src/test/java;androidTestSourceProvider.javaDirs=app/src/androidTest/java.slidingpanelayoutis in the unit test compile graph only: absent from the main and android test graphs.localbroadcastmanageris in the android test graph as a direct dependency. It is also a transitive main dependency, so it is a weaker marker thanslidingpanelayout.sync.pbmeta version is"3".Limitations
test/androidTestsource sets. Variant-specific ones (src/testDebug) are not carried, matching how main ignores variant source sets today. The main-side gap needs its own ticket.