Files
clawpanel/tests/agent-default-model-normalize.test.js
Cursor Agent 16e4f505e6 fix(dashboard): preserve agents.defaults.models entries during model self-heal
Dashboard normalization rebuilt defaults.models from only primary+fallbacks,
dropping valid per-model overrides for other configured models (unlike the
models page normalizeDefaultModelMap). Extract shared pure helpers and merge
orphan valid keys after rebuilding the chain.

Co-authored-by: 晴天 <1186258278@users.noreply.github.com>
2026-05-17 11:04:14 +00:00

57 lines
1.7 KiB
JavaScript
Raw Permalink 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.
/**
* 运行node --test tests/agent-default-model-normalize.test.js
*/
import test from 'node:test'
import assert from 'node:assert/strict'
import { normalizeDefaultModelConfig } from '../src/lib/agent-default-model-normalize.js'
test('normalizeDefaultModelConfig keeps valid per-model blocks off the fallback chain', () => {
const config = {
models: {
providers: {
openai: { models: [{ id: 'gpt-4' }, { id: 'gpt-4o-mini' }] },
anthropic: { models: [{ id: 'claude-3-5-sonnet' }] },
},
},
agents: {
defaults: {
model: {
primary: 'openai/deleted-model',
fallbacks: [],
},
models: {
'openai/deleted-model': { temperature: 0.1 },
'anthropic/claude-3-5-sonnet': { temperature: 0.7 },
},
},
},
}
normalizeDefaultModelConfig(config)
assert.equal(config.agents.defaults.model.primary, 'openai/gpt-4')
assert.deepEqual(config.agents.defaults.models['anthropic/claude-3-5-sonnet'], { temperature: 0.7 })
assert.equal(config.agents.defaults.models['openai/deleted-model'], undefined)
})
test('normalizeDefaultModelConfig still strips invalid model keys', () => {
const config = {
models: {
providers: {
openai: { models: [{ id: 'gpt-4' }] },
},
},
agents: {
defaults: {
model: { primary: 'openai/gpt-4', fallbacks: [] },
models: {
'openai/gpt-4': {},
'ghost/missing': { temperature: 1 },
},
},
},
}
normalizeDefaultModelConfig(config)
assert.equal(config.agents.defaults.models['ghost/missing'], undefined)
assert.ok(config.agents.defaults.models['openai/gpt-4'])
})