Files
odysseus/tests/emailReplyStream.test.mjs
T
pewdiepie-archdaemon 2e8413a54a Preserve preview harness, editor, email and task improvements
Snapshot current maintainer-preview application changes and regression fixtures for integration into lab. Excludes local runtime data, evaluation outputs and source backups. Focused Python regression selection: 140 passed; full suite not certified.
2026-10-01 01:34:26 +00:00

25 lines
1.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readEmailReplyResponse} from '../static/js/emailReplyStream.js';
const response = frames => new Response(frames.map(f => `data: ${JSON.stringify(f)}\n\n`).join(''),
{headers: {'content-type': 'text/event-stream'}});
test('streams body then requires successful terminal result', async () => {
const seen = [];
const result = await readEmailReplyResponse(response([
{type:'reply', text:'Hi'}, {type:'reply', text:'Hi Jonathan'},
{type:'result', success:true, reply:'Hi Jonathan'},
]), text => seen.push(text));
assert.deepEqual(seen, ['Hi', 'Hi Jonathan']);
assert.equal(result.success, true);
});
test('editing the draft stops streaming insertion', async () => {
await assert.rejects(readEmailReplyResponse(response([{type:'reply', text:'Hi'}]), () => false), /edited or closed/);
});
test('disconnect is not a completed draft', async () => {
await assert.rejects(readEmailReplyResponse(response([{type:'reply', text:'Hi'}]), () => {}), /before completion/);
});