CoolFace
Modelpublic

AXERA-TECH/lite_webui

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes7downloads
context.test.js65 linesDownload Raw Back to tests
1import { describe, expect, it } from 'vitest';2import { formatCompactTokenCount } from '../src/api.js';3import {4  DEFAULT_CONTEXT_LIMIT_TOKENS,5  DEFAULT_CONTEXT_RESET_THRESHOLD_PERCENT,6  resolveContextConfig,7  estimateThreadTokens,8} from '../src/context.js';9 10describe('context helpers – resolveContextConfig', () => {11  it('falls back to the default context window when nothing is configured', () => {12    const config = resolveContextConfig({}, '');13    expect(config.maxTokens).toBe(DEFAULT_CONTEXT_LIMIT_TOKENS);14    expect(config.resetPercent).toBe(DEFAULT_CONTEXT_RESET_THRESHOLD_PERCENT);15    expect(config.source).toBe('default');16  });17 18  it('prefers a manually configured context window', () => {19    const config = resolveContextConfig({ contextLimitTokens: 65536 }, 'qwen-32k');20    expect(config.maxTokens).toBe(65536);21    expect(config.source).toBe('manual');22  });23 24  it('does not infer context length from model ids anymore', () => {25    const config = resolveContextConfig({ contextLimitTokens: null }, 'qwen-128k');26    expect(config.maxTokens).toBe(DEFAULT_CONTEXT_LIMIT_TOKENS);27    expect(config.source).toBe('default');28  });29 30  it('respects thresholds below the default warning band', () => {31    const config = resolveContextConfig({32      contextLimitTokens: 4096,33      contextResetThresholdPercent: 70,34    }, '');35 36    expect(config.resetTokens).toBe(Math.floor(4096 * 0.7));37    expect(config.warnTokens).toBe(config.resetTokens);38  });39 40  it('keeps resetTokens below the hard window when threshold percent is too aggressive', () => {41    const config = resolveContextConfig({42      contextLimitTokens: 32768,43      contextResetThresholdPercent: 95,44    }, '');45 46    expect(config.warnTokens).toBe(Math.floor(32768 * 0.8));47    expect(config.resetTokens).toBe(30720);48  });49});50 51describe('context helpers – estimateThreadTokens', () => {52  it('includes pending messages in the projected estimate', () => {53    const messages = [{ role: 'user', content: 'hello world' }];54    const pending = { role: 'assistant', content: 'reply' };55 56    expect(estimateThreadTokens(messages, pending)).toBeGreaterThan(estimateThreadTokens(messages));57  });58});59 60describe('api helpers – formatCompactTokenCount', () => {61  it('keeps 4k-class windows readable without rounding them up', () => {62    expect(formatCompactTokenCount(4096)).toBe('4.1k');63  });64});65