# Kade Meds API — HTTP Smoke Test Results

**From:** Atlas
**Date:** 2026-05-22
**Status:** ✅ All endpoints functional. One contract-shape patch applied — **needs one more PM2 reload before Riv's bot fires.**

---

## Test results

| # | Endpoint | Expected | Actual | Pass |
|---|---|---|---|---|
| 1 | GET /today | 200, 5 doses with ISO timestamps `-05:00` | 200, 5 doses, correct tz offsets | ✅ |
| 2 | POST /fire (new) | 201 + log_id + follow_up_at | 201, log_id=1, follow_up_at=`2026-05-22T08:30:00-05:00` | ✅ |
| 3 | POST /fire (same external_id) | 200 + deduped:true + same log_id | 200, log_id=1, deduped=true | ✅ |
| 4 | POST /ack | 201 + ack_minutes_late | 201, log_id=3, ack_minutes_late=209 | ✅ |
| 5 | POST /skip | 201 + log_id | 201, log_id=4 | ✅ |
| 6 | POST /missed | 201 + log_id | 201, log_id=5 | ✅ |
| 7 | GET /adherence?days=7 | 200 + summary with rates | 200, Adderall morning fired=1 acked=1 skip=1 miss=1 rate=1.0 | ✅ |
| 8 | 401 (bad bearer token) | 401 unauthorized | 401, `{"ok":false,"error":"unauthorized"}` | ✅ |

Notes:
- `ack_minutes_late=209` is correct — fire scheduled_for was 08:00 CDT, ack happened ~11:29 CDT (this was a smoke-test fake fire, not a real morning dose)
- log_id=2 missing from the sequence is expected — Postgres identity sequence advances on `ON CONFLICT DO UPDATE` even when no new row is inserted (the dedupe in test #3)

---

## Patch applied after smoke test

**Issue:** `pg-node` returns Postgres `bigint` columns as JS strings (e.g. `"1"`) to avoid precision loss for values above `2^53`. The contract examples show integers (`"log_id": 142`), so Riv's bot will expect numbers, not strings.

**Fix:** Coerced `Number(...)` on all bigint-derived response fields across the 6 routes:
- `today`: `med_id`, `follow_up_minutes`
- `fire`: `log_id`
- `ack`: `log_id`, `ack_minutes_late`
- `skip`: `log_id`
- `missed`: `log_id`

Safe because Kade meds ids will never exceed `2^53`.

After patch: `npx tsc --noEmit` → exit 0. `npm run build` → all 6 routes built, zero errors/warnings.

---

## Cleanup

```
DELETE 4
 remaining_rows
----------------
              0
```

`kade_meds_log` is empty — Riv's first real fire starts on a clean log.

---

## Remaining step

**One more PM2 reload** for the response-shape patch to land in the running process:

```powershell
pm2 reload atlas
```

(elevated PowerShell — same as before)

Once reloaded, Riv's bot is unblocked.
