Skip to content

Fix Battle Log import attribution, counts and dialog races - #121

Merged
jamesembling merged 4 commits into
mainfrom
t3/battle-log-import-correctness
Nov 7, 2026
Merged

jamesembling merged 4 commits into
mainfrom
t3/battle-log-import-correctness

Conversation

@jamesembling

Copy link
Copy Markdown
Owner

Result

Battle Log imports preserve the recorded player identities, winner and counts, and discard asynchronous work belonging to an abandoned dialog session. Parser-derived draft facts and the database save contract remain unchanged. No schema, Replay implementation, or stats implementation changes.

Bugs fixed

Symptom Root cause File:line Regression proof
A win becomes a loss when the conceding player's name contains . ; an unrecognized winner silently becomes a loss Greedy winner capture accepted arbitrary text instead of resolving a recorded participant lib/log-import/parser/stats.ts:121 tests/log-import-player-identity.test.ts:11, participant-name variants, both perspectives, and unknown-winner rejection
Prize snapshots stay at six for a name ending in punctuation Actor detection required a regex word boundary after the name lib/log-import/parser/players.ts:124, lib/log-import/parser/turns.ts:175 Same identity case checks Trainer[+]'s prize snapshot
A hyphen-leading player's actions disappear into the preceding action and damage/prizes are missed Every initial hyphen was treated as a detail marker, even without separating whitespace lib/log-import/parser/turns.ts:96, lib/log-import/parser/stats.ts:90 Same identity case checks -Trainer's recorded damage and prizes
One player's deck evidence includes another player's cards when their usernames share a suffix Identification searched for username substrings anywhere in the line lib/log-import/parser/pokemon-mentions.ts:6 Same identity case checks Trainer versus OtherTrainer
A Pokémon-shaped username contributes fictitious deck evidence Tokenization and archetype text included the leading player identity lib/log-import/parser/pokemon-mentions.ts:75 Same identity case checks Dreepy versus Charizard, with independent expected card counts
An unnumbered four-turn export reports two total turns The fallback counted pairs of player turns, unlike numbered exports lib/log-import/parser/stats.ts:185 tests/local-e2e-battle-log-fixtures.test.ts:9 uses James's real identified export and expects four turns
Repeated recorded mulligans count as one Singular event counts were reduced with Math.max lib/log-import/parser/stats.ts:275 tests/log-import-stats.test.ts:33 repeats the real appendix's mulligan event and excludes the opponent's bonus draw
A review response restores a draft after the text was cleared or the dialog closed Clearing/resetting and effect cleanup did not invalidate the request identity components/ui/ImportLogDialog.tsx:226, components/ui/ImportLogDialog.tsx:523 Rendered interaction in tests/import-log-dialog.test.ts:22 resolves deferred responses after clear and close
A delayed clipboard read pastes an old log into a reopened dialog Clipboard completion had no session/request guard components/ui/ImportLogDialog.tsx:344 Same rendered journey resolves a deferred clipboard read after close/reopen
Two same-tick form submissions send two save requests React saving state did not synchronously guard the submit handler components/ui/ImportLogDialog.tsx:437 Same rendered journey submits twice before a response and asserts one network request
A save response navigates away from a newly reopened dialog Save completion and error handling ignored dialog session ownership components/ui/ImportLogDialog.tsx:454 Same rendered journey resolves the old save after close/reopen and checks that no navigation occurs

Each regression was observed red before retaining its corresponding fix. Player-name variants change only identities in the committed log fixture. Mulligan wording comes from the real PTCGL appendix. Existing damage scenarios retain their assertions. The only Replay test change is the importer summary expectation totalTurns: 2 → 4; Replay behavior is unchanged.

Suspected issues not fixed

  • Localized statistics — high confidence in the coverage gap, unverified wording. Coin-toss, damage and mulligan extraction still use English phrases even though player/setup parsing supports six languages. There are no complete real localized exports in the reviewed fixtures. Adding translations without recorded wording would violate the task's fixture rule.
  • Two participants matching configured primary/alternate usernames — medium confidence. resolveSelfOpponent currently selects the first accepted identity. A log containing both configured identities needs an explicit account-identity policy (prefer primary or reject ambiguity); the reviewed contract does not decide it. No speculative attribution rule was added.
  • The same raw game imported through separate drafts — medium confidence. The reviewed save path provides same-draft idempotency, but cross-draft content deduplication is not established by this work. Changing that policy requires a database-backed reproduction and agreement on whether repeated content must be rejected. No schema or persistence adapter changes were made.

Validation and test consolidation

  • npm ci completed.
  • npm run lint, npm run typecheck, and npm test pass.
  • Baseline npm test: 327 cases, 326 passed, 1 skipped. Final: 327 cases, 326 passed, 1 skipped. Executed-case delta: 0.
  • Added one rendered import journey, extending a previously untested UI boundary; consolidated two overlapping damage cases into one while retaining both scenarios. Existing identity, fixture-summary and statistics cases carry the parser regressions.
  • New rendered case usefulness: 9/10. It observes stale asynchronous responses and concurrent submissions through the real component and network boundary; parser/draft unit tests cannot cover those React lifecycle failures.
  • npx prettier --check was run for every changed file. The new rendered test and turns.ts pass. Eight existing files retain their baseline formatting warnings; changed code was formatted without reformatting untouched code. git diff --check passes.
  • The database import rehearsal and authenticated browser E2E were not run. Database locking, hosted persistence and clipboard permission prompts are not verified by the rendered test's deferred fetch/clipboard adapters. Existing draft immutability/idempotency tests pass in the full suite.

🤖 Generated with Claude Code

jamesembling and others added 2 commits November 7, 2026 08:06
Resolve winners against the recorded participants, keep usernames out of card evidence, preserve punctuation in actors, and count recorded turns and mulligan events consistently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Discard late parse, clipboard, and save responses after reset or unmount, and synchronously guard repeated save submissions. Exercise abandonment and concurrent submit behavior through the rendered dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
poke-notes-app Ready Ready Preview Nov 7, 2026 8:20am UTC

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T08:10:49.169551Z 73eaa74 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73eaa74728

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/ui/ImportLogDialog.tsx Resolved
Matching the acting player at the start of a line dropped indented
"- " / "• " detail lines, so Rare Candy evolutions and ability-driven
attachments no longer counted towards deck identification. Strip the
detail marker before matching.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamesembling jamesembling added the merge-when-green Squash-merge automatically once every check is green label Nov 7, 2026
Every keystroke invalidated the pending review request, but the
auto-review effect only reschedules when the trimmed log changes. A
trailing space or newline therefore discarded the pending review and
auto-review silently stopped. Invalidate only when the trimmed log
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamesembling
jamesembling merged commit a6fed6e into main Nov 7, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 9ed09b5e Deployed Nov 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-green Squash-merge automatically once every check is green

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant