* fix: align session status parsing and vscode reconnect reconcile * fix vscode session status fallback and reconcile cleanup safety --------- Co-authored-by: vhqtvn <8930337+vhqtvn@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
101 lines
2.5 KiB
JavaScript
101 lines
2.5 KiB
JavaScript
import { afterEach, describe, expect, it } from 'vitest';
|
|
|
|
import { createSessionRuntime } from './session-runtime.js';
|
|
|
|
describe('session runtime', () => {
|
|
const runtimes = [];
|
|
|
|
afterEach(() => {
|
|
for (const runtime of runtimes) {
|
|
runtime.dispose();
|
|
}
|
|
runtimes.length = 0;
|
|
});
|
|
|
|
it('broadcasts attention clears through the shared broadcaster', () => {
|
|
const events = [];
|
|
const runtime = createSessionRuntime({
|
|
writeSseEvent() {
|
|
throw new Error('SSE fallback should not be used when broadcastEvent is provided');
|
|
},
|
|
getNotificationClients: () => new Set(),
|
|
broadcastEvent: (payload) => {
|
|
events.push(payload);
|
|
},
|
|
});
|
|
runtimes.push(runtime);
|
|
|
|
runtime.processOpenCodeSsePayload({
|
|
type: 'session.status',
|
|
properties: {
|
|
sessionID: 'session-1',
|
|
status: {
|
|
type: 'busy',
|
|
},
|
|
},
|
|
});
|
|
runtime.markUserMessageSent('session-1');
|
|
runtime.processOpenCodeSsePayload({
|
|
type: 'session.status',
|
|
properties: {
|
|
sessionID: 'session-1',
|
|
status: {
|
|
type: 'idle',
|
|
},
|
|
},
|
|
});
|
|
runtime.markSessionViewed('session-1', 'client-1');
|
|
|
|
expect(events).toContainEqual({
|
|
type: 'openchamber:session-status',
|
|
properties: expect.objectContaining({
|
|
sessionId: 'session-1',
|
|
status: 'idle',
|
|
needsAttention: true,
|
|
}),
|
|
});
|
|
expect(events.at(-1)).toEqual({
|
|
type: 'openchamber:session-status',
|
|
properties: {
|
|
sessionId: 'session-1',
|
|
status: 'idle',
|
|
timestamp: expect.any(Number),
|
|
metadata: {},
|
|
needsAttention: false,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('accepts legacy session.status info.type payloads', () => {
|
|
const events = [];
|
|
const runtime = createSessionRuntime({
|
|
writeSseEvent() {
|
|
throw new Error('SSE fallback should not be used when broadcastEvent is provided');
|
|
},
|
|
getNotificationClients: () => new Set(),
|
|
broadcastEvent: (payload) => {
|
|
events.push(payload);
|
|
},
|
|
});
|
|
runtimes.push(runtime);
|
|
|
|
runtime.processOpenCodeSsePayload({
|
|
type: 'session.status',
|
|
properties: {
|
|
sessionID: 'legacy-session-1',
|
|
info: {
|
|
type: 'busy',
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(events).toContainEqual({
|
|
type: 'openchamber:session-status',
|
|
properties: expect.objectContaining({
|
|
sessionId: 'legacy-session-1',
|
|
status: 'busy',
|
|
}),
|
|
});
|
|
});
|
|
});
|