Skip to content

Feature/sharding paparazzi plugin - #134

Merged
sergio-sastre merged 9 commits into
masterfrom
feature/sharding_paparazzi_plugin
Jul 5, 2026
Merged

Feature/sharding paparazzi plugin#134
sergio-sastre merged 9 commits into
masterfrom
feature/sharding_paparazzi_plugin

Conversation

@sergio-sastre

@sergio-sastre sergio-sastre commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Showcases how to enable test sharding to run Paparazzi tests in parallel with ComposablePreviewScanner.

Summary by CodeRabbit

  • New Features
    • Added support for sharding generated Paparazzi preview tests across multiple test classes for better parallel execution.
    • Introduced a generatedTestClassCount configuration option to control the number of generated shards/classes.
  • Bug Fixes
    • Improved default sharding behavior by deriving the shard count from Gradle test maxParallelForks (with a safe fallback).
    • Updated the generated Paparazzi preview setup API level in generated output and examples.
  • Documentation
    • Expanded plugin documentation with sharding configuration guidance and important notes about parallel execution settings.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a generatedTestClassCount configuration to shard generated Paparazzi parameterized tests across multiple test classes, with a default derived from Gradle maxParallelForks. Updates the extension, plugin, task generation logic, sample build config, and documentation, plus a MAX_API_LEVEL example change.

Changes

Generated test sharding

Layer / File(s) Summary
Extension property and default derivation
paparazzi-plugin/src/main/kotlin/.../ComposablePreviewPaparazziExtension.kt, paparazzi-plugin/src/main/kotlin/.../ComposablePreviewPaparazziPlugin.kt
Adds generatedTestClassCount: Property<Int> to the extension; the plugin derives its default from Test task maxParallelForks during afterEvaluate.
Task input and sharding generation
paparazzi-plugin/src/main/kotlin/.../GenerateComposablePreviewPaparazziTestsTask.kt, paparazzi-plugin/src/main/kotlin/.../TaskSetup.kt
Adds generatedTestClassCount to the task, wires it from the extension, and updates generated output to branch on shard count, cache previews, and assemble shard sections.
Sample config and documentation
paparazzi-plugin-tests/build.gradle.kts, paparazzi-plugin/README.md, README.md
Updates sample test parallelism and shard count, documents the new option and parallel execution behavior, and changes the root README example MAX_API_LEVEL value from 36 to 34.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ComposablePreviewPaparazziPlugin
  participant ComposablePreviewPaparazziExtension
  participant TaskSetup
  participant GenerateComposablePreviewPaparazziTestsTask

  ComposablePreviewPaparazziPlugin->>ComposablePreviewPaparazziPlugin: afterEvaluate reads Test maxParallelForks
  ComposablePreviewPaparazziPlugin->>ComposablePreviewPaparazziExtension: set generatedTestClassCount convention
  TaskSetup->>GenerateComposablePreviewPaparazziTestsTask: set generatedTestClassCount
  GenerateComposablePreviewPaparazziTestsTask->>GenerateComposablePreviewPaparazziTestsTask: generateTests() computes shard count
  alt generatedTestClassCount == 1
    GenerateComposablePreviewPaparazziTestsTask->>GenerateComposablePreviewPaparazziTestsTask: emit one test class
  else generatedTestClassCount > 1
    GenerateComposablePreviewPaparazziTestsTask->>GenerateComposablePreviewPaparazziTestsTask: emit Shard1 plus shard-specific sections
  end
Loading

Poem

A rabbit split the tests in neat little rows,
With shards for the burrow and speedier flows.
Forks set the count, no magic in sight,
One header, many shards, all tidy and light.
Hoppity hop, the previews take flight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding sharding support to the Paparazzi plugin.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/sharding_paparazzi_plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@paparazzi-plugin-tests/build.gradle.kts`:
- Around line 35-39: The unit test fork count in testOptions/unitTests.all can
become zero on single-core runners because it uses
Runtime.getRuntime().availableProcessors() / 2. Update the maxParallelForks
assignment to clamp the computed value to at least 1 so the
Test.maxParallelForks setting always stays positive.

In
`@paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt`:
- Around line 46-47: The shard-count validation in
GenerateComposablePreviewPaparazziTestsTask currently only logs when shards is
less than 1, which allows the task to continue without generating tests. Update
the task’s shard validation path so an invalid generatedTestClassCount or shard
count fails the Gradle task immediately, using the existing task logic around
GenerateComposablePreviewPaparazziTestsTask and its generation entry point to
stop execution rather than silently skipping generation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 381db5f7-6bba-4147-8dc3-a5ce78ffe428

📥 Commits

Reviewing files that changed from the base of the PR and between 2f4fb2c and f776571.

📒 Files selected for processing (7)
  • README.md
  • paparazzi-plugin-tests/build.gradle.kts
  • paparazzi-plugin/README.md
  • paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/ComposablePreviewPaparazziExtension.kt
  • paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/ComposablePreviewPaparazziPlugin.kt
  • paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt
  • paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/TaskSetup.kt

Comment thread paparazzi-plugin-tests/build.gradle.kts
sergio-sastre and others added 2 commits July 1, 2026 18:46
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…sable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt (1)

342-354: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Sort previews before sharding
cachedPreviews feeds index % $numShards directly, so any JVM-dependent scan order changes shard membership and can leave previews duplicated or skipped across shards. Sort by a stable preview key before partitioning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt`
around lines 342 - 354, The sharding logic in
GenerateComposablePreviewPaparazziTestsTask uses cachedPreviews directly, so
scan order can change shard assignment and cause duplicates or missing previews.
Before computing shardedCachedPreviews, sort cachedPreviews by a stable preview
identifier/key, then apply the index % numShards partitioning so shard
membership is deterministic across JVM runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt`:
- Around line 342-354: The sharding logic in
GenerateComposablePreviewPaparazziTestsTask uses cachedPreviews directly, so
scan order can change shard assignment and cause duplicates or missing previews.
Before computing shardedCachedPreviews, sort cachedPreviews by a stable preview
identifier/key, then apply the index % numShards partitioning so shard
membership is deterministic across JVM runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ea3f28b-db5b-4e30-8ae8-d8c706789786

📥 Commits

Reviewing files that changed from the base of the PR and between f776571 and d7b22fa.

📒 Files selected for processing (2)
  • paparazzi-plugin-tests/build.gradle.kts
  • paparazzi-plugin/src/main/kotlin/io/github/sergio/sastre/composable/preview/scanner/paparazzi/plugin/GenerateComposablePreviewPaparazziTestsTask.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • paparazzi-plugin-tests/build.gradle.kts

@sergio-sastre
sergio-sastre merged commit cc0342d into master Jul 5, 2026
8 checks passed
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.

1 participant