-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_post_save.js
More file actions
140 lines (113 loc) Β· 5.35 KB
/
debug_post_save.js
File metadata and controls
140 lines (113 loc) Β· 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Debug script to test post saving with AI block
* This will help reproduce the Issue #5 - 500 error when saving posts
*/
const { chromium } = require('playwright');
async function debugPostSave() {
console.log('π Starting Issue #5 debug - Testing post save with AI block');
const browser = await chromium.launch({
headless: false, // Run with visible browser to see what's happening
slowMo: 1000 // Slow down actions to observe
});
try {
const context = await browser.newContext({
viewport: { width: 1280, height: 720 }
});
const page = await context.newPage();
// Enable console logging
page.on('console', msg => console.log('π Browser:', msg.text()));
page.on('pageerror', error => console.error('β Page Error:', error.message));
console.log('π Navigating to WordPress admin login...');
await page.goto('http://localhost:8080/wp-admin');
// Login
console.log('π Logging in...');
await page.fill('#user_login', 'admin');
await page.fill('#user_pass', '!3cTXkh)9iDHhV5o*N');
await page.click('#wp-submit');
// Wait for dashboard
await page.waitForSelector('.wp-admin', { timeout: 10000 });
console.log('β
Login successful');
// Navigate to new post
console.log('π Creating new post...');
await page.goto('http://localhost:8080/wp-admin/post-new.php');
await page.waitForSelector('.edit-post-header', { timeout: 15000 });
// Add title
console.log('π Adding post title...');
await page.fill('[placeholder="Add title"]', 'Issue #5 Debug Post');
// Add the AI Content Flow block
console.log('π€ Adding AI Content Flow block...');
await page.click('.editor-default-block-appender__content');
await page.keyboard.type('/ai');
await page.waitForSelector('.block-editor-inserter__menu', { timeout: 5000 });
// Look for AI Text Generator block
const aiBlockExists = await page.locator('text=AI Text Generator').count() > 0;
if (aiBlockExists) {
await page.click('text=AI Text Generator');
console.log('β
AI Text Generator block added');
// Wait for block to be inserted
await page.waitForSelector('.wp-content-flow-ai-text-generator', { timeout: 5000 });
// Try to configure the block
console.log('βοΈ Configuring AI block...');
// Add some content to make the post non-empty
await page.keyboard.press('Enter'); // Add new paragraph after AI block
await page.keyboard.type('This is a test post to debug Issue #5 - the 500 error when saving posts with AI blocks.');
} else {
console.log('β οΈ AI Text Generator block not found, adding regular content...');
await page.keyboard.type('This is a regular test post without AI blocks.');
}
// Try to save the post
console.log('πΎ Attempting to save post...');
// Listen for network requests to catch the 500 error
const failedRequests = [];
page.on('response', response => {
if (response.status() >= 400) {
failedRequests.push({
url: response.url(),
status: response.status(),
statusText: response.statusText()
});
console.log(`β Failed request: ${response.status()} ${response.statusText()} - ${response.url()}`);
}
});
// Click save draft
await page.click('button[data-label="Save draft"]');
// Wait a moment for the save attempt
await page.waitForTimeout(5000);
// Check for error messages
const errorNotices = await page.locator('.components-notice.is-error').count();
if (errorNotices > 0) {
const errorText = await page.locator('.components-notice.is-error').first().textContent();
console.log('β Error notice found:', errorText);
}
// Check for "Updating failed" message
const updatingFailedExists = await page.locator('text=Updating failed').count() > 0;
if (updatingFailedExists) {
console.log('β "Updating failed" message detected - this is the Issue #5 symptom!');
}
// Report failed requests
if (failedRequests.length > 0) {
console.log('β Failed HTTP requests during save:');
failedRequests.forEach(req => {
console.log(` ${req.status} ${req.statusText} - ${req.url}`);
});
} else {
console.log('β
No failed HTTP requests detected');
}
// Check if save was successful
const saveSuccessful = await page.locator('text=Draft saved').count() > 0;
if (saveSuccessful) {
console.log('β
Post saved successfully');
} else {
console.log('β Post save failed or unclear status');
}
// Keep browser open for 10 seconds to inspect
console.log('π Keeping browser open for inspection...');
await page.waitForTimeout(10000);
} catch (error) {
console.error('β Test failed:', error.message);
} finally {
await browser.close();
}
}
// Run the debug
debugPostSave().catch(console.error);