mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 20:20:57 +00:00
test(cli): cover preserving runtime-added models
This commit is contained in:
parent
7bb6cfd28c
commit
2c0fec1ff1
1 changed files with 80 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ import {
|
|||
USER_SETTINGS_PATH, // This IS the mocked path.
|
||||
getSystemSettingsPath,
|
||||
getSystemDefaultsPath,
|
||||
SettingScope,
|
||||
SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock.
|
||||
type Settings,
|
||||
loadEnvironment,
|
||||
|
|
@ -2334,6 +2335,85 @@ describe('Settings Loading and Merging', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('setValue persistence', () => {
|
||||
it('preserves models added to settings.json after startup when updating model.name', () => {
|
||||
(mockFsExistsSync as Mock).mockReturnValue(true);
|
||||
|
||||
const initialUserSettingsContent = {
|
||||
[SETTINGS_VERSION_KEY]: SETTINGS_VERSION,
|
||||
modelProviders: {
|
||||
openai: [
|
||||
{
|
||||
id: 'existing-model',
|
||||
name: 'Existing Model',
|
||||
baseUrl: 'https://example.com/v1',
|
||||
envKey: 'OPENAI_API_KEY',
|
||||
},
|
||||
],
|
||||
},
|
||||
model: {
|
||||
name: 'existing-model',
|
||||
},
|
||||
};
|
||||
|
||||
const externallyModifiedUserSettingsContent = {
|
||||
[SETTINGS_VERSION_KEY]: SETTINGS_VERSION,
|
||||
modelProviders: {
|
||||
openai: [
|
||||
{
|
||||
id: 'existing-model',
|
||||
name: 'Existing Model',
|
||||
baseUrl: 'https://example.com/v1',
|
||||
envKey: 'OPENAI_API_KEY',
|
||||
},
|
||||
{
|
||||
id: 'manually-added-model',
|
||||
name: 'Manually Added Model',
|
||||
baseUrl: 'https://example.com/v1',
|
||||
envKey: 'OPENAI_API_KEY',
|
||||
},
|
||||
],
|
||||
},
|
||||
model: {
|
||||
name: 'existing-model',
|
||||
},
|
||||
};
|
||||
|
||||
let currentUserSettingsContent = JSON.stringify(
|
||||
initialUserSettingsContent,
|
||||
);
|
||||
|
||||
(fs.readFileSync as Mock).mockImplementation(
|
||||
(p: fs.PathOrFileDescriptor) => {
|
||||
if (p === USER_SETTINGS_PATH) {
|
||||
return currentUserSettingsContent;
|
||||
}
|
||||
return '{}';
|
||||
},
|
||||
);
|
||||
|
||||
const settings = loadSettings(MOCK_WORKSPACE_DIR);
|
||||
currentUserSettingsContent = JSON.stringify(
|
||||
externallyModifiedUserSettingsContent,
|
||||
);
|
||||
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'model.name',
|
||||
'manually-added-model',
|
||||
);
|
||||
|
||||
const writeCall = (fs.writeFileSync as Mock).mock.calls.at(-1);
|
||||
expect(writeCall).toBeDefined();
|
||||
|
||||
const writtenContent = JSON.parse(String(writeCall?.[1]));
|
||||
expect(writtenContent.model.name).toBe('manually-added-model');
|
||||
expect(writtenContent.modelProviders.openai).toEqual(
|
||||
externallyModifiedUserSettingsContent.modelProviders.openai,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadEnvironment', () => {
|
||||
function setup({
|
||||
isFolderTrustEnabled = true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue