11import { kebabToCamelCase } from './string_utils' ;
22import { allowedTopLevelFields , sectionChecks , listTypes , stringTypes , directoryTypes } from './context_structure' ;
33
4+ export interface SectionValidationResult {
5+ isValid : boolean ;
6+ coveragePercentage : number ;
7+ coveredFields : number ;
8+ totalFields : number ;
9+ missingFields : string [ ] ;
10+ }
11+
412export interface ValidationResult {
513 isValid : boolean ;
614 coveragePercentage : number ;
15+ coveredFields : number ;
16+ totalFields : number ;
717 missingFields : string [ ] ;
18+ sections : Record < string , SectionValidationResult > ;
819}
920
1021export class ContextValidator {
@@ -19,6 +30,7 @@ export class ContextValidator {
1930 const coveredFields = new Set < string > ( ) ;
2031 let isValid = true ;
2132 const allMissingFields : string [ ] = [ ] ;
33+ const sections : Record < string , SectionValidationResult > = { } ;
2234
2335 for ( const [ field , value ] of Object . entries ( data ) ) {
2436 const normalizedField = isJson ? kebabToCamelCase ( field , this . kebabToCamelCache ) : field ;
@@ -34,20 +46,24 @@ export class ContextValidator {
3446
3547 const { coveragePercentage, missingFields } = this . calculateCoverage ( coveredFields , allowedTopLevelFields ) ;
3648 allMissingFields . push ( ...missingFields ) ;
37- console . log ( ` Context coverage: ${ coveragePercentage . toFixed ( 2 ) } % (${ coveredFields . size } /${ allowedTopLevelFields . size } fields)` ) ;
38- if ( missingFields . length > 0 ) {
39- console . log ( ` Missing top-level fields: ${ missingFields . join ( ', ' ) } ` ) ;
40- }
4149
4250 for ( const section of Object . keys ( sectionChecks ) ) {
4351 if ( section in data ) {
4452 const sectionResult = this . validateSectionFields ( section , data [ section ] as Record < string , unknown > , isJson ) ;
4553 isValid = sectionResult . isValid && isValid ;
4654 allMissingFields . push ( ...sectionResult . missingFields ) ;
55+ sections [ section ] = sectionResult ;
4756 }
4857 }
4958
50- return { isValid, coveragePercentage, missingFields : allMissingFields } ;
59+ return {
60+ isValid,
61+ coveragePercentage,
62+ coveredFields : coveredFields . size ,
63+ totalFields : allowedTopLevelFields . size ,
64+ missingFields : allMissingFields ,
65+ sections
66+ } ;
5167 }
5268
5369 private validateField ( field : string , value : unknown , isJson : boolean ) : boolean {
@@ -64,7 +80,7 @@ export class ContextValidator {
6480 return isValid ;
6581 }
6682
67- private validateSectionFields ( sectionName : string , data : Record < string , unknown > , isJson : boolean ) : ValidationResult {
83+ private validateSectionFields ( sectionName : string , data : Record < string , unknown > , isJson : boolean ) : SectionValidationResult {
6884 const checks = sectionChecks [ sectionName ] ;
6985 const coveredFields = new Set < string > ( ) ;
7086 let isValid = true ;
@@ -83,15 +99,23 @@ export class ContextValidator {
8399 }
84100
85101 const { coveragePercentage, missingFields } = this . calculateCoverage ( coveredFields , checks ) ;
86- console . log ( ` ${ sectionName } coverage: ${ coveragePercentage . toFixed ( 2 ) } % (${ coveredFields . size } /${ checks . size } fields)` ) ;
87- if ( missingFields . length > 0 ) {
88- console . log ( ` Missing fields in '${ sectionName } ' section: ${ missingFields . join ( ', ' ) } ` ) ;
89- }
90102
91- return { isValid, coveragePercentage, missingFields } ;
103+ return {
104+ isValid,
105+ coveragePercentage,
106+ coveredFields : coveredFields . size ,
107+ totalFields : checks . size ,
108+ missingFields
109+ } ;
92110 }
93111
94- return { isValid : true , coveragePercentage : 100 , missingFields : [ ] } ;
112+ return {
113+ isValid : true ,
114+ coveragePercentage : 100 ,
115+ coveredFields : 0 ,
116+ totalFields : 0 ,
117+ missingFields : [ ]
118+ } ;
95119 }
96120
97121 private calculateCoverage ( coveredFields : Set < string > , expectedFields : Set < string > ) : { coveragePercentage : number , missingFields : string [ ] } {
0 commit comments