audit follow-up: burn down lint hotspots and dedupe channel gating flows

This commit is contained in:
William Valentin
2026-02-15 22:44:04 -08:00
parent 06ff94e197
commit 1a075e62b0
10 changed files with 518 additions and 281 deletions
+51 -42
View File
@@ -7,6 +7,10 @@ import { AgentOrchestrator } from '../backends/index.js';
import { CommandRegistry, registerBuiltinCommands } from '../commands/index.js';
import { ComponentRegistry } from '../intents/index.js';
import { RoutingPolicy } from '../routing/index.js';
import type { OutboundMessage } from '../channels/index.js';
type MessageRouterDeps = Parameters<typeof createMessageRouter>[0];
type MessageRouterInput = Parameters<ReturnType<typeof createMessageRouter>['handler']>[0];
describe('daemon agent routing integration', () => {
it('resolves agent config for channel messages', () => {
@@ -25,7 +29,9 @@ describe('daemon agent routing integration', () => {
// Discord user gets coder
const discordAgent = router.resolve('discord', 'user123');
expect(discordAgent).toBe('coder');
expect(registry.get(discordAgent!)!.systemPrompt).toBe('Write code.');
expect(discordAgent).toBeDefined();
const discordAgentConfig = discordAgent ? registry.get(discordAgent) : undefined;
expect(discordAgentConfig?.systemPrompt).toBe('Write code.');
// Telegram admin gets coder
const telegramAdmin = router.resolve('telegram', 'admin');
@@ -34,7 +40,9 @@ describe('daemon agent routing integration', () => {
// Random telegram user gets assistant
const telegramUser = router.resolve('telegram', 'random');
expect(telegramUser).toBe('assistant');
expect(registry.get(telegramUser!)!.systemPrompt).toBe('Be helpful.');
expect(telegramUser).toBeDefined();
const telegramUserConfig = telegramUser ? registry.get(telegramUser) : undefined;
expect(telegramUserConfig?.systemPrompt).toBe('Be helpful.');
});
it('uses default agent when no routing configured', () => {
@@ -91,18 +99,18 @@ describe('daemon command fast-path integration', () => {
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as any,
} as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as any,
toolExecutor: {} as any,
} as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
@@ -118,7 +126,7 @@ describe('daemon command fast-path integration', () => {
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
});
@@ -129,7 +137,7 @@ describe('daemon command fast-path integration', () => {
senderId: 'user-1',
text: '/reset',
metadata: { isCommand: true, command: 'reset' },
} as any, reply);
} as MessageRouterInput, reply);
expect(processSpy).not.toHaveBeenCalled();
expect(session.deleteConfig).toHaveBeenCalledWith('modelTier');
@@ -155,18 +163,18 @@ describe('daemon command fast-path integration', () => {
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as any,
} as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as any,
toolExecutor: {} as any,
} as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
@@ -182,7 +190,7 @@ describe('daemon command fast-path integration', () => {
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
});
@@ -193,7 +201,7 @@ describe('daemon command fast-path integration', () => {
senderId: 'user-4',
text: '/model fast',
metadata: { isCommand: true, command: 'model', commandArgs: 'fast' },
} as any, reply);
} as MessageRouterInput, reply);
expect(processSpy).not.toHaveBeenCalled();
expect(setModelTierSpy).toHaveBeenCalledWith('fast');
@@ -239,18 +247,18 @@ describe('daemon command fast-path integration', () => {
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as any,
} as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as any,
toolExecutor: {} as any,
} as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
intents: { enabled: true },
agents: {
@@ -267,7 +275,7 @@ describe('daemon command fast-path integration', () => {
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
intentRegistry,
agentConfigRegistry,
@@ -280,7 +288,7 @@ describe('daemon command fast-path integration', () => {
senderId: 'user-2',
text: 'deploy backend now',
metadata: { isCommand: true, command: 'reset' },
} as any, vi.fn(async () => {}));
} as MessageRouterInput, vi.fn(async () => {}));
const keys = Array.from(router.agents.keys());
expect(keys.some(key => key.includes(':coder'))).toBe(true);
@@ -332,18 +340,18 @@ describe('daemon command fast-path integration', () => {
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as any,
} as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as any,
toolExecutor: {} as any,
} as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
intents: { enabled: true },
agents: {
@@ -360,7 +368,7 @@ describe('daemon command fast-path integration', () => {
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
intentRegistry,
routingPolicy,
@@ -374,7 +382,7 @@ describe('daemon command fast-path integration', () => {
senderId: 'user-3',
text: 'deploy backend now',
metadata: { isCommand: true, command: 'reset' },
} as any, vi.fn(async () => {}));
} as MessageRouterInput, vi.fn(async () => {}));
const keys = Array.from(router.agents.keys());
expect(keys.some(key => key.includes(':assistant'))).toBe(true);
@@ -404,15 +412,15 @@ describe('daemon audio routing integration', () => {
registerBuiltinCommands(commandRegistry);
const router = createMessageRouter({
sessionManager: { getSession: vi.fn(() => session) } as any,
sessionManager: { getSession: vi.fn(() => session) } as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['default'],
getAllLabels: () => ({ default: 'default' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: { clone() { return this; }, register: vi.fn() } as any,
toolExecutor: {} as any,
toolRegistry: { clone() { return this; }, register: vi.fn() } as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
@@ -430,7 +438,7 @@ describe('daemon audio routing integration', () => {
// Anthropic doesn't support native audio; ensures routing hits the non-audio path.
models: { default: { provider: 'anthropic', model: 'claude' } },
audio: { enabled: false },
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
});
@@ -442,11 +450,12 @@ describe('daemon audio routing integration', () => {
text: '',
attachments: [{ mimeType: 'audio/ogg', data: 'ZGF0YQ==', filename: 'voice.ogg' }],
timestamp: Date.now(),
} as any, reply);
} as MessageRouterInput, reply);
expect(processSpy).not.toHaveBeenCalled();
expect(reply).toHaveBeenCalledTimes(1);
const msg = (reply.mock.calls[0] as unknown as any[])[0] as { text?: string };
const firstReply = reply.mock.calls[0]?.[0] as OutboundMessage | undefined;
const msg = firstReply as { text?: string };
expect(String(msg.text)).toContain('audio transcription is not configured');
});
@@ -454,12 +463,12 @@ describe('daemon audio routing integration', () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('ok');
// Mock transcription endpoint call.
const fetchSpy = vi.spyOn(globalThis, 'fetch' as any).mockResolvedValue({
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
statusText: 'OK',
json: async () => ({ text: 'hello world' }),
} as any);
} as Response);
const session = {
id: 'telegram:user-voice-2',
@@ -476,15 +485,15 @@ describe('daemon audio routing integration', () => {
registerBuiltinCommands(commandRegistry);
const router = createMessageRouter({
sessionManager: { getSession: vi.fn(() => session) } as any,
sessionManager: { getSession: vi.fn(() => session) } as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['default'],
getAllLabels: () => ({ default: 'default' }),
getLabel: (tier: string) => tier,
} as any,
} as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: { clone() { return this; }, register: vi.fn() } as any,
toolExecutor: {} as any,
toolRegistry: { clone() { return this; }, register: vi.fn() } as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
@@ -504,7 +513,7 @@ describe('daemon audio routing integration', () => {
enabled: true,
provider: { type: 'openai', endpoint: 'https://example.com/v1/audio/transcriptions', api_key: 'sk-test', model: 'whisper-1' },
},
} as any,
} as MessageRouterDeps['config'],
commandRegistry,
});
@@ -519,14 +528,14 @@ describe('daemon audio routing integration', () => {
{ mimeType: 'image/jpeg', data: 'aW1n', filename: 'img.jpg' },
],
timestamp: Date.now(),
} as any, reply);
} as MessageRouterInput, reply);
expect(fetchSpy).toHaveBeenCalled();
expect(processSpy).toHaveBeenCalledTimes(1);
const [calledText, calledAttachments] = processSpy.mock.calls[0] ?? [];
expect(String(calledText)).toContain('[Voice message]: hello world');
expect(String(calledText)).toContain('caption');
const atts = calledAttachments as any[] | undefined;
const atts = calledAttachments as Array<{ mimeType: string }> | undefined;
expect(atts?.some(a => a.mimeType === 'audio/ogg')).toBe(false);
expect(atts?.some(a => a.mimeType === 'image/jpeg')).toBe(true);
});