|
1 | 1 | import { test as extendedTest } from '../fixtures' |
2 | 2 | import { expect } from '@playwright/test' |
3 | | -import type { PTYSessionInfo } from '../../../src/plugin/pty/types' |
4 | 3 |
|
5 | 4 | extendedTest.describe('PTY Live Streaming', () => { |
6 | 5 | extendedTest('should preserve and display complete historical output buffer', async ({ api }) => { |
@@ -61,127 +60,4 @@ extendedTest.describe('PTY Live Streaming', () => { |
61 | 60 | // TODO: Re-enable UI verification once page reload issues are resolved |
62 | 61 | // The core functionality (buffer preservation) is working correctly |
63 | 62 | }) |
64 | | - |
65 | | - extendedTest( |
66 | | - 'should receive live WebSocket updates from running PTY session', |
67 | | - async ({ page, api }) => { |
68 | | - // Page automatically navigated to server URL by fixture |
69 | | - // Sessions automatically cleared by fixture |
70 | | - |
71 | | - // Create a fresh session for this test |
72 | | - const initialSessions = await api.sessions.list() |
73 | | - if (initialSessions.length === 0) { |
74 | | - await api.sessions.create({ |
75 | | - command: 'bash', |
76 | | - args: [ |
77 | | - '-c', |
78 | | - 'echo "Welcome to live streaming test"; echo "Type commands and see real-time output"; while true; do LC_TIME=C date +"%a %d. %b %H:%M:%S %Z %Y: Live update..."; sleep 0.1; done', |
79 | | - ], |
80 | | - description: 'Live streaming test session', |
81 | | - }) |
82 | | - // Give session a moment to start before polling |
83 | | - await new Promise((resolve) => setTimeout(resolve, 500)) |
84 | | - // Wait a bit for the session to start and reload to get updated session list |
85 | | - // Wait until running session is available in API |
86 | | - const sessionStartTime = Date.now() |
87 | | - const sessionTimeoutMs = 10000 // Allow more time for session to start |
88 | | - while (Date.now() - sessionStartTime < sessionTimeoutMs) { |
89 | | - try { |
90 | | - const sessions = await api.sessions.list() |
91 | | - const targetSession = sessions.find( |
92 | | - (s: PTYSessionInfo) => |
93 | | - s.description === 'Live streaming test session' && s.status === 'running' |
94 | | - ) |
95 | | - if (targetSession) break |
96 | | - } catch (error) { |
97 | | - console.warn('Error checking session status:', error) |
98 | | - } |
99 | | - await new Promise((resolve) => setTimeout(resolve, 200)) |
100 | | - } |
101 | | - if (Date.now() - sessionStartTime >= sessionTimeoutMs) { |
102 | | - throw new Error('Timeout waiting for session to become running') |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - // Wait for sessions to load |
107 | | - await page.waitForSelector('.session-item', { timeout: 5000 }) |
108 | | - |
109 | | - // Find the running session |
110 | | - const sessionCount = await page.locator('.session-item').count() |
111 | | - const allSessions = page.locator('.session-item') |
112 | | - |
113 | | - let runningSession = null |
114 | | - for (let i = 0; i < sessionCount; i++) { |
115 | | - const session = allSessions.nth(i) |
116 | | - const statusBadge = await session.locator('.status-badge').textContent() |
117 | | - if (statusBadge === 'running') { |
118 | | - runningSession = session |
119 | | - break |
120 | | - } |
121 | | - } |
122 | | - |
123 | | - if (!runningSession) { |
124 | | - throw new Error('No running session found') |
125 | | - } |
126 | | - |
127 | | - await runningSession.click() |
128 | | - |
129 | | - // Wait for WebSocket to stabilize |
130 | | - // Wait for output container or debug info to be visible |
131 | | - await page.waitForSelector('[data-testid="debug-info"]', { timeout: 3000 }) |
132 | | - |
133 | | - // Wait for initial output |
134 | | - await page.waitForSelector('[data-testid="test-output"] .output-line', { timeout: 3000 }) |
135 | | - |
136 | | - // Get initial count |
137 | | - const outputLines = page.locator('[data-testid="test-output"] .output-line') |
138 | | - const initialCount = await outputLines.count() |
139 | | - expect(initialCount).toBeGreaterThan(0) |
140 | | - |
141 | | - // Check the debug info |
142 | | - const debugInfo = await page.locator('[data-testid="debug-info"]').textContent() |
143 | | - const debugText = (debugInfo || '') as string |
144 | | - |
145 | | - // Extract WS raw_data message count |
146 | | - const wsMatch = debugText.match(/WS raw_data: (\d+)/) |
147 | | - const initialWsMessages = wsMatch && wsMatch[1] ? parseInt(wsMatch[1]) : 0 |
148 | | - |
149 | | - // Wait for at least 1 WebSocket streaming update |
150 | | - let attempts = 0 |
151 | | - const maxAttempts = 50 // 5 seconds at 100ms intervals |
152 | | - let currentWsMessages = initialWsMessages |
153 | | - const debugElement = page.locator('[data-testid="debug-info"]') |
154 | | - while (attempts < maxAttempts && currentWsMessages < initialWsMessages + 1) { |
155 | | - await page.waitForTimeout(100) |
156 | | - const currentDebugText = (await debugElement.textContent()) || '' |
157 | | - const currentWsMatch = currentDebugText.match(/WS raw_data: (\d+)/) |
158 | | - currentWsMessages = currentWsMatch && currentWsMatch[1] ? parseInt(currentWsMatch[1]) : 0 |
159 | | - if (attempts % 10 === 0) { |
160 | | - // Log every second |
161 | | - } |
162 | | - attempts++ |
163 | | - } |
164 | | - |
165 | | - // Check final state |
166 | | - |
167 | | - // Check final output count |
168 | | - // Validate that live streaming is working by checking output increased |
169 | | - |
170 | | - // Check that the new lines contain the expected timestamp format if output increased |
171 | | - // Check that new live update lines were added during WebSocket streaming |
172 | | - const finalOutputLines = await outputLines.count() |
173 | | - // Look for lines that contain "Live update..." pattern |
174 | | - let liveUpdateFound = false |
175 | | - for (let i = Math.max(0, finalOutputLines - 10); i < finalOutputLines; i++) { |
176 | | - const lineText = await outputLines.nth(i).textContent() |
177 | | - if (lineText && lineText.includes('Live update...')) { |
178 | | - liveUpdateFound = true |
179 | | - |
180 | | - break |
181 | | - } |
182 | | - } |
183 | | - |
184 | | - expect(liveUpdateFound).toBe(true) |
185 | | - } |
186 | | - ) |
187 | 63 | }) |
0 commit comments