Skip to content

Conversation

@S1M0N38
Copy link
Collaborator

@S1M0N38 S1M0N38 commented Jul 9, 2025

This pull request introduces significant updates to the repository, including new development workflows, code quality improvements, and the removal of outdated Lua files. The most impactful changes involve adding conventional commit guidelines, enhancing testing workflows, integrating new formatting tools, and simplifying the Lua mod implementation by removing unused files.

Development Workflow Enhancements:

  • .claude/commands/commit.md: Added detailed instructions for generating conventional commit messages, including commit types, scopes, and a step-by-step workflow.
  • .claude/commands/test.md: Added instructions for running tests based on the testing guidelines in CLAUDE.md.

Code Quality Improvements:

  • .claude/settings.json: Introduced post-tool-use hooks for formatting Lua and Python files using StyLua and Ruff.
  • .editorconfig: Added configuration for consistent code formatting across Lua and Python files, including indentation, line endings, and charset settings.
  • .github/workflows/code_quality.yml: Added a StyLua job to check Lua file formatting in the CI pipeline.

Lua Mod Simplification:

  • balatrobot.lua: Simplified the mod initialization by removing unused middleware and bot-related files, focusing solely on the Lua API.
  • Removed outdated Lua files (src/lua/bot.lua, src/lua/hook.lua, src/lua/list.lua) that were no longer relevant to the current implementation. [1] [2] [3]

Developer Tools Integration:

Documentation Updates:

  • CLAUDE.md: Added comprehensive documentation on development commands, testing workflows, architecture overview, and coding standards for Python and Lua.

The new Lua API expose a limited set of function compare to the original API. However each API function is now well tested (The full gameplay test will be added in future release).

Functions:

  • get_game_state - Gets the current game state
  • go_to_menu - Navigates to the main menu
  • start_run - Starts a new game run with specified parameters (deck, stake, seed, challenge)
  • skip_or_select_blind - Skips or selects the current blind
  • play_hand_or_discard - Plays selected cards or discards them
  • cash_out - Cashes out from the current round to enter the shop
  • shop - Selects an action for shop (currently supports "next_round")

S1M0N38 added 30 commits July 8, 2025 17:58
Make max_fps optional
These are script useful for debugging that have been generated oneshot
with LLM. They are not commit-quality.
This action is already implemented in play_hand_or_discard action
@S1M0N38 S1M0N38 self-assigned this Jul 10, 2025
@S1M0N38 S1M0N38 requested a review from Copilot July 10, 2025 22:20

This comment was marked as outdated.

S1M0N38 and others added 16 commits July 11, 2025 00:54
Add structured commit message generation command with:
- Conventional commit types and project-specific scopes
- Workflow steps for comprehensive change analysis
- User approval flow before committing
- Co-authoring support for Claude-assisted development

Co-Authored-By: Claude <noreply@anthropic.com>
Simplified workflow steps by removing user approval step and duplicate step numbering.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add notes to explicitly exclude emojis and Claude Code generation
text from commit messages to maintain clean conventional commit
format.
Add new test command documentation and update CLAUDE.md to use
improved process detection that checks for both Balatro.app
and balatro.sh instead of the deprecated run_lovely_macos pattern.
- Add complete type system in src/lua/types.lua with API, game state, and socket types
- Add function documentation with type annotations to api.lua
- Add function documentation with type annotations to utils.lua
- Move type definitions from balatrobot.lua to dedicated types file
- Improve code maintainability and IDE support for Lua development
- Add shop function to handle shop state actions
- Implement next_round action to transition from shop to blind select
- Add ShopActionArgs type definition with action field
- Include validation for shop state before action execution
- Add pending request handling for state transitions

Co-Authored-By: Claude <noreply@anthropic.com>
- Add TestShop class with setup/teardown for shop state testing
- Test successful next_round action transitions from shop to blind select
- Test invalid action error handling with proper error response validation
- Test invalid state error when shop called outside shop state
- Include 3 test methods covering success and error cases

Co-Authored-By: Claude <noreply@anthropic.com>
- Update test count from 35 to 38 tests
- Update execution time from ~80 to ~110 seconds
- Reflects addition of shop API test suite
Simplified assert_error_response call formatting in shop test for consistency.
Include tests/ in the ruff format command to ensure consistent formatting
across test files.
- Add detailed documentation for main API functions
- Remove placeholder TODO functions to reduce code bloat
- Replace string-based G.FUNCS calls with direct function calls
- Enhance type annotations and inline comments
- Clean up blind selection logic with better variable naming

