mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
* fix(codex): show catalog-default Fast tier * fix(web): show inherited Fast tier in header
81 lines
3.3 KiB
TypeScript
81 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
codexModelAdvertisesFastTier,
|
|
getEffectiveCodexServiceTier,
|
|
getDisplayedCodexServiceTier,
|
|
isFastServiceTier
|
|
} from './codexFastMode'
|
|
|
|
// Mirrors the real Codex catalog: the Fast tier's id is 'priority' and its
|
|
// display name is 'Fast', so the CLI captures both as lowercased tokens
|
|
// (['priority','fast']). Models without Fast advertise no such token.
|
|
const models = [
|
|
{ id: 'gpt-5.5', isDefault: true, serviceTiers: ['priority', 'fast'] },
|
|
{ id: 'gpt-5.4-mini', isDefault: false, serviceTiers: [] },
|
|
{ id: 'o3', isDefault: false }
|
|
]
|
|
|
|
describe('codexModelAdvertisesFastTier', () => {
|
|
it('is true when the active model advertises a fast tier (real id=priority, name=Fast)', () => {
|
|
expect(codexModelAdvertisesFastTier('gpt-5.5', models)).toBe(true)
|
|
})
|
|
|
|
it('falls back to the catalog default model when session model is auto/null', () => {
|
|
// default model (gpt-5.5) advertises fast
|
|
expect(codexModelAdvertisesFastTier(null, models)).toBe(true)
|
|
expect(codexModelAdvertisesFastTier(undefined, models)).toBe(true)
|
|
expect(codexModelAdvertisesFastTier(' ', models)).toBe(true)
|
|
})
|
|
|
|
it('is false when the active model does not advertise a fast tier', () => {
|
|
expect(codexModelAdvertisesFastTier('gpt-5.4-mini', models)).toBe(false)
|
|
expect(codexModelAdvertisesFastTier('o3', models)).toBe(false)
|
|
})
|
|
|
|
it('is false when the model is unknown or the catalog is empty', () => {
|
|
expect(codexModelAdvertisesFastTier('gpt-9', models)).toBe(false)
|
|
expect(codexModelAdvertisesFastTier('gpt-5.5', [])).toBe(false)
|
|
})
|
|
|
|
it('matches fast tokens case-insensitively', () => {
|
|
expect(codexModelAdvertisesFastTier('m', [{ id: 'm', isDefault: true, serviceTiers: ['Fast'] }])).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('isFastServiceTier', () => {
|
|
it('detects the fast tier regardless of casing/spacing', () => {
|
|
expect(isFastServiceTier('fast')).toBe(true)
|
|
expect(isFastServiceTier(' Fast ')).toBe(true)
|
|
expect(isFastServiceTier('priority')).toBe(true)
|
|
})
|
|
|
|
it('treats null/standard as not fast', () => {
|
|
expect(isFastServiceTier(null)).toBe(false)
|
|
expect(isFastServiceTier(undefined)).toBe(false)
|
|
expect(isFastServiceTier('standard')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('getEffectiveCodexServiceTier', () => {
|
|
it('uses the active model default only when the session has no override', () => {
|
|
const modelsWithDefault = models.map((model) => (
|
|
model.id === 'gpt-5.5' ? { ...model, defaultServiceTier: 'priority' } : model
|
|
))
|
|
|
|
expect(getEffectiveCodexServiceTier(null, null, modelsWithDefault)).toBe('priority')
|
|
expect(getEffectiveCodexServiceTier('standard', null, modelsWithDefault)).toBe('standard')
|
|
})
|
|
})
|
|
|
|
describe('getDisplayedCodexServiceTier', () => {
|
|
it('displays untouched and explicit non-fast tiers as standard', () => {
|
|
expect(getDisplayedCodexServiceTier(null)).toBe('standard')
|
|
expect(getDisplayedCodexServiceTier(undefined)).toBe('standard')
|
|
expect(getDisplayedCodexServiceTier('standard')).toBe('standard')
|
|
})
|
|
|
|
it('preserves the fast selection', () => {
|
|
expect(getDisplayedCodexServiceTier('fast')).toBe('fast')
|
|
})
|
|
})
|