Skip to content

Bugfix/negative limit in preview parameterprovider - #132

Merged
sergio-sastre merged 3 commits into
masterfrom
bugfix/negative_limit_in_PreviewParameterprovider
Jun 17, 2026
Merged

Bugfix/negative limit in preview parameterprovider#132
sergio-sastre merged 3 commits into
masterfrom
bugfix/negative_limit_in_PreviewParameterprovider

Conversation

@sergio-sastre

@sergio-sastre sergio-sastre commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed preview parameter limit handling to properly constrain negative and oversized limits, preventing unintended preview generation behavior.
  • Tests

    • Added test coverage for preview parameter edge cases with negative limits and limits exceeding available values.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (9)
  • tests/src/test/screenshots/android/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_0.png is excluded by !**/*.png
  • tests/src/test/screenshots/android/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_1.png is excluded by !**/*.png
  • tests/src/test/screenshots/android/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_2.png is excluded by !**/*.png
  • tests/src/test/screenshots/sourceset/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_0.png is excluded by !**/*.png
  • tests/src/test/screenshots/sourceset/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_1.png is excluded by !**/*.png
  • tests/src/test/screenshots/sourceset/sergio.sastre.composable.preview.scanner.android.previewparameters.ComposablesKt.ExamplePreviewLimitGreaterThanValuesSize.preview-parameter-limit=4_String_2.png is excluded by !**/*.png
  • tests/src/test/snapshots/images/Paparazzi_Preview_Test_android.previewparameters.composableskt.examplepreviewlimitgreaterthanvaluessize.preview-parameter-limit=4_string_0.png is excluded by !**/*.png
  • tests/src/test/snapshots/images/Paparazzi_Preview_Test_android.previewparameters.composableskt.examplepreviewlimitgreaterthanvaluessize.preview-parameter-limit=4_string_1.png is excluded by !**/*.png
  • tests/src/test/snapshots/images/Paparazzi_Preview_Test_android.previewparameters.composableskt.examplepreviewlimitgreaterthanvaluessize.preview-parameter-limit=4_string_2.png is excluded by !**/*.png

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95f4c50b-3e29-4861-a38a-25ad591a64c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

ComposablePreviewWithPreviewParameterMapper now clamps the @PreviewParameter limit value to a non-negative integer via max(0, limit) before calling take. Two new test composable fixtures (limit = -1, limit = 4) and two corresponding JUnit tests are added to verify edge-case behavior.

Changes

Negative @PreviewParameter limit clamping

Layer / File(s) Summary
Clamp negative limit in mapper
core/.../mappers/ComposablePreviewWithPreviewParameterMapper.kt
Imports kotlin.math.max and replaces values.take(limit) with values.take(max(0, limit)) to prevent negative-limit sequence operations.
Test composables and JUnit assertions for edge-case limits
tests/.../previewparameters/Composables.kt, tests/.../scanner/AndroidComposablePreviewScannerTest.kt
Adds ExamplePreviewLimitMinus1 (limit=-1) and ExamplePreviewLimitGreaterThanValuesSize (limit=4) composable fixtures, plus two JUnit tests asserting an empty list for limit=-1 and a value-count-bounded list for limit=4.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 A limit of minus one, oh what a surprise,
The scanner once stumbled, now cleverly wise.
max(0, limit) keeps negative away,
No empty confusion shall ruin the day.
Hop hop, the tests pass — hip-hip hooray! 🎉

🚥 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 accurately describes the main change: fixing a bug where negative limits in preview parameter providers are now handled properly by clamping the limit value.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/negative_limit_in_PreviewParameterprovider

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 and usage tips.

@sergio-sastre
sergio-sastre merged commit 1949eb0 into master Jun 17, 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