Co-Authored-By: Claude <noreply@anthropic.com>
Simplify workflow by removing breaking change step and update
co-author section to use parameterized arguments system.
Relocate debugplus integration from main mod file to utils.lua
for better organization and add section headers for clarity.
Standardize logging tags to use "API" prefix for better
organization and consistency across the API module.
Update test to match API change from "function_name" to "name"
in error response context.
@S1M0N38 S1M0N38 marked this pull request as ready for review July 11, 2025 15:26
@S1M0N38 S1M0N38 requested a review from Copilot July 11, 2025 15:26
Copy link
Contributor

Copilot AI left a 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 pull request introduces a comprehensive rewrite of the Lua API implementation with significantly improved testing infrastructure and code quality standards. The most impactful change is the complete replacement of the complex middleware and hook system with a simplified, direct UDP-based API that provides better reliability and maintainability.

Key changes include:

  • Complete rewrite of the Lua API architecture removing middleware/hook dependencies
  • Addition of comprehensive test suites covering all API functions and connection handling
  • Implementation of development workflow improvements including conventional commits, code formatting, and CI enhancements

Reviewed Changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_connection.py New comprehensive UDP connection and protocol handling tests
tests/test_api_functions.py New test suite covering all API functions with game state validation
tests/conftest.py New shared test configuration and helper functions
src/lua/utils.lua Rewritten utility functions focusing on game state extraction
src/lua/types.lua New type definitions for improved code documentation
src/lua/api.lua Complete rewrite of API with direct UDP communication
balatrobot.lua Simplified mod initialization removing outdated dependencies



def assert_error_response(response, expected_error_text, expected_context_keys=None):
"""Helper function to assert error response format and content."""
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

Function is missing a docstring explaining its parameters and purpose. Should document what constitutes a valid error response format.

Suggested change
"""Helper function to assert error response format and content."""
"""
Helper function to assert the format and content of an error response.
Args:
response (dict): The response dictionary to validate. Must contain at least
the keys "error" and "state".
expected_error_text (str): The expected error message text to check within
the "error" field of the response.
expected_context_keys (list, optional): A list of keys expected to be present
in the "context" field of the response, if the "context" field exists.
Raises:
AssertionError: If the response does not match the expected format or content.
"""

Copilot uses AI. Check for mistakes.

function Utils.isTableInRange(table, min, max)
if table == nil then return true end
-- Load debug
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The debug integration appears to be optional but there's no comment explaining when/why this dependency might not be available or what debugplus-api provides.

Suggested change
-- Load debug
-- Load debug
-- Attempt to load the optional debugplus-api module. This module provides additional debugging utilities,
-- such as the ability to register custom debug commands and log structured data. It is not required for
-- the core functionality of the program and is primarily intended for development and debugging purposes.
-- If the module is unavailable or incompatible, the program will continue to function without it.

Copilot uses AI. Check for mistakes.
end
-- Constants
local UDP_BUFFER_SIZE = 65536
local SOCKET_TIMEOUT = 0
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

Magic number 3 for EVENT_QUEUE_THRESHOLD lacks explanation. Should document why this specific value is used for determining when game state transitions are complete.

Suggested change
local SOCKET_TIMEOUT = 0
local SOCKET_TIMEOUT = 0
-- The threshold for determining when game state transitions are complete.
-- This value represents the minimum number of events required in the queue
-- to trigger a state transition. The value of 3 was chosen based on empirical
-- testing and ensures smooth gameplay without unnecessary delays.

Copilot uses AI. Check for mistakes.
Comment on lines +269 to +274
for i, card_index in ipairs(args.cards) do
args.cards[i] = card_index + 1
end

-- Check that all cards are selectable
for _, card_index in ipairs(args.cards) do
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The conversion from 0-based to 1-based indexing is performed in-place, modifying the original args.cards array. This could cause confusion if the args are reused elsewhere. Consider creating a new array for the converted indices.

Copilot uses AI. Check for mistakes.
- Add detailed documentation for EVENT_QUEUE_THRESHOLD constant explaining the heuristic for game state stability
- Document DebugPlus integration with reference to GitHub repo and optional dependency behavior
- Enhance assert_error_response docstring with parameter descriptions and usage details

Co-Authored-By: Claude <noreply@anthropic.com>
@S1M0N38 S1M0N38 merged commit b06c259 into main Jul 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant