import http from 'k6/http'; import { check, sleep } from 'k6'; const profile = __ENV.K6_PROFILE || 'smoke'; const baseURL = (__ENV.K6_BASE_URL || '').replace(/\/$/, ''); const authToken = __ENV.K6_AUTH_TOKEN || 'dev-token'; export const options = profile === 'load' ? { vus: Number(__ENV.K6_VUS || 20), duration: __ENV.K6_DURATION || '2m', thresholds: { http_req_failed: ['rate<0.05'], http_req_duration: ['p(95)<500'], }, } : { vus: Number(__ENV.K6_VUS || 2), duration: __ENV.K6_DURATION || '20s', thresholds: { http_req_failed: ['rate<0.2'], http_req_duration: ['p(95)<800'], }, }; function assertBaseURL() { if (!baseURL) { throw new Error('K6_BASE_URL is required'); } } export default function gatewayCriticalPaths() { assertBaseURL(); const headers = { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${authToken}`, }, }; const top10 = http.get(`${baseURL}/api/v1/leaderboard/top10`); check(top10, { 'leaderboard top10 responds without 5xx': (r) => r.status < 500, }); const player = http.get(`${baseURL}/api/v1/leaderboard/players/player-1`, headers); check(player, { 'player lookup responds without 5xx': (r) => r.status < 500, }); const randomQuestion = http.post( `${baseURL}/api/v1/questions/random`, JSON.stringify({}), headers, ); check(randomQuestion, { 'random question responds without 5xx': (r) => r.status < 500, }); const startSession = http.post( `${baseURL}/api/v1/sessions/start`, JSON.stringify({ user_id: 'player-1' }), headers, ); check(startSession, { 'session start responds without 5xx': (r) => r.status < 500, }); sleep(Number(__ENV.K6_SLEEP_SECONDS || 0.5)); }