feat: add /backend command handler to MinimalTui
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { formatPrompt, parseCommand } from './minimal.js';
|
||||
import type { ModelConfig } from '../../config/schema.js';
|
||||
import { MinimalTui } from './minimal.js';
|
||||
|
||||
describe('formatPrompt', () => {
|
||||
it('formats default prompt', () => {
|
||||
@@ -34,3 +36,45 @@ describe('parseCommand (re-exported)', () => {
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('MinimalTui backend command', () => {
|
||||
it('switches local backend when provider is configured', async () => {
|
||||
const mockSession = {
|
||||
id: 'test',
|
||||
getHistory: () => [],
|
||||
addMessage: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
};
|
||||
|
||||
const mockRouter = {
|
||||
getTier: () => 'default' as const,
|
||||
getAvailableTiers: () => ['default', 'local'],
|
||||
setTier: vi.fn(() => true),
|
||||
getLocalProviderName: () => 'ollama',
|
||||
setLocalClient: vi.fn(),
|
||||
chat: vi.fn(),
|
||||
getClient: vi.fn(),
|
||||
};
|
||||
|
||||
const localProviders: Record<string, ModelConfig> = {
|
||||
llamacpp: {
|
||||
provider: 'llamacpp',
|
||||
model: '',
|
||||
endpoint: 'http://localhost:8080',
|
||||
},
|
||||
};
|
||||
|
||||
const tui = new MinimalTui({
|
||||
session: mockSession as any,
|
||||
modelClient: mockRouter as any,
|
||||
modelRouter: mockRouter as any,
|
||||
systemPrompt: 'test',
|
||||
localProviders,
|
||||
});
|
||||
|
||||
// Access private method for testing
|
||||
await (tui as any).handleBackendCommand('llamacpp');
|
||||
|
||||
expect(mockRouter.setLocalClient).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user