feat(runtime): forward Flynn prompt to pi and harden backend mode commands
This commit is contained in:
+155
-3
@@ -1348,6 +1348,9 @@ describe('daemon external backend integration', () => {
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
expect(piBackend.process).toHaveBeenCalled();
|
||||
expect(piBackend.process).toHaveBeenCalledWith(expect.objectContaining({
|
||||
systemPrompt: 'test prompt',
|
||||
}));
|
||||
expect(processSpy).not.toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'pi embedded response' }));
|
||||
});
|
||||
@@ -1425,7 +1428,80 @@ describe('daemon external backend integration', () => {
|
||||
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'native guarded response' }));
|
||||
});
|
||||
|
||||
it('supports manual global pi deactivation and re-activation via /backend command', async () => {
|
||||
it('forces native processing for pi_embedded no-tools mode on quick-check execution intent', async () => {
|
||||
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
|
||||
.mockResolvedValue('native guarded response');
|
||||
const history: Array<{ role: 'user' | 'assistant'; content: string }> = [];
|
||||
const session = {
|
||||
id: 'telegram:pi-no-tools-quick-check',
|
||||
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 piBackend = {
|
||||
name: 'pi_embedded',
|
||||
process: vi.fn(async () => 'pi embedded response'),
|
||||
};
|
||||
|
||||
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: true },
|
||||
},
|
||||
compaction: { enabled: false },
|
||||
models: { default: { provider: 'anthropic', model: 'claude' } },
|
||||
} as unknown as MessageRouterDeps['config'],
|
||||
externalBackends: { pi_embedded: piBackend } as unknown as MessageRouterDeps['externalBackends'],
|
||||
defaultName: 'pi_embedded',
|
||||
});
|
||||
|
||||
const reply = vi.fn(async (_message: OutboundMessage) => {});
|
||||
await router.handler({
|
||||
id: 'm-pi-no-tools-quick-check',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-no-tools-quick-check',
|
||||
text: 'run a quick check',
|
||||
timestamp: Date.now(),
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
expect(piBackend.process).not.toHaveBeenCalled();
|
||||
expect(processSpy).toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'native guarded response' }));
|
||||
});
|
||||
|
||||
it('supports manual global pi deactivation and re-activation via /runtime alias', async () => {
|
||||
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
|
||||
.mockResolvedValue('native fallback response');
|
||||
const history: Array<{ role: 'user' | 'assistant'; content: string }> = [];
|
||||
@@ -1499,9 +1575,9 @@ describe('daemon external backend integration', () => {
|
||||
id: 'm-backend-deactivate',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-manual-toggle',
|
||||
text: '/backend deactivate pi',
|
||||
text: '/runtime deactivate pi',
|
||||
timestamp: Date.now(),
|
||||
metadata: { isCommand: true, command: 'backend', commandArgs: 'deactivate pi' },
|
||||
metadata: { isCommand: true, command: 'runtime', commandArgs: 'deactivate pi' },
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
await router.handler({
|
||||
@@ -1536,6 +1612,82 @@ describe('daemon external backend integration', () => {
|
||||
expect(backendMode).toBe('force_pi_embedded');
|
||||
expect(piBackend.process).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('accepts full-command backend subcommand input and still returns status', 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-runtime-status-normalization',
|
||||
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 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: {} as unknown as MessageRouterDeps['externalBackends'],
|
||||
getBackendMode: () => 'config_default',
|
||||
setBackendMode: vi.fn(),
|
||||
});
|
||||
|
||||
const reply = vi.fn(async (_message: OutboundMessage) => {});
|
||||
|
||||
await router.handler({
|
||||
id: 'm-runtime-status-normalized',
|
||||
channel: 'telegram',
|
||||
senderId: 'pi-runtime-status-normalization',
|
||||
text: '/runtime status',
|
||||
timestamp: Date.now(),
|
||||
metadata: { isCommand: true, command: 'runtime', commandArgs: '/runtime status' },
|
||||
} as MessageRouterInput, reply);
|
||||
|
||||
expect(processSpy).not.toHaveBeenCalled();
|
||||
expect(reply).toHaveBeenCalledWith(expect.objectContaining({
|
||||
text: expect.stringContaining('Backend mode:'),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('daemon audio routing integration', () => {
|
||||
|
||||
Reference in New Issue
Block a user