Skip to content

Fix stall upgrade logic and test stability - #114

Closed
candour wants to merge 3 commits into
mainfrom
fix-stall-upgrade-and-tests-2852423425195058954
Closed

Fix stall upgrade logic and test stability#114
candour wants to merge 3 commits into
mainfrom
fix-stall-upgrade-and-tests-2852423425195058954

Conversation

@candour

@candour candour commented May 2, 2026

Copy link
Copy Markdown
Owner

This PR addresses several desynchronization bugs between the game's upgrade logic and its UI representation. It also fixes all existing unit test failures and performance issues (timeouts).

Key Changes:

  1. Refactoring: Synchronized stall upgrade logic across the app. This ensures that the "+X%" benefits shown in the UI are calculated using the exact same formulas used during gameplay.
  2. Legendary Names: Added "Boost" category entries to LegendaryNames.kt. Bak Kut Teh stalls can now reach legendary status at level 10.
  3. Test Reliability:
    • Fixed gameJob interference in unit tests by making it internal and cancelling it during test setup. This stops the background loop from causing nondeterministic state changes and timeouts.
    • Transitioned tests to use upgradeStallRandomly() to bypass UI-only overlay logic.
    • Fixed KitchelinBonusTest where enemies were moving out of range before projectiles could land in virtual time.
  4. Determinism: Updated MainViewModel to use its seeded random instance for stall upgrades, ensuring consistent results during testing.

All unit tests now pass in under 20 seconds.


PR created automatically by Jules for task 2852423425195058954 started by @candour

Summary by CodeRabbit

  • New Features

    • Legendary stalls gain a new "Boost" naming category, increasing unique name variety.
  • Core Systems

    • Centralized stall upgrade logic updated: upgrade cost calculation, specific-vs-random stat selection, free-specific-upgrade handling, milestone scaling, and legendary-name assignment at milestone levels.
  • Tests

    • Game timing and upgrade tests adjusted to stabilize outcomes and ensure consistent behavior.

- Centralized stall upgrade logic to ensure UI descriptions match gameplay scaling.
- Added missing "Boost" category to the legendary naming system for Bak Kut Teh stalls.
- Improved unit test stability and performance by explicitly managing the ViewModel's game loop.
- Resolved logical errors and timeouts in KitchelinBonusTest and BossWaveLogicTest.
- Updated MilestoneBoostTest to reflect corrected additive and multiplicative scaling rules.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7951f535-94ec-49f3-bb81-4f265ab682cb

📥 Commits

Reviewing files that changed from the base of the PR and between 1edd634 and ee9b09b.

📒 Files selected for processing (1)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt

📝 Walkthrough

Walkthrough

Stall upgrade logic was extracted into a new StallUpgradeManager that centralizes cost calculation, available-stat selection, upgrade application (including milestone scaling and special-case rules), and benefit-string formatting. MainViewModel and Registry delegate to it; tests and LegendaryNames were updated; MainViewModel.gameJob visibility changed to internal.

Changes

Stall Upgrade Manager Extraction

