This guide helps you test the complete AI-to-Compiler integration in CodeFlow, ensuring that AI-generated code is executable and meets compiler requirements.
- Server Running:
cd server && npm run dev - Client Running:
cd client && npm run dev - Environment:
.envfile with validGEMINI_API_KEY - Compiler: Built-in Piston API integration (no setup needed)
Objective: Verify AI generates executable JS code with output
Steps:
- Open CodeFlow and create a new file:
test.js - Open AI sidebar (sparkle icon ✨)
- Type:
"give me code for palindrome check" - Wait for AI response
Expected Result:
function isPalindrome(str) {
return str === str.split('').reverse().join('');
}
// Example usage
console.log("Testing 'racecar':", isPalindrome("racecar")); // true
console.log("Testing 'hello':", isPalindrome("hello")); // false
console.log("Testing 'A man a plan a canal Panama':",
isPalindrome("A man a plan a canal Panama".toLowerCase().replace(/\s/g, '')));Validation Checklist:
- ✅ Code has
console.log()statements - ✅ Function is defined AND called with examples
- ✅ "Compiler Ready" green badge appears
- ✅ Accept button is enabled
Action: Click "Accept"
Expected Outcome:
- Code appears in editor
- Can click "Run" button
- Output shows in console with test results
- Badge shows "Ready to Run!" with ✅ icon
Objective: Verify Python code has proper structure
Steps:
- Create new file:
test.py - Ask AI:
"create a fibonacci sequence generator"
Expected Result:
def fibonacci(n):
fib_sequence = []
a, b = 0, 1
for _ in range(n):
fib_sequence.append(a)
a, b = b, a + b
return fib_sequence
if __name__ == "__main__":
# Example usage
print("First 10 Fibonacci numbers:")
print(fibonacci(10))
print("\nFirst 5 Fibonacci numbers:")
print(fibonacci(5))Validation Checklist:
- ✅ Has
if __name__ == "__main__":block - ✅ Code includes
print()statements - ✅ Function is called in main block
- ✅ Complete, runnable code
Objective: Verify Java structure is compiler-ready
Steps:
- Create file:
Main.java - Ask AI:
"create a simple calculator class"
Expected Result:
public class Main {
public static int add(int a, int b) {
return a + b;
}
public static int subtract(int a, int b) {
return a - b;
}
public static void main(String[] args) {
// Example usage
System.out.println("Addition: 5 + 3 = " + add(5, 3));
System.out.println("Subtraction: 10 - 4 = " + subtract(10, 4));
}
}Validation Checklist:
- ✅ Has
public class Main - ✅ Has
public static void main(String[] args) - ✅ Uses
System.out.println() - ✅ Methods are called in main
Objective: Verify proper C++ structure
Steps:
- Create file:
test.cpp - Ask AI:
"create factorial function"
Expected Result:
#include <iostream>
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
int main() {
// Example usage
std::cout << "Factorial of 5: " << factorial(5) << std::endl;
std::cout << "Factorial of 0: " << factorial(0) << std::endl;
std::cout << "Factorial of 10: " << factorial(10) << std::endl;
return 0;
}Validation Checklist:
- ✅ Has
#include <iostream> - ✅ Has
int main()withreturn 0; - ✅ Uses
std::coutfor output - ✅ Function is called in main
Objective: Test AI editing existing code
Steps:
- Create
test.jswith:
function greet() {
console.log("Hello");
}
greet();- Ask AI:
"modify this to greet with a name parameter"
Expected Result:
function greet(name) {
console.log("Hello, " + name + "!");
}
// Example usage
greet("Alice");
greet("Bob");
greet("Charlie");Validation:
- ✅ Function updated with parameter
- ✅ Multiple example calls included
- ✅ Original structure maintained
- ✅ Still has console.log output
The AI context validates code for:
JavaScript/TypeScript:
- ❌ No
console.log()→ Error - ❌ Contains placeholders → Error
- ❌ Empty code → Error
Python:
- ❌ No
print()→ Error - ❌ Empty code → Error
Java:
- ❌ No
public static void main→ Error - ❌ No
System.out.println→ Error - ❌ No class definition → Error
C/C++:
- ❌ No
int main()→ Error - ❌ No output (printf/cout) → Error
Objective: Verify rejection cleans up properly
Steps:
- Get AI suggestion for any code
- Click "Reject" button
- Wait 1 second
Expected:
- Badge changes to "Rejected" (red)
- Suggestion fades out after 1 second
- Suggestion disappears from list
- Editor code remains unchanged
- No errors in console
Objective: Verify acceptance updates editor
Steps:
- Get AI suggestion
- Verify "Compiler Ready" badge
- Click "Accept" button
Expected:
- Badge changes to "Accepted" (green)
- Code appears in active editor
- Suggestion marked as accepted in list
- Can immediately run code in compiler
- File tab shows unsaved indicator (if applicable)
Setup: Temporarily modify server to generate bad code (for testing)
Expected Client Behavior:
-
Validation catches issues:
- Missing main function
- Missing output statements
- Contains placeholders
-
User sees error toast:
- "Code validation failed: [specific error]"
- Suggestion stays in "pending" state
- Accept button remains active to retry
Full Workflow:
- Start with empty
app.js - Ask AI:
"create a simple todo list array manager" - AI generates complete code with examples
- Click "Accept"
- Code appears in editor
- Click "Run" in RunView
- Output appears in console
- Ask AI:
"add a remove function" - AI provides updated code
- Accept and verify execution
Success Criteria:
- ✅ All steps complete without errors
- ✅ Code executes successfully each time
- ✅ Output is visible in compiler console
- ✅ State maintained between AI interactions
- Target: < 3 seconds for simple queries
- Acceptable: < 5 seconds for complex code
- Measure: Time from send to code suggestion appearance
- Completeness: 100% of generated code should be runnable
- Placeholders: 0 placeholders in generated code
- Output: 100% of code should produce visible output
Cause: Prompt not emphasizing output requirement Solution: Already fixed - server prompts now require console.log/print Test: Generate any code and verify output statements present
Cause: AI not following structure requirements Solution: Enhanced language requirements in server Test: Generate Java/C++ code and verify main() present
Cause: Validation failing Solution: Check browser console for validation errors Debug: Look for specific validation rule that failed
Cause: AI generated incomplete code Solution: Validation catches this and shows error Test: Try to accept - should see "contains placeholders" error
Use this checklist for complete testing:
- JavaScript: Function + console.log + examples
- Python: if name block + print + examples
- Java: class + main + System.out.println
- C++: includes + main + std::cout
- TypeScript: Types + console.log + examples
- Code Modification: Updates existing file correctly
- Accept: Code appears in editor
- Reject: Suggestion removed after 1s
- Validation: Catches missing output
- Validation: Catches missing main functions
- Validation: Catches placeholders
- Execution: Accepted code runs in compiler
- Output: Console shows results
- Multiple Files: Works across different files
- Chat History: AI uses context from previous messages
- Generate COMPLETE, executable code
- Include example usage that RUNS
- Add output statements (console.log, print, etc.)
- Follow language-specific structure requirements
- Provide full file content, not snippets
- Use placeholders like "...", "// rest of code"
- Generate function definitions without calling them
- Omit main functions/blocks
- Skip output statements
- Provide partial code
cd server
npm run dev
# Watch for AI_QUERY events and responses// In browser DevTools Console
localStorage.getItem('livewire-ai-messages')// Add breakpoint in AIContext.tsx validateCode function
// Step through validation rules// Check Network tab -> WS (WebSocket)
// Look for AI_QUERY, AI_RESPONSE, AI_CODE_SUGGESTION eventsCode Quality:
- 100% of generated code should be executable
- 0% placeholder usage
- 100% should have visible output
User Experience:
- < 3 clicks to generate and run code
- Clear visual feedback at each step
- No confusing error messages
Integration:
- AI → Editor: Seamless code transfer
- Editor → Compiler: Direct execution
- Compiler → Output: Visible results
- Report Issues: Document any AI behavior that doesn't match expectations
- Performance: Note any slow responses or timeouts
- Edge Cases: Try unusual queries (very long code, multiple languages, etc.)
- User Feedback: Have real users test and provide feedback
- Documentation: See
AI_README.mdfor feature details - Architecture: See
ARCHITECTURE.mdfor system design - Setup Issues: See
SETUP_GUIDE.mdfor configuration help - Quick Reference: See
QUICK_REFERENCE.mdfor commands
Last Updated: Jan 2025
Version: 2.0 (Enhanced Compiler Integration)