JSON errors in non-interactive auth validation (#8373)

This commit is contained in:
Jerop Kipruto
2025-09-13 08:18:40 +09:00
committed by GitHub
parent b416508ef1
commit 1f70a27e9c
3 changed files with 190 additions and 29 deletions

View File

@@ -34,4 +34,38 @@ describe('JSON output', () => {
expect(parsed).toHaveProperty('stats');
expect(typeof parsed.stats).toBe('object');
});
it('should return a JSON error for enforced auth mismatch before running', async () => {
process.env['GOOGLE_GENAI_USE_GCA'] = 'true';
await rig.setup('json-output-auth-mismatch', {
settings: {
security: { auth: { enforcedType: 'gemini-api-key' } },
},
});
let thrown: Error | undefined;
try {
await rig.run('Hello', '--output-format', 'json');
expect.fail('Expected process to exit with error');
} catch (e) {
thrown = e as Error;
} finally {
delete process.env['GOOGLE_GENAI_USE_GCA'];
}
expect(thrown).toBeDefined();
const message = (thrown as Error).message;
const jsonStart = message.indexOf('{');
expect(jsonStart).toBeGreaterThan(-1);
const payload = JSON.parse(message.slice(jsonStart));
expect(payload.error).toBeDefined();
expect(payload.error.type).toBe('Error');
expect(payload.error.code).toBe(1);
expect(payload.error.message).toContain(
'configured auth type is gemini-api-key',
);
expect(payload.error.message).toContain(
'current auth type is oauth-personal',
);
});
});