Conversation
WalkthroughThis PR introduces intelligent asset preference matching by adding a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt (1)
690-697: Consider usingAssetPreferenceMatcherfor consistency withInstalledAppsRepositoryImpl.The asset selection logic here uses simple exact-name matching via
firstOrNull { it.name == ... }, whileInstalledAppsRepositoryImpl.checkForUpdates()andAppsViewModel.updateSingleApp()useAssetPreferenceMatcher.choosePreferredAsset()which provides fuzzy matching (family-based, extension-aware, similarity scoring).This inconsistency could lead to different asset selection behavior during updates initiated from the details screen versus the apps list screen. If the asset name changes slightly between releases (e.g., version number in filename), this simple matching will fail while
AssetPreferenceMatcherwould still find a match.♻️ Suggested refactor for consistency
+import zed.rainxch.core.domain.model.AssetPreferenceMatcher + private fun update() { val installedApp = _state.value.installedApp val selectedRelease = _state.value.selectedRelease if (installedApp != null && selectedRelease != null && installedApp.isUpdateAvailable) { val latestAsset = - _state.value.primaryAsset - ?: _state.value.installableAssets.firstOrNull { - it.name == installedApp.latestAssetName - } - ?: _state.value.installableAssets.firstOrNull { - it.name == installedApp.installedAssetName - } + _state.value.primaryAsset + ?: AssetPreferenceMatcher.choosePreferredAsset( + assets = _state.value.installableAssets, + preferredAssetNames = listOf(installedApp.latestAssetName, installedApp.installedAssetName), + )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt` around lines 690 - 697, DetailsViewModel currently selects latestAsset by exact name equality which differs from InstalledAppsRepositoryImpl and AppsViewModel that use AssetPreferenceMatcher; replace the two firstOrNull name-equality checks in DetailsViewModel.kt (the latestAsset assignment) with a call to AssetPreferenceMatcher.choosePreferredAsset passing _state.value.installableAssets and the preferred names (installedApp.latestAssetName and installedApp.installedAssetName) so matching uses the same fuzzy/family/extension-aware logic as InstalledAppsRepositoryImpl and AppsViewModel.core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AssetPreferenceMatcher.kt (1)
100-103: Consider extendingVERSION_TOKEN_REGEXto cover additional version patterns.The current regex
^v?\\d+(?:[._-]?\\d+)*[a-z]*$handles common semver patterns but may miss:
- Date-based versions:
2024.04.14,20240414- Named pre-releases:
rc1,alpha,beta2,preview- Build metadata:
build123,nightlyThese tokens remaining in the family key could cause family mismatches when asset naming changes between releases.
♻️ Optional: Extended version token detection
- private fun isLikelyVersionToken(token: String): Boolean = VERSION_TOKEN_REGEX.matches(token) + private fun isLikelyVersionToken(token: String): Boolean = + VERSION_TOKEN_REGEX.matches(token) || + PRERELEASE_TOKEN_REGEX.matches(token) || + DATE_VERSION_REGEX.matches(token) private val NON_ALNUM_REGEX = Regex("[^a-z0-9]+") private val VERSION_TOKEN_REGEX = Regex("^v?\\d+(?:[._-]?\\d+)*[a-z]*$") + private val PRERELEASE_TOKEN_REGEX = Regex("^(alpha|beta|rc|preview|nightly|canary|dev|snapshot)\\d*$") + private val DATE_VERSION_REGEX = Regex("^\\d{8}$")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AssetPreferenceMatcher.kt` around lines 100 - 103, The VERSION_TOKEN_REGEX used by isLikelyVersionToken is too narrow and misses date-based, named pre-release, and build-metadata tokens; update VERSION_TOKEN_REGEX to match additional patterns like YYYY(.MM(.DD)?) and compact dates (e.g., 20240414), named pre-releases (alpha|beta|rc|preview) with optional digits, and build metadata prefixes (build|nightly) while preserving the existing semver handling so isLikelyVersionToken detects these tokens; locate and modify VERSION_TOKEN_REGEX (and adjust any dependent logic in isLikelyVersionToken if needed) and ensure NON_ALNUM_REGEX remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AssetPreferenceMatcher.kt`:
- Around line 100-103: The VERSION_TOKEN_REGEX used by isLikelyVersionToken is
too narrow and misses date-based, named pre-release, and build-metadata tokens;
update VERSION_TOKEN_REGEX to match additional patterns like YYYY(.MM(.DD)?) and
compact dates (e.g., 20240414), named pre-releases (alpha|beta|rc|preview) with
optional digits, and build metadata prefixes (build|nightly) while preserving
the existing semver handling so isLikelyVersionToken detects these tokens;
locate and modify VERSION_TOKEN_REGEX (and adjust any dependent logic in
isLikelyVersionToken if needed) and ensure NON_ALNUM_REGEX remains unchanged.
In
`@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt`:
- Around line 690-697: DetailsViewModel currently selects latestAsset by exact
name equality which differs from InstalledAppsRepositoryImpl and AppsViewModel
that use AssetPreferenceMatcher; replace the two firstOrNull name-equality
checks in DetailsViewModel.kt (the latestAsset assignment) with a call to
AssetPreferenceMatcher.choosePreferredAsset passing
_state.value.installableAssets and the preferred names
(installedApp.latestAssetName and installedApp.installedAssetName) so matching
uses the same fuzzy/family/extension-aware logic as InstalledAppsRepositoryImpl
and AppsViewModel.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 87297cd7-493b-440c-9e6b-7fd8816bd03a
📒 Files selected for processing (6)
core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/InstalledAppsRepositoryImpl.ktcore/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/AssetPreferenceMatcher.ktfeature/apps/data/src/commonMain/kotlin/zed/rainxch/apps/data/repository/AppsRepositoryImpl.ktfeature/apps/domain/src/commonMain/kotlin/zed/rainxch/apps/domain/repository/AppsRepository.ktfeature/apps/presentation/src/commonMain/kotlin/zed/rainxch/apps/presentation/AppsViewModel.ktfeature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt
Summary by CodeRabbit
Release Notes