@ooples/token-optimizer-mcp
Version:
Intelligent context window optimization for Claude Code - store content externally via caching and compression, freeing up your context window for what matters
199 lines • 4.99 kB
TypeScript
/**
* Smart Test Tool - 80% Token Reduction
*
* Wraps Jest to provide:
* - Incremental test runs (only affected tests)
* - Cached test results
* - Failure summarization (not full logs)
* - Coverage delta tracking
*/
import { CacheEngine } from '../../core/cache-engine.js';
import { TokenCounter } from '../../core/token-counter.js';
import { MetricsCollector } from '../../core/metrics.js';
interface SmartTestOptions {
/**
* Pattern to match test files
*/
pattern?: string;
/**
* Run only tests that changed since last run
*/
onlyChanged?: boolean;
/**
* Force full test run (ignore cache)
*/
force?: boolean;
/**
* Collect coverage information
*/
coverage?: boolean;
/**
* Watch mode
*/
watch?: boolean;
/**
* Project root directory
*/
projectRoot?: string;
/**
* Maximum cache age in seconds (default: 3600 = 1 hour)
*/
maxCacheAge?: number;
}
interface SmartTestOutput {
/**
* Summary of test run
*/
summary: {
total: number;
passed: number;
failed: number;
skipped: number;
duration: number;
fromCache: boolean;
};
/**
* Only failed tests with concise error messages
*/
failures: Array<{
testFile: string;
testName: string;
error: string;
location?: string;
}>;
/**
* Coverage delta (only if coverage enabled)
*/
coverageDelta?: {
statements: number;
branches: number;
functions: number;
lines: number;
};
/**
* New tests added since last run
*/
newTests: string[];
/**
* Token reduction metrics
*/
metrics: {
originalTokens: number;
compactedTokens: number;
reductionPercentage: number;
};
}
export declare class SmartTest {
private cache;
private cacheNamespace;
private projectRoot;
constructor(cache: CacheEngine, _tokenCounter: TokenCounter, _metrics: MetricsCollector, projectRoot?: string);
/**
* Run tests with smart caching and output reduction
*/
run(options?: SmartTestOptions): Promise<SmartTestOutput>;
/**
* Run Jest and capture results
*/
private runJest;
/**
* Generate cache key based on test file contents
*/
private generateCacheKey;
/**
* Get cached result if available and fresh
*/
private getCachedResult;
/**
* Cache test result
*/
private cacheResult;
/**
* Transform full Jest output to smart output
*/
private transformOutput;
/**
* Format cached output
*/
private formatCachedOutput;
/**
* Extract only failures with concise error messages
*/
private extractFailures;
/**
* Extract concise error message from Jest failure
*/
private extractConciseError;
/**
* Extract error location from stack trace
*/
private extractErrorLocation;
/**
* Detect new tests (simplified version - would need test history)
*/
private detectNewTests;
/**
* Calculate coverage delta (simplified version - would need previous coverage)
*/
private calculateCoverageDelta;
/**
* Estimate compact output size for token calculation
*/
private estimateCompactSize;
/**
* Close cache connection
*/
close(): void;
}
/**
* Factory function for creating SmartTest with shared resources (benchmark usage)
*/
export declare function getSmartTestTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector, projectRoot?: string): SmartTest;
/**
* CLI-friendly function for running smart tests
*/
export declare function runSmartTest(options?: SmartTestOptions): Promise<string>;
export declare const SMART_TEST_TOOL_DEFINITION: {
name: string;
description: string;
inputSchema: {
type: string;
properties: {
pattern: {
type: string;
description: string;
};
onlyChanged: {
type: string;
description: string;
default: boolean;
};
force: {
type: string;
description: string;
default: boolean;
};
coverage: {
type: string;
description: string;
default: boolean;
};
watch: {
type: string;
description: string;
default: boolean;
};
projectRoot: {
type: string;
description: string;
};
maxCacheAge: {
type: string;
description: string;
default: number;
};
};
};
};
export {};
//# sourceMappingURL=smart-test.d.ts.map