sessionModel.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from 'vitest'
  2. import { modelForChoiceId, modelForSession, modelSelectionFromSessionInfo } from '@/utils/sessionModel'
  3. import { normalizeSession } from '@/utils/normalize'
  4. const models = [
  5. { id: 'gpt-5.6-terra', name: 'GPT 5.6 Terra', provider: 'custom' },
  6. { id: 'glm-5.3', name: 'GLM 5.3', provider: 'custom', isDefault: true },
  7. ]
  8. describe('session model selection', () => {
  9. it('restores the saved model case-insensitively instead of the profile default', () => {
  10. expect(modelForSession(models, 'GPT-5.6-terra', 'CUSTOM')).toEqual(models[0])
  11. })
  12. it('keeps an unavailable stored model visible until the user chooses another', () => {
  13. expect(modelForSession(models, 'archived-model', 'legacy')).toEqual({ id: 'archived-model', name: 'archived-model', provider: 'legacy' })
  14. })
  15. it('reads model changes from both session.info payload shapes', () => {
  16. expect(modelSelectionFromSessionInfo({ model: 'gpt-5.6-sol', provider: 'openai-codex' })).toEqual({
  17. model: 'gpt-5.6-sol', provider: 'openai-codex',
  18. })
  19. expect(modelSelectionFromSessionInfo({ info: { model: 'MiniMax-M3', provider: 'minimax' } })).toEqual({
  20. model: 'MiniMax-M3', provider: 'minimax',
  21. })
  22. expect(modelSelectionFromSessionInfo({ info: { provider: 'minimax' } })).toBeUndefined()
  23. })
  24. it('restores the provider from Hermes model_config session details', () => {
  25. expect(normalizeSession({
  26. id: 'session-1', model: 'omni',
  27. model_config: JSON.stringify({ model: 'omni', provider: 'custom:tingly' }),
  28. })).toMatchObject({ model: 'omni', provider: 'custom:tingly' })
  29. })
  30. it('finds a chosen model when its provider contains a colon', () => {
  31. const tinglyModel = { id: 'omni', name: 'Omni', provider: 'Custom:Tingly' }
  32. expect(modelForChoiceId([tinglyModel], 'Custom:Tingly:omni')).toEqual(tinglyModel)
  33. })
  34. })