Guard combat HP writes with character versions - #198
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughCombatService now validates authoritative character HP state and version data before damage, healing, and stabilization. Guarded writes reject stale or invalid updates, restore live combat state, and report errors. Tests update database mocks and cover conflicts, missing rows, and rollback behavior. ChangesCombat HP concurrency protection
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CombatService
participant Database
participant CombatState
participant Session
CombatService->>Database: Load authoritative character state and version
Database-->>CombatService: Character row
CombatService->>CombatState: Apply combat HP mutation
CombatService->>Database: Persist HP with version guard
alt Update succeeds
Database-->>CombatService: Updated version
CombatService->>Session: Emit combat update
else Update fails
Database-->>CombatService: Conflict or invalid result
CombatService->>CombatState: Restore prior state
CombatService->>Session: Send retry error
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
What changed
Why
Combat HP actions previously wrote without an optimistic version condition. A simultaneous character-sheet edit could be overwritten, and failed writes could leave the live room state ahead of PostgreSQL.
Validation
npm teston Node 24: 145 files, 1,794 tests passednpm run linton Node 24npm run buildon Node 24npm audit --audit-level=high: 0 vulnerabilitiesSummary by CodeRabbit