46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
|
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||
|
|
import * as smartchat from '../ts/index.js';
|
||
|
|
|
||
|
|
tap.test('should export ChatSession class', async () => {
|
||
|
|
expect(smartchat.ChatSession).toBeTypeOf('function');
|
||
|
|
});
|
||
|
|
|
||
|
|
tap.test('ChatSession should initialize with options', async () => {
|
||
|
|
// Use a mock model (just needs to be an object)
|
||
|
|
const mockModel = {} as any;
|
||
|
|
const session = new smartchat.ChatSession({ model: mockModel });
|
||
|
|
expect(session).toBeInstanceOf(smartchat.ChatSession);
|
||
|
|
});
|
||
|
|
|
||
|
|
tap.test('ChatSession should track usage', async () => {
|
||
|
|
const mockModel = {} as any;
|
||
|
|
const session = new smartchat.ChatSession({ model: mockModel });
|
||
|
|
const usage = session.getUsage();
|
||
|
|
expect(usage.turns).toEqual(0);
|
||
|
|
expect(usage.totalTokens).toEqual(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
tap.test('ChatSession should manage messages', async () => {
|
||
|
|
const mockModel = {} as any;
|
||
|
|
const session = new smartchat.ChatSession({ model: mockModel });
|
||
|
|
|
||
|
|
expect(session.getMessages()).toHaveLength(0);
|
||
|
|
|
||
|
|
// Set messages
|
||
|
|
const fakeMessages = [{ role: 'user' as const, content: 'hello' }] as any[];
|
||
|
|
session.setMessages(fakeMessages);
|
||
|
|
expect(session.getMessages()).toHaveLength(1);
|
||
|
|
|
||
|
|
// Clear
|
||
|
|
session.clear();
|
||
|
|
expect(session.getMessages()).toHaveLength(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
tap.test('ChatSession should report busy state', async () => {
|
||
|
|
const mockModel = {} as any;
|
||
|
|
const session = new smartchat.ChatSession({ model: mockModel });
|
||
|
|
expect(session.isBusy()).toBeFalse();
|
||
|
|
});
|
||
|
|
|
||
|
|
export default tap.start();
|