You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
Paul Caplan
committed
feat: add environment-controlled mock AI and comprehensive E2E tests
- Add USE_MOCK_AI environment variable to control mock vs real AI responses
- Remove streaming complexity, implement simple non-streaming chat
- Create comprehensive E2E test suite with 8 passing tests
- Configure Playwright for fast tests (1s timeout, Chromium only, no HTML report)
- Add env.test file for E2E testing configuration
- Clean up environment files and remove unused OPENAI_API_KEY
- Update package dependencies and switch to pnpm
- All tests passing in under 2 seconds
Copy file name to clipboardExpand all lines: app/api/chat/route.ts
+62-8Lines changed: 62 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,34 @@ export async function POST (req: Request): Promise<Response> {
4
4
try{
5
5
const{ messages }=awaitreq.json()
6
6
7
-
// Simple OpenRouter API call
7
+
// Check if we should use mock responses
8
+
if(env.USE_MOCK_AI){
9
+
console.log('Using mock AI response')
10
+
constmockResponse={
11
+
id: `chatcmpl-mock-${Date.now()}`,
12
+
object: 'chat.completion',
13
+
created: Date.now(),
14
+
model: env.OPENROUTER_MODEL,
15
+
choices: [{
16
+
index: 0,
17
+
message: {
18
+
role: 'assistant',
19
+
content: "Hello! I'm a mock AI response. The chat interface is working correctly! 🎉 To use real AI responses, set USE_MOCK_AI=false in your environment variables."
content: "Sorry, your OpenRouter API key has exceeded its limit. Please check your account at https://openrouter.ai/settings/keys and either add credits or get a new API key. You can also set USE_MOCK_AI=true in your environment variables to use mock responses for testing."
67
+
},
68
+
finish_reason: 'stop'
69
+
}]
70
+
}
71
+
72
+
returnnewResponse(JSON.stringify(errorResponse),{
73
+
headers: {
74
+
'Content-Type': 'application/json',
75
+
'Cache-Control': 'no-cache'
76
+
}
77
+
})
78
+
}
79
+
80
+
thrownewError(`OpenRouter API error: ${response.status}${response.statusText} - ${errorText}`)
0 commit comments