git clone https://garage44.eu/jeroen/midas.git.. /web/src/lib/feed.test.ts
import {expect, test} from 'bun:test'
import {buildFeed, involving} from '@/lib/feed'
import type {WorkspaceEvent} from '@/lib/types'
const ev = (kind: string, ts: string, fields: Record<string, unknown>): WorkspaceEvent => ({kind, ts: `2026-10-21T10:${ts}Z`, ...fields})
test('without ids, a note is read once its recipient (or its gate) took notes after it', () => {
const feed = buildFeed([
ev('note', '00:00', {actor: 'a', to: 'b', note_kind: 'say', text: 'hi'}),
ev('note', '01:00', {actor: 'hub', to: 'c', note_kind: 'nudge', text: 'release it'}),
ev('notes_taken', '02:00', {actor: 'gate-b', notes: [{kind: 'say', age_s: 120}]}),
ev('note', '03:00', {actor: 'a', to: 'b', text: 'and again'}),
])
expect(feed.map((m) => [m.from, m.to, m.read])).toEqual([
['a', 'b', true],
['hub', 'c', false],
['a', 'b', false],
])
})
test('with ids, read by id; an expired note says why', () => {
const feed = buildFeed([
ev('note', '00:00', {actor: 'a', to: 'b', id: 'n1', text: 'one'}),
ev('note', '00:30', {actor: 'a', to: 'b', id: 'n2', text: 'two'}),
ev('notes_taken', '01:00', {actor: 'b', ids: ['n1']}),
ev('note', '02:00', {actor: 'a', to: 'gone', id: 'n3', text: 'three'}),
ev('note_expired', '03:00', {id: 'n3', to: 'gone', from: 'a', reason: 'session_ended'}),
])
expect(feed.map((m) => [m.id, m.read, m.expired])).toEqual([
['n1', true, null],
['n2', false, null],
['n3', false, 'session_ended'],
])
})
test('a question goes to the person, its answer back to the session that asked', () => {
const feed = buildFeed([
ev('decision_asked', '00:00', {actor: 's1', id: 'd1', question: 'Wait?', options: ['Yes', 'No']}),
ev('decision_answered', '01:00', {actor: 'web:sam', id: 'd1', answer: 'Yes', note: 'after lunch'}),
])
expect(feed.map((m) => [m.from, m.to, m.kind, m.text])).toEqual([
['s1', 'you', 'question', 'Wait?\n(Yes / No)'],
['you', 's1', 'answer', 'd1: Yes — after lunch'],
])
expect(involving(feed, 's1')).toHaveLength(2)
expect(involving(feed, 's2')).toHaveLength(0)
})