fix(vscode): prevent early SSE replay loss

This commit is contained in:
Bohdan Triapitsyn
2026-07-30 00:31:15 +03:00
parent 34aefb731b
commit d69ee1033e
7 changed files with 51 additions and 19 deletions
+14 -1
View File
@@ -21,7 +21,7 @@ describe('VS Code webview bridge requests', () => {
}),
});
const { sendBridgeMessageWithOptions } = await import('./bridge');
const { sendBridgeMessageWithOptions, startSseProxy } = await import('./bridge');
const controller = new AbortController();
controller.abort();
@@ -36,6 +36,19 @@ describe('VS Code webview bridge requests', () => {
assert.ok(result instanceof DOMException);
assert.equal(result.name, 'AbortError');
assert.equal(messages.length, 0);
const startPromise = startSseProxy({ path: '/global/event', streamId: 'sse_webview_1_1' });
const request = messages[0] as { id: string; payload?: { streamId?: string } };
assert.equal(request.payload?.streamId, 'sse_webview_1_1');
globalThis.window.dispatchEvent(new MessageEvent('message', {
data: {
id: request.id,
type: 'api:sse:start',
success: true,
data: { status: 200, headers: {}, streamId: 'sse_webview_1_1' },
},
}));
assert.equal((await startPromise).streamId, 'sse_webview_1_1');
} finally {
Object.defineProperty(globalThis, 'window', { configurable: true, value: originalWindow });
Object.defineProperty(globalThis, 'acquireVsCodeApi', { configurable: true, value: originalAcquire });
+1
View File
@@ -189,6 +189,7 @@ export type ProxiedSseStartResponse = {
export async function startSseProxy(options: {
path: string;
headers?: Record<string, string>;
streamId?: string;
}): Promise<ProxiedSseStartResponse> {
return sendBridgeMessage<ProxiedSseStartResponse>('api:sse:start', options);
}