Unify TUI runtime commands with gateway and harden gateway restart
This commit is contained in:
@@ -403,7 +403,33 @@ describe('MinimalTui backend command', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('prints guidance when /runtime is invoked in TUI mode', async () => {
|
||||
it('forwards /runtime command through runtime command callback', async () => {
|
||||
const mockSession = {
|
||||
id: 'test',
|
||||
getHistory: () => [],
|
||||
addMessage: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
};
|
||||
const onRuntimeCommand = vi.fn(async () => 'Backend mode: config_default');
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
try {
|
||||
const tui = new MinimalTui({
|
||||
session: asSession(mockSession),
|
||||
modelClient: asModelClient({}),
|
||||
systemPrompt: 'test',
|
||||
onRuntimeCommand,
|
||||
});
|
||||
|
||||
await minimalTuiPrivates(tui).handleCommand({ type: 'runtime', input: 'status' });
|
||||
expect(onRuntimeCommand).toHaveBeenCalledWith('status');
|
||||
expect(logSpy).toHaveBeenCalledWith('Backend mode: config_default\n');
|
||||
} finally {
|
||||
logSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('prints guidance when runtime command service is unavailable', async () => {
|
||||
const mockSession = {
|
||||
id: 'test',
|
||||
getHistory: () => [],
|
||||
@@ -420,7 +446,33 @@ describe('MinimalTui backend command', () => {
|
||||
});
|
||||
|
||||
await minimalTuiPrivates(tui).handleCommand({ type: 'runtime', input: 'status' });
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Runtime backend mode command is not available in this TUI mode.'));
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Runtime backend mode command service is unavailable in this TUI session.'));
|
||||
} finally {
|
||||
logSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps /backend status local-only and does not invoke runtime command callback', async () => {
|
||||
const mockSession = {
|
||||
id: 'test',
|
||||
getHistory: () => [],
|
||||
addMessage: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
};
|
||||
const onRuntimeCommand = vi.fn(async () => 'should not be called');
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
try {
|
||||
const tui = new MinimalTui({
|
||||
session: asSession(mockSession),
|
||||
modelClient: asModelClient({}),
|
||||
systemPrompt: 'test',
|
||||
onRuntimeCommand,
|
||||
});
|
||||
|
||||
await minimalTuiPrivates(tui).handleCommand({ type: 'backend', provider: 'status' });
|
||||
expect(onRuntimeCommand).not.toHaveBeenCalled();
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Backend switching not available.'));
|
||||
} finally {
|
||||
logSpy.mockRestore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user