- Removed deprecated functions related to document parsing and blob storage in blobstore.ts. - Introduced new PDF rendering logic in pdf-preview-renderer.ts and pdf-preview-pdfjs-runtime.ts. - Updated previews-render.ts to utilize the new PDF rendering functions. - Refactored user-whisper-align-job.ts to use the compute-worker client for alignment requests. - Enhanced artifact.ts and operation.ts to validate parsed PDF artifacts and resolve current PDF parses. - Updated snapshot.ts to align with new worker operation types. - Adjusted runtime-config.ts to check for compute-worker availability. - Modified types in parsed-pdf.ts and tts.ts to reflect changes in the compute-worker protocol. - Added unit tests for PDF artifact validation and compute-worker client contract. - Removed obsolete pdf-op-key.vitest.spec.ts test file.
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { encodeSseFrame, parseSseEventId, parseSsePayload } from '../../../src/compute/control-plane/sse';
|
|
|
|
describe('sse codec', () => {
|
|
test('encodes event id and payload and decodes both reliably', () => {
|
|
const frame = encodeSseFrame({
|
|
id: 42,
|
|
event: 'snapshot',
|
|
data: { ok: true, opId: 'op-1' },
|
|
});
|
|
|
|
expect(frame).toContain('event: snapshot');
|
|
expect(parseSseEventId(frame)).toBe(42);
|
|
expect(parseSsePayload(frame)).toBe('{"ok":true,"opId":"op-1"}');
|
|
});
|
|
|
|
test('supports multiline data payload', () => {
|
|
const frame = encodeSseFrame({
|
|
id: 5,
|
|
data: 'line1\nline2',
|
|
});
|
|
|
|
expect(parseSseEventId(frame)).toBe(5);
|
|
expect(parseSsePayload(frame)).toBe('line1\nline2');
|
|
});
|
|
|
|
test('emits a retry directive when provided', () => {
|
|
const frame = encodeSseFrame({ retry: 120_000 });
|
|
expect(frame).toContain('retry: 120000');
|
|
});
|
|
|
|
test('omits retry when not finite and floors fractional values', () => {
|
|
expect(encodeSseFrame({ retry: Number.NaN })).not.toContain('retry:');
|
|
expect(encodeSseFrame({ retry: 1500.9 })).toContain('retry: 1500');
|
|
});
|
|
});
|