All files / vqa/_collections/utils deterministic-finding.util.ts

96.96% Statements 128/132
76.47% Branches 13/17
100% Functions 2/2
96.96% Lines 128/132

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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 1331x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x     4x 4x 4x 5x 5x 5x 2x 2x 3x 5x     3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 4x 1x 1x 1x 1x 1x 1x  
import { DyE2E_VQA_DOMEvidence_Detector } from '../../_enums/dom-evidence-detector.enum';
import { DyE2E_VQA_FindingSeverity_Type } from '../../_enums/finding-severity.enum';
import { DyE2E_VQA_FindingStatus_Type } from '../../_enums/finding-status.enum';
import { DyE2E_VQA_Finding_Interface } from '../../_models/interfaces/finding.interface';
 
/**
 * `DyE2E_VQA_DeterministicFinding_Util` — egyértelmű DOM-evidence → finding-skeleton
 * agent nélkül (organizer MP-7 SP-7.3 mintából).
 *
 * **scope-LOCK**: csak a "vita nélküli" detektor-eseteket alakítja át. Ahol az
 * evidence szignifikánsan értelmezhető, az AI agent kell hogy döntsön.
 *
 * **Önállóan finding-építő detektorok** (low-noise, high-precision):
 *  - `nested-scroll` (body + modal egyidejű scroll = mindig probléma)
 *  - `modal-viewport-fit` (modal > viewport = mindig probléma)
 *  - `hidden-error` (aria-invalid + hiányzó error-element = mindig probléma)
 *  - `viewport-off-cta` (primary CTA fold alatt = mindig probléma legalább `high`)
 *
 * Minden más detektor evidence-szinten marad, az AI agent dönt.
 */
const DETERMINISTIC_DETECTORS: Set<DyE2E_VQA_DOMEvidence_Detector> = new Set([
  DyE2E_VQA_DOMEvidence_Detector.nestedScroll,
  DyE2E_VQA_DOMEvidence_Detector.modalViewportFit,
  DyE2E_VQA_DOMEvidence_Detector.hiddenError,
  DyE2E_VQA_DOMEvidence_Detector.viewportOffCTA,
]);
 
const FINDING_TEMPLATES: Record<string, {
  severity: DyE2E_VQA_FindingSeverity_Type;
  description: string;
  expectedBehavior: string;
  suggestedFix: string;
}> = {
  [DyE2E_VQA_DOMEvidence_Detector.nestedScroll]: {
    severity: DyE2E_VQA_FindingSeverity_Type.high,
    description: 'Dupla scroll detektálva — a body és egy beágyazott container (pl. modal) is scrollozható.',
    expectedBehavior: 'Modal-open állapotban a body NEM lehet scrollozható; csak a modal-content görgessen.',
    suggestedFix: 'A modal megnyitásakor `document.body.style.overflow = "hidden"` vagy CSS `body.modal-open { overflow: hidden }`.',
  },
  [DyE2E_VQA_DOMEvidence_Detector.modalViewportFit]: {
    severity: DyE2E_VQA_FindingSeverity_Type.high,
    description: 'Modal-content magasabb/szélesebb a viewportnál — a user a modal-content egy részét nem látja.',
    expectedBehavior: 'A modal vagy belül scrollozható (modal-body overflow:auto), vagy a content rövidebb a viewport-nál.',
    suggestedFix: 'A modal-body-ra `max-height: calc(100vh - <header+footer>); overflow-y: auto`.',
  },
  [DyE2E_VQA_DOMEvidence_Detector.hiddenError]: {
    severity: DyE2E_VQA_FindingSeverity_Type.high,
    description: 'aria-invalid input + nincs látható error-element. A user nem tudja MIÉRT invalid.',
    expectedBehavior: 'Minden aria-invalid mezőhöz tartozik egy látható error-message (összekötve aria-describedby-vel).',
    suggestedFix: 'Render error-message DOM-elemet az invalid mező alá, ne csak aria-invalid-et.',
  },
  [DyE2E_VQA_DOMEvidence_Detector.viewportOffCTA]: {
    severity: DyE2E_VQA_FindingSeverity_Type.high,
    description: 'Primary CTA viewport-fold alatt — a user csak görgetés után látja.',
    expectedBehavior: 'A primary CTA fold-felett legyen, különösen mobil viewporton.',
    suggestedFix: 'Layout-átrendezés: a CTA közelebb a top-hoz, vagy sticky-bottom CTA-bar.',
  },
};
 
