# E2E Testing Status - Automated Slide Demo System

**Date**: 2025-10-12
**Issue**: #126 - End-to-End Testing
**Status**: In Progress - Deployment Pending

---

## System Architecture

### Overview
The system enables Tavus AI avatars to generate and present custom slide decks during live conversations:

```
User Browser
    ↓
Tavus Avatar (in Daily.co room)
    ↓ Calls: generate_custom_deck()
    ↓ Via: WebSocket app-message
    ↓
Tool Forwarder Bot (Python, headless in same room)
    ↓ Intercepts tool call
    ↓ Forwards to Railway API
    ↓
Railway API (slide-system on Railway)
    ├─ Creates Supabase session
    ├─ Generates slide HTML
    └─ Publishes to GitHub Pages
    ↓
Screenshare Bot (Pipecat, spawned by Railway)
    └─ Joins room and displays slides via Daily.co screenshare
```

---

## Environments & Credentials

### Production Environment
- **Railway API**: `https://slide-system-production-5813.up.railway.app`
- **Supabase**: `https://dwdytxxqcvlrmyemonxz.supabase.co`
- **Tavus API**: Production account (`prod1_TAVUS_API_KEY`)
- **Daily.co**: `buzztrail.daily.co` domain
- **GitHub Pages**: `https://buzztrail.github.io/buzztrail-presentations/`

### Testing Environment
- **Tavus API**: Testing account (`testing_larsbell_TAVUS_API_KEY`)
- **Tavus Persona**: `pebf4f03342e` (Slide Show Wizard Test Clone)
  - FAST MODE enabled (generates deck within 30 seconds)
  - Max call duration: 3 minutes
  - Ends 5 seconds after user leaves

