-
Notifications
You must be signed in to change notification settings - Fork 654
Record missing stats #2407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Record missing stats #2407
Conversation
WalkthroughAdded telemetry recording calls to TradeShipExecution.complete() to measure two outcomes: boatCapturedTrade when a trade ship is captured, and boatArriveTrade when it arrives normally. Test mock objects now include clientID properties to support these telemetry scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks✅ Passed checks (3 passed)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/execution/TradeShipExecution.ts(2 hunks)src/core/game/UnitImpl.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-05-19T06:00:38.007Z
Learnt from: scottanderson
Repo: openfrontio/OpenFrontIO PR: 784
File: src/core/game/StatsImpl.ts:125-134
Timestamp: 2025-05-19T06:00:38.007Z
Learning: In StatsImpl.ts, unused parameters in boat/stats-related methods are intentionally kept for future use and shouldn't be removed.
Applied to files:
src/core/execution/TradeShipExecution.tssrc/core/game/UnitImpl.ts
📚 Learning: 2025-05-22T23:48:51.113Z
Learnt from: jrouillard
Repo: openfrontio/OpenFrontIO PR: 848
File: src/core/execution/TradeShipExecution.ts:125-127
Timestamp: 2025-05-22T23:48:51.113Z
Learning: In TradeShipExecution, the path length is already checked in the computeNewPath() function. If the path is empty, it returns PathFindResultType.PathNotFound instead of PathFindResultType.Completed, making additional empty path checks unnecessary when handling the Completed case.
Applied to files:
src/core/execution/TradeShipExecution.ts
📚 Learning: 2025-08-29T16:16:11.309Z
Learnt from: BrewedCoffee
Repo: openfrontio/OpenFrontIO PR: 1957
File: src/core/execution/PlayerExecution.ts:40-52
Timestamp: 2025-08-29T16:16:11.309Z
Learning: In OpenFrontIO PlayerExecution.ts, when Defense Posts are captured due to tile ownership changes, the intended behavior is to first call u.decreaseLevel() to downgrade them, then still transfer them to the capturing player via captureUnit(). This is not a bug - Defense Posts should be both downgraded and captured, not destroyed outright.
Applied to files:
src/core/game/UnitImpl.ts
📚 Learning: 2025-10-20T20:15:28.858Z
Learnt from: sambokai
Repo: openfrontio/OpenFrontIO PR: 2225
File: src/core/execution/FakeHumanExecution.ts:51-51
Timestamp: 2025-10-20T20:15:28.858Z
Learning: In src/core/execution/FakeHumanExecution.ts, game balance constants like MIRV_COOLDOWN_TICKS, MIRV_HESITATION_ODDS, VICTORY_DENIAL_TEAM_THRESHOLD, VICTORY_DENIAL_INDIVIDUAL_THRESHOLD, and STEAMROLL_CITY_GAP_MULTIPLIER are experimental tuning parameters subject to frequent change during balance testing. Do not flag changes to these values as issues or compare them against previous values.
Applied to files:
src/core/game/UnitImpl.ts
📚 Learning: 2025-06-05T02:34:45.899Z
Learnt from: Egraveline
Repo: openfrontio/OpenFrontIO PR: 1012
File: src/core/execution/UpgradeStructureExecution.ts:49-54
Timestamp: 2025-06-05T02:34:45.899Z
Learning: In the upgrade system, gold deduction for structure upgrades is handled internally by the `upgradeUnit` method in PlayerImpl, not in the UpgradeStructureExecution class. The UpgradeStructureExecution only needs to check if the player has sufficient gold before calling `upgradeUnit`.
Applied to files:
src/core/game/UnitImpl.ts
🪛 GitHub Actions: 🧪 CI
src/core/execution/TradeShipExecution.ts
[error] 173-173: TypeError: player.clientID is not a function
🔇 Additional comments (2)
src/core/execution/TradeShipExecution.ts (1)
151-154: Stat recording is correct—no changes needed.The implementations in
StatsImpl.ts(lines 180-189) are clean and properly handle both scenarios. The calls inTradeShipExecution.tspass the correct parameters in the right order: the capturing player and original owner forboatCapturedTrade, and both port owners forboatArriveTrade. Tests validate the behavior works as intended.src/core/game/UnitImpl.ts (1)
425-435: Stat recording is safe—approve as-is.The
unitUpgradecall chain properly handles nullclientIDvalues. When_makePlayerStats(player)encounters a nullclientIDat line 56, it returnsundefined(line 57), and_addOtherUnitgracefully exits early (line 126). This defensive pattern is consistent across all stats tracking methods (_addAttack,_addBoat,_addBomb, etc.), so stats recording simply skips for players with null IDs rather than causing a pipeline failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/core/executions/TradeShipExecution.test.ts (1)
32-32: AddclientIDto the pirate mock for consistency.The
origOwneranddstOwnermocks now includeclientIDto support telemetry recording. However, thepiratemock (lines 46-53) lacks this property. Since a captured trade ship is owned by the pirate when it completes, the telemetry code would needpirate.clientID()in that scenario.While current tests don't exercise a captured trade completion, adding
clientIDto the pirate mock prevents future test failures and keeps all player mocks consistent.Apply this diff:
pirate = { id: jest.fn(() => 3), + clientID: jest.fn(() => 3), addGold: jest.fn(), displayName: jest.fn(() => "Destination"), units: jest.fn(() => [piratePort]), unitCount: jest.fn(() => 1), canTrade: jest.fn(() => true), } as any;Also applies to: 42-42, 46-53
Description:
Some stats are missing from the recorded game stats:
The gold from trade/steal was introduced with PR 784 but was quickly reverted with PR 927, probably involuntarily.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
IngloriousTom