Initial import: open-design source for helix-mind.ai distribution
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 12s
github-metrics / Generate repository metrics SVG (push) Failing after 2m8s
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 12s
github-metrics / Generate repository metrics SVG (push) Failing after 2m8s
This repository contains the open-design daemon CLI source code, built and packaged at https://helix-mind.ai/cli/open-design/latest.tgz for use by the HelixMind /design slash command. Licenses: Apache-2.0 (root) + MIT (skills/*)
This commit is contained in:
82
apps/web/tests/state/maxTokens.test.ts
Normal file
82
apps/web/tests/state/maxTokens.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import litellmData from '../../src/state/litellm-models.json';
|
||||
import {
|
||||
effectiveMaxTokens,
|
||||
FALLBACK_MAX_TOKENS,
|
||||
MAX_MAX_TOKENS,
|
||||
MIN_MAX_TOKENS,
|
||||
modelMaxTokensDefault,
|
||||
} from '../../src/state/maxTokens';
|
||||
|
||||
describe('modelMaxTokensDefault', () => {
|
||||
it('falls through to LiteLLM data for canonical Anthropic ids', () => {
|
||||
// 64k for the 4.5 line is the upstream value; this guards against the
|
||||
// sync script silently dropping or rewriting these entries.
|
||||
expect(modelMaxTokensDefault('claude-sonnet-4-5')).toBe(64000);
|
||||
expect(modelMaxTokensDefault('claude-opus-4-5')).toBe(64000);
|
||||
expect(modelMaxTokensDefault('claude-haiku-4-5')).toBe(64000);
|
||||
});
|
||||
|
||||
it('lets OVERRIDES win over LiteLLM data', () => {
|
||||
// mimo-v2.5-pro is not in LiteLLM, so this asserts the OVERRIDES path
|
||||
// (not the LiteLLM path) supplied the answer.
|
||||
expect((litellmData.models as Record<string, number>)['mimo-v2.5-pro']).toBeUndefined();
|
||||
expect(modelMaxTokensDefault('mimo-v2.5-pro')).toBe(32768);
|
||||
});
|
||||
|
||||
it('returns FALLBACK_MAX_TOKENS for unknown ids', () => {
|
||||
expect(modelMaxTokensDefault('definitely-not-a-real-model-x9z')).toBe(FALLBACK_MAX_TOKENS);
|
||||
expect(FALLBACK_MAX_TOKENS).toBe(8192);
|
||||
});
|
||||
});
|
||||
|
||||
describe('effectiveMaxTokens', () => {
|
||||
it('honors an explicit user override over the model default', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: 12345, model: 'claude-sonnet-4-5' })).toBe(12345);
|
||||
});
|
||||
|
||||
it('uses the model default when no override is set', () => {
|
||||
expect(effectiveMaxTokens({ model: 'mimo-v2.5-pro' })).toBe(32768);
|
||||
expect(effectiveMaxTokens({ model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('falls back to FALLBACK_MAX_TOKENS for unknown models with no override', () => {
|
||||
expect(effectiveMaxTokens({ model: 'unknown-model' })).toBe(FALLBACK_MAX_TOKENS);
|
||||
});
|
||||
});
|
||||
|
||||
describe('effectiveMaxTokens override validation', () => {
|
||||
// Stale localStorage, hand-edited config, or future schema drift can put
|
||||
// anything in cfg.maxTokens. The Settings UI advertises a [1024, 200000]
|
||||
// integer-stepped range, and the daemon proxy already clamps `> 0`, so
|
||||
// we tighten this entry point to match the advertised contract.
|
||||
|
||||
it('rejects negative overrides and falls back to the model default', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: -5, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('rejects zero', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: 0, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('rejects overrides below MIN_MAX_TOKENS', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: MIN_MAX_TOKENS - 1, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('rejects overrides above MAX_MAX_TOKENS', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: MAX_MAX_TOKENS + 1, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
expect(effectiveMaxTokens({ maxTokens: 999_999_999, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('rejects non-integer overrides', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: 123.9, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
expect(effectiveMaxTokens({ maxTokens: Number.NaN, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
expect(effectiveMaxTokens({ maxTokens: Number.POSITIVE_INFINITY, model: 'claude-sonnet-4-5' })).toBe(64000);
|
||||
});
|
||||
|
||||
it('accepts the boundary values exactly', () => {
|
||||
expect(effectiveMaxTokens({ maxTokens: MIN_MAX_TOKENS, model: 'claude-sonnet-4-5' })).toBe(MIN_MAX_TOKENS);
|
||||
expect(effectiveMaxTokens({ maxTokens: MAX_MAX_TOKENS, model: 'claude-sonnet-4-5' })).toBe(MAX_MAX_TOKENS);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user