feat(core): add robustness tests, logging, and metrics for CodeAssistServer SSE parsing (#21013)

Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
Yuna Seol
2026-03-04 14:27:47 -05:00
committed by GitHub
parent 7423139905
commit 7e510951d7
5 changed files with 338 additions and 5 deletions
@@ -33,6 +33,7 @@ import {
logFlashFallback,
logChatCompression,
logMalformedJsonResponse,
logInvalidChunk,
logFileOperation,
logRipgrepFallback,
logToolOutputTruncated,
@@ -68,6 +69,7 @@ import {
EVENT_AGENT_START,
EVENT_AGENT_FINISH,
EVENT_WEB_FETCH_FALLBACK_ATTEMPT,
EVENT_INVALID_CHUNK,
ApiErrorEvent,
ApiRequestEvent,
ApiResponseEvent,
@@ -77,6 +79,7 @@ import {
FlashFallbackEvent,
RipgrepFallbackEvent,
MalformedJsonResponseEvent,
InvalidChunkEvent,
makeChatCompressionEvent,
FileOperationEvent,
ToolOutputTruncatedEvent,
@@ -1736,6 +1739,39 @@ describe('loggers', () => {
});
});
describe('logInvalidChunk', () => {
beforeEach(() => {
vi.spyOn(ClearcutLogger.prototype, 'logInvalidChunkEvent');
vi.spyOn(metrics, 'recordInvalidChunk');
});
it('logs the event to Clearcut and OTEL', () => {
const mockConfig = makeFakeConfig();
const event = new InvalidChunkEvent('Unexpected token');
logInvalidChunk(mockConfig, event);
expect(
ClearcutLogger.prototype.logInvalidChunkEvent,
).toHaveBeenCalledWith(event);
expect(mockLogger.emit).toHaveBeenCalledWith({
body: 'Invalid chunk received from stream.',
attributes: {
'session.id': 'test-session-id',
'user.email': 'test-user@example.com',
'installation.id': 'test-installation-id',
'event.name': EVENT_INVALID_CHUNK,
'event.timestamp': '2025-01-01T00:00:00.000Z',
interactive: false,
'error.message': 'Unexpected token',
},
});
expect(metrics.recordInvalidChunk).toHaveBeenCalledWith(mockConfig);
});
});
describe('logFileOperation', () => {
const mockConfig = {
getSessionId: () => 'test-session-id',