/** * QA360 Source Code Analyzer * * Analyzes source code to extract test requirements and generate test specifications. * Supports TypeScript, JavaScript, Python, and Go source code. * * @example * ```typescript * const analyzer = new SourceAnalyzer(); * const spec = await analyzer.analyzeFile('./src/userService.ts'); * const tests = await analyzer.generateTests(spec); * ``` */ import type { UnitTestSpec, ApiTestSpec, GenerationSource } from './types.js'; /** * Analysis result for a source file */ export interface SourceAnalysis { filePath: string; language: 'typescript' | 'javascript' | 'python' | 'go'; exports: string[]; functions: FunctionInfo[]; classes: ClassInfo[]; imports: ImportInfo[]; hasTests: boolean; testFilePath?: string; complexity: number; linesOfCode: number; } /** * Function information */ export interface FunctionInfo { name: string; params: string[]; returnType?: string; isAsync: boolean; isPublic: boolean; lineNumber: number; complexity: number; } /** * Class information */ export interface ClassInfo { name: string; methods: FunctionInfo[]; properties: string[]; extends?: string; lineNumber: number; } /** * Import information */ export interface ImportInfo { module: string; imports: string[]; isExternal: boolean; } /** * Source analyzer options */ export interface SourceAnalyzerOptions { /** Include private members in analysis */ includePrivate?: boolean; /** Maximum complexity threshold */ maxComplexity?: number; /** Exclude patterns */ exclude?: string[]; /** Follow imports for dependency analysis */ followImports?: boolean; } /** * Test generation suggestion */ export interface TestSuggestion { type: 'unit' | 'integration' | 'e2e'; priority: 'high' | 'medium' | 'low'; description: string; functionName?: string; assertions: string[]; mocks: string[]; } /** * Source Analyzer * * Analyzes source code to extract testable elements and suggest tests. */ export declare class SourceAnalyzer { private readonly options; private readonly defaultOptions; constructor(options?: SourceAnalyzerOptions); /** * Analyze a single source file */ analyzeFile(filePath: string): SourceAnalysis; /** * Analyze a directory recursively */ analyzeDirectory(dirPath: string): SourceAnalysis[]; /** * Generate test specification from analysis */ generateSpec(analysis: SourceAnalysis): UnitTestSpec; /** * Generate test suggestions */ generateSuggestions(analysis: SourceAnalysis): TestSuggestion[]; /** * Generate API spec from Express/HTTP handlers */ generateApiSpec(analysis: SourceAnalysis): ApiTestSpec | null; /** * Analyze TypeScript/JavaScript code */ private analyzeTypeScriptScript; /** * Analyze Python code */ private analyzePython; /** * Analyze Go code */ private analyzeGo; /** * Get language from file extension */ private getLanguage; /** * Check if file is a source file */ private isSourceFile; /** * Traverse directory recursively */ private traverseDirectory; /** * Find test file for a source file */ private findTestFile; /** * Calculate overall complexity score */ private calculateComplexity; /** * Estimate function complexity */ private estimateFunctionComplexity; /** * Parse function parameters */ private parseParams; /** * Extract class content */ private extractClassContent; /** * Find line number for a position in content */ private findLineNumber; /** * Generate test name from file path */ private generateTestName; /** * Recommend testing framework based on language */ private recommendFramework; /** * Generate assertions for a function */ private generateAssertions; /** * Generate mocks for a function */ private generateMocks; /** * Generate mocks for a class */ private generateMocksForClass; /** * Check if module is an HTTP module */ private isHttpModule; /** * Check if module is external */ private isExternalModule; /** * Extract base URL from imports */ private extractBaseUrl; /** * Extract API endpoint from function */ private extractEndpoint; /** * Get analysis as GenerationSource */ toGenerationSource(analysis: SourceAnalysis): GenerationSource; } /** * Convenience function to analyze a source file */ export declare function analyzeSourceFile(filePath: string, options?: SourceAnalyzerOptions): SourceAnalysis; /** * Convenience function to analyze a directory */ export declare function analyzeSourceDirectory(dirPath: string, options?: SourceAnalyzerOptions): SourceAnalysis[]; /** * Convenience function to generate test spec from analysis */ export declare function generateTestSpec(analysis: SourceAnalysis): UnitTestSpec;