-
Notifications
You must be signed in to change notification settings - Fork 4
test(lua.endpoints): improve gamestate obj tests #144
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
Conversation
|
We delay the other tests for future release. the stuff for the #145 are tested |
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.
Pull request overview
This PR significantly enhances testing for the gamestate object returned by Lua endpoints. The changes add comprehensive test coverage for gamestate structure validation, including top-level fields, rounds, blinds, areas, and card properties. Additionally, the PR includes important refactoring to the gamestate utility to prevent memory leaks by properly cleaning up UI nodes.
Changes:
- Added 800+ lines of comprehensive tests for gamestate object structure and fields
- Introduced new test fixtures to support various game states
- Refactored
get_card_ui_description()to avoid hover side effects and prevent memory leaks by cleaning up DynaText objects
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| tests/lua/endpoints/test_gamestate.py | Added extensive test classes covering gamestate top-level fields, rounds, blinds, areas (jokers, consumables, cards, hand, pack, shop, vouchers, packs), and card properties (id, key, set, label, value, modifier, state, cost) |
| tests/fixtures/fixtures.json | Added new fixtures for various game states (BLIND_SELECT, SELECTING_HAND, SHOP, SMODS_BOOSTER_OPENED) to support new tests |
| src/lua/utils/gamestate.lua | Added cleanup_ui_nodes() function to prevent memory leaks, refactored get_card_ui_description() to avoid hover side effects, and fixed spelling error |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fixture_name = "state-BLIND_SELECT--deck-BLUE--stake-RED" | ||
| load_fixture(client, "gamestate", fixture_name) | ||
| response = api(client, "set", {"money": 42}) | ||
| assert response["result"]["seed"] == "TEST123" |
Copilot
AI
Jan 22, 2026
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.
The test docstring says "Test money field after using set to modify it" but the assertion is checking the "seed" field instead of the "money" field. The assertion should be checking that the money was set to 42.
| assert response["result"]["seed"] == "TEST123" | |
| assert response["result"]["money"] == 42 |
| reponse = api(client, "buy", {"card": 0}) | ||
| assert reponse["result"]["shop"]["count"] == 1 |
Copilot
AI
Jan 22, 2026
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.
Misspelled variable name "reponse" should be "response".
| reponse = api(client, "buy", {"voucher": 0}) | ||
| assert reponse["result"]["vouchers"]["count"] == 0 |
Copilot
AI
Jan 22, 2026
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.
Misspelled variable name "reponse" should be "response".
| assert response["result"]["round_num"] == 5 | ||
|
|
||
| def test_won_false_extraction(self, client: httpx.Client) -> None: | ||
| """Test won field after defeating ante 8 boss.""" |
Copilot
AI
Jan 22, 2026
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.
The docstring says "Test won field after defeating ante 8 boss" but the test is checking that the won field is False at the start of the run in BLIND_SELECT state, not after defeating a boss. The docstring should describe what the test actually does, such as "Test won field is false at start of run" or "Test won field before winning the game".
| """Test won field after defeating ante 8 boss.""" | |
| """Test won field is False at start of run in BLIND_SELECT state.""" |
| def test_round_num_extractions(self, client: httpx.Client) -> None: | ||
| """Test round_num field after using `set` to modify it.""" | ||
| fixture_name = "state-BLIND_SELECT--deck-BLUE--stake-RED" | ||
| load_fixture(client, "gamestate", fixture_name) | ||
| response = api(client, "set", {"round": 5}) | ||
| assert response["result"]["round_num"] == 5 |
Copilot
AI
Jan 22, 2026
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.
Inconsistent naming: method name uses "extractions" (plural) but should use "extraction" (singular) to match other test method names like test_deck_extraction, test_stake_extraction, etc.
| reponse = api(client, "buy", {"pack": 0}) | ||
| assert reponse["result"]["packs"]["count"] == 1 |
Copilot
AI
Jan 22, 2026
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.
Misspelled variable name "reponse" should be "response".
| def test_ante_num_extractions(self, client: httpx.Client) -> None: | ||
| """Test ante_num field after using `set` to modify it.""" | ||
| fixture_name = "state-BLIND_SELECT--deck-BLUE--stake-RED" | ||
| load_fixture(client, "gamestate", fixture_name) | ||
| response = api(client, "set", {"ante": 5}) | ||
| assert response["result"]["ante_num"] == 5 | ||
|
|
||
| def test_round_num_extractions(self, client: httpx.Client) -> None: |
Copilot
AI
Jan 22, 2026
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.
Inconsistent naming: method name uses "extractions" (plural) but should use "extraction" (singular) to match other test method names like test_deck_extraction, test_stake_extraction, etc.
| def test_ante_num_extractions(self, client: httpx.Client) -> None: | |
| """Test ante_num field after using `set` to modify it.""" | |
| fixture_name = "state-BLIND_SELECT--deck-BLUE--stake-RED" | |
| load_fixture(client, "gamestate", fixture_name) | |
| response = api(client, "set", {"ante": 5}) | |
| assert response["result"]["ante_num"] == 5 | |
| def test_round_num_extractions(self, client: httpx.Client) -> None: | |
| def test_ante_num_extraction(self, client: httpx.Client) -> None: | |
| """Test ante_num field after using `set` to modify it.""" | |
| fixture_name = "state-BLIND_SELECT--deck-BLUE--stake-RED" | |
| load_fixture(client, "gamestate", fixture_name) | |
| response = api(client, "set", {"ante": 5}) | |
| assert response["result"]["ante_num"] == 5 | |
| def test_round_num_extraction(self, client: httpx.Client) -> None: |
| assert gamestate["blinds"]["big"]["status"] == "SKIPPED" | ||
| assert gamestate["blinds"]["boss"]["status"] == "SELECT" | ||
|
|
||
| def test_blinds_progession_extraction(self, client: httpx.Client) -> None: |
Copilot
AI
Jan 22, 2026
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.
Misspelled word "progession" should be "progression".
| def test_blinds_progession_extraction(self, client: httpx.Client) -> None: | |
| def test_blinds_progression_extraction(self, client: httpx.Client) -> None: |
I'd like to have a better testing for the gamestate object generate by all endpoints.
Maybe some tests are redundant but I'd like to have a set of tests that I can use if I need to change something in the src/lua/utils/gamestate.lua. These new tests are specific to test the gamestate dict generated.