Update coverage reports and fix Ollama client abort handling

This commit is contained in:
2026-05-06 23:44:29 +02:00
parent 0920e0959e
commit cec8302dbe
15 changed files with 1945 additions and 1469 deletions
+114
View File
@@ -1,6 +1,7 @@
/**
* Unit tests for utility functions, particularly validation functions
*/
import { LogLevel, Logger } from '../src/utils';
import {
validateOllamaUrl,
validateModelName,
@@ -202,3 +203,116 @@ describe('Validation Functions', () => {
});
});
});
describe('Logger', () => {
beforeEach(() => {
// Reset logger level before each test
Logger.setLevel(LogLevel.DEBUG);
});
describe('setLevel', () => {
it('should set level using string values', () => {
Logger.setLevel('debug');
expect((Logger as any).minLevel).toBe(LogLevel.DEBUG);
Logger.setLevel('info');
expect((Logger as any).minLevel).toBe(LogLevel.INFO);
Logger.setLevel('warn');
expect((Logger as any).minLevel).toBe(LogLevel.WARN);
Logger.setLevel('error');
expect((Logger as any).minLevel).toBe(LogLevel.ERROR);
});
it('should set level using numeric values', () => {
Logger.setLevel(LogLevel.DEBUG);
expect((Logger as any).minLevel).toBe(LogLevel.DEBUG);
Logger.setLevel(LogLevel.INFO);
expect((Logger as any).minLevel).toBe(LogLevel.INFO);
Logger.setLevel(LogLevel.WARN);
expect((Logger as any).minLevel).toBe(LogLevel.WARN);
Logger.setLevel(LogLevel.ERROR);
expect((Logger as any).minLevel).toBe(LogLevel.ERROR);
});
it('should default to DEBUG for unknown string levels', () => {
Logger.setLevel('unknown-level');
expect((Logger as any).minLevel).toBe(LogLevel.DEBUG);
});
it('should be case insensitive for string levels', () => {
Logger.setLevel('DEBUG');
expect((Logger as any).minLevel).toBe(LogLevel.DEBUG);
Logger.setLevel('Info');
expect((Logger as any).minLevel).toBe(LogLevel.INFO);
});
});
describe('logging methods with different levels', () => {
it('should log debug messages when level is DEBUG', () => {
const consoleSpy = jest.spyOn(console, 'debug').mockImplementation();
Logger.setLevel('debug');
Logger.debug('test message', 'test-category');
Logger.info('test message', 'test-category');
Logger.warn('test message', 'test-category');
Logger.error('test message', 'test-category');
expect(consoleSpy).toHaveBeenCalledWith('[test-category] DEBUG: test message');
consoleSpy.mockRestore();
});
it('should not log debug messages when level is INFO', () => {
const consoleSpy = jest.spyOn(console, 'debug').mockImplementation();
Logger.setLevel('info');
Logger.debug('test message', 'test-category');
Logger.info('test message', 'test-category');
expect(consoleSpy).not.toHaveBeenCalled();
consoleSpy.mockRestore();
});
it('should not log debug or info messages when level is WARN', () => {
const consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation();
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
Logger.setLevel('warn');
Logger.debug('test message', 'test-category');
Logger.info('test message', 'test-category');
Logger.warn('test message', 'test-category');
expect(consoleDebugSpy).not.toHaveBeenCalled();
expect(consoleInfoSpy).not.toHaveBeenCalled();
consoleDebugSpy.mockRestore();
consoleInfoSpy.mockRestore();
});
it('should only log error messages when level is ERROR', () => {
const consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation();
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
Logger.setLevel('error');
Logger.debug('test message', 'test-category');
Logger.info('test message', 'test-category');
Logger.warn('test message', 'test-category');
Logger.error('test message', 'test-category');
expect(consoleDebugSpy).not.toHaveBeenCalled();
expect(consoleInfoSpy).not.toHaveBeenCalled();
expect(consoleWarnSpy).not.toHaveBeenCalled();
expect(consoleErrorSpy).toHaveBeenCalledWith('[test-category] ERROR: test message');
consoleDebugSpy.mockRestore();
consoleInfoSpy.mockRestore();
consoleWarnSpy.mockRestore();
consoleErrorSpy.mockRestore();
});
});
});