import { afterEach, describe, expect, it, vi } from 'vitest'; import type { AgentPersona } from '@waggle/agent'; import { ExecutorRegistry } from '../../src/local/executor-registry.js'; function persona(id: string, overrides: Partial = {}): AgentPersona { return { id, name: id, description: '', icon: '', systemPrompt: '', modelPreference: '', tools: [], workspaceAffinity: [], suggestedCommands: [], defaultWorkflow: null, ...overrides, }; } const PERSONAS = [ persona('writer'), persona('coordinator'), persona('analyst'), persona('general-purpose'), persona('researcher'), persona('coder'), persona('planner', { isReadOnly: true }), ]; afterEach(() => { vi.restoreAllMocks(); }); describe('ExecutorRegistry', () => { it('offers the five v1 personas and no external coding agents', async () => { const registry = new ExecutorRegistry({ personas: () => PERSONAS }); const candidates = await registry.snapshot(1_000); expect(candidates.map((candidate) => candidate.id)).toEqual([ 'persona:general-purpose', 'persona:coder', 'persona:writer', 'persona:researcher', 'persona:analyst', ]); expect(candidates.find((candidate) => candidate.id === 'persona:coder')).toMatchObject({ kind: 'persona', authClass: 'api-key', installed: true, healthy: true, rateLimit: { state: 'unknown' }, supportsHeadless: false, egressDestination: 'configured model provider', taskFit: { coding: 0.85, writing: 0.3 }, }); }); it('expires rate-limit observations', async () => { vi.spyOn(Date, 'now').mockReturnValue(10_000); const registry = new ExecutorRegistry({ personas: () => PERSONAS }); registry.noteRateLimit('persona:coder', null); const exhausted = (await registry.snapshot(10_000)) .find((candidate) => candidate.id === 'persona:coder'); expect(exhausted?.rateLimit).toEqual({ state: 'observed_exhausted' }); const recovered = (await registry.snapshot(10_000 + 15 * 60_000)) .find((candidate) => candidate.id === 'persona:coder'); expect(recovered?.rateLimit).toEqual({ state: 'available' }); registry.noteRateLimit('persona:coder', 2_000_000); const withReset = (await registry.snapshot(1_999_999)) .find((candidate) => candidate.id === 'persona:coder'); expect(withReset?.rateLimit).toEqual({ state: 'observed_exhausted', resumeAtMs: 2_000_000, }); registry.noteHealthy('persona:coder'); const healthy = (await registry.snapshot(1_999_999)) .find((candidate) => candidate.id === 'persona:coder'); expect(healthy?.rateLimit).toEqual({ state: 'available' }); }); });