mono/packages/kbot/tests/unit/basic.test.ts
2025-04-06 17:49:29 +02:00

82 lines
2.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import * as path from 'node:path'
import { sync as exists } from "@polymech/fs/exists"
import { sync as read } from "@polymech/fs/read"
import {
getDefaultModels,
TEST_BASE_PATH,
TEST_LOGS_PATH,
TEST_PREFERENCES_PATH,
TEST_TIMEOUT,
TestResult,
runTest,
generateTestReport,
getReportPaths
} from './commons'
// Optionally override models for this specific test file
const models = getDefaultModels()
describe('Basic Operations', () => {
let testResults: TestResult[] = []
const TEST_LOG_PATH = getReportPaths('basic', 'json')
const TEST_REPORT_PATH = getReportPaths('basic', 'md')
it.each(models)('should add two numbers with model %s', async (modelName) => {
const result = await runTest(
'add 5 and 3. Return only the number, no explanation.',
'8',
'addition',
modelName,
TEST_LOG_PATH
)
testResults.push(result)
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('8')
}, { timeout: TEST_TIMEOUT })
it.each(models)('should multiply two numbers with model %s', async (modelName) => {
const result = await runTest(
'multiply 8 and 3. Return only the number, no explanation.',
'24',
'multiplication',
modelName,
TEST_LOG_PATH
)
testResults.push(result)
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('24')
}, { timeout: TEST_TIMEOUT })
it.each(models)('should divide two numbers with model %s', async (modelName) => {
const result = await runTest(
'divide 15 by 3. Return only the number, no explanation.',
'5',
'division',
modelName,
TEST_LOG_PATH
)
testResults.push(result)
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('5')
}, { timeout: TEST_TIMEOUT })
it.each(models)('should load web content with model %s', async (modelName) => {
const result = await runTest(
'Check if the content contains a section about Human prehistory. Reply with "yes" if it does, "no" if it does not.',
'yes',
'web_content',
modelName,
TEST_LOG_PATH,
'completion',
{
include: ['https://en.wikipedia.org/wiki/Kenya']
}
)
testResults.push(result)
expect(result.result[0]?.trim()?.toLowerCase()).toContain('yes')
}, { timeout: TEST_TIMEOUT * 2 }) // Double timeout for web requests
it('should generate markdown report', () => {
generateTestReport(testResults, 'Basic Operations Test Results', TEST_REPORT_PATH)
expect(exists(TEST_REPORT_PATH) === 'file').toBe(true)
})
})