### Local Development
- **Motia Dev Server**: `http://localhost:3005` (not used for E2E - can't be reached by Tavus)
- **Tool Forwarder Bot**: Runs locally, connects to Railway API

---

## Key Credentials

### Tavus
- **Production**: `d6e7b4726aa342b69ef4cf129cfd2016`
- **Testing**: `18660aa29360404a9400810530f99d3a`
- **Test Persona**: `pebf4f03342e`

### Daily.co
- **API Key**: `d5d545965205921e0b71a5d5160b01ce8be558e6e2dfeb2961756ac31eac5528`
- **Domain**: `buzztrail.daily.co`

### Supabase
- **URL**: `https://dwdytxxqcvlrmyemonxz.supabase.co`
- **Service Key**: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImR3ZHl0eHhxY3Zscm15ZW1vbnh6Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1OTg2NDU1MywiZXhwIjoyMDc1NDQwNTUzfQ.5Uf2zXKAqcxE3XQ4gxB8lbph7z4JZEXxtgINTPJnTMk`

### GitHub
- **Token**: `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`
- **Repo**: `BuzzTrail/buzztrail-presentations`
- **Pages URL**: `https://buzztrail.github.io/buzztrail-presentations/{deckId}/`

---

## What Works ✅

### 1. Tavus Persona Configuration
- ✅ Persona `pebf4f03342e` configured with FAST MODE
- ✅ Tool definitions for `generate_custom_deck()` and `control_slide()`
- ✅ Webhooks pointing to Railway API (though not used - tool calls via room messages)
- ✅ Timeouts configured (3 min max, 5 sec after leave)

### 2. Tool Forwarder Bot (Python)
**Location**: `apps/slide-system/bots/tavus-tool-forwarder/`

✅ **Fixed Issues**:
- Daily SDK API corrected (was using wrong `join()` signature)
- Changed endpoint from `/api/slidev/generate` to `/api/tavus/generate-deck`
- Fixed payload format to match Tavus webhook structure
- Fixed response parser to handle `{success, deck_url, session_id}` format

✅ **Current Status**:
- Bot successfully joins Daily.co rooms
- Listens for `app-message` events
- Intercepts `generate_custom_deck` tool calls
- Forwards to Railway API with correct format
- Parses responses correctly

### 3. Railway API Endpoints
**Deployment**: `https://slide-system-production-5813.up.railway.app`

✅ **Working Endpoints**:
- `POST /api/tavus/generate-deck` - Receives tool calls from bot
- `POST /api/slidev/generate` - Generates slide HTML and publishes to GitHub
- `POST /api/bots/screenshare/spawn` - Spawns screenshare bot (endpoint exists)

✅ **Recent Fixes**:
- GitHub Pages publishing implemented (was TODO)
- Creates `index.html` in `buzztrail-presentations/{deckId}/` via GitHub API
- Base64 encodes HTML content
- Uses `GITHUB_TOKEN` from Railway environment

---

## What's Not Working Yet ⚠️

### 1. Screenshare Bot Spawning
**Status**: Endpoint exists but bot doesn't appear in room

**Symptoms**:
- Deck generation succeeds
- GitHub Pages publishes successfully
- Bot spawn API called by tool forwarder
- But no screenshare bot joins the Daily.co room
- Slides don't appear to user

**Possible Issues**:
- Bot spawn implementation may be incomplete
- Bot may fail silently during startup
- Daily.co room joining may fail
- Pipecat transport initialization issues

**Location**: `apps/slide-system/bots/screenshare-bot/`

### 2. Slide Control Commands
**Status**: Parser rejects commands

**Symptoms**:
```
WARNING [tool_call_parser:61] Invalid command: . Valid: {'prev', 'goto', 'next', 'reload'}
ERROR [__main__:392] Failed to parse control_slide arguments
```

**Issue**: Tavus sends `control_slide` with empty/invalid command field

---

## Testing Flow

### Current Test Setup

1. **Create Tavus Conversation**:
```bash
curl -X POST https://tavusapi.com/v2/conversations \
  -H "x-api-key: 18660aa29360404a9400810530f99d3a" \
  -H "Content-Type: application/json" \
  -d '{
    "persona_id": "pebf4f03342e",
    "conversation_name": "E2E Test",
    "properties": {
      "max_call_duration": 180,
      "participant_left_timeout": 5,
      "participant_absent_timeout": 60
    }
  }'
```

2. **Start Tool Forwarder Bot** (locally):
```bash
cd apps/slide-system/bots/tavus-tool-forwarder
.venv/bin/python bot.py <room_url> <bot_id> <session_id>
```

3. **Join Conversation**:
- Open `https://tavus.daily.co/{conversation_id}` in browser
- Avatar greets you
- Say "show me a demo about X"

4. **Expected Behavior**:
- Avatar calls `generate_custom_deck()`
- Tool forwarder intercepts
- Railway API generates deck
- Deck published to GitHub Pages
- Screenshare bot spawns
- **Slides appear in room** ← NOT HAPPENING YET

### Latest Test Results

**Last Conversation**: `c99e9e44448ec4dd`
**Bot Logs**:
```
✅ Bot joined room
✅ Received tool call: generate_custom_deck
✅ Parsed arguments correctly
✅ Called Railway API
❌ Response parser failed (NOW FIXED)
```

**Railway Logs**:
```
✅ Received webhook call
✅ Session created in Supabase
✅ Deck generated: a9vg-xqv8-de2m
✅ Published to GitHub (AFTER FIX)
⚠️  Screenshare bot spawn status unknown
```

**What User Sees**:
- ✅ Avatar appears and talks
- ✅ Avatar calls function
- ❌ No slides appear
- ❌ No screenshare bot in participants list

---

## Recent Code Changes

### Commits Made (2025-10-12)

1. **Fix tool forwarder bot: Daily SDK API + correct Railway endpoint** (`9a77d3c`)
   - Fixed `join()` API signature
   - Changed endpoint to `/api/tavus/generate-deck`
   - Added proper Tavus webhook payload format

2. **Fix: Make deck_id optional in response parser** (`3dc484e`)
   - Handle API response format `{success, deck_url, session_id}`
   - Use session_id as fallback for deck_id

3. **Implement GitHub Pages publishing for slide decks** (`def0ba1`)
   - Added GitHub API integration
   - Publishes HTML to `buzztrail-presentations` repo
   - Fixes 404 errors on deck URLs

**Deployment Status**:
- ✅ Code pushed to `main`
- ⏳ Railway rebuild in progress (~2-5 minutes)

---

## Files Modified

### Bot Files
- `apps/slide-system/bots/tavus-tool-forwarder/bot.py`
  - Lines 508-528: Fixed Daily SDK join() API

- `apps/slide-system/bots/tavus-tool-forwarder/railway_client.py`
  - Lines 128-145: Changed endpoint + payload format
  - Lines 157-175: Fixed response parser

### API Files
- `apps/slide-system/steps/slidev-generate.step.ts`
  - Lines 328-363: Added GitHub Pages publishing

### Documentation
- `apps/slide-system/docs/TROUBLESHOOTING.md` (created)
- `apps/slide-system/docs/PRODUCTION_DEPLOYMENT_RUNBOOK.md` (updated)
- `apps/slide-system/docs/INTERNAL_TESTING_REPORT.md` (template created)

---

## Next Steps

### Immediate (After Railway Deployment)

1. **Verify GitHub Publishing Works**:
   - Create new test conversation
   - Trigger deck generation
   - Check if URL works: `https://buzztrail.github.io/buzztrail-presentations/{deckId}/`

2. **Debug Screenshare Bot Spawning**:
   - Check Railway logs for bot spawn attempts
   - Verify bot process starts
   - Check Daily.co room for bot participant
   - Review Pipecat transport initialization

3. **Test Complete E2E Flow**:
   - User joins → Avatar talks → Deck generates → **Slides appear**

### Medium Term

1. **Fix Control Slide Parser**:
   - Debug why Tavus sends empty command field
   - Add better error handling
   - Test slide navigation during presentation

2. **Improve Bot Reliability**:
   - Add retry logic for bot spawning
   - Better error messages
   - Health check endpoints

3. **Complete Testing Matrix**:
   - Run 5+ happy path tests
   - Test error scenarios
   - Measure timings and costs
   - Document in `INTERNAL_TESTING_REPORT.md`

### Long Term

1. **Production Readiness**:
   - Switch to production Tavus account
   - Configure monitoring/alerting
   - Set up automated bot restarts
   - Add rate limiting

2. **Feature Enhancements**:
   - Better slide templates
   - Real Slidev builds (not just HTML)
   - Custom branding
   - Analytics dashboard

---

## Known Issues

### High Priority
1. **Screenshare bot doesn't appear** - Blocking E2E testing
2. **Control slide commands fail** - Limits interactivity

### Medium Priority
3. Vite frontend build errors (doesn't affect backend)
4. Supabase state tracking disabled in local bot (non-critical)

### Low Priority
5. GitHub Pages may have ~1 minute deploy lag
6. No automated cleanup of old decks

---

## Success Criteria (From Issue #126)

- [ ] 5+ successful test runs completed
- [ ] Average deck generation < 30 seconds
- [ ] Bot spawn < 5 seconds
- [ ] Success rate > 90%
- [ ] Cost per test ~$1.50
- [ ] Full documentation complete
- [ ] Troubleshooting guide with real issues

**Current Progress**: ~60% complete

---

## Quick Reference Commands

### Start Local Tool Forwarder Bot
```bash
cd apps/slide-system/bots/tavus-tool-forwarder
.venv/bin/python bot.py <room_url> <bot_id> <session_id>
```

### Create Test Conversation
```bash
curl -X POST https://tavusapi.com/v2/conversations \
  -H "x-api-key: 18660aa29360404a9400810530f99d3a" \
  -H "Content-Type: application/json" \
  -d @/tmp/tavus-conversation.json
```

### Check Railway Deployment
```bash
railway status
railway logs --service slide-system
```

### Monitor Bot Logs
```bash
# Watch tool forwarder bot output
tail -f bot.log

# Check Railway API logs
railway logs --service slide-system -f
```

### Test GitHub Pages URL
```bash
# After deck generation
curl -I https://buzztrail.github.io/buzztrail-presentations/{deckId}/
```

---

## Contact & Resources

- **Tavus Docs**: https://docs.tavus.io
- **Daily.co Docs**: https://docs.daily.co
- **Pipecat Docs**: https://docs.pipecat.ai
- **GitHub Issues**: Track progress in #126

**Last Updated**: 2025-10-12 22:40 UTC
