Files
tiennm99 f4acc12668 refactor(wsapi): split wsapi_test.go by topic, delete hub_test.go
wsapi_test.go was 2688 lines and 82 tests spanning every topic in the
package. Pure moves: wsapi_test.go keeps the harness (the hand-built
dictionary, the server-over-a-real-socket helpers, and the client-side
driving methods every topic file below uses); game_test.go,
presence_test.go, resume_test.go, lobby_test.go, protocol_test.go,
ratelimit_test.go, bot_board_test.go, chat_test.go, deadend_test.go
and report_test.go each hold one topic's tests. Three tests about
sanitizing and distinguishing nicknames moved into the existing
nickname_test.go alongside its fuzz target.

hub_test.go was three lines of comment pointing at hub.go; the note
now lives there instead, next to roomCount.

Verified by counting: the wsapi package's declaration count is
unchanged, `go test -list` finds the same tests it did before the
split, and go build/vet/test -race and golangci-lint stay clean.
2026-09-21 16:32:57 +07:00

32 lines
914 B
Go

package wsapi
import (
"slices"
"testing"
"time"
"github.com/tiennm99dev/noitu/server/internal/game"
)
// The bot's frozen view of a position.
func TestFreezeBoardIncludesTheOpeningWord(t *testing.T) {
// The engine counts the opening word as played but Snapshot's history does
// not list it. A frozen board that missed it would let the bot choose a
// word the engine then rejects as already used — the two would disagree
// about the position while appearing to share one dictionary.
dict := chainDict()
e, err := game.New(dict, []game.PlayerID{"p1", "p2"}, "a b", time.Second, time.Now())
if err != nil {
t.Fatalf("engine: %v", err)
}
board := freezeBoard(e)
if !board.Used("a b") {
t.Error("frozen board does not consider the opening word played")
}
if !slices.Contains(board.LegalMoves(), "b c") {
t.Errorf("legal moves = %v, want the one continuation", board.LegalMoves())
}
}