2026-04-20 15:41:15 +03:00
|
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
2026-04-17 16:07:26 +08:00
|
|
|
|
|
|
|
|
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',
|
2026-05-06 23:45:31 +07:00
|
|
|
status: {
|
2026-04-17 16:07:26 +08:00
|
|
|
type: 'busy',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
runtime.markUserMessageSent('session-1');
|
|
|
|
|
runtime.processOpenCodeSsePayload({
|
|
|
|
|
type: 'session.status',
|
|
|
|
|
properties: {
|
|
|
|
|
sessionID: 'session-1',
|
2026-05-06 23:45:31 +07:00
|
|
|
status: {
|
2026-04-17 16:07:26 +08:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-05-06 23:45:31 +07:00
|
|
|
|
|
|
|
|
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',
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-04-17 16:07:26 +08:00
|
|
|
});
|