feat: add persisted manual pi backend mode controls
This commit is contained in:
@@ -1424,6 +1424,118 @@ describe('daemon external backend integration', () => {
|
||||
expect(processSpy).toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'native guarded response' }));
|
||||
});
|
||||
|
||||
it('supports manual global pi deactivation and re-activation via /backend command', async () => {
|
||||
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
|
||||
.mockResolvedValue('native fallback response');
|
||||
const history: Array<{ role: 'user' | 'assistant'; content: string }> = [];
|
||||
const session = {
|
||||
id: 'telegram:pi-manual-toggle',
|
||||
addMessage: vi.fn((msg: { role: 'user' | 'assistant'; content: string }) => {
|
||||
history.push(msg);
|
||||
return msg;
|
||||
}),
|
||||
getHistory: vi.fn(() => [...history]),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
getConfig: vi.fn(() => undefined),
|
||||
setConfig: vi.fn(),
|
||||
deleteConfig: vi.fn(),
|
||||
};
|
||||
|
||||
const commandRegistry = new CommandRegistry();
|
||||
registerBuiltinCommands(commandRegistry);
|
||||
|
||||
const piBackend = {
|
||||
name: 'pi_embedded',
|
||||
process: vi.fn(async () => 'pi embedded response'),
|
||||
};
|
||||
|
||||
let backendMode: 'config_default' | 'force_native' | 'force_pi_embedded' = 'force_pi_embedded';
|
||||
const router = createMessageRouter({
|
||||
sessionManager: { getSession: vi.fn(() => session) } as unknown as MessageRouterDeps['sessionManager'],
|
||||
modelRouter: {
|
||||
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
|
||||
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
|
||||
getLabel: (tier: string) => tier,
|
||||
} as unknown as MessageRouterDeps['modelRouter'],
|
||||
systemPrompt: 'test prompt',
|
||||
toolRegistry: {
|
||||
clone() { return this; },
|
||||
register: vi.fn(),
|
||||
} as unknown as MessageRouterDeps['toolRegistry'],
|
||||
toolExecutor: {} as unknown as MessageRouterDeps['toolExecutor'],
|
||||
config: {
|
||||
agents: {
|
||||
primary_tier: 'default',
|
||||
delegation: {
|
||||
compaction: 'fast',
|
||||
memory_extraction: 'fast',
|
||||
classification: 'fast',
|
||||
tool_summarisation: 'fast',
|
||||
complex_reasoning: 'complex',
|
||||
},
|
||||
max_delegation_depth: 3,
|
||||
max_iterations: 10,
|
||||
},
|
||||
backends: {
|
||||
pi_embedded: { no_tools_mode: false },
|
||||
},
|
||||
compaction: { enabled: false },
|
||||
models: { default: { provider: 'anthropic', model: 'claude' } },
|
||||
} as unknown as MessageRouterDeps['config'],
|
||||
commandRegistry,
|
||||
externalBackends: { pi_embedded: piBackend } as unknown as MessageRouterDeps['externalBackends'],
|
||||
defaultName: 'pi_embedded',
|
||||
getBackendMode: () => backendMode,
|
||||
setBackendMode: (mode) => {
|
||||
backendMode = mode;
|
||||
},
|
||||
});
|
||||
|
||||
const reply = vi.fn(async (_message: OutboundMessage) => {});
|
||||
|
||||
await router.handler({
|
||||
id: 'm-backend-deactivate',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-manual-toggle',
|
||||
text: '/backend deactivate pi',
|
||||
timestamp: Date.now(),
|
||||
metadata: { isCommand: true, command: 'backend', commandArgs: 'deactivate pi' },
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
await router.handler({
|
||||
id: 'm-after-deactivate',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-manual-toggle',
|
||||
text: 'hello after deactivate',
|
||||
timestamp: Date.now(),
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
expect(backendMode).toBe('force_native');
|
||||
expect(piBackend.process).not.toHaveBeenCalled();
|
||||
expect(processSpy).toHaveBeenCalled();
|
||||
|
||||
await router.handler({
|
||||
id: 'm-backend-activate',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-manual-toggle',
|
||||
text: '/backend activate pi',
|
||||
timestamp: Date.now(),
|
||||
metadata: { isCommand: true, command: 'backend', commandArgs: 'activate pi' },
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
await router.handler({
|
||||
id: 'm-after-activate',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-manual-toggle',
|
||||
text: 'hello after activate',
|
||||
timestamp: Date.now(),
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
expect(backendMode).toBe('force_pi_embedded');
|
||||
expect(piBackend.process).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('daemon audio routing integration', () => {
|
||||
|
||||
Reference in New Issue
Block a user