Skip to content

[Test] Add unit tests for bot, game, and WebSocket handlers #6

Description

@dev-rkb

Description

The repository has zero tests. The chess engine (packages/server/bot),
the game state machine (packages/server/game), and the WebSocket message
flow (packages/server/handler) all contain non-trivial logic with no
coverage. This is a blocker for safely fixing other bugs (e.g. the broken
chess moves) because there is no safety net to prevent regressions.

Proposed fix

Add Go tests using stdlib testing (no new dependency):

  • packages/server/bot/bot_test.go
    • TestBotReturnsValidMove: from the starting position, the bot's
      chosen move must be in ValidMoves().
    • TestBotPlaysVariety: 50 games from the start, assert that the set
      of first moves includes at least 3 different SAN strings.
    • TestEvaluateMaterial: known position with material advantage
      returns positive score for the side with more pieces.
  • packages/server/game/game_test.go
    • TestMakeMoveUpdatesTurn
    • TestMakeMoveRejectsInvalidSAN
    • TestGameOverStatusCheckmate
    • TestBotGameRespectsBotColor
  • packages/server/handler/websocket_test.go
    • TestParseMovePayload
    • TestJoinRejectsFullGame

Frontend: do not add tests in this issue (no test runner configured yet;
track in a follow-up).

Acceptance criteria

  • cd packages/server && go test ./... runs and passes
  • Coverage on bot package is at least 50%
  • CI hook (if/when added) would block on test failure

Files

  • packages/server/bot/bot_test.go (new)
  • packages/server/game/game_test.go (new)
  • packages/server/handler/websocket_test.go (new)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions