| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | import { translateLegacyRuntimeEvent } from '../../../src/main/ipc/runtime/event-contract' |
| 5 | |
| 6 | describe('Runtime Event legacy IPC contract', () => { |
| 7 | it('forwards only generation chunks with their pre-existing channel and payload', () => { |
| 8 | const chunk = { |
| 9 | type: 'page_generated' as const, |
| 10 | payload: { |
| 11 | runId: 'run-1', |
| 12 | pageId: 'page-1', |
| 13 | pageNumber: 1, |
| 14 | title: 'Overview', |
| 15 | html: '<div>Overview</div>' |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | expect( |
| 20 | translateLegacyRuntimeEvent({ |
| 21 | type: 'generation.chunk', |
| 22 | payload: chunk, |
| 23 | jobId: 'run-1', |
| 24 | domain: 'generation', |
| 25 | owner: { sessionId: 'session-1' }, |
| 26 | audience: { kind: 'broadcast' }, |
| 27 | occurredAt: 1 |
| 28 | }) |
| 29 | ).toMatchInlineSnapshot(` |
| 30 | { |
| 31 | "channel": "generate:chunk", |
| 32 | "payload": { |
| 33 | "payload": { |
| 34 | "html": "<div>Overview</div>", |
| 35 | "pageId": "page-1", |
| 36 | "pageNumber": 1, |
| 37 | "runId": "run-1", |
| 38 | "title": "Overview", |
| 39 | }, |
| 40 | "type": "page_generated", |
| 41 | }, |
| 42 | } |
| 43 | `) |
| 44 | }) |
| 45 | |
| 46 | it('does not invent legacy push channels for lifecycle or image events', () => { |
| 47 | expect( |
| 48 | translateLegacyRuntimeEvent({ |
| 49 | type: 'job.completed', |
| 50 | payload: {}, |
| 51 | jobId: 'run-1', |
| 52 | domain: 'generation', |
| 53 | owner: { sessionId: 'session-1' }, |
| 54 | audience: { kind: 'broadcast' }, |
| 55 | occurredAt: 1 |
| 56 | }) |
| 57 | ).toBeNull() |
| 58 | expect( |
| 59 | translateLegacyRuntimeEvent({ |
| 60 | type: 'image.progress', |
| 61 | payload: { |
| 62 | runId: 'image-run-1', |
| 63 | sessionId: 'session-1', |
| 64 | pageId: 'page-1', |
| 65 | progress: 80, |
| 66 | label: 'Saving images', |
| 67 | status: 'running' |
| 68 | }, |
| 69 | jobId: 'image-run-1', |
| 70 | domain: 'image', |
| 71 | owner: { sessionId: 'session-1', imageHistoryOwner: 'session-1' }, |
| 72 | audience: { kind: 'broadcast' }, |
| 73 | occurredAt: 1 |
| 74 | }) |
| 75 | ).toBeNull() |
| 76 | }) |
| 77 | |
| 78 | it('makes IPC setup use the explicit compatibility table', () => { |
| 79 | const ipcIndex = fs.readFileSync(path.resolve('src/main/ipc/index.ts'), 'utf8') |
| 80 | |
| 81 | expect(ipcIndex).toContain("import { translateLegacyRuntimeEvent } from './runtime/event-contract'") |
| 82 | expect(ipcIndex).toContain('translate: translateLegacyRuntimeEvent') |
| 83 | }) |
| 84 | }) |
| 85 |