mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-15 22:33:05 -07:00
fix: remove global string slice to guarantee JSON parseability
This commit is contained in:
@@ -124,18 +124,6 @@ describe('truncateForTelemetry', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should enforce a global payload string limit', () => {
|
||||
const obj = {
|
||||
a: 'x'.repeat(100),
|
||||
b: 'y'.repeat(100),
|
||||
};
|
||||
// Let's cap global string length to 50
|
||||
const result = truncateForTelemetry(obj, 100, 100, 4, 50) as string;
|
||||
expect(result.length).toBeGreaterThan(50);
|
||||
expect(result).toContain('...[TRUNCATED: original payload length');
|
||||
expect(result.startsWith('{"a":"xxxx')).toBe(true);
|
||||
});
|
||||
|
||||
it('should stringify objects unchanged if within maxLength', () => {
|
||||
const obj = { a: 1 };
|
||||
expect(truncateForTelemetry(obj, 100)).toBe(JSON.stringify(obj));
|
||||
|
||||
@@ -67,7 +67,6 @@ export function truncateForTelemetry(
|
||||
maxStringLength = 10000,
|
||||
maxArrayLength = 100,
|
||||
maxDepth = 4,
|
||||
maxGlobalStringLength = 50000,
|
||||
): AttributeValue | undefined {
|
||||
const truncateObj = (v: unknown, depth: number): unknown => {
|
||||
if (typeof v === 'string') {
|
||||
@@ -149,13 +148,6 @@ export function truncateForTelemetry(
|
||||
}
|
||||
|
||||
const stringified = safeJsonStringify(truncated);
|
||||
if (stringified.length > maxGlobalStringLength) {
|
||||
const graphemes = Array.from(stringified);
|
||||
if (graphemes.length > maxGlobalStringLength) {
|
||||
return (graphemes.slice(0, maxGlobalStringLength).join('') +
|
||||
`...[TRUNCATED: original payload length ${graphemes.length}]`) as AttributeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return stringified as AttributeValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user