Spaces:
Sleeping
Download DEBUG_MOCK_VS_REAL.md from vinith17/CodeBug: direct link, hf CLI and curl.
- Browser
- Download file 4.02 kB
-
https://huggingface.co/spaces/vinith17/CodeBug/resolve/main/DEBUG_MOCK_VS_REAL.md
- Command line
-
hf download hf://spaces/vinith17/CodeBug/DEBUG_MOCK_VS_REAL.md
-
curl -L -o DEBUG_MOCK_VS_REAL.md https://huggingface.co/spaces/vinith17/CodeBug/resolve/main/DEBUG_MOCK_VS_REAL.md
Why Frontend Shows Mock Data - And How to Verify Real API Works
β THE REAL API IS WORKING
Proof from direct testing:
Code with bugs:
try:
x = int("abc")
except:
pass
def recurse(n):
return recurse(n-1)
API Response: 2 bugs detected
1. Infinite recursion - Confidence: 0.87 (REAL)
2. Bare except - Confidence: 0.96 (REAL)
But the Browser Shows: "Approved - Style - 50% Confidence" β This is the mock fallback!
π Why Frontend Shows Mock Data
The frontend falls back to mock when:
- β API throws an error
- β API response isn't being received
- β Network issue / CORS problem
- β Frontend catches any exception
When this happens, instead of showing real API bugs, it shows a generic "No obvious bugs - style - logging suggestion"
π οΈ How to Verify Real vs Mock Data
Step 1: Open Browser DevTools
- Press
F12in your browser - Go to Console tab
- Clear any old messages
Step 2: Paste This Code in the CodeBug Frontend:
try:
x = int("abc")
except:
pass
def recurse(n):
return recurse(n-1)
DO NOT include recurse(5) at the end - that causes infinite recursion
Step 3: Click Analyze
Step 4: Check Console Output
If you see REAL API data:
β Real API response received: {
bugs_found: 2,
bugs: [
{ comment: "Infinite recursion...", confidence: 0.87 },
{ comment: "Bare except...", confidence: 0.96 }
]
}
OR if you see MOCK fallback:
β API call failed: [error message]
Using fallback local analysis...
Fallback result: { type: 'approve', ... }
β Debug Checklist
Check if API is responding:
- Open console (F12)
- Look for "β Real API response received"
- If you see "β API call failed", note the error
Common errors and fixes:
ERR_CONNECTION_REFUSEDβ API server not runningERR_NETWORK_TIMEOUTβ API is hanging (code with infinite recursion)CORS errorβ Cross-origin issue404 Not Foundβ Wrong endpoint path
Test with Safe Code:
- Start with simple code:
x = 5 - Gradually add complexity
- AVOID code with infinite recursion at module level
- Start with simple code:
π Real vs Mock Data Indicators
###Real Data (from API):
- β Confidence: 0.75-0.99 (never 0.5 or 1.0)
- β Multiple bugs shown
- β Specific error types (SQL injection, bare except, etc.)
- β Severity: 2-5
- β Specific line hints: "Line 3", "Line 5"
Mock Data (fallback):
- β Confidence: 1.0 (clean code) or varies
- β Generic suggestions: "logging module"
- β Category: mostly "style"
- β Line hint: "Not specified"
π¨ Current Known Issue
The frontend is currently showing mock data for all requests because there might be:
- A network/CORS issue
- The API endpoint returning an error
- Browser security restrictions
Solution:
- Check browser console (F12)
- Look for the error message
- Report what you see
##β What to Try
Option 1: Direct Test
// Paste in browser console:
fetch('/api/review', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
code: 'try:\n x = int("abc")\nexcept:\n pass',
language: 'python'
})
})
.then(r => r.json())
.then(data => console.log(data))
Option 2: Test with cURL
$body = @{
code = 'try:\n x = int("abc")\nexcept:\n pass'
language = 'python'
} | ConvertTo-Json
Invoke-WebRequest -Uri http://127.0.0.1:7860/api/review `
-Method POST `
-ContentType 'application/json' `
-Body $body
β NEXT STEPS
Verify API is running:
.venv\Scripts\python -m uvicorn main:app --host 127.0.0.1 --port 7860Open browser console (F12)
Paste code and analyze - check console output
Share console error message if fallback appears
The REAL API IS WORKING. We just need to figure out why the frontend isn't showing it. π