Adds the agentMetrics table to SQLite schema for storing pre-computed per-agent event counts (questions, subagents, compactions), enabling listForRadar to fetch one row per agent instead of scanning log chunks. Also fixes pre-existing Drizzle snapshot chain collision in meta/ (0035/0036 snapshots had wrong prevId due to parallel agent branches) to unblock drizzle-kit generate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { createTestDatabase } from './test-helpers.js';
|
|
import { agentMetrics } from '../../schema.js';
|
|
|
|
describe('agentMetrics table', () => {
|
|
it('select from empty agentMetrics returns []', async () => {
|
|
const db = createTestDatabase();
|
|
const rows = await db.select().from(agentMetrics);
|
|
expect(rows).toEqual([]);
|
|
});
|
|
|
|
it('insert and select a metrics row round-trips correctly', async () => {
|
|
const db = createTestDatabase();
|
|
await db.insert(agentMetrics).values({
|
|
agentId: 'agent-abc',
|
|
questionsCount: 3,
|
|
subagentsCount: 1,
|
|
compactionsCount: 0,
|
|
updatedAt: new Date('2024-01-01T00:00:00Z'),
|
|
});
|
|
const rows = await db.select().from(agentMetrics);
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0].agentId).toBe('agent-abc');
|
|
expect(rows[0].questionsCount).toBe(3);
|
|
expect(rows[0].subagentsCount).toBe(1);
|
|
expect(rows[0].compactionsCount).toBe(0);
|
|
});
|
|
|
|
it('agentId is primary key — duplicate insert throws', async () => {
|
|
const db = createTestDatabase();
|
|
await db.insert(agentMetrics).values({
|
|
agentId: 'agent-dup',
|
|
questionsCount: 0,
|
|
subagentsCount: 0,
|
|
compactionsCount: 0,
|
|
updatedAt: new Date(),
|
|
});
|
|
await expect(
|
|
db.insert(agentMetrics).values({
|
|
agentId: 'agent-dup',
|
|
questionsCount: 1,
|
|
subagentsCount: 0,
|
|
compactionsCount: 0,
|
|
updatedAt: new Date(),
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
});
|