# stream_chat.php — Test Summary (Prompts 1–4)

**Run date:** 2026-02-20

---

## PROMPT 1 — 30-second throttle

| Test | Result | Notes |
|------|--------|--------|
| **SYNTAX CHECK** | **PASS** | `php -l otto/chat/stream_chat.php` — No syntax errors detected. |
| **BURST TEST** | **SKIP** | Requires live endpoint (BASE_URL). Run 6 rapid POSTs with same `session_id`; expect first 5 → 200, 6th → 429. |
| **WINDOW RESET TEST** | **SKIP** | Requires live endpoint. Wait 31s, then 1 POST; expect 200. |

---

## PROMPT 2 — 80% daily spend Slack warning

| Test | Result | Notes |
|------|--------|--------|
| **SYNTAX CHECK** | **PASS** | Same as above. |
| **SLACK ALERT TRIGGERED** | **SKIP** | Manual: lower `daily_spend_cap` in otto_settings, trigger GPT request until spend ≥80% of cap, confirm Slack message. |

---

## PROMPT 3 — Daily cap hard stop (validation only)

| Test | Result | Notes |
|------|--------|--------|
| **DAILY CAP TEST** | **SKIP** | Manual: set small `daily_spend_cap`, trigger until exceed; expect HTTP 429, `{"status":"spend_limit_reached"}`, no streaming, JSON only. |

---

## PROMPT 4 — Global spend cap

| Test | Result | Notes |
|------|--------|--------|
| **SYNTAX CHECK** | **PASS** | Same as above. |
| **GLOBAL CAP TEST** | **SKIP** | Manual: set small `global_spend_cap` in otto_settings, trigger GPT; expect 429 and "Global spend cap reached." |

---

## How to run HTTP tests locally

1. **Start your stack** (e.g. Lando, local PHP + DB) so `stream_chat.php` is served (e.g. `https://projectlando.net/genie/stream_chat.php` or `http://localhost/.../stream_chat.php`).
2. **Burst test:**  
   `for i in {1..6}; do curl -s -o /dev/null -w "%{http_code}\n" -X POST -H "Content-Type: application/json" -d '{"session_id":"burst-test","messages":[{"role":"user","content":"Hi"}]}' YOUR_BASE_URL/stream_chat.php; done`  
   Expect: 200,200,200,200,200,429.
3. **Window reset:** Wait 31 seconds, then one more POST; expect 200.
4. **Slack / daily cap / global cap:** Adjust `otto_settings` and trigger requests as in the notes above.

---

## Return format (fill after manual runs)

```
PROMPT 1:
  SYNTAX CHECK: PASS
  BURST TEST: (run 6 POSTs) PASS/FAIL
  WINDOW RESET TEST: (wait 31s, 1 POST) PASS/FAIL

PROMPT 2:
  SYNTAX CHECK: PASS
  SLACK ALERT TRIGGERED: YES/NO

PROMPT 3:
  DAILY CAP TEST: PASS/FAIL

PROMPT 4:
  SYNTAX CHECK: PASS
  GLOBAL CAP TEST: PASS/FAIL
```
