fix: address code review feedback

- Add parentheses for clearer operator precedence in reduction calculation
- Remove magic number comments in tests for better maintainability

Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-31 15:15:36 +00:00
parent d25a85a1bf
commit f280cd593d
2 changed files with 7 additions and 7 deletions

View File

@@ -196,7 +196,7 @@ ${content}`;
}; };
} }
const reductionPercent = ((originalLength - compressedLength) / originalLength * 100).toFixed(1); const reductionPercent = (((originalLength - compressedLength) / originalLength) * 100).toFixed(1);
console.log(`Compressed output: ${originalLength} -> ${compressedLength} chars (${reductionPercent}% reduction)`); console.log(`Compressed output: ${originalLength} -> ${compressedLength} chars (${reductionPercent}% reduction)`);
return { return {

View File

@@ -155,16 +155,16 @@ describe('CompressionService', () => {
const text = 'Hello world'; const text = 'Hello world';
const tokens = estimateTokenCount(text); const tokens = estimateTokenCount(text);
// 11 characters / 4 = 2.75, ceil = 3 // Estimate based on ~4 chars per token
expect(tokens).toBe(3); expect(tokens).toBe(Math.ceil(text.length / 4));
}); });
it('should estimate tokens for longer text', () => { it('should estimate tokens for longer text', () => {
const text = 'This is a longer piece of text that should have more tokens'; const text = 'This is a longer piece of text that should have more tokens';
const tokens = estimateTokenCount(text); const tokens = estimateTokenCount(text);
// 59 characters / 4 = 14.75, ceil = 15 // Estimate based on ~4 chars per token
expect(tokens).toBe(15); expect(tokens).toBe(Math.ceil(text.length / 4));
}); });
it('should handle empty string', () => { it('should handle empty string', () => {
@@ -183,7 +183,7 @@ describe('CompressionService', () => {
}); });
it('should return true for large content', () => { it('should return true for large content', () => {
// Create content larger than the threshold (1000 tokens = ~4000 chars) // Create content larger than the threshold
const content = 'x'.repeat(5000); const content = 'x'.repeat(5000);
const result = shouldCompress(content, 100000); const result = shouldCompress(content, 100000);
@@ -191,7 +191,7 @@ describe('CompressionService', () => {
}); });
it('should use 10% of maxInputTokens as threshold', () => { it('should use 10% of maxInputTokens as threshold', () => {
// With maxInputTokens = 1000, threshold = 100 tokens = ~400 chars // Test threshold behavior with different content sizes
const smallContent = 'x'.repeat(300); const smallContent = 'x'.repeat(300);
const largeContent = 'x'.repeat(500); const largeContent = 'x'.repeat(500);