// Have the test mitra "accept" the most recent pending pairing request via
// the dev-only /internal/_test/mitra-accept-latest endpoint (no JWT needed).
//
// Reads MITRA_ID from the env that the calling flow injects — typically
// `${output.MITRA_ID}` from a prior seed_history_session.js run.
const mitraId = MITRA_ID
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
if (!mitraId) {
  throw new Error('MITRA_ID env not set — pass output.MITRA_ID from seed_history_session.js')
}
const resp = http.post(`${url}/internal/_test/mitra-accept-latest`, {
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ mitra_id: mitraId }),
})
if (resp.status !== 200) {
  throw new Error(`mitra-accept-latest failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.ACCEPTED_SESSION_ID = data.session_id
