57 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest';
import { defaultProjectModel, knownModels, orderProjectModels } from '../src/models.js';
import { MAX_RUN_TOKENS, budgetSchema, countedTokens, modelName, projectModelsInput, wishInput } from '../src/index.js';
describe('model names a project may offer', () => {
it('accepts names as executors and the model gateway spell them', () => {
for (const name of ['deepseek-pro@latest', 'deepseek-flash@latest', 'gpt-5.4', 'claude-sonnet-4-5', 'org/model:v2'])
expect(modelName.parse(name)).toBe(name);
expect(modelName.parse(' deepseek-pro@latest ')).toBe('deepseek-pro@latest');
});
it('refuses anything that could become another command-line argument or carry text', () => {
for (const name of ['', '-p', '--model', 'a b', 'a;b', 'a\nb', '$(id)', 'x'.repeat(161)])
expect(modelName.safeParse(name).success, name).toBe(false);
});
it('lists each model once, twenty at most', () => {
expect(projectModelsInput.parse(['a', 'b'])).toEqual(['a', 'b']);
expect(projectModelsInput.safeParse(['a', 'a']).success).toBe(false);
expect(projectModelsInput.safeParse(Array.from({ length: 21 }, (_, i) => `m${i}`)).success).toBe(false);
});
it('lets a wish name a model', () => {
expect(wishInput.parse({ goal: 'g', acceptanceCriteria: ['c'], model: 'deepseek-flash@latest' }).model).toBe(
'deepseek-flash@latest',
);
});
it('lists flash before pro, and a wish defaults to flash when the project offers it', () => {
expect([...knownModels]).toEqual(['deepseek-flash@latest', 'deepseek-pro@latest']);
expect(orderProjectModels(['deepseek-pro@latest', 'deepseek-flash@latest', 'gpt-5.4'])).toEqual([
'deepseek-flash@latest',
'deepseek-pro@latest',
'gpt-5.4',
]);
expect(defaultProjectModel(['deepseek-pro@latest', 'deepseek-flash@latest'])).toBe('deepseek-flash@latest');
expect(defaultProjectModel(['deepseek-pro@latest'])).toBe('deepseek-pro@latest');
expect(defaultProjectModel([])).toBeUndefined();
});
});
describe('the tokens a model’s usage counts', () => {
it('counts input, output and cache creation in full and cache reads a tenth, rounded up', () => {
expect(
countedTokens({
input_tokens: 138034,
output_tokens: 42105,
cache_creation_input_tokens: 0,
cache_read_input_tokens: 5059584,
}),
).toBe(138034 + 42105 + 505959);
expect(countedTokens({ input_tokens: 1, cache_read_input_tokens: 1 })).toBe(2);
expect(countedTokens({})).toBe(0);
});
it('lets a run be given up to five hundred million tokens', () => {
expect(MAX_RUN_TOKENS).toBe(500_000_000);
expect(budgetSchema.parse({ maxTokens: 500_000_000 }).maxTokens).toBe(500_000_000);
expect(budgetSchema.safeParse({ maxTokens: 500_000_001 }).success).toBe(false);
});
});