11#!/usr/bin/env bun
2- import { copyFile , readFile } from "node:fs/promises" ;
2+ import { access , copyFile , readFile } from "node:fs/promises" ;
33import { dirname , join } from "node:path" ;
44import { fileURLToPath } from "node:url" ;
55import { systemPrompt } from "@corbits/code-agent-dispatch" ;
@@ -195,13 +195,23 @@ type DispatchEvaluate = (
195195 options : EvaluateOptions < string , string , RoutingExpect > ,
196196) => Promise < Report < string , string , RoutingExpect > > ;
197197
198+ async function baselinePresent ( path : string ) : Promise < boolean > {
199+ try {
200+ await access ( path ) ;
201+ return true ;
202+ } catch {
203+ return false ;
204+ }
205+ }
206+
198207export async function evaluateRouting ( args : {
199208 cases : readonly Case < string , RoutingExpect > [ ] ;
200209 run : ( input : string , signal : AbortSignal ) => Promise < string > ;
201210 lastPath : string ;
202211 baselinePath : string ;
203212 evaluateFn ?: DispatchEvaluate ;
204213} ) : Promise < number > {
214+ const hadBaseline = await baselinePresent ( args . baselinePath ) ;
205215 const evaluateFn : DispatchEvaluate =
206216 args . evaluateFn ?? ( ( name , options ) => evaluate ( name , options ) ) ;
207217 try {
@@ -227,8 +237,18 @@ export async function evaluateRouting(args: {
227237 ollamaUrl : OLLAMA_URL ,
228238 } ,
229239 } ) ;
230- await copyFile ( args . lastPath , args . baselinePath ) ;
231240 console . log ( report . markdown ( ) ) ;
241+ const routeMisses = report . checks [ "routes" ] ?. missed ;
242+ if ( ! hadBaseline ) {
243+ console . error (
244+ `eval "${ DISPATCH_EVAL } " failed: no baseline at ${ args . baselinePath } ` ,
245+ ) ;
246+ return 1 ;
247+ }
248+ if ( routeMisses !== 0 ) {
249+ return 0 ;
250+ }
251+ await copyFile ( args . lastPath , args . baselinePath ) ;
232252 return 0 ;
233253 } catch ( err : unknown ) {
234254 if ( err instanceof EvalFailure ) {
0 commit comments