import { test, expect } from '@playwright/test'; test.describe('Grok API Diagnostic (Backend Only)', () => { test('backend should successfully call xAI Grok and return a response', async ({ request }) => { test.setTimeout(120000); // Grok can be slow const payload = { message: "Plan a short day trip from Milton Keynes to Telford in a Model Y. Include one Supercharger stop.", vehicle: { name: "Model Y Long Range", rangeKm: 514 }, itinerary: null, history: [] }; const response = await request.post('http://localhost:3000/api/chat', { data: payload, headers: { 'Content-Type': 'application/json' } }); expect(response.ok()).toBeTruthy(); const body = await response.json(); console.log('[Diagnostic] Grok reply length:', body.reply?.length); console.log('[Diagnostic] Has itinerary update:', !!body.itinerary); expect(body.reply).toBeDefined(); expect(body.reply.length).toBeGreaterThan(50); // It should NOT be the generic error message expect(body.reply).not.toContain('having trouble reaching Grok'); // If it produced an itinerary, validate basic shape if (body.itinerary) { expect(body.itinerary.days).toBeDefined(); expect(Array.isArray(body.itinerary.days)).toBe(true); expect(body.itinerary.days.length).toBeGreaterThan(0); console.log('[Diagnostic] Itinerary days:', body.itinerary.days.length); } console.log('✅ Backend successfully called real Grok!'); }); });