Skip to content

Commit 7b89d8a

Browse files
Fix failing CI checks
- Fixed backend dependencies in requirements.txt (removed cors package) - Fixed backend API issues in main.py (get_available_locations calls, perform_item_action function) - Fixed frontend test configuration and mocking for gameApi - Fixed frontend linting issues (unused imports, missing dependencies) - Updated App.test.tsx to test for correct content - Added useCallback optimizations in GameInterface.tsx - All tests now passing (backend: 6/6, frontend: 1/1) - All linting checks now passing
1 parent 1c4f79c commit 7b89d8a

File tree

8 files changed

+47
-35
lines changed

8 files changed

+47
-35
lines changed

packages/backend/api/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ async def get_game_state(session_id: str):
8181
world = session["world"]
8282

8383
current_location = get_current_location(world)
84-
available_locations = get_available_locations(world, current_location)
84+
available_locations = get_available_locations(world)
8585

8686
available_actions = [
8787
"look around",
8888
"check inventory",
8989
"check status",
90-
f"go to {loc.lower()}" for loc in available_locations
91-
]
90+
] + [f"go to {loc.lower()}" for loc in available_locations]
9291

9392
# Add location-specific items as actions
9493
location_items = world["locations"][current_location].get("items", [])
@@ -139,7 +138,7 @@ async def perform_action(action_request: ActionRequest):
139138
elif action.startswith("go to "):
140139
destination = action.replace("go to ", "").title()
141140
current_location = get_current_location(world)
142-
available_locations = get_available_locations(world, current_location)
141+
available_locations = get_available_locations(world)
143142

144143
if destination in available_locations:
145144
world["current_location"] = destination
@@ -208,4 +207,3 @@ async def list_saves():
208207
if __name__ == "__main__":
209208
import uvicorn
210209
uvicorn.run(app, host="0.0.0.0", port=8000)
211-

packages/backend/game/items.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def get_item_description(item):
3434
}
3535
return item_descriptions.get(item, "A mysterious item.")
3636

37+
def perform_item_action(player, world, item_name):
38+
"""Perform an action with an item (alias for use_item)"""
39+
return use_item(player, item_name, world)
40+
3741
def use_item(player, item, world):
3842
if item not in player["inventory"]:
3943
print(f"You don't have {item} in your inventory.")
@@ -155,7 +159,7 @@ def use_item(player, item, world):
155159
if world["current_location"] == "Mountain":
156160
print("The necklace begins to glow, revealing hidden runes on nearby rocks!")
157161
print("You discover a secret path leading to a hidden cave.")
158-
# update_world_state(world, "reveal_hidden_cave")
162+
# update_player_knowledge(player, "ancient_history")
159163
else:
160164
print("The necklace sparkles beautifully, but nothing else happens.")
161165
return True

packages/backend/requirements.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
fastapi==0.104.1
2-
uvicorn[standard]==0.24.0
3-
pydantic==2.5.0
4-
python-multipart==0.0.6
5-
cors==1.0.1
6-
pytest==7.4.3
7-
httpx==0.25.2
1+
fastapi>=0.104.1
2+
uvicorn[standard]>=0.24.0
3+
pydantic>=2.5.0
4+
python-multipart>=0.0.6
5+
pytest>=7.4.3
6+
httpx>=0.25.2
87

