Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

1.4 KB
Raw Blame
import { expect, it } from 'vitest';
import { activityRows } from './activity-model';
import { emptyAgentsState, withEvent } from './agent-store';
import type { AgentEvent } from './agent-event';

const event = (patch: Partial<AgentEvent>): AgentEvent => ({
    agent: 'Ada', run: 'one', seq: 1, ts: 1000, tool: 'Read', phase: 'end',
    path: 'src/main.ts', detail: 'inspect', source: 'bridge', replay: false, ...patch,
});
const state = [event({}), event({ seq: 2, ts: 2000, tool: 'Edit', path: 'missing.ts' }),
    event({ agent: 'Ben', run: 'two', ts: 3000, path: '' })]
    .reduce(withEvent, emptyAgentsState());
const all = { agent: '', run: '', kind: '' as const };

it('keeps unmapped events and orders recorded activity newest first', () => {
    expect(activityRows(state, all).map((row) => row.path)).toEqual(['', 'missing.ts', 'src/main.ts']);
});
it('intersects agent, run and work kind filters', () => {
    expect(activityRows(state, { agent: 'Ada', run: 'one', kind: 'write' }))
        .toEqual([event({ seq: 2, ts: 2000, tool: 'Edit', path: 'missing.ts' })]);
    expect(activityRows(state, { ...all, agent: 'Ben', run: 'one' })).toEqual([]);
});
it('does not change the store when ordering or filtering', () => {
    const before = state.actors.map((actor) => actor.events.map((row) => row.seq));
    activityRows(state, all);
    expect(state.actors.map((actor) => actor.events.map((row) => row.seq))).toEqual(before);
});