Skip to content

ADFA-7115: Carry test source sets and test compile graphs in the Android model - #2251

Closed
hal-eisen-adfa wants to merge 2 commits into
stagefrom
fix/ADFA-7115-test-source-dirs
Closed

hal-eisen-adfa wants to merge 2 commits into
stagefrom
fix/ADFA-7115-test-source-dirs

Conversation

@hal-eisen-adfa

@hal-eisen-adfa hal-eisen-adfa commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7115

PR 1 of 4. Code features don't work in src/test / src/androidTest because nothing in the Android project model describes them. This PR adds that data and changes no behavior. The stack:

  1. This PR: tooling model. Test source providers and test compile graphs reach the proto model.
  2. Project API: getTestSourceDirectories(scope) / getTestCompileClasspaths(scope), kept out of the transitive getCompileSourceDirectories().
  3. Kotlin LSP: separate unit-test and android-test KtSourceModules, each friend of main.
  4. Java LSP: scope chosen by the file's source root.

Changes

  • android.proto: SourceSetContainer gains unitTestSourceProvider and androidTestSourceProvider. VariantDependencies gains unitTestArtifact and androidTestArtifact.
  • AndroidProjectExts.kt serializes them through AGP's deprecated single-artifact getters. They exist in AGP 7.3, our minimum (checked the 7.3.0 builder-model jar). AGP 9.3.1 implements them over hostTestSourceProviders / deviceTestSourceProviders and hostTestArtifacts / deviceTestArtifacts (checked the SourceSetContainerImpl / VariantDependenciesImpl bytecode), so one path covers every supported version.
  • AndroidVariant gains unitTestGeneratedSourceFolderPaths and androidTestGeneratedSourceFolderPaths: 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 fifth TestArtifactsSerializationTest case, which fails with the fields serialized empty.
  • SYNC_META_VERSION 2 -> 3. Without the bump, cached projects would read the new fields as unset until a manual re-sync.
  • The model builder needs no change: it already requests test compile graphs and only turns off test runtime classpaths.

Verification

  • TestArtifactsSerializationTest (4 tests) plus the existing serializer tests pass. With the four new fields set to null in the serializer, the two positive tests fail.
  • Device (emulator-5554, arm64): fresh install of this build, then synced an AGP 9.3.1 project with src/test and src/androidTest plus testImplementation(slidingpanelayout) and androidTestImplementation(localbroadcastmanager). Decoded .cg/gradle-sync/project.pb with protoc:
    • unitTestSourceProvider.javaDirs = app/src/test/java; androidTestSourceProvider.javaDirs = app/src/androidTest/java.
    • slidingpanelayout is in the unit test compile graph only: absent from the main and android test graphs.
    • localbroadcastmanager is in the android test graph as a direct dependency. It is also a transitive main dependency, so it is a weaker marker than slidingpanelayout.
    • sync.pb meta version is "3".
    • The generated-folder fields came after this check; they are covered by the unit test only.
  • No UI change, so no font-scale check.

Limitations

  • Only the default test / androidTest source 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.
  • The model grows by two extra compile graphs per Android module (54 and 53 nodes in the test project, against 52 for main).

…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).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Release notes

  • The Android project model now includes unit-test and Android-test source providers.
  • The Android project model now includes unit-test and Android-test compile graphs. Each Android module gets two additional compile graphs.
  • The variant dependency model now includes optional unit-test and Android-test artifact dependencies.
  • The Android variant model now includes generated source-folder paths for the unit-test and Android-test artifacts.
  • SYNC_META_VERSION changes from "2" to "3". Cached projects re-sync on the next open.
  • Test source directories are not added to the transitive main compile source directories. Existing behavior is unchanged.
  • Scope is limited to the default test and androidTest source sets. Variant-specific test source sets, such as testDebug, are not included.
  • Generated test-source folders are not carried in the model unless the test artifact getters report them.
  • No UI change is included.

