Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 7, 2025

This PR adds comprehensive support for puzzle endpoints with proper type safety and test coverage.

Changes Made

New puzzle method:

  • Added client.puzzles.get_next() method that calls the /api/puzzle/next endpoint to retrieve the next puzzle for the authenticated user

Enhanced type safety:

  • Created comprehensive TypedDict definitions in berserk/types/puzzles.py:
    • Puzzle - Complete puzzle data structure with FEN, moves, rating, themes, etc.
    • PuzzleGame - Nested game information (ID, PGN, clock)
    • Enhanced existing PuzzleRace type
  • Updated all puzzle client methods (get_daily(), get_next(), get()) to return properly typed Puzzle objects instead of Dict[str, Any]

Test coverage:

  • Added tests/clients/test_puzzles.py with tests for non-authenticated GET endpoints
  • Tests follow existing patterns with VCR recording and type validation
  • Covers get_daily() and get(id) endpoints (non-auth required)

Usage

import berserk

client = berserk.Client(session=your_authenticated_session)

# Get the next puzzle for the authenticated user (new method)
next_puzzle = client.puzzles.get_next()

# All puzzle methods now return properly typed Puzzle objects
daily_puzzle = client.puzzles.get_daily()
specific_puzzle = client.puzzles.get("ponnQ")

# Full type safety with IDE support
print(next_puzzle["rating"])  # Type-safe access to puzzle fields
print(next_puzzle["game"]["id"])  # Type-safe nested field access

The implementation provides complete type safety for puzzle data while maintaining backward compatibility. All puzzle-related methods now have proper return type annotations and comprehensive TypedDict definitions.

Fixes #114.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: kraktus <56031107+kraktus@users.noreply.github.com>
Copilot AI changed the title [WIP] Add /api/puzzle/next as puzzle.get_next Add client.puzzles.get_next method for /api/puzzle/next endpoint Aug 7, 2025
Copilot AI requested a review from kraktus August 7, 2025 22:03
Copilot finished work on behalf of kraktus August 7, 2025 22:03
@kraktus
Copy link
Member

kraktus commented Aug 7, 2025

@copilot do

  • Typed the returned JSON using TypedDicts in berserk/types/, example
  • Written tests for GET endpoints not requiring authentification. Documentation, example

Co-authored-by: kraktus <56031107+kraktus@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot do

  • Typed the returned JSON using TypedDicts in berserk/types/, example
  • Written tests for GET en...

Done! I've completed both requested tasks:

Added TypedDict definitions in berserk/types/puzzles.py - Created comprehensive types for Puzzle and PuzzleGame with proper field typing and optional fields using NotRequired

Created tests in tests/clients/test_puzzles.py - Added tests for non-authenticated GET endpoints (get_daily() and get(id)) following the existing patterns with @pytest.mark.vcr and validate() function

The puzzle client methods now return properly typed Puzzle objects instead of Dict[str, Any]. The tests will need network access to record the VCR cassettes when run with --record-mode=once.

Changes in commit eb77c1e.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)
  • lichess.org
    • Triggering command: `python3 -c
      import requests
      import json

Test a real call to get the daily puzzle to understand the structure

try:
response = requests.get('REDACTED')
if response.status_code == 200:
puzzle = response.json()
print('Daily puzzle structure:')
print(json.dumps(puzzle, indent=2))
else:
print('Failed to fetch daily puzzle:', response.status_code)
except Exception as e:
print('Error:', e)` (dns block)

  • Triggering command: python3 -m pytest tests/clients/test_teams.py::TestLichessGames::test_get_team -v (dns block)
  • Triggering command: python3 -m pytest tests/clients/test_teams.py::TestLichessGames::test_get_team -v -s (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add client.puzzles.get_next method for /api/puzzle/next endpoint Add client.puzzles.get_next method with proper TypedDict types and tests Aug 7, 2025
Copilot finished work on behalf of kraktus August 7, 2025 22:21
@kraktus kraktus closed this Aug 7, 2025
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.

Add /api/puzzle/next as puzzle.get_next

2 participants