mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-27 19:56:56 -07:00
security: update dependencies to fix critical and high vulnerabilities (#27077)
This commit is contained in:
committed by
GitHub
parent
928a311fb0
commit
b213fd68ec
@@ -5,6 +5,10 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import {
|
||||
AggregationTemporality,
|
||||
type ResourceMetrics,
|
||||
} from '@opentelemetry/sdk-metrics';
|
||||
import {
|
||||
FileSpanExporter,
|
||||
FileLogExporter,
|
||||
@@ -13,19 +17,17 @@ import {
|
||||
import { ExportResultCode } from '@opentelemetry/core';
|
||||
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
||||
import type { ReadableLogRecord } from '@opentelemetry/sdk-logs';
|
||||
import {
|
||||
AggregationTemporality,
|
||||
type ResourceMetrics,
|
||||
} from '@opentelemetry/sdk-metrics';
|
||||
import * as fs from 'node:fs';
|
||||
|
||||
function createMockWriteStream(): {
|
||||
write: ReturnType<typeof vi.fn>;
|
||||
end: ReturnType<typeof vi.fn>;
|
||||
writable: boolean;
|
||||
} {
|
||||
return {
|
||||
write: vi.fn((_data: string, cb: (err?: Error | null) => void) => cb()),
|
||||
end: vi.fn((cb: () => void) => cb()),
|
||||
writable: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -186,8 +188,51 @@ describe('FileMetricExporter', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should resolve forceFlush', async () => {
|
||||
it('should resolve forceFlush after pending writes complete', async () => {
|
||||
let writeFinished = false;
|
||||
mockWriteStream.write.mockImplementation(
|
||||
(_data: string, cb: (err?: Error | null) => void) => {
|
||||
setTimeout(() => {
|
||||
writeFinished = true;
|
||||
cb();
|
||||
}, 50);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
|
||||
const exporter = new FileMetricExporter('/tmp/test-metrics.log');
|
||||
|
||||
// Start an export
|
||||
const exportDone = new Promise<void>((resolve) => {
|
||||
exporter.export({ resource: { attributes: {} } } as ResourceMetrics, () =>
|
||||
resolve(),
|
||||
);
|
||||
});
|
||||
|
||||
const flushPromise = exporter.forceFlush();
|
||||
|
||||
expect(writeFinished).toBe(false);
|
||||
await flushPromise;
|
||||
expect(writeFinished).toBe(true);
|
||||
await exportDone;
|
||||
});
|
||||
|
||||
it('should handle write error in forceFlush', async () => {
|
||||
const writeError = new Error('flush failed');
|
||||
mockWriteStream.write.mockImplementation(
|
||||
(_data: string, cb: (err?: Error | null) => void) => cb(writeError),
|
||||
);
|
||||
|
||||
const exporter = new FileMetricExporter('/tmp/test-metrics.log');
|
||||
await expect(exporter.forceFlush()).rejects.toThrow('flush failed');
|
||||
});
|
||||
|
||||
it('should resolve forceFlush immediately if stream is not writable', async () => {
|
||||
const exporter = new FileMetricExporter('/tmp/test-metrics.log');
|
||||
// @ts-expect-error - accessing protected member for test
|
||||
exporter.writeStream.writable = false;
|
||||
|
||||
await expect(exporter.forceFlush()).resolves.toBeUndefined();
|
||||
expect(mockWriteStream.write).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,27 @@ class FileExporter {
|
||||
return safeJsonStringify(data, 2) + '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that all pending writes are flushed to the underlying stream.
|
||||
*/
|
||||
forceFlush(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.writeStream.writable) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
// write('') will be queued after all previous writes and its callback
|
||||
// will be called when it (and thus all previous writes) are flushed.
|
||||
this.writeStream.write('', (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
shutdown(): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
this.writeStream.end(resolve);
|
||||
@@ -86,8 +107,4 @@ export class FileMetricExporter
|
||||
getPreferredAggregationTemporality(): AggregationTemporality {
|
||||
return AggregationTemporality.CUMULATIVE;
|
||||
}
|
||||
|
||||
async forceFlush(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ export class GcpTraceExporter extends TraceExporter {
|
||||
resourceFilter: /^gcp\./,
|
||||
});
|
||||
}
|
||||
|
||||
async forceFlush(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -136,6 +136,7 @@ vi.mock('systeminformation', () => ({
|
||||
describe('loggers', () => {
|
||||
const mockLogger = {
|
||||
emit: vi.fn(),
|
||||
enabled: vi.fn().mockReturnValue(true),
|
||||
};
|
||||
const mockUiEvent = {
|
||||
addEvent: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user