feat(telemetry): complete bb-buff.1.3 - Backend Liveness Refactor
STORY: The session backend needed to aggregate agent health from a live telemetry stream rather than static bead metadata. This refactor makes liveness signals real-time and accurate. COLLABORATION: We extended the ActivityEvent model with a native 'heartbeat' kind, updated extendActivityLease() to emit through the activity bus, and refactored getAgentLivenessMap() to prioritize heartbeat activity history over stale bead metadata. DELIVERABLES: - ActivityEvent extended with 'heartbeat' kind - extendActivityLease() emits heartbeats through activity bus - getAgentLivenessMap() prefers telemetry over static metadata - Registry APIs support projectRoot injection for testing - Tests verify preference logic via TDD VERIFICATION: - 93/93 tests PASSING - Heartbeat override verified in isolated temp projects CLOSES: bb-buff.1.3 BLOCKS: bb-buff.3.2, bb-buff.3.3, bb-buff.2.1
This commit is contained in:
parent
0016b57e37
commit
4ee550c333
36 changed files with 1380 additions and 541 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
import { IssuesEventBus, ActivityEventBus } from '../../src/lib/realtime';
|
||||
import { IssuesWatchManager } from '../../src/lib/watcher';
|
||||
|
|
@ -44,7 +45,7 @@ test('IssuesWatchManager emits event after file change in watched .beads path',
|
|||
assert.equal(events.length >= 1, true);
|
||||
});
|
||||
|
||||
test('IssuesWatchManager emits event after beads.db change', async () => {
|
||||
test('IssuesWatchManager emits telemetry event after beads.db change (not issues)', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'beadboard-watch-db-'));
|
||||
const beadsDir = path.join(root, '.beads');
|
||||
const dbPath = path.join(beadsDir, 'beads.db');
|
||||
|
|
@ -54,9 +55,9 @@ test('IssuesWatchManager emits event after beads.db change', async () => {
|
|||
const bus = new IssuesEventBus();
|
||||
const manager = new IssuesWatchManager({ eventBus: bus, debounceMs: 40 });
|
||||
|
||||
const events: string[] = [];
|
||||
const events: Array<{ kind: string; changedPath?: string }> = [];
|
||||
const stop = bus.subscribe((event) => {
|
||||
events.push(event.projectRoot);
|
||||
events.push({ kind: event.kind, changedPath: event.changedPath });
|
||||
});
|
||||
|
||||
await manager.startWatch(root);
|
||||
|
|
@ -67,7 +68,14 @@ test('IssuesWatchManager emits event after beads.db change', async () => {
|
|||
stop();
|
||||
await manager.stopAll();
|
||||
|
||||
assert.equal(events.length >= 1, true);
|
||||
// REGRESSION: beads.db should emit 'telemetry', not 'issues'
|
||||
// This prevents the "typing interrupt" refresh loop during agent heartbeats
|
||||
assert.equal(events.length >= 1, true, 'Expected at least one event');
|
||||
const dbEvents = events.filter(e => e.changedPath?.includes('beads.db'));
|
||||
assert.ok(dbEvents.length > 0, 'Expected beads.db change event');
|
||||
for (const event of dbEvents) {
|
||||
assert.equal(event.kind, 'telemetry', `beads.db change should emit 'telemetry', got '${event.kind}'. This prevents refresh loops during agent heartbeats.`);
|
||||
}
|
||||
});
|
||||
|
||||
test('IssuesWatchManager emits event after beads.db-wal change', async () => {
|
||||
|
|
@ -99,13 +107,15 @@ test('IssuesWatchManager emits event after beads.db-wal change', async () => {
|
|||
test('IssuesWatchManager emits ActivityEvent on issue change', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'beadboard-watch-activity-'));
|
||||
const beadsDir = path.join(root, '.beads');
|
||||
const issuesPath = path.join(beadsDir, 'issues.jsonl');
|
||||
|
||||
await fs.mkdir(beadsDir, { recursive: true });
|
||||
|
||||
// Initial state: 1 issue
|
||||
const issuev1 = { id: 'bb-1', title: 'Task A', status: 'open' };
|
||||
await fs.writeFile(issuesPath, JSON.stringify(issuev1) + '\n', 'utf8');
|
||||
// Initialize bd in temp dir
|
||||
execSync('bd init --prefix bb --force', { cwd: root, stdio: 'ignore' });
|
||||
|
||||
// Initial state: 1 issue via bd
|
||||
execSync('bd create "Task A" --id bb-1', { cwd: root, stdio: 'ignore' });
|
||||
execSync('bd update bb-1 --status open', { cwd: root, stdio: 'ignore' });
|
||||
|
||||
const issuesBus = new IssuesEventBus();
|
||||
const activityBus = new ActivityEventBus();
|
||||
|
|
@ -126,16 +136,25 @@ test('IssuesWatchManager emits ActivityEvent on issue change', async () => {
|
|||
// Wait for initial read to settle
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Modify issue: status change
|
||||
const issuev2 = { ...issuev1, status: 'in_progress' };
|
||||
await fs.writeFile(issuesPath, JSON.stringify(issuev2) + '\n', 'utf8');
|
||||
// Modify issue via bd: status change
|
||||
execSync('bd update bb-1 --status in_progress', { cwd: root, stdio: 'ignore' });
|
||||
|
||||
// Wait for debounce + processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
// Wait for debounce + processing with retry loop
|
||||
let found = false;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
if (activities.includes('status_changed:bb-1')) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stop();
|
||||
await manager.stopAll();
|
||||
|
||||
// Expect status_changed for bb-1
|
||||
assert.ok(activities.includes('status_changed:bb-1'), `Expected status_changed event. Got: ${activities.join(', ')}`);
|
||||
if (!found) {
|
||||
console.error('WATCHER FAIL. Activities found:', JSON.stringify(activities, null, 2));
|
||||
}
|
||||
assert.ok(found, `Expected status_changed event. Got: ${activities.join(', ')}`);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue