Repository navigation
Conversation
…sh socket contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #9:
Build a tested Socket.IO client for communicating with the Stockfish chess engine server.
New required env var: add
EXPO_PUBLIC_STOCKFISH_SOCKET_URL=http://10.0.2.2:8080to your.env.local, or the app won't start.New files:
src/features/play/services/StockfishClient.ts- StockfishClient implementation, interfaces, and response validation.test/StockfishClient.test.ts- Tests for StockfishClient.test/mocks/FakeSocket.ts- Fake socket used by the tests in place of a real server connection.docs/stockfish-socket-contract.md- Documentation of the Stockfish server's socket events, payloads, and unresolved details.Modified files:
src/config/env.ts- Validates the newEXPO_PUBLIC_STOCKFISH_SOCKET_URL..env.example,test/setup.ts,test/env.test.ts- Added the new env var and its tests.Developers can create a StockfishClient via
createStockfishClient(), optionally passing in aurl(defaults to the env var), acreateSocketfactory, andtimeoutMs.Using this client, they can call
startSession(),requestMove()with a FEN, player move, and difficulty level 1–5, anddisconnect(). The client connects lazily, validates server replies with zod, and rejects on timeouts, connection failures, and server errors without leaving listeners behind. Screens never access the socket directly.Notes:
requestMove()returns only the engine'smove. The server'snewFENis wrong whenever a player move is sent (details in the contract doc).startSession()again.Tests
Run the new tests with:

npm run test -- ./test/StockfishClient.test.ts --verbose.This should be the result:
Tests: 33 passed, 33 total