packages/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"start": "react-scripts start",
2626
"build": "react-scripts build",
2727
"test": "react-scripts test",
28-
"eject": "react-scripts eject"
28+
"eject": "react-scripts eject",
29+
"lint": "eslint src --ext .ts,.tsx --max-warnings 0"
2930
},
3031
"eslintConfig": {
3132
"extends": [

packages/frontend/package.json.tmp

Whitespace-only changes.

packages/frontend/src/App.test.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import App from './App';
44

5-
test('renders learn react link', () => {
5+
// Mock the gameApi module to avoid ES module issues
6+
jest.mock('./services/gameApi', () => ({
7+
gameApi: {
8+
createNewGame: jest.fn(),
9+
getGameState: jest.fn(),
10+
performAction: jest.fn(),
11+
saveGame: jest.fn(),
12+
listSaves: jest.fn(),
13+
},
14+
}));
15+
16+
test('renders start screen initially', () => {
617
render(<App />);
7-
const linkElement = screen.getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
18+
const titleElement = screen.getByText(/Kevin's Adventure Game/i);
19+
expect(titleElement).toBeInTheDocument();
920
});
21+

packages/frontend/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState } from 'react';
22
import styled from 'styled-components';
33
import GameInterface from './components/GameInterface';
44
import StartScreen from './components/StartScreen';
@@ -63,4 +63,3 @@ const App: React.FC = () => {
6363
};
6464

6565
export default App;
66-

packages/frontend/src/components/GameInterface.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useRef } from 'react';
1+
import React, { useState, useEffect, useRef, useCallback } from 'react';
22
import styled from 'styled-components';
33
import { GameSession, GameState } from '../types/game';
44
import { gameApi } from '../services/gameApi';
@@ -89,33 +89,33 @@ const GameInterface: React.FC<GameInterfaceProps> = ({ gameSession, onEndGame })
8989
const [isLoading, setIsLoading] = useState(false);
9090
const logRef = useRef<HTMLDivElement>(null);
9191

92-
useEffect(() => {
93-
loadGameState();
94-
}, [gameSession.sessionId]);
95-
9692
useEffect(() => {
9793
// Scroll to bottom of log when new messages are added
9894
if (logRef.current) {
9995
logRef.current.scrollTop = logRef.current.scrollHeight;
10096
}
10197
}, [gameLog]);
10298

103-
const loadGameState = async () => {
99+
const addToLog = useCallback((message: string) => {
100+
setGameLog(prev => [...prev, message]);
101+
}, []);
102+
103+
const loadGameState = useCallback(async () => {
104104
try {
105105
const state = await gameApi.getGameState(gameSession.sessionId);
106106
setGameState(state);
107-
addToLog(`Welcome to ${state.current_location}! ${state.message}`);
107+
addToLog(`Welcome to ${state.current_location}!`);
108108
} catch (error) {
109109
console.error('Error loading game state:', error);
110110
addToLog('Error loading game state. Please try again.');
111111
}
112-
};
112+
}, [gameSession.sessionId, addToLog]);
113113

114-
const addToLog = (message: string) => {
115-
setGameLog(prev => [...prev, message]);
116-
};
114+
useEffect(() => {
115+
loadGameState();
116+
}, [loadGameState]);
117117

118-
const performAction = async (action: string) => {
118+
const performAction = useCallback(async (action: string) => {
119119
if (!gameState || isLoading) return;
120120

121121
setIsLoading(true);
@@ -124,11 +124,11 @@ const GameInterface: React.FC<GameInterfaceProps> = ({ gameSession, onEndGame })
124124
try {
125125
const response = await gameApi.performAction({
126126
session_id: gameSession.sessionId,
127-
action: action,
127+
action: action
128128
});
129129

130130
addToLog(response.message);
131-
131+
132132
// Update game state
133133
const newState = await gameApi.getGameState(gameSession.sessionId);
134134
setGameState(newState);
@@ -138,7 +138,7 @@ const GameInterface: React.FC<GameInterfaceProps> = ({ gameSession, onEndGame })
138138
} finally {
139139
setIsLoading(false);
140140
}
141-
};
141+
}, [gameState, isLoading, addToLog, gameSession.sessionId]);
142142

143143
const handleSaveGame = async () => {
144144
try {
@@ -197,4 +197,3 @@ const GameInterface: React.FC<GameInterfaceProps> = ({ gameSession, onEndGame })
197197
};
198198

199199
export default GameInterface;
200-

0 commit comments

Comments
 (0)