@@ -18,12 +18,14 @@ import * as kpTest from "knowpro-test";
1818import * as cm from "conversation-memory" ;
1919import {
2020 changeFileExt ,
21+ ensureDir ,
2122 getAbsolutePath ,
2223 getFileName ,
2324 htmlToMd ,
2425 readAllText ,
2526 simplifyHtml ,
2627 simplifyText ,
28+ writeJsonFile ,
2729} from "typeagent" ;
2830import chalk from "chalk" ;
2931import { openai } from "aiclient" ;
@@ -203,8 +205,6 @@ export async function createKnowproTestCommands(
203205 srcPath : argSourceFile ( ) ,
204206 } ,
205207 options : {
206- startAt : argNum ( "Start at this query" , 0 ) ,
207- count : argNum ( "Number to run" ) ,
208208 verbose : argBool ( "Verbose error output" , false ) ,
209209 } ,
210210 } ;
@@ -219,27 +219,23 @@ export async function createKnowproTestCommands(
219219
220220 const namedArgs = parseNamedArguments ( args , verifySearchBatchDef ( ) ) ;
221221 const srcPath = namedArgs . srcPath ;
222- let errorCount = 0 ;
223222 const results = await kpTest . verifyLangSearchResultsBatch (
224223 context ,
225224 srcPath ,
226225 ( result , index , total ) => {
227226 context . printer . writeProgress ( index + 1 , total ) ;
228227 if ( result . success ) {
229- if ( ! writeSearchScore ( result . data , namedArgs . verbose ) ) {
230- errorCount ++ ;
231- }
228+ writeSearchScore ( result . data , namedArgs . verbose ) ;
232229 } else {
233230 context . printer . writeError ( result . message ) ;
234231 }
235232 } ,
236233 ) ;
237234 if ( ! results . success ) {
238235 context . printer . writeError ( results . message ) ;
236+ return ;
239237 }
240- if ( errorCount > 0 ) {
241- context . printer . writeLine ( `${ errorCount } errors` ) ;
242- }
238+ await writeSearchValidationReport ( results . data , srcPath ) ;
243239 } finally {
244240 endTestBatch ( ) ;
245241 }
@@ -442,11 +438,12 @@ export async function createKnowproTestCommands(
442438 ) : boolean {
443439 const error = result . error ;
444440 if ( error !== undefined && error . length > 0 ) {
445- context . printer . writeInColor (
446- chalk . redBright ,
447- `[ ${ error } ]: ${ result . expected . cmd ! } ` ,
441+ context . printer . writeLineInColor (
442+ chalk . gray ,
443+ result . actual . searchText ,
448444 ) ;
449- context . printer . writeInColor ( chalk . red , `Error: ${ error } ` ) ;
445+ context . printer . writeInColor ( chalk . red , `${ result . expected . cmd ! } ` ) ;
446+ context . printer . writeInColor ( chalk . red , `Error:\n ${ error } ` ) ;
450447 if ( verbose ) {
451448 context . printer . writeLine ( "===========" ) ;
452449 context . printer . writeJsonInColor (
@@ -477,6 +474,25 @@ export async function createKnowproTestCommands(
477474 }
478475 }
479476
477+ async function writeSearchValidationReport (
478+ results : kpTest . Comparison < kpTest . LangSearchResults > [ ] ,
479+ srcPath ?: string ,
480+ ) {
481+ const errorResults = results . filter (
482+ ( c ) => c . error !== undefined && c . error . length > 0 ,
483+ ) ;
484+ if ( errorResults . length === 0 ) {
485+ context . printer . writeLineInColor ( chalk . green , "No errors" ) ;
486+ return ;
487+ }
488+
489+ context . printer . writeLine ( `${ errorResults . length } errors` ) ;
490+ context . printer . writeList ( errorResults . map ( ( e ) => e . expected . cmd ) ) ;
491+ if ( srcPath ) {
492+ await saveReport ( srcPath , errorResults ) ;
493+ }
494+ }
495+
480496 function writeAnswerScore (
481497 result : kpTest . SimilarityComparison < kpTest . QuestionAnswer > ,
482498 threshold : number ,
@@ -498,6 +514,13 @@ export async function createKnowproTestCommands(
498514 }
499515 }
500516
517+ async function saveReport ( srcPath : string , report : any ) {
518+ const outputDir = path . join ( context . basePath , "logs/testReports" ) ;
519+ await ensureDir ( outputDir ) ;
520+ const outputPath = path . join ( outputDir , getFileName ( srcPath ) + ".json" ) ;
521+ await writeJsonFile ( outputPath , report ) ;
522+ }
523+
501524 function beginTestBatch ( ) {
502525 context . retryNoAnswer = true ;
503526 }
0 commit comments