# 📋 MANUAL TEST PROCEDURE: Complete File Mapping Fix

## ✅ **Fix Status**

The code is ready with complete URL mapping for all 4 fixable documents:

- **PL689** → Will use PL11089's file (contains PL689 content) ✅
- **BP102** → Will use PL689's file (contains BP102 content) ✅
- **PL6204** → Will use BP102's file (contains PL6204 content) ✅
- **PL12321** → Will use PL6204's file (contains PL12321 content) ✅
- **PL11089** → No fix (real file not found) ❌

---

## 🚀 **STEP-BY-STEP DEPLOYMENT**

### **Step 1: Start Server Manually** (Terminal 1)

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

# Activate virtual environment
source venv/bin/activate

# Start server in foreground to see logs
python3 aumentum_api.py
```

**Leave this terminal open** - you'll see live logs here

---

### **Step 2: Test in New Terminal** (Terminal 2)

Open a **new terminal** and run:

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

# Clear cache
rm -rf /tmp/aumentum_pdfs/*

# Test PL689 (should now show PL689 content)
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=PL689&document_id=10000000012415" \
  --output /tmp/TEST_PL689.pdf

# Check file type
file /tmp/TEST_PL689.pdf

# If it's a PDF, open it
if file /tmp/TEST_PL689.pdf | grep -q "PDF"; then
    xdg-open /tmp/TEST_PL689.pdf
    echo "✅ PDF generated successfully"
else
    echo "❌ Not a PDF file"
    cat /tmp/TEST_PL689.pdf
fi
```

---

### **Step 3: Check Server Logs** (Terminal 1)

In the server terminal, you should see:

```
🔄 APPLYING FILE URL FIX for PL689
   Reason: File currently labeled as PL11089 actually contains PL689 content
   Using correct file: store://2015/3/26/15/8/3eee6f3f-0b98-41b9-a6cb-2c4488152fed.bin
   ✅ Replaced with correct file URL
```

**If you DON'T see this**, the mapping isn't being applied.

---

### **Step 4: Test All Documents**

If PL689 works, test the others:

```bash
# Test BP102
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=BP102&document_id=10000000014368" \
  -o /tmp/TEST_BP102.pdf && xdg-open /tmp/TEST_BP102.pdf

# Test PL6204
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=PL6204&document_id=10000000018017" \
  -o /tmp/TEST_PL6204.pdf && xdg-open /tmp/TEST_PL6204.pdf

# Test PL12321
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=PL12321&document_id=10000000020989" \
  -o /tmp/TEST_PL12321.pdf && xdg-open /tmp/TEST_PL12321.pdf
```

---

## 🔍 **Troubleshooting**

### **If Server Won't Start:**

Check if another process is using port 8001:
```bash
lsof -i :8001
kill -9 <PID>
```

### **If Still Getting "No content found":**

Check if the mapping is defined:
```bash
grep -A20 "CORRECT_FILE_MAPPING" /home/plagis/workspace/plagis_aumentum/aumentum_browser_service.py
```

Should show all 4 mappings (PL689, BP102, PL6204, PL12321).

### **If PDF is text/plain:**

The server isn't applying the mapping. Check:
1. Is CORRECT_FILE_MAPPING defined in the class (should be around line 821)?
2. Is the mapping application code present (around line 913-931)?
3. Are there any Python syntax errors?

```bash
python3 -m py_compile aumentum_browser_service.py
```

---

## 📊 **Expected Behavior**

### **When You Query PL689:**

**Server Console Should Show:**
```
✅ Found 13 document(s) for 'PL689'
📊 Database returned 0 reference(s) for 'PL689'
🔄 APPLYING FILE URL FIX for PL689
   Reason: File currently labeled as PL11089 actually contains PL689 content
   Using correct file: store://2015/3/26/15/8/3eee6f3f-0b98-41b9-a6cb-2c4488152fed.bin
   ✅ Replaced with correct file URL
✅ Total: 1 document ID(s) processed
```

**PDF Generated:**
- File type: PDF document ✅
- Content: Shows PL689 document number ✅
- Size: ~130-300 KB ✅

---

## 🎯 **Quick Verification**

Once server is running, run this one command:

```bash
curl "http://localhost:8001/documents/pdf-by-document-number?document_number=PL689&document_id=10000000012415" \
  -o /tmp/QUICK_TEST_PL689.pdf && \
file /tmp/QUICK_TEST_PL689.pdf && \
xdg-open /tmp/QUICK_TEST_PL689.pdf
```

**Expected output:**
```
/tmp/QUICK_TEST_PL689.pdf: PDF document, version 1.4
```

**Then PDF opens showing PL689 content** ✅

---

## ⚡ **If All Else Fails**

Share the output of:
```bash
# Server startup
tail -50 /tmp/api_with_fix.log

# Python syntax check
python3 -c "from aumentum_browser_service import AumentumBrowserService; print('✅ Import successful')"
```

---

**Ready**: Start server in Terminal 1, test in Terminal 2!

