Unify TUI runtime commands with gateway and harden gateway restart
This commit is contained in:
@@ -241,6 +241,67 @@ describe('createAgentHandlers command fast-path', () => {
|
||||
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Cancellation requested');
|
||||
});
|
||||
|
||||
it('handles /runtime status via command fast-path without calling agent.process', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
const req: GatewayRequest = {
|
||||
id: 13,
|
||||
method: 'agent.send',
|
||||
params: {
|
||||
message: '/runtime status',
|
||||
connectionId: 'conn-1',
|
||||
metadata: { isCommand: true, command: 'runtime', commandArgs: 'status' },
|
||||
},
|
||||
};
|
||||
|
||||
await handlers['agent.send'](req, send);
|
||||
|
||||
expect(mockAgent.process).not.toHaveBeenCalled();
|
||||
expect((sent[0] as GatewayEvent).event).toBe('done');
|
||||
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Backend mode:');
|
||||
});
|
||||
|
||||
it('handles /runtime deactivate pi via shared backend mode service callbacks', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
let backendMode: 'config_default' | 'force_native' | 'force_pi_embedded' = 'force_pi_embedded';
|
||||
const handlersWithBackendMode = createAgentHandlers({
|
||||
sessionBridge: sessionBridge as unknown as AgentHandlerDeps['sessionBridge'],
|
||||
laneQueue: new LaneQueue(),
|
||||
sessionManager: sessionManager as unknown as AgentHandlerDeps['sessionManager'],
|
||||
commandRegistry,
|
||||
runtimeConfig: {
|
||||
backends: {
|
||||
default: 'pi_embedded',
|
||||
claude_code: { enabled: false },
|
||||
opencode: { enabled: false },
|
||||
codex: { enabled: false },
|
||||
gemini: { enabled: false },
|
||||
pi_embedded: { enabled: true },
|
||||
},
|
||||
} as unknown as AgentHandlerDeps['runtimeConfig'],
|
||||
getBackendMode: () => backendMode,
|
||||
setBackendMode: (mode) => {
|
||||
backendMode = mode;
|
||||
},
|
||||
});
|
||||
const req: GatewayRequest = {
|
||||
id: 14,
|
||||
method: 'agent.send',
|
||||
params: {
|
||||
message: '/runtime deactivate pi',
|
||||
connectionId: 'conn-1',
|
||||
metadata: { isCommand: true, command: 'runtime', commandArgs: 'deactivate pi' },
|
||||
},
|
||||
};
|
||||
|
||||
await handlersWithBackendMode['agent.send'](req, send);
|
||||
|
||||
expect(mockAgent.process).not.toHaveBeenCalled();
|
||||
expect(backendMode).toBe('force_native');
|
||||
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('deactivated globally');
|
||||
});
|
||||
|
||||
it('falls through to agent.process for unknown commands', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
|
||||
Reference in New Issue
Block a user