Layer / File(s) Summary
Upgrade Manager Creation
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
Adds StallUpgradeManager with calculateUpgradeCost, getAvailableUpgradeStats, applyUpgrade (per-stat level increments, milestone scaling every 10 levels, stall-type special cases, disabledWaves handling, legendary naming updates), and getBenefitString (user-facing delta formatting).
MainViewModel Refactor
app/src/main/java/com/messark/hawker/MainViewModel.kt
Imports StallUpgradeManager; refactors applyUpgrade to compute hasFreeUpgrade, call calculateUpgradeCost, choose statToUpgrade (validate specificStat or pick random available), call applyUpgrade, update stall in hexes, decrement gold and freeSpecificUpgrades as appropriate; gameJob visibility changed to internal.
Registry Delegation
app/src/main/java/com/messark/hawker/registry/Registry.kt
StallDefinition.getUpgradeBenefit now delegates to StallUpgradeManager.getBenefitString, removing prior inline benefit computation and its level<=0 handling.
Legendary Names Extend
app/src/main/java/com/messark/hawker/utils/LegendaryNames.kt
Adds a "Boost" category to both suffixes and prefixes maps, extending available name components.
Tests: Coroutine Cleanup & Upgrade Selection
app/src/test/java/com/messark/hawker/*Test.kt
Multiple tests now call viewModel.gameJob?.cancel() after constructing MainViewModel to stop background coroutines. Several tests switch from upgradeStall() to upgradeStallRandomly() to match new selection behavior.
Tests: Assertion/Timing Adjustments
app/src/test/java/com/messark/hawker/KitchelinBonusTest.kt, .../MilestoneBoostTest.kt
KitchelinBudget tests removed intermediate idle-advances and assert bonuses after a single updateGame(1000L); MilestoneBoost expectations updated for damage benefit strings and numeric outcomes at milestone levels.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

🚥 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 'Fix stall upgrade logic and test stability' directly summarizes the main changes: refactoring upgrade logic, fixing test failures, and improving test reliability.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-stall-upgrade-and-tests-2852423425195058954
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix-stall-upgrade-and-tests-2852423425195058954

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

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

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f11c911-d714-4fa1-91ae-12e535820e0e

📥 Commits

Reviewing files that changed from the base of the PR and between 9d83172 and 1edd634.

📒 Files selected for processing (8)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • app/src/main/java/com/messark/hawker/registry/Registry.kt
  • app/src/main/java/com/messark/hawker/utils/LegendaryNames.kt
  • app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
  • app/src/test/java/com/messark/hawker/BossWaveLogicTest.kt
  • app/src/test/java/com/messark/hawker/KitchelinBonusTest.kt
  • app/src/test/java/com/messark/hawker/LegendaryNamingTest.kt
  • app/src/test/java/com/messark/hawker/MilestoneBoostTest.kt

Comment thread app/src/main/java/com/messark/hawker/MainViewModel.kt
Comment thread app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt
@candour
candour enabled auto-merge (squash) May 2, 2026 02:06
- Centralized stall upgrade logic to ensure UI descriptions match gameplay scaling.
- Added missing "Boost" category to the legendary naming system for Bak Kut Teh stalls.
- Improved unit test stability and performance by explicitly managing the ViewModel's game loop.
- Resolved logical errors and timeouts in KitchelinBonusTest and BossWaveLogicTest.
- Updated MilestoneBoostTest to reflect corrected additive and multiplicative scaling rules.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

- Validate specificStat in MainViewModel.kt before applying upgrades to prevent invalid state changes.
- Add "Boost" category to LegendaryNames.kt for Bak Kut Teh legendary titles.
- Improve unit test reliability by explicitly managing the ViewModel's game loop (cancelling gameJob).
- Synchronize MilestoneBoostTest with current scaling logic and deterministic upgrade methods.
- Fix KitchelinBonusTest failures by ensuring projectile hits are correctly processed in virtual time.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@candour
candour disabled auto-merge May 2, 2026 05:45
@candour
candour enabled auto-merge (squash) May 2, 2026 05:45
candour added a commit that referenced this pull request May 2, 2026
- Ported upgrade logic synchronization and legendary naming from PR #114.
- Made RNG injectable in MainViewModel constructor with a default value.
- Updated all unit tests to inject a fixed-seed Random(42) for determinism.
- Changed gameJob visibility to internal and cancelled it in test setups.
- Validated specificStat in applyUpgrade.
- Verified all unit tests pass.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
candour added a commit that referenced this pull request May 2, 2026
…115)

- Centralized stall upgrade logic to ensure UI descriptions match gameplay scaling.
- Added "Boost" category to the legendary naming system for Bak Kut Teh stalls.
- Improved unit test stability by explicitly managing the ViewModel's game loop (cancelling gameJob).
- Resolved logical errors and timeouts in KitchelinBonusTest and BossWaveLogicTest.
- Updated MilestoneBoostTest and LegendaryNamingTest to reflect current scaling rules and use deterministic upgrade methods.
- Validated specificStat in MainViewModel.kt to prevent invalid state changes.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@candour candour closed this May 2, 2026
auto-merge was automatically disabled May 2, 2026 09:10

Pull request was closed

@candour
candour deleted the fix-stall-upgrade-and-tests-2852423425195058954 branch June 26, 2026 05:02
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