Validate troop limit commands#1931
Conversation
|
Even though a limit > soldier count might not look right, it doesn't cause any issues: A large limit is just the same as no limit. So if this doesn't fix an actual wrong behavior resulting from that I'd keep it, especially as it is virtually impossible to trigger/use the wrong count, so nothing will be gained by the added code. |
dfc7524 to
754b79d
Compare
Good point. I removed the count clamp. Large troop-limit values now keep the existing behavior. The PR only keeps the invalid-rank guard before indexing the troop-limit array. |
|
See my prior comment |
|
Updated this PR according to the deserialization-boundary feedback. The invalid rank is no longer silently ignored in Invalid serialized ranks now throw Validation:
|
|
Applied the two review suggestions with one correction.
I used I also noticed |
Flamefire
left a comment
There was a problem hiding this comment.
I also noticed ChangeReserve deserializes a soldier rank directly, but I left it unchanged here to avoid broadening this PR beyond the reviewed SetTroopLimit command path.
I'd be fine with using the new function in all command deserializations where it applies, at least for consistency, possibly without (new) tests. In the future we might otherwise wonder why it wasn't used.
Of course just where it is obviously correct, i.e. also had the same rank(ser.PopUnsignedChar())
|
Applied the remaining review feedback.
Validation passed locally:
I also checked the previously reported GitHub Actions failure. The Linux test job itself completed with |
Flamefire
left a comment
There was a problem hiding this comment.
Looks good now, only 2 minor things in the test.
Consolidated the invalid-rank coverage: the deserialize test now covers both rank-based commands.
How so? Because both commands would use the same function that triggers the error? Or am I missing something in the tests?
Flamefire
left a comment
There was a problem hiding this comment.
I also added an explicit uniqueness check so the test fails immediately if that setup invariant ever changes.
While not wrong I think this is where your AI overshot the target:
a) The uniqueness isn't strictly required, fully random values would do
b) There is no invariant as far as I can see. If you want to state that unique values shall be used then rather state the reason than adding complexity
See inline suggestions
Flamefire
left a comment
There was a problem hiding this comment.
To be transparent, I did not independently review the AI-assisted follow-up to the standard it needed before posting it.
That really is an issue for us. We currently get a lot of AI assisted/generated PRs but AI is still bad at understanding such a complex code base and producing clean, maintainable code.
We work on this project in our spare time so if it feels like we spend too much time on AI slop that hasn't been cleaned up before submission we'll need to ban use of AI as other projects already do.
So please help us here and make sure the changes are clean and reviewed before pushing. It would be bad if we couldn't profit from the increased speed enabled by AI due to its shortcomings.
You are right to raise this. My earlier wording was imprecise: I did review the generated follow-up and validate it locally before pushing it, but I did not review the resulting test structure deeply enough against the existing codebase patterns. That distinction does not change the unnecessary review work it caused. I understand that AI assistance is only useful here when it reduces maintainer effort rather than shifting cleanup work to reviewers. I will treat generated output as a draft, review the final diff and surrounding project patterns more critically, and only push follow-ups that I can clearly explain and justify. Sorry for the unnecessary churn. |
Summary
SetTroopLimitandChangeReserve, both usingpopSoldierRankMotivation
Troop limits and reserves are normally changed through UI paths where rank values are bounded.
However, the affected game commands store the rank as a raw
uint8_tand deserialize it from the command stream before forwarding it into game-state handling.Review feedback pointed out that silently ignoring invalid values inside
nobMilitary::SetTroopLimitis not the preferred style. This version validates the deserialized command value instead, matching the existing approach used for invalid/out-of-range enum values.Behavior
std::range_errorviahelpers::makeOutOfRangeSetTroopLimitandChangeReservenow both usepopSoldierRanknobMilitary::SetTroopLimitkeeps only an internal assertValidation
Test_integrationlocally with Visual Studio 2022 / DebugTest_integration.exe --run_test=GameCommandSuite --report_level=shortTest_integration.exe --run_test=AttackSuite --report_level=shortTest_integration.exe --report_level=shortctest -R "^Test_integration$" --output-on-failuregit diff --check upstream/master...HEAD