Spaces:
Running
Running
Commit
·
144940a
1
Parent(s):
62b9a40
Sync changes - automated commit
Browse files- DEBUG-README.md +131 -0
- api-test-script.js +434 -0
- debug-report.md +161 -0
- test-html.html +90 -0
- test-plan.md +131 -0
- visual-test-script.js +206 -0
DEBUG-README.md
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AutoSite Application Debug Guide
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
|
5 |
+
This document provides a comprehensive guide for debugging and testing the AutoSite application, with a particular focus on the AskAI component and its integration with the backend server.
|
6 |
+
|
7 |
+
## Application Structure
|
8 |
+
|
9 |
+
### Frontend Components
|
10 |
+
|
11 |
+
- **App.tsx**: Main application container that manages the HTML content state and layout
|
12 |
+
- **AskAI Component**: Handles AI interactions with streaming response processing
|
13 |
+
- **Preview Component**: Renders HTML content in an iframe with refresh capability
|
14 |
+
|
15 |
+
### Backend Services
|
16 |
+
|
17 |
+
- **/api/ask-ai**: Processes prompts and streams AI responses (full HTML or diff mode)
|
18 |
+
- **/api/apply-diffs**: Applies diff blocks to original HTML content
|
19 |
+
|
20 |
+
## Key Features to Test
|
21 |
+
|
22 |
+
### AskAI Component
|
23 |
+
|
24 |
+
1. **Response Handling**
|
25 |
+
- Full HTML mode for initial requests
|
26 |
+
- Diff mode for follow-up requests
|
27 |
+
- Streaming implementation with real-time preview updates
|
28 |
+
|
29 |
+
2. **Progress Indicators**
|
30 |
+
- Progress bar with percentage
|
31 |
+
- Response mode indicator (diff/full)
|
32 |
+
- Loading animations
|
33 |
+
- Success animation and sound
|
34 |
+
|
35 |
+
3. **Error Handling**
|
36 |
+
- Network error handling
|
37 |
+
- Authentication error handling with login modal
|
38 |
+
- Malformed response handling
|
39 |
+
|
40 |
+
## Testing Resources
|
41 |
+
|
42 |
+
The following files have been created to assist with testing:
|
43 |
+
|
44 |
+
1. **test-plan.md**: Comprehensive test plan outlining test cases and approaches
|
45 |
+
2. **test-html.html**: Sample HTML file for testing the application
|
46 |
+
3. **visual-test-script.js**: Browser-based script for testing UI components
|
47 |
+
4. **api-test-script.js**: Node.js script for testing backend API endpoints
|
48 |
+
5. **debug-report.md**: Detailed analysis of the application architecture and potential issues
|
49 |
+
|
50 |
+
## Running the Application
|
51 |
+
|
52 |
+
### Prerequisites
|
53 |
+
|
54 |
+
1. Create a `.env` file based on `.env.example` with the following variables:
|
55 |
+
- `OAUTH_CLIENT_ID`: HuggingFace OAuth client ID
|
56 |
+
- `OAUTH_CLIENT_SECRET`: HuggingFace OAuth client secret
|
57 |
+
- `APP_PORT`: Port for the backend server (default: 3000)
|
58 |
+
- `REDIRECT_URI`: OAuth redirect URI
|
59 |
+
- `DEFAULT_HF_TOKEN`: HuggingFace API token for anonymous users
|
60 |
+
|
61 |
+
### Starting the Application
|
62 |
+
|
63 |
+
1. Start the frontend development server:
|
64 |
+
```
|
65 |
+
npm run dev
|
66 |
+
```
|
67 |
+
|
68 |
+
2. Start the backend server in a separate terminal:
|
69 |
+
```
|
70 |
+
node server.js
|
71 |
+
```
|
72 |
+
|
73 |
+
3. Access the application at:
|
74 |
+
- Frontend: http://localhost:5173
|
75 |
+
- Backend API: http://localhost:3000
|
76 |
+
|
77 |
+
## Testing Procedures
|
78 |
+
|
79 |
+
### Visual Testing
|
80 |
+
|
81 |
+
1. Open the application in a browser
|
82 |
+
2. Open the browser console
|
83 |
+
3. Load the visual test script:
|
84 |
+
```javascript
|
85 |
+
const script = document.createElement('script');
|
86 |
+
script.src = '/visual-test-script.js';
|
87 |
+
document.head.appendChild(script);
|
88 |
+
```
|
89 |
+
4. Run the tests:
|
90 |
+
```javascript
|
91 |
+
runAllTests();
|
92 |
+
```
|
93 |
+
|
94 |
+
### API Testing
|
95 |
+
|
96 |
+
1. Ensure the backend server is running
|
97 |
+
2. Run the API test script using Node.js:
|
98 |
+
```
|
99 |
+
node api-test-script.js
|
100 |
+
```
|
101 |
+
|
102 |
+
## Common Issues and Solutions
|
103 |
+
|
104 |
+
### Environment Configuration
|
105 |
+
|
106 |
+
- **Missing HuggingFace Token**: The application requires a valid HuggingFace API token in the `DEFAULT_HF_TOKEN` environment variable
|
107 |
+
- **Port Conflicts**: Ensure ports 3000 (backend) and 5173 (frontend) are available
|
108 |
+
|
109 |
+
### Network Issues
|
110 |
+
|
111 |
+
- **CORS Errors**: If testing the frontend and backend on different ports, CORS issues may occur
|
112 |
+
- **Rate Limiting**: HuggingFace API has rate limits that may affect testing
|
113 |
+
|
114 |
+
### UI Issues
|
115 |
+
|
116 |
+
- **Responsive Layout**: Test on different screen sizes to verify responsive behavior
|
117 |
+
- **Progress Indicator**: Verify progress updates correctly during streaming
|
118 |
+
- **Preview Updates**: Check that preview updates in real-time during streaming
|
119 |
+
|
120 |
+
## Debugging Tips
|
121 |
+
|
122 |
+
1. **Console Logging**: The application includes extensive console logging for debugging
|
123 |
+
2. **Network Monitoring**: Use browser DevTools to monitor API requests and responses
|
124 |
+
3. **State Inspection**: Monitor React state changes during AI processing
|
125 |
+
4. **Visual Verification**: Check progress indicators and animations during processing
|
126 |
+
|
127 |
+
## Conclusion
|
128 |
+
|
129 |
+
The AutoSite application demonstrates a well-structured approach to integrating AI assistance into a web development tool. The streaming response handling, progress indicators, and dual-mode response processing provide a solid foundation for an interactive AI-assisted development experience.
|
130 |
+
|
131 |
+
Refer to the detailed test plan and debug report for more comprehensive information on testing and potential improvements.
|
api-test-script.js
ADDED
@@ -0,0 +1,434 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* API Test Script for AutoSite Application
|
3 |
+
*
|
4 |
+
* This script provides functions to test the backend API endpoints
|
5 |
+
* that support the AskAI component functionality.
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Configuration
|
9 |
+
const API_BASE_URL = 'http://localhost:3000';
|
10 |
+
const TEST_HTML = `<!DOCTYPE html>
|
11 |
+
<html>
|
12 |
+
<head>
|
13 |
+
<title>Test Page</title>
|
14 |
+
</head>
|
15 |
+
<body>
|
16 |
+
<h1>Hello World</h1>
|
17 |
+
<p>This is a test page.</p>
|
18 |
+
</body>
|
19 |
+
</html>`;
|
20 |
+
|
21 |
+
// Test prompts for different scenarios
|
22 |
+
const TEST_PROMPTS = {
|
23 |
+
initial: "Create a simple landing page with a header and footer",
|
24 |
+
followUp: "Add a contact form to the page",
|
25 |
+
complex: "Create a responsive portfolio page with navigation, hero section, project gallery, and contact form"
|
26 |
+
};
|
27 |
+
|
28 |
+
// Helper function for making API requests
|
29 |
+
async function makeRequest(endpoint, method = 'GET', body = null) {
|
30 |
+
const options = {
|
31 |
+
method,
|
32 |
+
headers: {
|
33 |
+
'Content-Type': 'application/json'
|
34 |
+
}
|
35 |
+
};
|
36 |
+
|
37 |
+
if (body) {
|
38 |
+
options.body = JSON.stringify(body);
|
39 |
+
}
|
40 |
+
|
41 |
+
try {
|
42 |
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, options);
|
43 |
+
const contentType = response.headers.get('Content-Type');
|
44 |
+
|
45 |
+
// Log response headers for debugging
|
46 |
+
console.log('Response headers:', {
|
47 |
+
'Content-Type': contentType,
|
48 |
+
'X-Response-Type': response.headers.get('X-Response-Type')
|
49 |
+
});
|
50 |
+
|
51 |
+
// Handle different response types
|
52 |
+
if (contentType && contentType.includes('application/json')) {
|
53 |
+
return {
|
54 |
+
status: response.status,
|
55 |
+
headers: response.headers,
|
56 |
+
body: await response.json()
|
57 |
+
};
|
58 |
+
} else {
|
59 |
+
return {
|
60 |
+
status: response.status,
|
61 |
+
headers: response.headers,
|
62 |
+
body: await response.text()
|
63 |
+
};
|
64 |
+
}
|
65 |
+
} catch (error) {
|
66 |
+
console.error('API request failed:', error);
|
67 |
+
return {
|
68 |
+
error: error.message
|
69 |
+
};
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
// Test the /api/ask-ai endpoint with initial prompt (full HTML mode)
|
74 |
+
async function testAskAiInitial() {
|
75 |
+
console.log('\n--- Testing /api/ask-ai with initial prompt ---');
|
76 |
+
|
77 |
+
const requestBody = {
|
78 |
+
prompt: TEST_PROMPTS.initial
|
79 |
+
};
|
80 |
+
|
81 |
+
console.log('Request:', requestBody);
|
82 |
+
|
83 |
+
// For streaming endpoints, we need to handle the response differently
|
84 |
+
try {
|
85 |
+
const response = await fetch(`${API_BASE_URL}/api/ask-ai`, {
|
86 |
+
method: 'POST',
|
87 |
+
headers: {
|
88 |
+
'Content-Type': 'application/json'
|
89 |
+
},
|
90 |
+
body: JSON.stringify(requestBody)
|
91 |
+
});
|
92 |
+
|
93 |
+
console.log('Response status:', response.status);
|
94 |
+
console.log('Response headers:', {
|
95 |
+
'Content-Type': response.headers.get('Content-Type'),
|
96 |
+
'X-Response-Type': response.headers.get('X-Response-Type')
|
97 |
+
});
|
98 |
+
|
99 |
+
if (!response.ok) {
|
100 |
+
const errorText = await response.text();
|
101 |
+
console.error('Error response:', errorText);
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
+
// Handle streaming response
|
106 |
+
const reader = response.body.getReader();
|
107 |
+
const decoder = new TextDecoder('utf-8');
|
108 |
+
let receivedChunks = 0;
|
109 |
+
let receivedContent = '';
|
110 |
+
|
111 |
+
while (true) {
|
112 |
+
const { done, value } = await reader.read();
|
113 |
+
|
114 |
+
if (done) {
|
115 |
+
console.log('Stream complete after', receivedChunks, 'chunks');
|
116 |
+
break;
|
117 |
+
}
|
118 |
+
|
119 |
+
const chunk = decoder.decode(value, { stream: true });
|
120 |
+
receivedContent += chunk;
|
121 |
+
receivedChunks++;
|
122 |
+
|
123 |
+
// Log progress
|
124 |
+
if (receivedChunks % 5 === 0) {
|
125 |
+
console.log(`Received ${receivedChunks} chunks, total length: ${receivedContent.length}`);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
// Validate response content
|
130 |
+
const hasHtmlStructure = receivedContent.includes('<!DOCTYPE html>') ||
|
131 |
+
(receivedContent.includes('<html') && receivedContent.includes('</html>'));
|
132 |
+
|
133 |
+
if (hasHtmlStructure) {
|
134 |
+
console.log('Response contains valid HTML structure');
|
135 |
+
// Log a sample of the response
|
136 |
+
console.log('Sample of response:', receivedContent.substring(0, 200) + '...');
|
137 |
+
return true;
|
138 |
+
} else {
|
139 |
+
console.error('Response does not contain valid HTML structure');
|
140 |
+
console.log('Response content:', receivedContent);
|
141 |
+
return false;
|
142 |
+
}
|
143 |
+
|
144 |
+
} catch (error) {
|
145 |
+
console.error('Test failed:', error);
|
146 |
+
return false;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
// Test the /api/ask-ai endpoint with follow-up prompt (diff mode)
|
151 |
+
async function testAskAiFollowUp() {
|
152 |
+
console.log('\n--- Testing /api/ask-ai with follow-up prompt (diff mode) ---');
|
153 |
+
|
154 |
+
const requestBody = {
|
155 |
+
prompt: TEST_PROMPTS.followUp,
|
156 |
+
html: TEST_HTML,
|
157 |
+
previousPrompt: TEST_PROMPTS.initial
|
158 |
+
};
|
159 |
+
|
160 |
+
console.log('Request:', requestBody);
|
161 |
+
|
162 |
+
try {
|
163 |
+
const response = await fetch(`${API_BASE_URL}/api/ask-ai`, {
|
164 |
+
method: 'POST',
|
165 |
+
headers: {
|
166 |
+
'Content-Type': 'application/json'
|
167 |
+
},
|
168 |
+
body: JSON.stringify(requestBody)
|
169 |
+
});
|
170 |
+
|
171 |
+
console.log('Response status:', response.status);
|
172 |
+
console.log('Response headers:', {
|
173 |
+
'Content-Type': response.headers.get('Content-Type'),
|
174 |
+
'X-Response-Type': response.headers.get('X-Response-Type')
|
175 |
+
});
|
176 |
+
|
177 |
+
if (!response.ok) {
|
178 |
+
const errorText = await response.text();
|
179 |
+
console.error('Error response:', errorText);
|
180 |
+
return false;
|
181 |
+
}
|
182 |
+
|
183 |
+
// Verify response type header indicates diff mode
|
184 |
+
const responseType = response.headers.get('X-Response-Type');
|
185 |
+
if (responseType !== 'diff') {
|
186 |
+
console.warn(`Expected response type 'diff', but got '${responseType}'`);
|
187 |
+
}
|
188 |
+
|
189 |
+
// Handle streaming response
|
190 |
+
const reader = response.body.getReader();
|
191 |
+
const decoder = new TextDecoder('utf-8');
|
192 |
+
let receivedChunks = 0;
|
193 |
+
let receivedContent = '';
|
194 |
+
|
195 |
+
while (true) {
|
196 |
+
const { done, value } = await reader.read();
|
197 |
+
|
198 |
+
if (done) {
|
199 |
+
console.log('Stream complete after', receivedChunks, 'chunks');
|
200 |
+
break;
|
201 |
+
}
|
202 |
+
|
203 |
+
const chunk = decoder.decode(value, { stream: true });
|
204 |
+
receivedContent += chunk;
|
205 |
+
receivedChunks++;
|
206 |
+
|
207 |
+
// Log progress
|
208 |
+
if (receivedChunks % 5 === 0) {
|
209 |
+
console.log(`Received ${receivedChunks} chunks, total length: ${receivedContent.length}`);
|
210 |
+
}
|
211 |
+
}
|
212 |
+
|
213 |
+
// For diff mode, check if response contains search/replace blocks
|
214 |
+
const hasDiffBlocks = receivedContent.includes('<<<<<<< SEARCH') &&
|
215 |
+
receivedContent.includes('======= REPLACE') &&
|
216 |
+
receivedContent.includes('>>>>>>> END');
|
217 |
+
|
218 |
+
if (hasDiffBlocks) {
|
219 |
+
console.log('Response contains valid diff blocks');
|
220 |
+
// Log a sample of the response
|
221 |
+
console.log('Sample of response:', receivedContent.substring(0, 200) + '...');
|
222 |
+
return true;
|
223 |
+
} else {
|
224 |
+
console.warn('Response may not contain valid diff blocks');
|
225 |
+
console.log('Response content:', receivedContent);
|
226 |
+
return false;
|
227 |
+
}
|
228 |
+
|
229 |
+
} catch (error) {
|
230 |
+
console.error('Test failed:', error);
|
231 |
+
return false;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
// Test the /api/apply-diffs endpoint
|
236 |
+
async function testApplyDiffs() {
|
237 |
+
console.log('\n--- Testing /api/apply-diffs endpoint ---');
|
238 |
+
|
239 |
+
// Create a sample diff response
|
240 |
+
const sampleDiff = `Here are the changes to add a contact form:
|
241 |
+
|
242 |
+
<<<<<<< SEARCH
|
243 |
+
<p>This is a test page.</p>
|
244 |
+
</body>
|
245 |
+
======= REPLACE
|
246 |
+
<p>This is a test page.</p>
|
247 |
+
|
248 |
+
<h2>Contact Us</h2>
|
249 |
+
<form>
|
250 |
+
<div>
|
251 |
+
<label for="name">Name:</label>
|
252 |
+
<input type="text" id="name" name="name" required>
|
253 |
+
</div>
|
254 |
+
<div>
|
255 |
+
<label for="email">Email:</label>
|
256 |
+
<input type="email" id="email" name="email" required>
|
257 |
+
</div>
|
258 |
+
<div>
|
259 |
+
<label for="message">Message:</label>
|
260 |
+
<textarea id="message" name="message" rows="4" required></textarea>
|
261 |
+
</div>
|
262 |
+
<button type="submit">Send</button>
|
263 |
+
</form>
|
264 |
+
</body>
|
265 |
+
>>>>>>> END`;
|
266 |
+
|
267 |
+
const requestBody = {
|
268 |
+
originalHtml: TEST_HTML,
|
269 |
+
aiResponseContent: sampleDiff
|
270 |
+
};
|
271 |
+
|
272 |
+
console.log('Request:', requestBody);
|
273 |
+
|
274 |
+
try {
|
275 |
+
const response = await fetch(`${API_BASE_URL}/api/apply-diffs`, {
|
276 |
+
method: 'POST',
|
277 |
+
headers: {
|
278 |
+
'Content-Type': 'application/json'
|
279 |
+
},
|
280 |
+
body: JSON.stringify(requestBody)
|
281 |
+
});
|
282 |
+
|
283 |
+
console.log('Response status:', response.status);
|
284 |
+
|
285 |
+
if (!response.ok) {
|
286 |
+
const errorText = await response.text();
|
287 |
+
console.error('Error response:', errorText);
|
288 |
+
return false;
|
289 |
+
}
|
290 |
+
|
291 |
+
const responseText = await response.text();
|
292 |
+
|
293 |
+
// Verify the response contains the applied changes
|
294 |
+
const hasContactForm = responseText.includes('<h2>Contact Us</h2>') &&
|
295 |
+
responseText.includes('<form>') &&
|
296 |
+
responseText.includes('</form>');
|
297 |
+
|
298 |
+
if (hasContactForm) {
|
299 |
+
console.log('Diff was successfully applied');
|
300 |
+
console.log('Modified HTML:', responseText);
|
301 |
+
return true;
|
302 |
+
} else {
|
303 |
+
console.error('Diff was not applied correctly');
|
304 |
+
console.log('Response:', responseText);
|
305 |
+
return false;
|
306 |
+
}
|
307 |
+
|
308 |
+
} catch (error) {
|
309 |
+
console.error('Test failed:', error);
|
310 |
+
return false;
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
// Test error handling for /api/ask-ai endpoint
|
315 |
+
async function testAskAiErrorHandling() {
|
316 |
+
console.log('\n--- Testing /api/ask-ai error handling ---');
|
317 |
+
|
318 |
+
// Test with empty prompt (should return 400)
|
319 |
+
const requestBody = {
|
320 |
+
prompt: ""
|
321 |
+
};
|
322 |
+
|
323 |
+
console.log('Request with empty prompt:', requestBody);
|
324 |
+
|
325 |
+
try {
|
326 |
+
const response = await fetch(`${API_BASE_URL}/api/ask-ai`, {
|
327 |
+
method: 'POST',
|
328 |
+
headers: {
|
329 |
+
'Content-Type': 'application/json'
|
330 |
+
},
|
331 |
+
body: JSON.stringify(requestBody)
|
332 |
+
});
|
333 |
+
|
334 |
+
console.log('Response status:', response.status);
|
335 |
+
|
336 |
+
if (response.status === 400) {
|
337 |
+
console.log('Server correctly returned 400 for empty prompt');
|
338 |
+
const errorJson = await response.json();
|
339 |
+
console.log('Error response:', errorJson);
|
340 |
+
return true;
|
341 |
+
} else {
|
342 |
+
console.error('Expected 400 status, but got', response.status);
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
|
346 |
+
} catch (error) {
|
347 |
+
console.error('Test failed:', error);
|
348 |
+
return false;
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
// Test error handling for /api/apply-diffs endpoint
|
353 |
+
async function testApplyDiffsErrorHandling() {
|
354 |
+
console.log('\n--- Testing /api/apply-diffs error handling ---');
|
355 |
+
|
356 |
+
// Test with malformed diff (should return 400)
|
357 |
+
const requestBody = {
|
358 |
+
originalHtml: TEST_HTML,
|
359 |
+
aiResponseContent: "This is not a valid diff format"
|
360 |
+
};
|
361 |
+
|
362 |
+
console.log('Request with invalid diff format:', requestBody);
|
363 |
+
|
364 |
+
try {
|
365 |
+
const response = await fetch(`${API_BASE_URL}/api/apply-diffs`, {
|
366 |
+
method: 'POST',
|
367 |
+
headers: {
|
368 |
+
'Content-Type': 'application/json'
|
369 |
+
},
|
370 |
+
body: JSON.stringify(requestBody)
|
371 |
+
});
|
372 |
+
|
373 |
+
console.log('Response status:', response.status);
|
374 |
+
|
375 |
+
// The server should either return 400 or successfully process with no changes
|
376 |
+
if (response.status === 400) {
|
377 |
+
console.log('Server correctly returned 400 for invalid diff format');
|
378 |
+
const errorJson = await response.json();
|
379 |
+
console.log('Error response:', errorJson);
|
380 |
+
return true;
|
381 |
+
} else if (response.ok) {
|
382 |
+
const responseText = await response.text();
|
383 |
+
// If server didn't error, it should return the original HTML unchanged
|
384 |
+
if (responseText === TEST_HTML) {
|
385 |
+
console.log('Server returned original HTML unchanged (acceptable fallback)');
|
386 |
+
return true;
|
387 |
+
} else {
|
388 |
+
console.warn('Server did not error but returned modified HTML');
|
389 |
+
console.log('Response:', responseText);
|
390 |
+
return false;
|
391 |
+
}
|
392 |
+
} else {
|
393 |
+
console.error('Unexpected response status:', response.status);
|
394 |
+
return false;
|
395 |
+
}
|
396 |
+
|
397 |
+
} catch (error) {
|
398 |
+
console.error('Test failed:', error);
|
399 |
+
return false;
|
400 |
+
}
|
401 |
+
}
|
402 |
+
|
403 |
+
// Run all tests
|
404 |
+
async function runAllTests() {
|
405 |
+
console.log('Starting API tests for AutoSite application...');
|
406 |
+
|
407 |
+
const results = {
|
408 |
+
askAiInitial: await testAskAiInitial(),
|
409 |
+
askAiFollowUp: await testAskAiFollowUp(),
|
410 |
+
applyDiffs: await testApplyDiffs(),
|
411 |
+
askAiErrorHandling: await testAskAiErrorHandling(),
|
412 |
+
applyDiffsErrorHandling: await testApplyDiffsErrorHandling()
|
413 |
+
};
|
414 |
+
|
415 |
+
console.log('\n--- Test Results Summary ---');
|
416 |
+
Object.entries(results).forEach(([test, passed]) => {
|
417 |
+
console.log(`${test}: ${passed ? '✅ PASSED' : '❌ FAILED'}`);
|
418 |
+
});
|
419 |
+
|
420 |
+
const passedCount = Object.values(results).filter(Boolean).length;
|
421 |
+
const totalCount = Object.values(results).length;
|
422 |
+
console.log(`\nTests passed: ${passedCount}/${totalCount} (${Math.round(passedCount/totalCount*100)}%)`);
|
423 |
+
|
424 |
+
return results;
|
425 |
+
}
|
426 |
+
|
427 |
+
// Execute tests when run in Node.js
|
428 |
+
if (typeof window === 'undefined') {
|
429 |
+
console.log('AutoSite API Test Script running in Node.js');
|
430 |
+
runAllTests().catch(console.error);
|
431 |
+
} else {
|
432 |
+
console.log('AutoSite API Test Script loaded in browser');
|
433 |
+
console.log('Run tests by calling: runAllTests()');
|
434 |
+
}
|
debug-report.md
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AutoSite Application Debug Report
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
|
5 |
+
This report documents the analysis and debugging of the AutoSite application, with a particular focus on the AskAI component and its integration with the backend server. The application allows users to create and edit HTML content with AI assistance.
|
6 |
+
|
7 |
+
## Architecture Analysis
|
8 |
+
|
9 |
+
### Frontend Components
|
10 |
+
|
11 |
+
1. **App.tsx**
|
12 |
+
- Main application container
|
13 |
+
- Manages state for HTML content, AI working status
|
14 |
+
- Handles layout and resizing between editor and preview panels
|
15 |
+
- Integrates the AskAI component
|
16 |
+
|
17 |
+
2. **AskAI Component**
|
18 |
+
- Handles user prompts and AI interactions
|
19 |
+
- Manages streaming responses from the AI
|
20 |
+
- Processes both full HTML and diff-based responses
|
21 |
+
- Provides visual feedback through progress indicators
|
22 |
+
|
23 |
+
3. **Preview Component**
|
24 |
+
- Renders HTML content in an iframe
|
25 |
+
- Provides refresh functionality
|
26 |
+
- Handles resizing and AI working states
|
27 |
+
|
28 |
+
### Backend Services
|
29 |
+
|
30 |
+
1. **/api/ask-ai Endpoint**
|
31 |
+
- Processes user prompts
|
32 |
+
- Determines response type (full HTML or diff)
|
33 |
+
- Streams AI responses to the client
|
34 |
+
- Handles rate limiting and authentication
|
35 |
+
|
36 |
+
2. **/api/apply-diffs Endpoint**
|
37 |
+
- Processes diff blocks from AI responses
|
38 |
+
- Applies changes to the original HTML
|
39 |
+
- Handles error cases for malformed diffs
|
40 |
+
|
41 |
+
## Key Findings
|
42 |
+
|
43 |
+
### AskAI Component Analysis
|
44 |
+
|
45 |
+
1. **Response Handling**
|
46 |
+
- The component handles two types of responses:
|
47 |
+
- **Full HTML**: Complete HTML document for initial requests
|
48 |
+
- **Diff Mode**: Targeted changes for follow-up requests
|
49 |
+
- Streaming implementation provides real-time feedback
|
50 |
+
- Progress indicator updates based on chunks received
|
51 |
+
|
52 |
+
2. **Error Handling**
|
53 |
+
- Comprehensive error handling for network issues
|
54 |
+
- Authentication errors trigger login modal
|
55 |
+
- Type-safe error processing with appropriate user feedback
|
56 |
+
|
57 |
+
3. **UI/UX Features**
|
58 |
+
- Progress bar with percentage indicator
|
59 |
+
- Response mode indicator (diff/full)
|
60 |
+
- Success animation and sound
|
61 |
+
- Disabled state during processing
|
62 |
+
|
63 |
+
### Server-Side Processing
|
64 |
+
|
65 |
+
1. **Diff Processing**
|
66 |
+
- Server uses a structured format for diffs (SEARCH/REPLACE blocks)
|
67 |
+
- Fuzzy matching for more robust diff application
|
68 |
+
- Fallback mechanisms for handling malformed responses
|
69 |
+
|
70 |
+
2. **AI Integration**
|
71 |
+
- Uses HuggingFace inference API
|
72 |
+
- Different system prompts for initial vs. follow-up requests
|
73 |
+
- Handles both streaming and non-streaming responses
|
74 |
+
|
75 |
+
3. **Authentication**
|
76 |
+
- OAuth integration with HuggingFace
|
77 |
+
- Rate limiting for unauthenticated users
|
78 |
+
- Token management for API requests
|
79 |
+
|
80 |
+
## Potential Issues
|
81 |
+
|
82 |
+
1. **Environment Configuration**
|
83 |
+
- Application requires several environment variables
|
84 |
+
- Missing `DEFAULT_HF_TOKEN` would prevent AI functionality
|
85 |
+
- Server and client ports must be correctly configured
|
86 |
+
|
87 |
+
2. **Error States**
|
88 |
+
- Malformed AI responses could lead to rendering issues
|
89 |
+
- Network interruptions during streaming need careful handling
|
90 |
+
- Rate limiting could surprise users without clear feedback
|
91 |
+
|
92 |
+
3. **Performance Considerations**
|
93 |
+
- Large HTML documents might cause performance issues
|
94 |
+
- Frequent preview updates could cause flickering
|
95 |
+
- Diff application for complex documents might be unreliable
|
96 |
+
|
97 |
+
## Testing Recommendations
|
98 |
+
|
99 |
+
### Functional Testing
|
100 |
+
|
101 |
+
1. **AI Response Modes**
|
102 |
+
- Test initial requests (full HTML mode)
|
103 |
+
- Test follow-up requests (diff mode)
|
104 |
+
- Verify correct mode selection based on context
|
105 |
+
|
106 |
+
2. **UI State Management**
|
107 |
+
- Verify disabled states during processing
|
108 |
+
- Test progress indicator accuracy
|
109 |
+
- Confirm response mode indicator displays correctly
|
110 |
+
|
111 |
+
3. **Error Scenarios**
|
112 |
+
- Test network failures during streaming
|
113 |
+
- Verify authentication error handling
|
114 |
+
- Test malformed response handling
|
115 |
+
|
116 |
+
### Visual Testing
|
117 |
+
|
118 |
+
1. **Responsive Design**
|
119 |
+
- Test on various screen sizes
|
120 |
+
- Verify resizer functionality
|
121 |
+
- Check mobile vs. desktop layouts
|
122 |
+
|
123 |
+
2. **Visual Feedback**
|
124 |
+
- Verify progress bar animation
|
125 |
+
- Test success animation
|
126 |
+
- Check loading indicators
|
127 |
+
|
128 |
+
### Performance Testing
|
129 |
+
|
130 |
+
1. **Streaming Performance**
|
131 |
+
- Test with large responses
|
132 |
+
- Measure time to first meaningful content
|
133 |
+
- Verify memory usage during streaming
|
134 |
+
|
135 |
+
2. **Diff Application**
|
136 |
+
- Test with complex HTML structures
|
137 |
+
- Measure time to apply diffs
|
138 |
+
- Verify accuracy of applied changes
|
139 |
+
|
140 |
+
## Improvement Suggestions
|
141 |
+
|
142 |
+
1. **Developer Experience**
|
143 |
+
- Create a more comprehensive setup guide
|
144 |
+
- Add better error messages for missing environment variables
|
145 |
+
- Implement development mocks for AI responses
|
146 |
+
|
147 |
+
2. **User Experience**
|
148 |
+
- Add estimated time remaining to progress indicator
|
149 |
+
- Provide more detailed feedback during diff application
|
150 |
+
- Implement undo functionality for AI changes
|
151 |
+
|
152 |
+
3. **Robustness**
|
153 |
+
- Enhance diff application algorithm for better matching
|
154 |
+
- Implement client-side fallbacks for server failures
|
155 |
+
- Add more comprehensive logging for debugging
|
156 |
+
|
157 |
+
## Conclusion
|
158 |
+
|
159 |
+
The AutoSite application, particularly the AskAI component, demonstrates a well-structured approach to integrating AI assistance into a web development tool. The streaming response handling, progress indicators, and dual-mode response processing (full HTML vs. diffs) provide a solid foundation for an interactive AI-assisted development experience.
|
160 |
+
|
161 |
+
The main challenges revolve around environment configuration, handling edge cases in AI responses, and ensuring robust performance across different usage scenarios. With the testing recommendations and improvement suggestions outlined in this report, the application can be further enhanced to provide an even more reliable and user-friendly experience.
|
test-html.html
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>AutoSite Test Page</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
max-width: 800px;
|
11 |
+
margin: 0 auto;
|
12 |
+
padding: 20px;
|
13 |
+
line-height: 1.6;
|
14 |
+
}
|
15 |
+
h1 {
|
16 |
+
color: #333;
|
17 |
+
border-bottom: 2px solid #eee;
|
18 |
+
padding-bottom: 10px;
|
19 |
+
}
|
20 |
+
.container {
|
21 |
+
display: flex;
|
22 |
+
flex-wrap: wrap;
|
23 |
+
gap: 20px;
|
24 |
+
margin-top: 20px;
|
25 |
+
}
|
26 |
+
.card {
|
27 |
+
flex: 1 1 300px;
|
28 |
+
border: 1px solid #ddd;
|
29 |
+
border-radius: 8px;
|
30 |
+
padding: 15px;
|
31 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
32 |
+
}
|
33 |
+
button {
|
34 |
+
background-color: #4CAF50;
|
35 |
+
color: white;
|
36 |
+
border: none;
|
37 |
+
padding: 10px 15px;
|
38 |
+
border-radius: 4px;
|
39 |
+
cursor: pointer;
|
40 |
+
font-size: 16px;
|
41 |
+
margin-top: 10px;
|
42 |
+
}
|
43 |
+
button:hover {
|
44 |
+
background-color: #45a049;
|
45 |
+
}
|
46 |
+
img {
|
47 |
+
max-width: 100%;
|
48 |
+
height: auto;
|
49 |
+
border-radius: 4px;
|
50 |
+
}
|
51 |
+
</style>
|
52 |
+
</head>
|
53 |
+
<body>
|
54 |
+
<h1>AutoSite Test Page</h1>
|
55 |
+
<p>This is a test page to verify the functionality of the AutoSite application. It includes various HTML elements to test the rendering and editing capabilities.</p>
|
56 |
+
|
57 |
+
<div class="container">
|
58 |
+
<div class="card">
|
59 |
+
<h2>Feature 1</h2>
|
60 |
+
<p>This card demonstrates a basic content block with a heading and paragraph.</p>
|
61 |
+
<button id="btn1">Click Me</button>
|
62 |
+
</div>
|
63 |
+
|
64 |
+
<div class="card">
|
65 |
+
<h2>Feature 2</h2>
|
66 |
+
<p>This card includes an image element to test media handling.</p>
|
67 |
+
<img src="https://via.placeholder.com/300x200" alt="Placeholder Image">
|
68 |
+
</div>
|
69 |
+
|
70 |
+
<div class="card">
|
71 |
+
<h2>Feature 3</h2>
|
72 |
+
<p>This card includes a form element to test input handling.</p>
|
73 |
+
<form>
|
74 |
+
<input type="text" placeholder="Enter your name" style="width: 100%; padding: 8px; margin-bottom: 10px;">
|
75 |
+
<button type="button">Submit</button>
|
76 |
+
</form>
|
77 |
+
</div>
|
78 |
+
</div>
|
79 |
+
|
80 |
+
<script>
|
81 |
+
// Simple script to test JavaScript functionality
|
82 |
+
document.getElementById('btn1').addEventListener('click', function() {
|
83 |
+
alert('Button clicked!');
|
84 |
+
});
|
85 |
+
|
86 |
+
// Log to console to test console output
|
87 |
+
console.log('Test page loaded successfully');
|
88 |
+
</script>
|
89 |
+
</body>
|
90 |
+
</html>
|
test-plan.md
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AutoSite Application Test Plan
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
This test plan outlines a comprehensive approach to debug and verify the functionality of the AutoSite application, with particular focus on the AskAI component and its integration with the backend.
|
5 |
+
|
6 |
+
## Prerequisites
|
7 |
+
1. Environment setup
|
8 |
+
- Create a `.env` file based on `.env.example`
|
9 |
+
- Ensure `DEFAULT_HF_TOKEN` is set with a valid Hugging Face API token
|
10 |
+
- Verify `OAUTH_CLIENT_ID` and `OAUTH_CLIENT_SECRET` if testing authentication
|
11 |
+
|
12 |
+
## Test Cases
|
13 |
+
|
14 |
+
### 1. Basic Application Functionality
|
15 |
+
- **Verify UI Components**
|
16 |
+
- Editor panel renders correctly
|
17 |
+
- Preview panel displays HTML content
|
18 |
+
- Resizer works for adjusting panel sizes
|
19 |
+
- Responsive design works on different screen sizes
|
20 |
+
|
21 |
+
- **Code Editor**
|
22 |
+
- HTML editing works correctly
|
23 |
+
- Syntax highlighting functions
|
24 |
+
- Error validation works
|
25 |
+
|
26 |
+
### 2. AskAI Component Testing
|
27 |
+
|
28 |
+
#### 2.1 UI Elements
|
29 |
+
- **Input Field**
|
30 |
+
- Placeholder text changes after first query
|
31 |
+
- Disabled state works during AI processing
|
32 |
+
- Enter key triggers AI request
|
33 |
+
|
34 |
+
- **Progress Indicators**
|
35 |
+
- Progress bar appears and updates during streaming
|
36 |
+
- Response mode indicator shows correct mode (diff/full)
|
37 |
+
- Loading animation displays correctly
|
38 |
+
- Success animation plays after completion
|
39 |
+
|
40 |
+
#### 2.2 API Integration
|
41 |
+
|
42 |
+
- **Full HTML Mode**
|
43 |
+
- Initial requests generate complete HTML
|
44 |
+
- Streaming updates preview in real-time
|
45 |
+
- Final HTML is properly formatted
|
46 |
+
- Success sound plays on completion
|
47 |
+
|
48 |
+
- **Diff Mode**
|
49 |
+
- Follow-up requests use diff mode
|
50 |
+
- Diffs are correctly sent to server
|
51 |
+
- Server applies diffs correctly
|
52 |
+
- Original HTML is preserved if diff application fails
|
53 |
+
|
54 |
+
#### 2.3 Error Handling
|
55 |
+
|
56 |
+
- **Authentication Errors**
|
57 |
+
- Login modal appears when rate limit exceeded
|
58 |
+
- Error messages display correctly
|
59 |
+
|
60 |
+
- **Network Errors**
|
61 |
+
- Appropriate error handling for failed requests
|
62 |
+
- UI recovers gracefully from errors
|
63 |
+
|
64 |
+
- **Malformed Responses**
|
65 |
+
- Application handles incomplete HTML
|
66 |
+
- Application handles malformed diffs
|
67 |
+
|
68 |
+
### 3. Backend Testing
|
69 |
+
|
70 |
+
#### 3.1 API Endpoints
|
71 |
+
|
72 |
+
- **/api/ask-ai**
|
73 |
+
- Correctly processes different prompt types
|
74 |
+
- Rate limiting works as expected
|
75 |
+
- Streaming response works correctly
|
76 |
+
- Sets appropriate response headers
|
77 |
+
|
78 |
+
- **/api/apply-diffs**
|
79 |
+
- Correctly parses diff blocks
|
80 |
+
- Applies changes accurately
|
81 |
+
- Handles edge cases (empty blocks, malformed blocks)
|
82 |
+
- Returns appropriate error messages
|
83 |
+
|
84 |
+
#### 3.2 Authentication
|
85 |
+
|
86 |
+
- **HuggingFace OAuth**
|
87 |
+
- Login flow works correctly
|
88 |
+
- Token storage and retrieval works
|
89 |
+
- User information is correctly fetched
|
90 |
+
|
91 |
+
## Visual Testing
|
92 |
+
|
93 |
+
### UI Components
|
94 |
+
- Verify all UI elements render correctly across different screen sizes
|
95 |
+
- Check animations and transitions
|
96 |
+
- Verify loading states and progress indicators
|
97 |
+
|
98 |
+
### Accessibility
|
99 |
+
- Verify keyboard navigation
|
100 |
+
- Check color contrast
|
101 |
+
- Verify screen reader compatibility
|
102 |
+
|
103 |
+
## Performance Testing
|
104 |
+
|
105 |
+
- Measure response time for AI requests
|
106 |
+
- Verify memory usage during streaming
|
107 |
+
- Check for UI freezing during intensive operations
|
108 |
+
|
109 |
+
## Security Testing
|
110 |
+
|
111 |
+
- Verify token handling
|
112 |
+
- Check for exposed secrets
|
113 |
+
- Verify rate limiting effectiveness
|
114 |
+
|
115 |
+
## Recommendations
|
116 |
+
|
117 |
+
1. **Environment Setup**
|
118 |
+
- Create a comprehensive setup guide for developers
|
119 |
+
- Document all required environment variables
|
120 |
+
|
121 |
+
2. **Error Handling**
|
122 |
+
- Enhance error messages for common setup issues
|
123 |
+
- Add more detailed logging for debugging
|
124 |
+
|
125 |
+
3. **Testing Tools**
|
126 |
+
- Implement automated tests for critical paths
|
127 |
+
- Create a test harness for simulating AI responses
|
128 |
+
|
129 |
+
4. **Documentation**
|
130 |
+
- Document the different response modes
|
131 |
+
- Create troubleshooting guides for common issues
|
visual-test-script.js
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Visual Test Script for AutoSite Application
|
3 |
+
*
|
4 |
+
* This script provides functions to visually test the AutoSite application,
|
5 |
+
* particularly focusing on the AskAI component and its integration with the UI.
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Test data for AI prompts
|
9 |
+
const TEST_PROMPTS = [
|
10 |
+
"Create a simple landing page with a header, hero section, and footer",
|
11 |
+
"Add a contact form to the page",
|
12 |
+
"Change the background color to light blue",
|
13 |
+
"Add a navigation menu with Home, About, and Contact links"
|
14 |
+
];
|
15 |
+
|
16 |
+
// Helper function to wait for a specified time
|
17 |
+
function wait(ms) {
|
18 |
+
return new Promise(resolve => setTimeout(resolve, ms));
|
19 |
+
}
|
20 |
+
|
21 |
+
// Test the AskAI component's UI elements
|
22 |
+
async function testAskAIUI() {
|
23 |
+
console.log('Testing AskAI UI elements...');
|
24 |
+
|
25 |
+
// Test input field
|
26 |
+
const inputField = document.querySelector('.group input[type="text"]');
|
27 |
+
if (!inputField) {
|
28 |
+
console.error('Input field not found');
|
29 |
+
return false;
|
30 |
+
}
|
31 |
+
|
32 |
+
// Test send button
|
33 |
+
const sendButton = document.querySelector('.group button');
|
34 |
+
if (!sendButton) {
|
35 |
+
console.error('Send button not found');
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
|
39 |
+
// Test placeholder text
|
40 |
+
console.log('Initial placeholder:', inputField.placeholder);
|
41 |
+
|
42 |
+
console.log('AskAI UI elements test passed');
|
43 |
+
return true;
|
44 |
+
}
|
45 |
+
|
46 |
+
// Test the progress indicator
|
47 |
+
async function testProgressIndicator() {
|
48 |
+
console.log('Testing progress indicator...');
|
49 |
+
|
50 |
+
// Submit a prompt to trigger the progress indicator
|
51 |
+
const inputField = document.querySelector('.group input[type="text"]');
|
52 |
+
const sendButton = document.querySelector('.group button');
|
53 |
+
|
54 |
+
if (!inputField || !sendButton) {
|
55 |
+
console.error('Input field or send button not found');
|
56 |
+
return false;
|
57 |
+
}
|
58 |
+
|
59 |
+
// Enter a test prompt
|
60 |
+
inputField.value = TEST_PROMPTS[0];
|
61 |
+
|
62 |
+
// Click the send button
|
63 |
+
sendButton.click();
|
64 |
+
|
65 |
+
// Wait for the progress indicator to appear
|
66 |
+
await wait(1000);
|
67 |
+
|
68 |
+
// Check if progress indicator is visible
|
69 |
+
const progressBar = document.querySelector('.bg-gradient-to-r');
|
70 |
+
if (!progressBar) {
|
71 |
+
console.error('Progress indicator not found after submitting prompt');
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
|
75 |
+
console.log('Progress indicator test passed');
|
76 |
+
return true;
|
77 |
+
}
|
78 |
+
|
79 |
+
// Test the response mode indicator
|
80 |
+
async function testResponseModeIndicator() {
|
81 |
+
console.log('Testing response mode indicator...');
|
82 |
+
|
83 |
+
// Wait for the response mode indicator to appear
|
84 |
+
await wait(2000);
|
85 |
+
|
86 |
+
// Check if response mode indicator is visible
|
87 |
+
const modeIndicator = document.querySelector('.bg-gray-800\/90');
|
88 |
+
if (!modeIndicator) {
|
89 |
+
console.warn('Response mode indicator not found - this may be normal for first request');
|
90 |
+
return true;
|
91 |
+
}
|
92 |
+
|
93 |
+
// Check the text content to verify mode
|
94 |
+
const modeText = modeIndicator.textContent.trim();
|
95 |
+
console.log('Response mode:', modeText);
|
96 |
+
|
97 |
+
console.log('Response mode indicator test passed');
|
98 |
+
return true;
|
99 |
+
}
|
100 |
+
|
101 |
+
// Test the preview panel updates
|
102 |
+
async function testPreviewUpdates() {
|
103 |
+
console.log('Testing preview panel updates...');
|
104 |
+
|
105 |
+
// Get the preview iframe
|
106 |
+
const previewFrame = document.querySelector('iframe');
|
107 |
+
if (!previewFrame) {
|
108 |
+
console.error('Preview iframe not found');
|
109 |
+
return false;
|
110 |
+
}
|
111 |
+
|
112 |
+
// Store initial content for comparison
|
113 |
+
const initialContent = previewFrame.srcdoc;
|
114 |
+
|
115 |
+
// Wait for content to update (this may take some time depending on AI response)
|
116 |
+
await wait(10000);
|
117 |
+
|
118 |
+
// Check if content has changed
|
119 |
+
const updatedContent = previewFrame.srcdoc;
|
120 |
+
if (initialContent === updatedContent) {
|
121 |
+
console.warn('Preview content did not update - this may indicate an issue');
|
122 |
+
return false;
|
123 |
+
}
|
124 |
+
|
125 |
+
console.log('Preview updates test passed');
|
126 |
+
return true;
|
127 |
+
}
|
128 |
+
|
129 |
+
// Test the success animation
|
130 |
+
async function testSuccessAnimation() {
|
131 |
+
console.log('Testing success animation...');
|
132 |
+
|
133 |
+
// Wait for AI processing to complete
|
134 |
+
await wait(15000);
|
135 |
+
|
136 |
+
// Check if success class was added to body
|
137 |
+
if (document.body.classList.contains('ai-success')) {
|
138 |
+
console.log('Success animation detected');
|
139 |
+
return true;
|
140 |
+
}
|
141 |
+
|
142 |
+
// It's possible the animation already completed and class was removed
|
143 |
+
console.warn('Success animation not detected - may have already completed');
|
144 |
+
return true;
|
145 |
+
}
|
146 |
+
|
147 |
+
// Test responsive design
|
148 |
+
async function testResponsiveDesign() {
|
149 |
+
console.log('Testing responsive design...');
|
150 |
+
|
151 |
+
// Store original window dimensions
|
152 |
+
const originalWidth = window.innerWidth;
|
153 |
+
const originalHeight = window.innerHeight;
|
154 |
+
|
155 |
+
// Test mobile layout
|
156 |
+
console.log('Testing mobile layout...');
|
157 |
+
window.resizeTo(375, 667); // iPhone 8 dimensions
|
158 |
+
await wait(1000);
|
159 |
+
|
160 |
+
// Check if layout has adjusted
|
161 |
+
const editorMobile = document.querySelector('.w-full.h-\\[30dvh\\]');
|
162 |
+
if (!editorMobile) {
|
163 |
+
console.warn('Mobile layout may not be applied correctly');
|
164 |
+
}
|
165 |
+
|
166 |
+
// Test tablet layout
|
167 |
+
console.log('Testing tablet layout...');
|
168 |
+
window.resizeTo(768, 1024); // iPad dimensions
|
169 |
+
await wait(1000);
|
170 |
+
|
171 |
+
// Test desktop layout
|
172 |
+
console.log('Testing desktop layout...');
|
173 |
+
window.resizeTo(1440, 900); // Common desktop dimensions
|
174 |
+
await wait(1000);
|
175 |
+
|
176 |
+
// Restore original dimensions
|
177 |
+
window.resizeTo(originalWidth, originalHeight);
|
178 |
+
|
179 |
+
console.log('Responsive design test completed');
|
180 |
+
return true;
|
181 |
+
}
|
182 |
+
|
183 |
+
// Run all tests
|
184 |
+
async function runAllTests() {
|
185 |
+
console.log('Starting visual tests for AutoSite application...');
|
186 |
+
|
187 |
+
const results = {
|
188 |
+
uiElements: await testAskAIUI(),
|
189 |
+
progressIndicator: await testProgressIndicator(),
|
190 |
+
responseModeIndicator: await testResponseModeIndicator(),
|
191 |
+
previewUpdates: await testPreviewUpdates(),
|
192 |
+
successAnimation: await testSuccessAnimation(),
|
193 |
+
responsiveDesign: await testResponsiveDesign()
|
194 |
+
};
|
195 |
+
|
196 |
+
console.log('Test results:', results);
|
197 |
+
console.log('Tests completed:', Object.values(results).filter(Boolean).length, 'of', Object.values(results).length, 'passed');
|
198 |
+
|
199 |
+
return results;
|
200 |
+
}
|
201 |
+
|
202 |
+
// Execute tests when run in browser console
|
203 |
+
if (typeof window !== 'undefined') {
|
204 |
+
console.log('AutoSite Visual Test Script loaded');
|
205 |
+
console.log('Run tests by calling: runAllTests()');
|
206 |
+
}
|