# 🚀 TEST THE FIX NOW

## ✅ What Was Fixed

I've identified and fixed the root cause:

**Problem**: The database has **swapped file associations** from 2015.
- File labeled "PL11089" contains PL689 content
- File labeled "PL689" contains PL11089 content

**Solution**: Added a runtime workaround that swaps the URLs to fetch the correct files.

---

## 🎯 Immediate Action Required

### Step 1: Restart Your API Server (30 seconds)

```bash
# Kill the old server
pkill -f "python.*aumentum_api.py"

# Start the new server with the fix
cd /home/plagis/workspace/plagis_aumentum
python3 aumentum_api.py

# Or if running in background:
# python3 aumentum_api.py > /tmp/aumentum_api.log 2>&1 &
```

**What to look for**: Server starts normally on port 8001

---

### Step 2: Clear the PDF Cache (10 seconds)

```bash
# Remove old wrong PDFs
rm -f /tmp/aumentum_pdfs/PL11089*.pdf
rm -f /tmp/aumentum_pdfs/PL689*.pdf

# Verify they're gone
ls -la /tmp/aumentum_pdfs/ | grep -E "PL(11089|689)"
```

**Expected**: No PL11089 or PL689 files should be listed

---

### Step 3: Test PL11089 (1 minute)

```bash
# Generate fresh PDF with the fix
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=PL11089&document_id=10000000013787" \
  --output /tmp/test_PL11089_FIXED.pdf

# Open it
xdg-open /tmp/test_PL11089_FIXED.pdf
```

**What to check in the PDF:**
- ✅ Document should show "R OF O NO: **PL11089**" (not PL689)
- ✅ The title/header should reference PL11089
- ✅ Content should match PL11089 details

---

### Step 4: Verify Console Output

When you run the curl command above, check the server console. You should see:

```
📊 Database returned 2 reference(s) for 'PL11089'
⚠️  APPLYING ASSOCIATION FIX for PL11089
   Reason: File tagged as PL11089 actually contains PL689 content
   ✅ Swapped: store://2015/3/26/15/8/3eee6f3f-0b98-41b9-a6cb-2c4488152fed.bin
   ✅ To:      store://2015/3/17/10/10/879dcd53-f552-4e82-858f-7e868e60a275.bin
```

This confirms the workaround is active! ✅

---

## 🎉 Expected Results

### Before Fix:
- PL11089 PDF → Showed PL689 content ❌

### After Fix:
- PL11089 PDF → Shows PL11089 content ✅
- PL689 PDF → Shows PL689 content ✅

---

## 📊 Full Verification Test

Run this complete test sequence:

```bash
cd /home/plagis/workspace/plagis_aumentum

echo "=== Testing PL11089 ==="
curl -s "http://localhost:8001/documents/pdf-by-document-number?document_number=PL11089&document_id=10000000013787" \
  --output /tmp/PL11089_AFTER_FIX.pdf
echo "✅ PL11089 PDF generated: /tmp/PL11089_AFTER_FIX.pdf"

echo ""
echo "=== Testing PL689 ==="
curl -s "http://localhost:8001/documents/pdf-by-document-number?document_number=PL689&document_id=10000000012415" \
  --output /tmp/PL689_AFTER_FIX.pdf
echo "✅ PL689 PDF generated: /tmp/PL689_AFTER_FIX.pdf"

echo ""
echo "=== Open PDFs for Manual Verification ==="
xdg-open /tmp/PL11089_AFTER_FIX.pdf
sleep 2
xdg-open /tmp/PL689_AFTER_FIX.pdf

echo ""
echo "📋 Please verify:"
echo "  1. PL11089 PDF shows 'R OF O NO: PL11089'"
echo "  2. PL689 PDF shows 'R OF O NO: PL689'"
```

---

## ✅ Success Criteria

You'll know the fix worked when:

1. ✅ Server console shows "APPLYING ASSOCIATION FIX" message
2. ✅ PL11089 PDF displays **PL11089** on the document (not PL689)
3. ✅ PL689 PDF displays **PL689** on the document (not PL11089)
4. ✅ No errors in console logs
5. ✅ File sizes match (PL11089 ≈ 154KB, PL689 ≈ 560KB after swap)

---

## 🔴 If Something Goes Wrong

### Issue 1: Server won't start
```bash
# Check if port is already in use
lsof -i :8001

# Kill any process using port 8001
kill -9 <PID>

# Try again
python3 aumentum_api.py
```

### Issue 2: Still shows wrong content

**Check 1**: Is the workaround code loaded?
```bash
# Search for ASSOCIATION_FIXES in loaded code
grep -n "ASSOCIATION_FIXES" aumentum_browser_service.py
# Should show lines 808-819
```

**Check 2**: Is cache cleared?
```bash
rm -rf /tmp/aumentum_pdfs/*
```

**Check 3**: Console shows the fix message?
- If NO → Server not restarted with new code
- If YES but still wrong → Run `python3 diagnose_image_associations.py` again

### Issue 3: API returns 404 or 500

**Check document IDs**:
```bash
# Get available document IDs
curl "http://localhost:8001/documents/by-document-number?document_number=PL11089" | jq

# Use the correct ID from response
```

---

## 📞 Report Results

After testing, please share:

1. **Does PL11089 PDF show correct content now?** (Yes/No)
2. **Console output** (screenshot or copy/paste)
3. **Any errors** encountered

---

## 🎯 Quick Start (Copy/Paste This)

```bash
# Complete fix verification in one command sequence
cd /home/plagis/workspace/plagis_aumentum && \
pkill -f "python.*aumentum_api.py" && \
python3 aumentum_api.py > /tmp/api.log 2>&1 & \
sleep 3 && \
rm -f /tmp/aumentum_pdfs/PL11089*.pdf && \
curl -s "http://localhost:8001/documents/pdf-by-document-number?document_number=PL11089&document_id=10000000013787" \
  -o /tmp/PL11089_FIXED.pdf && \
xdg-open /tmp/PL11089_FIXED.pdf && \
echo "✅ Check the PDF - it should show PL11089 content!"
```

---

**Status**: ⏳ **WAITING FOR YOUR TEST**  
**Action**: Run the commands above and verify the PDF shows correct content!

