mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 18:11:02 -07:00
fix(cli): resolve environment loading and auth validation issues in ACP mode (#18025)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,8 +11,65 @@ import {
|
||||
toFriendlyError,
|
||||
BadRequestError,
|
||||
ForbiddenError,
|
||||
getErrorMessage,
|
||||
} from './errors.js';
|
||||
|
||||
describe('getErrorMessage', () => {
|
||||
it('should return plain error message', () => {
|
||||
expect(getErrorMessage(new Error('plain error'))).toBe('plain error');
|
||||
});
|
||||
|
||||
it('should parse simple JSON error response', () => {
|
||||
const json = JSON.stringify({ error: { message: 'json error' } });
|
||||
expect(getErrorMessage(new Error(json))).toBe('json error');
|
||||
});
|
||||
|
||||
it('should parse double-encoded JSON error response', () => {
|
||||
const innerJson = JSON.stringify({ error: { message: 'nested error' } });
|
||||
const outerJson = JSON.stringify({ error: { message: innerJson } });
|
||||
expect(getErrorMessage(new Error(outerJson))).toBe('nested error');
|
||||
});
|
||||
|
||||
it('should parse array-style JSON error response', () => {
|
||||
const json = JSON.stringify([{ error: { message: 'array error' } }]);
|
||||
expect(getErrorMessage(new Error(json))).toBe('array error');
|
||||
});
|
||||
|
||||
it('should parse JSON with top-level message field', () => {
|
||||
const json = JSON.stringify({ message: 'top-level message' });
|
||||
expect(getErrorMessage(new Error(json))).toBe('top-level message');
|
||||
});
|
||||
|
||||
it('should handle JSON with trailing newline', () => {
|
||||
const json = JSON.stringify({ error: { message: 'newline error' } }) + '\n';
|
||||
expect(getErrorMessage(new Error(json))).toBe('newline error');
|
||||
});
|
||||
|
||||
it('should return original message if JSON parsing fails', () => {
|
||||
const invalidJson = '{ not-json }';
|
||||
expect(getErrorMessage(new Error(invalidJson))).toBe(invalidJson);
|
||||
});
|
||||
|
||||
it('should handle non-Error inputs', () => {
|
||||
expect(getErrorMessage('string error')).toBe('string error');
|
||||
expect(getErrorMessage(123)).toBe('123');
|
||||
});
|
||||
|
||||
it('should handle structured HTTP errors via toFriendlyError', () => {
|
||||
const error = {
|
||||
response: {
|
||||
data: {
|
||||
error: {
|
||||
code: 400,
|
||||
message: 'Bad Request Message',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(getErrorMessage(error)).toBe('Bad Request Message');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAuthenticationError', () => {
|
||||
it('should detect error with code: 401 property (MCP SDK style)', () => {
|
||||
const error = { code: 401, message: 'Unauthorized' };
|
||||
|
||||
Reference in New Issue
Block a user