/** * @fileoverview Fix Validator for Security Fixes * @module @nahisaho/musubix-security/remediation/fix-validator * * Validates security fixes before and after application to ensure * they correctly address vulnerabilities without introducing new issues. */ import type { Fix, Vulnerability, SourceLocation } from '../types/index.js'; /** * Validation result */ export interface ValidationResult { /** Whether validation passed */ valid: boolean; /** Fix that was validated */ fixId: string; /** Validation checks performed */ checks: ValidationCheck[]; /** Overall score (0-100) */ score: number; /** Recommendations */ recommendations: string[]; /** Validation timestamp */ timestamp: Date; } /** * Individual validation check */ export interface ValidationCheck { /** Check name */ name: string; /** Check category */ category: 'syntax' | 'semantic' | 'security' | 'regression' | 'compatibility'; /** Whether check passed */ passed: boolean; /** Check details */ details: string; /** Severity if failed */ severity?: 'error' | 'warning' | 'info'; } /** * Syntax validation result */ export interface SyntaxValidationResult { /** Whether syntax is valid */ valid: boolean; /** Syntax errors */ errors: SyntaxError[]; /** Abstract syntax tree available */ hasAST: boolean; } /** * Syntax error */ export interface SyntaxError { /** Error message */ message: string; /** Location */ location?: SourceLocation; /** Error code */ code?: string; } /** * Regression test result */ export interface RegressionTestResult { /** Total tests */ total: number; /** Passed tests */ passed: number; /** Failed tests */ failed: number; /** Skipped tests */ skipped: number; /** Test details */ details: TestDetail[]; } /** * Test detail */ export interface TestDetail { /** Test name */ name: string; /** Test status */ status: 'passed' | 'failed' | 'skipped'; /** Duration in ms */ duration: number; /** Error if failed */ error?: string; } /** * Security re-scan result */ export interface SecurityRescanResult { /** Original vulnerability resolved */ vulnerabilityResolved: boolean; /** New vulnerabilities introduced */ newVulnerabilities: Vulnerability[]; /** Remaining vulnerabilities */ remainingVulnerabilities: Vulnerability[]; /** Security improvement score */ improvementScore: number; } /** * Fix validator options */ export interface FixValidatorOptions { /** Enable syntax validation */ syntaxValidation?: boolean; /** Enable semantic validation */ semanticValidation?: boolean; /** Enable security re-scan */ securityRescan?: boolean; /** Enable regression testing */ regressionTesting?: boolean; /** Strict mode (fail on warnings) */ strictMode?: boolean; /** Custom validation rules */ customRules?: CustomValidationRule[]; } /** * Custom validation rule */ export interface CustomValidationRule { /** Rule ID */ id: string; /** Rule name */ name: string; /** Validation function */ validate: (fix: Fix, originalCode: string, fixedCode: string) => ValidationCheck; } /** * Validator for security fixes * * @example * ```typescript * const validator = createFixValidator(); * const result = await validator.validate(fix, originalCode, fixedCode); * if (!result.valid) { * console.log('Fix validation failed:', result.checks); * } * ``` */ export declare class FixValidator { private options; private customRules; constructor(options?: FixValidatorOptions); /** * Validate a fix */ validate(fix: Fix, originalCode: string, fixedCode: string, _originalVulnerability?: Vulnerability): Promise; /** * Validate fix syntax */ validateSyntax(code: string): ValidationCheck; /** * Validate semantic properties */ validateSemantics(originalCode: string, fixedCode: string): ValidationCheck[]; /** * Validate security properties of the fix */ validateSecurityProperties(fix: Fix, fixedCode: string): ValidationCheck[]; /** * Register a custom validation rule */ registerRule(rule: CustomValidationRule): void; /** * Remove a custom validation rule */ removeRule(ruleId: string): boolean; /** * Get all validation rules */ getRules(): CustomValidationRule[]; private validateFixStructure; private checkBalancedBrackets; private checkCommonSyntaxIssues; private checkStructurePreservation; private checkVariableUsage; private fixAddressesVulnerabilityType; private checkSecurityAntiPatterns; private checkDangerousFunctions; private calculateScore; private determineValidity; } /** * Create a fix validator */ export declare function createFixValidator(options?: FixValidatorOptions): FixValidator; /** * Quick validate a fix */ export declare function quickValidate(fix: Fix, originalCode: string, fixedCode: string): Promise; //# sourceMappingURL=fix-validator.d.ts.map