Skip to content

Commit bf69469

Browse files
committed
fix: resolve Playwright E2E CI failures
Two root causes: 1. FloatingWidget not enqueued in CI: The enqueue_assets() method guarded on function_exists('wp_ai_client_prompt'), which failed in the wp-env environment before the compat layer could define it. The floating widget UI (FAB + panel) does not need the AI client to render — remove the guard. Provider availability is enforced at message-send time via the REST API. 2. Session management tests timing out: Tests submitted a message and waited for the send button to reappear (sending=false), which requires the background job to complete. In CI without an AI provider, the loopback worker never runs and the job stays in 'processing' state indefinitely. Fix: wait for the stop button (sending=true, immediate) instead of the send button (sending=false, requires job completion). Also call fetchSessions() immediately after session creation so the sidebar reflects the new session even when the job never completes.
1 parent 495304c commit bf69469

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

includes/Admin/FloatingWidget.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ public static function enqueue_assets( string $hook_suffix ): void {
4343
return;
4444
}
4545

46-
// Require the AI client.
47-
if ( ! function_exists( 'wp_ai_client_prompt' ) ) {
48-
return;
49-
}
46+
// Note: wp_ai_client_prompt() availability is NOT checked here.
47+
// The floating widget UI (FAB + panel) renders independently of the AI
48+
// client. The REST API handles provider availability at message-send time.
5049

5150
$asset_file = GRATIS_AI_AGENT_DIR . '/build/floating-widget.asset.php';
5251

src/store/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,10 @@ const actions = {
12301230
select.getCurrentSessionMessages(),
12311231
[]
12321232
);
1233+
// Refresh the sidebar immediately so the new session appears
1234+
// even if the subsequent run job never completes (e.g. no AI
1235+
// provider configured in the test environment).
1236+
dispatch.fetchSessions();
12331237
} catch {
12341238
dispatch.appendMessage( {
12351239
role: 'system',

tests/e2e/admin-page.spec.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
goToAgentPage,
1414
getMessageInput,
1515
getSendButton,
16+
getStopButton,
1617
getChatPanel,
1718
getMessageList,
1819
} = require( './utils/wp-admin' );
@@ -107,13 +108,15 @@ test.describe( 'Admin Page - Session Management', () => {
107108
await input.fill( 'Test message' );
108109
await input.press( 'Enter' );
109110

110-
// Wait for input to clear (message submitted).
111+
// Wait for input to clear (message submitted synchronously).
111112
await expect( input ).toHaveValue( '' );
112113

113-
// Wait for the send/stop cycle to complete before clicking New Chat.
114-
// The send button replaces the stop button when sending=false.
115-
const sendButton = getSendButton( page );
116-
await expect( sendButton ).toBeVisible( { timeout: 15_000 } );
114+
// Wait for the stop button to appear — this confirms sending=true and
115+
// that the session was created. We do NOT wait for the send button to
116+
// reappear because the background job may not complete in CI (no AI
117+
// provider configured). New Chat works regardless of sending state.
118+
const stopButton = getStopButton( page );
119+
await expect( stopButton ).toBeVisible( { timeout: 10_000 } );
117120

118121
// Click new chat.
119122
const newChatButton = page.locator( '.ai-agent-new-chat-btn' );
@@ -131,11 +134,14 @@ test.describe( 'Admin Page - Session Management', () => {
131134
await input.fill( 'Create a session' );
132135
await input.press( 'Enter' );
133136

134-
// Wait for the send/stop cycle to complete — the session list refreshes
135-
// after the run completes (or errors). The send button reappears when
136-
// sending=false, which is when fetchSessions is dispatched.
137-
const sendButton = getSendButton( page );
138-
await expect( sendButton ).toBeVisible( { timeout: 15_000 } );
137+
// Wait for the stop button to appear — this confirms sending=true and
138+
// that the session was created via POST /sessions (which happens before
139+
// the background job is spawned). The session list is refreshed after
140+
// session creation, so the sidebar item should appear shortly after.
141+
// We do NOT wait for the send button to reappear because the background
142+
// job may not complete in CI (no AI provider configured).
143+
const stopButton = getStopButton( page );
144+
await expect( stopButton ).toBeVisible( { timeout: 10_000 } );
139145

140146
// At least one session item should appear in the sidebar.
141147
const sessionItems = page.locator( '.ai-agent-session-item' );
@@ -154,10 +160,13 @@ test.describe( 'Admin Page - Keyboard Shortcuts', () => {
154160
await input.fill( 'Some text' );
155161
await input.press( 'Enter' );
156162

157-
// Wait for the send/stop cycle to complete before triggering the shortcut.
158-
// The send button replaces the stop button when sending=false.
159-
const sendButton = getSendButton( page );
160-
await expect( sendButton ).toBeVisible( { timeout: 15_000 } );
163+
// Wait for the stop button to appear — this confirms sending=true and
164+
// that the message was submitted. We do NOT wait for the send button to
165+
// reappear because the background job may not complete in CI (no AI
166+
// provider configured). The Ctrl+N shortcut works regardless of sending
167+
// state.
168+
const stopButton = getStopButton( page );
169+
await expect( stopButton ).toBeVisible( { timeout: 10_000 } );
161170

162171
// Trigger new chat shortcut.
163172
await page.keyboard.press( 'ControlOrMeta+n' );

0 commit comments

Comments
 (0)