Skip to content

fix(client): respect legal Adventure cast faces - #6552

Merged
matthewevans merged 4 commits into
mainfrom
ship/fix-legal-adventure-faces
Jul 23, 2026
Merged

fix(client): respect legal Adventure cast faces#6552
matthewevans merged 4 commits into
mainfrom
ship/fix-legal-adventure-faces

Conversation

@matthewevans

@matthewevans matthewevans commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Adventure casting now displays only face-selection options currently available for the game state.
    • Prevented unauthorized creature or adventure choices from appearing or being submitted.
    • Improved handling of cast offers so actions are dispatched accurately and consistently.
    • Cast prompts now remain hidden when the offer belongs to another player.
  • Tests

    • Added coverage for authorized choices, unavailable options, dispatched actions, and player-specific cast offers.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@matthewevans, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0d775d0f-3c9b-4d0e-8a23-9f39fa0d0f24

📥 Commits

Reviewing files that changed from the base of the PR and between 97dc5b3 and 9acf7b7.

📒 Files selected for processing (1)
  • client/src/test/factories/gameStateFactory.ts
📝 Walkthrough

Walkthrough

Adventure 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.

Changes

Adventure cast and waiting-for factories

Layer / File(s) Summary
Typed waiting-for factory contracts
client/src/test/factories/gameStateFactory.ts
Adds generic and per-variant factories that merge data overrides while preserving defaults and support player-specific setters.
Fluent variant builders and game-state wiring
client/src/test/factories/gameStateFactory.ts, client/src/test/factories/__tests__/factories.test.ts
Adds fluent cast-offer and shortcut builders, updates variant construction, changes GameStateFactory.castOffer to accept options, and tests the resulting shapes.
Legal-action-driven adventure casting
client/src/components/modal/AdventureCastModal.tsx, client/src/components/modal/__tests__/AdventureCastModal.test.tsx
AdventureCastModal selects authorized creature and adventure actions, conditionally renders matching buttons, and dispatches the selected actions; tests cover authorization, ordering, and player ownership.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: Adventure cast face options now respect the legal actions provided by the game engine.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/fix-legal-adventure-faces

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

@matthewevans
matthewevans enabled auto-merge July 23, 2026 17:20

@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.

🧹 Nitpick comments (2)
client/src/components/modal/AdventureCastModal.tsx (1)

59-96: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No fallback when neither Adventure face action is authorized.

If legalActions doesn't yet contain a matching ChooseAdventureFace action for either face (e.g. a transient render before legalActions catches up with the new waitingFor), both creatureAction and adventureAction are undefined, and the dialog renders with an empty body instead of nothing. Consider returning null from AdventureCastModal when 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 win

Duplicate CastOffer override-application logic across three call sites.

buildCastOfferWaitingFor (Lines 326-337) and WaitingForVariantFactory.castOffer (Lines 380-391) contain identical if (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 in GameStateFactory.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 shared CastOfferOverrides type, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ae8737 and 97dc5b3.

📒 Files selected for processing (4)
  • client/src/components/modal/AdventureCastModal.tsx
  • client/src/components/modal/__tests__/AdventureCastModal.test.tsx
  • client/src/test/factories/__tests__/factories.test.ts
  • client/src/test/factories/gameStateFactory.ts

@matthewevans
matthewevans added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 0b38b1a Jul 23, 2026
14 checks passed
@matthewevans
matthewevans deleted the ship/fix-legal-adventure-faces branch July 23, 2026 18:42
jsdevninja pushed a commit to jsdevninja/phase that referenced this pull request Jul 24, 2026
* 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>
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