Skip to content

Comments

fix(game-store): guard against splice(-1) in processScuttle#1336

Merged
itsalaidbacklife merged 2 commits intomainfrom
fix/scuttle-splice-negative-index
Feb 13, 2026
Merged

fix(game-store): guard against splice(-1) in processScuttle#1336
itsalaidbacklife merged 2 commits intomainfrom
fix/scuttle-splice-negative-index

Conversation

@seriouslysean
Copy link
Collaborator

@seriouslysean seriouslysean commented Feb 10, 2026

Found during a code audit.processScuttle() checks targetCardIndex === -1 before splicing but doesn't check playedCardIndex. If socket events arrive out of order and the played card is already missing from local state, splice(-1, 1) silently removes the last card in hand instead.

Added the same -1 guard that already exists for targetCardIndex.

Issue number

  • N/A (found during code audit)

Please check the following

  • Do the tests still pass?
  • Is the code formatted properly?

Please describe additional details for testing this change

  1. npm run test:unit
  2. Hard to reproduce manually (requires socket race condition), but the guard matches the existing pattern for targetCardIndex right above it

@seriouslysean seriouslysean added bug Something isn't working version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1) labels Feb 10, 2026
Copilot AI review requested due to automatic review settings February 10, 2026 03:27
@seriouslysean seriouslysean self-assigned this Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents hand corruption in the client game store by guarding against splice(-1, 1) when a scuttle event arrives and the played card is already missing from local state (e.g., socket event race/out-of-order delivery).

Changes:

  • Add a playedCardIndex === -1 guard in processScuttle() to avoid removing the wrong card from hand.
  • Fall back to updateGame(game) when local state is missing the played card, matching the existing targetCardIndex guard behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@seriouslysean seriouslysean force-pushed the fix/scuttle-splice-negative-index branch from 24422c8 to 07513da Compare February 10, 2026 14:09
Copilot AI review requested due to automatic review settings February 13, 2026 02:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@itsalaidbacklife itsalaidbacklife added the frontend Requires changes to the frontend (vue) client label Feb 13, 2026
@itsalaidbacklife itsalaidbacklife merged commit e7672dc into main Feb 13, 2026
9 checks passed
@itsalaidbacklife itsalaidbacklife deleted the fix/scuttle-splice-negative-index branch February 13, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend Requires changes to the frontend (vue) client version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants