CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
integration.test.circular.ts112 linesDownload Raw Back to telemetry
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7/**8 * Integration test to verify circular reference handling with proxy agents9 */10 11import { afterEach, beforeEach, describe, expect, it } from 'vitest';12import type { Config } from '../config/config.js';13import type { RumEvent } from './qwen-logger/event-types.js';14import { QwenLogger } from './qwen-logger/qwen-logger.js';15 16describe('Circular Reference Integration Test', () => {17  beforeEach(() => {18    // Clear singleton instance before each test19    // eslint-disable-next-line @typescript-eslint/no-explicit-any20    (QwenLogger as any).instance = undefined;21  });22 23  afterEach(() => {24    // eslint-disable-next-line @typescript-eslint/no-explicit-any25    (QwenLogger as any).instance = undefined;26  });27 28  it('should handle HttpsProxyAgent-like circular references in qwen logging', () => {29    // Create a mock config with proxy30    const mockConfig = {31      getTelemetryEnabled: () => true,32      getUsageStatisticsEnabled: () => true,33      getSessionId: () => 'test-session',34      getModel: () => 'test-model',35      getEmbeddingModel: () => 'test-embedding',36      getDebugMode: () => false,37      getProxy: () => 'http://proxy.example.com:8080',38    } as unknown as Config;39 40    // Simulate the structure that causes the circular reference error41    // eslint-disable-next-line @typescript-eslint/no-explicit-any42    const proxyAgentLike: any = {43      sockets: {},44      options: { proxy: 'http://proxy.example.com:8080' },45    };46 47    // eslint-disable-next-line @typescript-eslint/no-explicit-any48    const socketLike: any = {49      _httpMessage: {50        agent: proxyAgentLike,51        socket: null,52      },53    };54 55    socketLike._httpMessage.socket = socketLike; // Create circular reference56    proxyAgentLike.sockets['cloudcode-pa.googleapis.com:443'] = [socketLike];57 58    // Create an event that would contain this circular structure59    const problematicEvent: RumEvent = {60      timestamp: Date.now(),61      event_type: 'exception',62      type: 'error',63      name: 'api_error',64      error: new Error('Network error'),65      function_args: {66        filePath: '/test/file.txt',67        httpAgent: proxyAgentLike, // This would cause the circular reference68      },69    } as RumEvent;70 71    // Test that QwenLogger can handle this72    const logger = QwenLogger.getInstance(mockConfig);73 74    expect(() => {75      // eslint-disable-next-line @typescript-eslint/no-explicit-any76      logger?.enqueueLogEvent(problematicEvent as any);77    }).not.toThrow();78  });79 80  it('should handle event overflow without memory leaks', () => {81    const mockConfig = {82      getTelemetryEnabled: () => true,83      getUsageStatisticsEnabled: () => true,84      getSessionId: () => 'test-session',85      getDebugMode: () => true,86    } as unknown as Config;87 88    const logger = QwenLogger.getInstance(mockConfig);89 90    // Add more events than the maximum capacity91    for (let i = 0; i < 1100; i++) {92      logger?.enqueueLogEvent({93        timestamp: Date.now(),94        event_type: 'action',95        type: 'test',96        name: `overflow-test-${i}`,97      });98    }99 100    // Logger should still be functional101    expect(logger).toBeDefined();102    expect(() => {103      logger?.enqueueLogEvent({104        timestamp: Date.now(),105        event_type: 'action',106        type: 'test',107        name: 'final-test',108      });109    }).not.toThrow();110  });111});112 
basant307/AI_Governance_Project · CoolFace