All files / lib/meta rewrite_validator.ts

0% Statements 0/26
0% Branches 0/1
0% Functions 0/1
0% Lines 0/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                                   
/**
 * يتحقق أن الـ Blueprints منطقية (sanity checks)
 * - baseCorrelation ضمن نطاق منطقي
 * - volatility محدود
 * - support كافي
 */
import { MetaConfig } from '../../config/meta.config';
 
export function validateRewrites(
  blueprints: Array<{
    policyId: string;
    baseCorrelation: number;
    volatility: number;
    support: number;
    mutation: 'expand' | 'contract';
    version: number;
    rationale: string;
  }>
) {
  return blueprints.map((bp) => {
    const okCorr = Math.abs(bp.baseCorrelation) <= 1.25; // guard بسيط
    const okVol = bp.volatility <= MetaConfig.volatilityMax;
    const okSup = bp.support >= MetaConfig.minSupport;
 
    const valid = okCorr && okVol && okSup;
 
    return {
      policyId: bp.policyId,
      version: bp.version,
      valid,
      reason: valid
        ? 'Blueprint منطقي ومستقر ويمكن تجربته.'
        : `مرفوض: corr=${bp.baseCorrelation}, vol=${bp.volatility}, support=${bp.support}`,
      action: valid
        ? bp.mutation === 'expand'
          ? 'increase_weight_gradually'
          : 'decrease_weight_or_monitor'
        : 'none',
    };
  });
}