import axios from 'axios'; const baseURL = 'http://localhost:27531'; async function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function testServer() { try { await axios.post(`${baseURL}/shutdown`); return // Test 1: Health check console.log('\nTest 1: Health Check'); const health = await axios.get(`${baseURL}/health`); console.log('Health status:', health.data); // Wait for engine initialization await delay(2000); // Test 2: Validate FEN console.log('\nTest 1.5: Validate MOVE'); const moveVal = await axios.post(`${baseURL}/move`, { move: '@a6' }); console.log('MOVE validation:', moveVal); await delay(2000); // Test 2: Validate FEN console.log('\nTest 2: Validate FEN'); const startPos = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'; const validation = await axios.post(`${baseURL}/validate`, { fen: startPos }); console.log('FEN validation:', validation.data); // Test 3: Create new game console.log('\nTest 3: Create New Game'); const newGame = await axios.post(`${baseURL}/new`, { variant: 'chess' }); console.log('New game created:', newGame.data); // Test 4: Set position console.log('\nTest 4: Set Position'); const position = await axios.post(`${baseURL}/position`, { fen: startPos, variant: 'chess' }); console.log('Position set:', position.data); // Test 5: Get engine move from starting position console.log('\nTest 5: Get Engine Move'); const engineMove = await axios.post(`${baseURL}/enginemove`, { depth: 15, movetime: 1000 }); console.log('Engine move:', engineMove.data); // Test 6: Make a specific move console.log('\nTest 6: Make Move (UCI)'); const moveUCI = await axios.post(`${baseURL}/move`, { move: 'e2e4', notation: 'uci' }); console.log('UCI move made:', moveUCI.data); // Test 7: Make move using SAN notation console.log('\nTest 7: Make Move (SAN)'); const moveSAN = await axios.post(`${baseURL}/move`, { move: 'Nf6', notation: 'san' }); console.log('SAN move made:', moveSAN.data); // Test 8: Get current state console.log('\nTest 8: Get Current State'); const state = await axios.get(`${baseURL}/state`); console.log('Current state:', state.data); // Test 9: Position Analysis console.log('\nTest 9: Position Analysis'); const analysis = await axios.post(`${baseURL}/analyze`, { depth: 15, movetime: 1000 }); console.log('Position analysis:', analysis.data); // Test 10: Test variant chess console.log('\nTest 10: Test Chess Variant'); const variantGame = await axios.post(`${baseURL}/new`, { variant: 'crazyhouse' }); console.log('Crazyhouse game created:', variantGame.data); // Test 11: Test invalid FEN console.log('\nTest 11: Test Invalid FEN'); try { await axios.post(`${baseURL}/position`, { fen: 'invalid fen string', variant: 'chess' }); } catch (error) { console.log('Invalid FEN correctly rejected:', error.response.data); } // Test 12: Test invalid move console.log('\nTest 12: Test Invalid Move'); try { await axios.post(`${baseURL}/move`, { move: 'e2e5', // Invalid move notation: 'uci' }); } catch (error) { console.log('Invalid move correctly rejected:', error.response.data); } // Test 13: Engine Analysis with Different Settings console.log('\nTest 13: Engine Analysis with Custom Settings'); const customAnalysis = await axios.post(`${baseURL}/analyze`, { depth: 20, movetime: 2000 }); console.log('Custom analysis:', customAnalysis.data); // Test 14: Final State Check console.log('\nTest 14: State Check'); const finalHealth = await axios.get(`${baseURL}/health`); console.log('Final server status:', { engineReady: finalHealth.data.engineReady, status: finalHealth.data.status }); console.log('\nTest 15: SHUTDOWN'); await axios.post(`${baseURL}/shutdown`); console.log('\nAll tests completed successfully!'); } catch (error) { console.error('Test failed:', error.message); if (error.response) { console.error('Error details:', { status: error.response.status, data: error.response.data }); } } } // Run tests console.log('Starting Fairy-Chess server tests...'); testServer().then(() => { console.log('Test suite completed.'); }).catch(err => { console.error('Test suite failed:', err); });