mirror of
https://github.com/ValueCell-ai/ClawX.git
synced 2026-08-14 08:53:09 +00:00
fix provider validation to use configured model (#1220)
This commit is contained in:
@@ -169,6 +169,13 @@ test.describe('ClawX provider lifecycle', () => {
|
||||
if (body.apiKey !== 'sk-lm-test') {
|
||||
return respond(request.id, { valid: false, error: `unexpected key: ${String(body.apiKey)}` });
|
||||
}
|
||||
const options = body.options as Record<string, unknown> | undefined;
|
||||
if (options?.modelId !== 'local-model') {
|
||||
return respond(request.id, {
|
||||
valid: false,
|
||||
error: `unexpected validation model: ${String(options?.modelId)}`,
|
||||
});
|
||||
}
|
||||
return respond(request.id, { valid: true });
|
||||
}
|
||||
|
||||
@@ -270,6 +277,13 @@ test.describe('ClawX provider lifecycle', () => {
|
||||
|
||||
if (request.action === 'validateKey') {
|
||||
if (body.apiKey === 'sk-good') {
|
||||
const options = body.options as Record<string, unknown> | undefined;
|
||||
if (options?.modelId !== 'kimi-k2.6') {
|
||||
return respond(request.id, {
|
||||
valid: false,
|
||||
error: `unexpected validation model: ${String(options?.modelId)}`,
|
||||
});
|
||||
}
|
||||
return respond(request.id, { valid: true });
|
||||
}
|
||||
return respond(request.id, { valid: false, error: 'Invalid API key' });
|
||||
|
||||
@@ -452,12 +452,17 @@ describe('host services', () => {
|
||||
await expect(providersApi.validateKey({
|
||||
accountId: 'custom-local',
|
||||
apiKey: 'sk-test',
|
||||
options: { baseUrl: 'http://live.example/v1', apiProtocol: 'openai-responses' },
|
||||
options: {
|
||||
baseUrl: 'http://live.example/v1',
|
||||
apiProtocol: 'openai-responses',
|
||||
modelId: 'live-model',
|
||||
},
|
||||
})).resolves.toEqual({ valid: true });
|
||||
|
||||
expect(validateApiKeyWithProviderMock).toHaveBeenCalledWith('custom', 'sk-test', {
|
||||
baseUrl: 'http://live.example/v1',
|
||||
apiProtocol: 'openai-responses',
|
||||
modelId: 'live-model',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ describe('useProviderStore - validateAccountApiKey()', () => {
|
||||
const result = await useProviderStore.getState().validateAccountApiKey('custom', ' sk-lm-test \n', {
|
||||
baseUrl: 'http://127.0.0.1:1234/v1',
|
||||
apiProtocol: 'openai-completions',
|
||||
modelId: 'local-model',
|
||||
});
|
||||
|
||||
expect(result).toEqual({ valid: true });
|
||||
@@ -41,6 +42,7 @@ describe('useProviderStore - validateAccountApiKey()', () => {
|
||||
options: {
|
||||
baseUrl: 'http://127.0.0.1:1234/v1',
|
||||
apiProtocol: 'openai-completions',
|
||||
modelId: 'local-model',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,6 +69,7 @@ describe('validateApiKeyWithProvider', () => {
|
||||
const result = await validateApiKeyWithProvider('custom', 'sk-response-test', {
|
||||
baseUrl: 'https://responses.example.com/v1',
|
||||
apiProtocol: 'openai-responses',
|
||||
modelId: 'glm-5.2',
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ valid: true });
|
||||
@@ -86,6 +87,10 @@ describe('validateApiKeyWithProvider', () => {
|
||||
'https://responses.example.com/v1/responses',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
model: 'glm-5.2',
|
||||
input: 'hi',
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -109,6 +114,7 @@ describe('validateApiKeyWithProvider', () => {
|
||||
const result = await validateApiKeyWithProvider('custom', 'sk-chat-test', {
|
||||
baseUrl: 'https://chat.example.com/v1',
|
||||
apiProtocol: 'openai-completions',
|
||||
modelId: 'chat-model',
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ valid: true });
|
||||
@@ -117,6 +123,11 @@ describe('validateApiKeyWithProvider', () => {
|
||||
'https://chat.example.com/v1/chat/completions',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
model: 'chat-model',
|
||||
messages: [{ role: 'user', content: 'hi' }],
|
||||
max_tokens: 1,
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user