Files
openchamber/packages/web/server/lib/notifications/emitter-runtime.test.js
T
Bohdan Triapitsyn 91de51d1a5 fix: deduplicate desktop notifications and tighten notification text extraction
Desktop notifications no longer duplicate when native delivery succeeds
Reasoning chain-of-thought is excluded from notification body text
Untyped message parts are ignored in notification text extraction
2026-06-16 15:21:27 +03:00

48 lines
1.7 KiB
JavaScript

import { describe, expect, it, vi } from 'vitest';
import { createNotificationEmitterRuntime } from './emitter-runtime.js';
const createRuntime = (overrides = {}) => createNotificationEmitterRuntime({
process: { stdout: { write: vi.fn() } },
getDesktopNotifyEnabled: () => true,
desktopNotifyPrefix: '[desktop-notify]',
getUiNotificationClients: () => new Set(),
getBroadcastGlobalUiEvent: () => null,
...overrides,
});
describe('notification emitter runtime', () => {
it('reports desktop delivery through the injected native callback', () => {
const onDesktopNotification = vi.fn();
const runtime = createRuntime({ onDesktopNotification });
const payload = { title: 'Ready', body: 'Done' };
expect(runtime.emitDesktopNotification(payload)).toBe(true);
expect(onDesktopNotification).toHaveBeenCalledWith(payload);
});
it('reports stdout desktop delivery for legacy shells', () => {
const write = vi.fn();
const runtime = createRuntime({ process: { stdout: { write } } });
expect(runtime.emitDesktopNotification({ title: 'Ready' })).toBe(true);
expect(write).toHaveBeenCalledWith('[desktop-notify]{"title":"Ready"}\n');
});
it('marks UI broadcasts that were already delivered natively', () => {
const broadcastGlobalUiEvent = vi.fn();
const runtime = createRuntime({ getBroadcastGlobalUiEvent: () => broadcastGlobalUiEvent });
runtime.broadcastUiNotification({ title: 'Ready' }, { desktopNotificationDelivered: true });
expect(broadcastGlobalUiEvent).toHaveBeenCalledWith({
type: 'openchamber:notification',
properties: {
title: 'Ready',
desktopNotificationDelivered: true,
desktopStdoutActive: true,
},
});
});
});