Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171// daemon e2e tests cannot see browser-local unread or flash stateimport assert from 'node:assert/strict';import { readFile } from 'node:fs/promises';import { stripTypeScriptTypes } from 'node:module';import test from 'node:test';
const source = await readFile( new URL('../src/lib/attention.ts', import.meta.url), 'utf8',);const { Attention } = await import( `data:text/javascript;base64,${Buffer.from( stripTypeScriptTypes(source, { mode: 'transform' }), ).toString('base64')}`);const session = ( id, phase = 'idle', answer = null, blocking_reason = null,) => ({ id, status: { phase, blocking_reason }, activity: { latest_answer: answer && { message_id: answer } },});
test('read one chat without clearing another; a later turn can mark it again', () => { const attention = new Attention(); for (const id of ['one', 'two']) assert.equal( attention.changed(session(id, 'running'), session(id), true, true), 'finished', ); attention.read('one'); assert.deepEqual([...attention.unread], ['two']); assert.equal( attention.changed(session('one', 'running'), session('one'), true, true), 'finished', ); assert.equal( attention.changed(session('two', 'running'), session('two'), true, true), null, ); assert.equal(attention.unread.size, 2);});
test('initial loads, attended chats, and unwatched sessions do not become unread', () => { const attention = new Attention(); assert.equal( attention.changed(undefined, session('one', 'idle', 'old'), true, true), null, ); assert.equal( attention.changed(session('one', 'running'), session('one'), true, false), null, ); assert.equal( attention.changed(session('one', 'running'), session('one'), false, true), null, ); assert.equal(attention.unread.size, 0);});
test('a complete turn missed between list reads still marks its new answer', () => { const attention = new Attention(); assert.equal( attention.changed( session('one', 'idle', 'old'), session('one', 'idle', 'new'), true, true, ), 'finished', ); attention.read('one'); assert.equal( attention.changed( session('one', 'idle', 'new'), session('one', 'idle', 'new'), true, true, ), null, ); attention.changed( session('two'), session('two', 'idle', null, { kind: 'approval' }), true, true, ); attention.prune(new Set(['two'])); assert.deepEqual([...attention.unread], ['two']);});
test('reading mail does not let its replay mark a chat unread again', () => { const attention = new Attention(); const mail = { mail_id: 'm1', sender_session_id: 'child', receiver_session_id: 'parent', kind: 'result', }; assert.equal(attention.mail(mail, true, true), 'mail'); attention.read('parent'); assert.equal(attention.mail(mail, true, true), null); assert.equal(attention.unread.size, 0);});
test('a completion in the viewed board stays unread without flashing, even after leaving', () => { const attention = new Attention(); assert.equal( attention.changed( session('one', 'running'), session('one'), true, true, true, ), 'finished', ); assert.deepEqual([...attention.unread], ['one']); assert.equal(attention.flashing.size, 0); attention.changed( session('one', 'running'), session('one'), true, true, false, ); assert.equal(attention.flashing.size, 0); attention.read('one'); attention.changed( session('one', 'running'), session('one'), true, true, false, ); assert.deepEqual([...attention.flashing], ['one']); attention.read('one'); assert.equal(attention.unread.size, 0); assert.equal(attention.flashing.size, 0);});
test('background-board flashes are pruned with unread state; mail on the viewed board stays quiet', () => { const attention = new Attention(); attention.changed( session('one', 'running'), session('one'), true, true, false, ); attention.mail( { mail_id: 'm1', sender_session_id: 'child', receiver_session_id: 'two', kind: 'result', }, true, true, true, ); assert.deepEqual([...attention.flashing], ['one']); assert.deepEqual([...attention.unread], ['one', 'two']); attention.prune(new Set(['two'])); assert.equal(attention.flashing.size, 0); assert.deepEqual([...attention.unread], ['two']);});