fix(client): respect legal Adventure cast faces - #6552
Conversation
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdventure casting now derives buttons from engine-authorized legal actions and dispatches those actions directly. Waiting-for test factories were reorganized into typed fluent builders with merged data overrides, expanded cast-offer support, and updated factory tests. ChangesAdventure cast and waiting-for factories
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AdventureCastModal
participant gameStore
participant AdventureCastContent
participant useGameDispatch
AdventureCastModal->>gameStore: read legalActions
AdventureCastModal->>AdventureCastContent: pass matching face actions
AdventureCastContent->>useGameDispatch: dispatch selected action
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
client/src/components/modal/AdventureCastModal.tsx (1)
59-96: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winNo fallback when neither Adventure face action is authorized.
If
legalActionsdoesn't yet contain a matchingChooseAdventureFaceaction for either face (e.g. a transient render beforelegalActionscatches up with the newwaitingFor), bothcreatureActionandadventureActionareundefined, and the dialog renders with an empty body instead of nothing. Consider returningnullfromAdventureCastModalwhen neither action is found, so the modal never appears in a dead-end state.🛡️ Proposed guard
const adventureAction = legalActions.find( (action): action is ChooseAdventureFaceAction => action.type === "ChooseAdventureFace" && !action.data.creature, ); + + if (!creatureAction && !adventureAction) return null;🤖 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 `@client/src/components/modal/AdventureCastModal.tsx` around lines 59 - 96, Update AdventureCastModal to return null when both creatureAction and adventureAction are undefined, before rendering DialogShell. Keep rendering the existing dialog unchanged whenever either authorized action is available.client/src/test/factories/gameStateFactory.ts (1)
295-336: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate CastOffer override-application logic across three call sites.
buildCastOfferWaitingFor(Lines 326-337) andWaitingForVariantFactory.castOffer(Lines 380-391) contain identicalif (player !== undefined) factory = factory.forPlayer(player); if (kind !== undefined) factory = factory.withKind(kind);logic, and the inline{ player?: PlayerId; kind?: CastOfferWaitingFor["data"]["kind"] }options shape is repeated a third time inGameStateFactory.castOffer(Line 618-627). If a new override field is added to one, the others can silently drift out of sync.Extract a shared helper (e.g.
applyCastOfferOverrides(factory, { player, kind })) and a sharedCastOfferOverridestype, then have all three call sites delegate to it.♻️ Proposed consolidation
+type CastOfferOverrides = { + player?: PlayerId; + kind?: CastOfferWaitingFor["data"]["kind"]; +}; + +const applyCastOfferOverrides = ( + factory: typeof castOfferWaitingForFactory, + { player, kind }: CastOfferOverrides, +) => { + let result = factory; + if (player !== undefined) result = result.forPlayer(player); + if (kind !== undefined) result = result.withKind(kind); + return result; +}; + -export const buildCastOfferWaitingFor = ({ - player, - kind, -}: { - player?: PlayerId; - kind?: CastOfferWaitingFor["data"]["kind"]; -} = {}): CastOfferWaitingFor => { - let factory = castOfferWaitingForFactory; - if (player !== undefined) factory = factory.forPlayer(player); - if (kind !== undefined) factory = factory.withKind(kind); - return factory.build(); -}; +export const buildCastOfferWaitingFor = ( + overrides: CastOfferOverrides = {}, +): CastOfferWaitingFor => applyCastOfferOverrides(castOfferWaitingForFactory, overrides).build();🤖 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 `@client/src/test/factories/gameStateFactory.ts` around lines 295 - 336, Extract a shared CastOfferOverrides type and applyCastOfferOverrides helper near CastOfferWaitingForFactory, encapsulating the optional player and kind updates. Replace the duplicated override conditionals in buildCastOfferWaitingFor, WaitingForVariantFactory.castOffer, and GameStateFactory.castOffer with this helper, and use the shared type for all three options parameters.
🤖 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.
Nitpick comments:
In `@client/src/components/modal/AdventureCastModal.tsx`:
- Around line 59-96: Update AdventureCastModal to return null when both
creatureAction and adventureAction are undefined, before rendering DialogShell.
Keep rendering the existing dialog unchanged whenever either authorized action
is available.
In `@client/src/test/factories/gameStateFactory.ts`:
- Around line 295-336: Extract a shared CastOfferOverrides type and
applyCastOfferOverrides helper near CastOfferWaitingForFactory, encapsulating
the optional player and kind updates. Replace the duplicated override
conditionals in buildCastOfferWaitingFor, WaitingForVariantFactory.castOffer,
and GameStateFactory.castOffer with this helper, and use the shared type for all
three options parameters.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2584f4e1-715f-4e11-8304-c9884f8d35fb
📒 Files selected for processing (4)
client/src/components/modal/AdventureCastModal.tsxclient/src/components/modal/__tests__/AdventureCastModal.test.tsxclient/src/test/factories/__tests__/factories.test.tsclient/src/test/factories/gameStateFactory.ts
* fix(client): respect legal Adventure cast faces * fix(client): preserve waiting factory variant types * fix(client): retain concrete waiting factories --------- Co-authored-by: matthewevans <matthewevans@users.noreply.github.com>
Summary by CodeRabbit
Bug Fixes
Tests