export class DyE2E_VQA_DeterministicFinding_Util {
 
  /**
   * Egy evidence-tömbből kihúzza azokat, amik **agent nélkül** is finding-skeleton-t
   * eredményeznek. Az AI agent ezeket találja a `findings/auto-deterministic.json`-ben,
   * és csak verify-eli + commit-eli (review-rubric-on átengedheti egyszerűsítve).
   */
  static emit(
    evidence: unknown[],
    context: {
      featureId: string;
      stateId: string;
      viewport: string;
      orientation?: 'portrait' | 'landscape';
      screenshotRef: string;
      domSnapshotRef?: string;
      runId: string;
      findingIdSeed: number;
      projectSlug: string;
    },
  ): DyE2E_VQA_Finding_Interface[] {
    if (!Array.isArray(evidence)) {
      return [];
    }
    const findings: DyE2E_VQA_Finding_Interface[] = [];
    let seq: number = context.findingIdSeed;
    for (const e of evidence) {
      const ev: { detector?: DyE2E_VQA_DOMEvidence_Detector; detected?: boolean; details?: unknown; suggestedRegions?: string[] } =
        e as never;
      if (!ev?.detected || !ev.detector || !DETERMINISTIC_DETECTORS.has(ev.detector)) {
        continue;
      }
      const tmpl = FINDING_TEMPLATES[ev.detector];
      if (!tmpl) {
        continue;
      }
      const findingId: string = `VQA-${context.projectSlug}-${context.featureId}-${String(seq).padStart(3, '0')}`;
      seq++;
      findings.push({
        findingId,
        featureId: context.featureId,
        stateId: context.stateId,
        viewport: context.viewport,
        orientation: context.orientation,
        screenshotRef: context.screenshotRef,
        domSnapshotRef: context.domSnapshotRef,
        description: tmpl.description + ` (evidence-details: ${JSON.stringify(ev.details ?? {}).slice(0, 200)})`,
        expectedBehavior: tmpl.expectedBehavior,
        severity: tmpl.severity,
        status: DyE2E_VQA_FindingStatus_Type.open,
        reproSteps: [
          `Nyisd meg a feature route-ját és vidd a state-be: '${context.stateId}'`,
          `Állítsd be a viewport-ot: '${context.viewport}${context.orientation ? '/' + context.orientation : ''}'`,
          `Vizsgáld meg a következő DOM-régiókat: ${(ev.suggestedRegions ?? []).join(', ') || 'lásd evidence.json'}`,
        ],
        suggestedFix: tmpl.suggestedFix,
        aiConfidence: 0.95,
        detectorEvidenceRefs: [String(ev.detector)],
        createdInRunId: context.runId,
        priority: tmpl.severity === DyE2E_VQA_FindingSeverity_Type.blocker ? 'p0' : 'p1',
        tags: ['deterministic-detector'],
        reAuditInstruction: `A re-audit comparison-bundle-ben az '${ev.detector}' evidence-diff-jét nézd: ` +
          `ha az 'after' clean → verified; ha még detected → reopened/in-progress.`,
      });
    }
    return findings;
  }
 
  /** A determinisztikus detektorok listája — manifest-author / dokumentációs lookup. */
  static getDeterministicDetectors(): DyE2E_VQA_DOMEvidence_Detector[] {
    return Array.from(DETERMINISTIC_DETECTORS);
  }
}