feat: add /backend command handler to MinimalTui

This commit is contained in:
William Valentin
2026-02-05 13:36:36 -08:00
parent 465b4a0c3c
commit f722cf2bf0
2 changed files with 113 additions and 1 deletions
+45 -1
View File
@@ -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();
});
});