Risks and best-practice concerns

  • The serializer uses AGP's deprecated single-artifact getters. The change suppresses deprecation warnings for these calls. Future AGP versions can remove these getters, which breaks the serializer at compile time or run time.
  • The minimum supported AGP version for these getters is not verified in the reviewed sources. The behavior depends on AGP version.
  • Test results are author-reported, not CI-verified. The author reports that the four new TestArtifactsSerializationTest tests pass and that existing serializer tests pass. The author reports that setting the four new fields to null makes the two positive tests fail. The author reports a device sync with AGP 9.3.1 that showed src/test/java and src/androidTest/java in the decoded model. The slidingpanelayout marker appeared only in the unit-test compile graph. The localbroadcastmanager result is a weaker marker because it is also a transitive main dependency. No completed CI results are available for this review.
  • Incrementing SYNC_META_VERSION forces a full re-sync for all cached projects. This is intended. It increases sync time for existing users.
  • Consumers of the sync model must handle the new fields. An unset field means that no test provider or artifact is present. Downstream code that assumes these fields are always set can fail.
  • Each Android module adds two compile graphs to the model. This increases model size and serialization work per module.
  • No font-scale check was performed because no UI change was made.

The proto model adds unit-test and Android-test source-provider and artifact fields, plus generated source-folder paths. Serialization maps these fields and tests cover populated and unset values. The sync metadata version changes from 2 to 3.

Changes: Test artifact model

Layer / File(s) Summary
Proto fields and sync version
subprojects/project-models/src/main/proto/android.proto, subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/sync/ProjectSyncHelper.kt
VariantDependencies and SourceSetContainer gain unit-test and Android-test fields. AndroidVariant gains generated source-folder path lists for both test artifact types. SYNC_META_VERSION changes from "2" to "3".
Serialize and test test models
subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/serial/AndroidProjectExts.kt, subprojects/tooling-api-impl/src/test/java/com/itsaky/androidide/tooling/impl/serial/TestArtifactsSerializationTest.kt
Serialization maps the test source providers, artifact dependencies, and generated source-folder paths. Tests cover populated fields and fields left unset when test providers or artifacts are absent.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: itsaky-adfa

Merge Risk: Minimal · up to 25a8e

This change exposes unit-test and Android-test source sets and compile graphs in the project model and forces cached projects to re-sync. No concrete merge-blocking risk was found. A one-time full re-sync after upgrade is expected.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: carrying test source sets and test compile graphs in the Android project model. The raw summary confirms new proto fields for unit-test and Android-test source provide…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the PR adds test source providers and test compile graphs to the Android project model. It names the affected files (android.proto, AndroidProjectExts.kt), the AGP version handl…
Full details: Title check

Explanation

The title names the main change: carrying test source sets and test compile graphs in the Android project model. The raw summary confirms new proto fields for unit-test and Android-test source providers and artifacts, serializer changes, tests, and a sync meta version bump.

Full details: Description check

Explanation

The description states the PR adds test source providers and test compile graphs to the Android project model. It names the affected files (android.proto, AndroidProjectExts.kt), the AGP version handling, the SYNC_META_VERSION bump, and the verification steps. This matches the changeset, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the fields in spring,
Test paths and source sets join the string.
The proto carries what tests provide,
Empty fields stay quiet inside.
Sync counts to three; the carrots cheer,
A tidy model hops into gear.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 2b0b1a0c-7abd-4017-8e17-9858114fb0e3
Commits

Reviewing files that changed from the base of the PR and between c115445 and 25a8e83.

Files selected for processing: 3

  • subprojects/project-models/src/main/proto/android.proto
  • subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/serial/AndroidProjectExts.kt
  • subprojects/tooling-api-impl/src/test/java/com/itsaky/androidide/tooling/impl/serial/TestArtifactsSerializationTest.kt

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

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 hal-eisen-adfa left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`() {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@itsaky-adfa

Copy link
Copy Markdown
Contributor

Superseded by #2266, part of the new ADFA-7115 stack (#2266-#2270).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants