The mjai-manue-go project employs a multi-layered testing strategy to ensure the correctness of the Go port, maintain behavioral parity with the original CoffeeScript implementation, and verify the integrity of the Mahjong game logic. The suite ranges from low-level domain unit tests to complex integration frameworks involving Dockerized environments.
The testing architecture is divided into three primary categories:
The codebase includes comprehensive unit tests for the internal/domain layer, covering tile primitives, hand analysis, and the round state machine. A significant portion of the integration testing is handled via Golden-File Tests within the MJAI runtime.
The internal/application package contains high-level tests for the Bot entity, ensuring that it correctly dispatches events to the domain and generates appropriate reactions (e.g., ReactionAction or ReactionNone) internal/application/bot_test.go17-103 Additionally, the round.State includes a BoardRenderer used in tests to visualize the board state in a human-readable format, facilitating easier debugging of complex game scenarios internal/domain/game/round/board_renderer_test.go12-47
Key Components:
Bot.Process is tested for various scenarios including self-draws, other-player draws, and Riichi acceptance internal/application/bot_test.go29-152RenderBoard function provides a text-based representation of the table, including hands, rivers (ho), and melds internal/domain/game/round/board_renderer.go19-49mustNewBotForTest and newValidHands provide standardized setups for application-level tests internal/application/test_utils_test.go15-61For details, see Unit and Integration Tests.
To guarantee that the Go port behaves identically to the original mjai-manue, a specialized comparison framework resides in test/original_vs_port/. This framework identifies "divergence points" where the two implementations choose different actions given the same game state.
Sources: test/original_vs_port/compare/main.go40-58 test/original_vs_port/gen_log/compose.yaml15-45
Key Components:
gen_log: A Docker Compose setup running the original CoffeeScript manue against akochan opponents to generate baseline logs test/original_vs_port/gen_log/compose.yaml27-45compare utility: A Go program that parses logs using inbound.ParseMessage test/original_vs_port/compare/comparer.go90-93 feeds them into ManueAgent.Decide, and compares the result with the original action recorded in the log test/original_vs_port/compare/comparer.go182-198normalizeRawAction function ensures that differences in JSON formatting or non-essential fields do not trigger false mismatches test/original_vs_port/compare/comparer.go96-101For details, see Original-vs-Port Comparison Framework.
The scripts/self-match/ directory (and related Docker configurations) contains tools for running the Go agent against itself. This is primarily used for generating large volumes of data for the tools/ suite to process into game statistics (game_stats.json).
Key Components:
compose.yaml defines services for the MJAI server, Go Manue instances, and Akochan instances for diverse testing environments test/original_vs_port/gen_log/compose.yaml15-45NUM_GAMES, ROOM, and PORT are used to control the simulation parameters test/original_vs_port/gen_log/compose.yaml5-13For details, see Self-Match Log Generation.
The following diagram maps the testing infrastructure to the specific code entities responsible for execution.
Sources: internal/application/bot_test.go17-27 test/original_vs_port/compare/comparer.go69-81 test/original_vs_port/gen_log/compose.yaml1-14