Fixed pirating not being disabled when a warship's owner has no port in that body of water#4458
Fixed pirating not being disabled when a warship's owner has no port in that body of water#4458TKTK123456 wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesWarship Piracy Reachability Gate
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
evanpelle
left a comment
There was a problem hiding this comment.
from claude:
src/core changes require tests (CLAUDE.md) — the diff has none and all 29 existing warship tests pass with or without this change, so the new reachable-port logic is completely uncovered.
The port loop should filter isActive() && !isUnderConstruction() && !isMarkedForDeletion() like TradeShipExecution.ts does — otherwise a warship still captures trades that get instantly deleted for zero gold.
When warshipComponent is null, hasReachablePort stays undefined (skipping via !undefined) and the warshipComponent !== null guard at line 292 is now dead — one always-firing init block with .some() would remove the third state and the dead guard.
This is the third in-file copy of "owner's port in my water component" (findNearestPort, nearestAvailablePortTile) — consider a shared Player-level helper, which would also fix #2.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/Warship.test.ts (1)
142-146: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSimplify: unused mock branch.
getWaterComponent'stile === warshipTile ? 1 : 2distinction has no effect sincehasWaterComponentis mocked withmockReturnValue(false)unconditionally — the reachability check infindBestTargetnever inspects the returned component values differently. Consider returning a constant since the branching doesn't drive any behavior being tested.♻️ Simplify mock setup
- const warshipTile = warship.tile(); - vi.spyOn(game, "getWaterComponent").mockImplementation((tile) => - tile === warshipTile ? 1 : 2, - ); + vi.spyOn(game, "getWaterComponent").mockReturnValue(1); vi.spyOn(game, "hasWaterComponent").mockReturnValue(false);🤖 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 `@tests/Warship.test.ts` around lines 142 - 146, The mock setup in the Warship test has an unnecessary branch because `hasWaterComponent` is always forced to return false, so `findBestTarget` never uses different values from `getWaterComponent`. Simplify the `warship.tile()` / `game.getWaterComponent` spy in `Warship.test.ts` to return a constant value instead of branching on `tile === warshipTile`, and keep the `game.hasWaterComponent` mock as-is unless the test actually needs reachability to vary.
🤖 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 `@tests/Warship.test.ts`:
- Around line 143-146: The spies on game.getWaterComponent and
game.hasWaterComponent in the Warship test are not being cleaned up, so they can
leak into later tests. Update the Warship.test setup to restore these vi.spyOn
calls after the assertions, or add an afterEach cleanup in this test file that
restores all mocks. Keep the fix scoped to the existing test helpers and the
specific getWaterComponent/hasWaterComponent spies.
---
Nitpick comments:
In `@tests/Warship.test.ts`:
- Around line 142-146: The mock setup in the Warship test has an unnecessary
branch because `hasWaterComponent` is always forced to return false, so
`findBestTarget` never uses different values from `getWaterComponent`. Simplify
the `warship.tile()` / `game.getWaterComponent` spy in `Warship.test.ts` to
return a constant value instead of branching on `tile === warshipTile`, and keep
the `game.hasWaterComponent` mock as-is unless the test actually needs
reachability to vary.
🪄 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: 3df45008-feab-4233-b559-413a2c3c6c00
📒 Files selected for processing (1)
tests/Warship.test.ts
Add approved & assigned issue number here:
Resolves #4291
Description:
Fixes pirating not being disabled when a warship's owner has no port in that body of water
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tktk1234567