@@ -23,6 +23,7 @@ import {
2323 createDesignCheck ,
2424} from "../builds/design-check.ts" ;
2525import { REPETITION_ABORT } from "../inference/repetition.ts" ;
26+ import { trimHistory } from "./compaction.ts" ;
2627import { compactingDirector } from "./director.ts" ;
2728
2829const director = ( replyOnFailure : boolean ) =>
@@ -280,6 +281,7 @@ test("designer director holds replies until the latest edits pass check_design a
280281 text : 'check passed: served .builder/designs\nFiled design_option: {"artifactId":"design-1","kind":"design_option","version":1,"sha256":"a"}' ,
281282 } ,
282283 ] ,
284+ detail : { checkPassed : true , filed : true } ,
283285 } ,
284286 ] ,
285287 timestamp : 4 ,
@@ -295,6 +297,115 @@ test("designer director holds replies until the latest edits pass check_design a
295297 expect ( accepted . some ( ( action ) => action . type === "reply" ) ) . toBe ( true ) ;
296298} ) ;
297299
300+ test ( "coder director takes a check-app verdict from the result's detail after trimming drops its text" , async ( ) => {
301+ const subject = compactingDirector ( "@corbits-builder/coder-test" ) . factory (
302+ { contextWindow : 200_000 , compactAt : 0.8 , checkBeforeDone : true } ,
303+ { } as never ,
304+ { systemPrompt : "" , toolDefinitions : [ ] , compactorNames : [ ] } ,
305+ ) as ReactorDirector ;
306+ const replyTurn = {
307+ role : "assistant" as const ,
308+ model : "gpt-5" ,
309+ content : [ { type : "text" as const , text : "Done." } ] ,
310+ timestamp : 5 ,
311+ } ;
312+ const checked = (
313+ output : string ,
314+ checkPassed : boolean ,
315+ ) : ConversationTurn [ ] => [
316+ {
317+ role : "user" ,
318+ content : [ { type : "text" , text : "Build the app." } ] ,
319+ timestamp : 0 ,
320+ } ,
321+ {
322+ role : "assistant" ,
323+ content : [
324+ {
325+ type : "tool_call" ,
326+ id : "call-write" ,
327+ name : "write_file" ,
328+ arguments : { path : "src/App.tsx" , content : "export {}" } ,
329+ } ,
330+ ] ,
331+ timestamp : 1 ,
332+ } ,
333+ {
334+ role : "user" ,
335+ content : [
336+ {
337+ type : "tool_result" ,
338+ callId : "call-write" ,
339+ content : [ { type : "text" , text : "wrote src/App.tsx" } ] ,
340+ } ,
341+ ] ,
342+ timestamp : 2 ,
343+ } ,
344+ {
345+ role : "assistant" ,
346+ content : [
347+ {
348+ type : "tool_call" ,
349+ id : "call-check" ,
350+ name : "run_shell" ,
351+ arguments : { command : "check-app" } ,
352+ } ,
353+ ] ,
354+ timestamp : 3 ,
355+ } ,
356+ {
357+ role : "user" ,
358+ content : [
359+ {
360+ type : "tool_result" ,
361+ callId : "call-check" ,
362+ content : [ { type : "text" , text : output } ] ,
363+ detail : { checkPassed } ,
364+ } ,
365+ ] ,
366+ timestamp : 4 ,
367+ } ,
368+ ] ;
369+ const decideTrimmed = async ( output : string , checkPassed : boolean ) => {
370+ const { output : turns } = await trimHistory ( 1 ) . apply (
371+ checked ( output , checkPassed ) ,
372+ { state, trigger : "context" } ,
373+ ) ;
374+ const result = turns
375+ . flatMap ( ( turn ) => turn . content )
376+ . find (
377+ ( block ) =>
378+ block . type === "tool_result" && block . callId === "call-check" ,
379+ ) ;
380+ expect ( JSON . stringify ( result ) ) . not . toContain ( output . slice ( 0 , 20 ) ) ;
381+ const actions = await subject . decide (
382+ {
383+ type : "inference.done" ,
384+ turn : replyTurn ,
385+ usage : state . tokenUsage ,
386+ source : { sourceId : "openai" , provider : "openai" , model : "gpt-5" } ,
387+ } ,
388+ { ...state , turns : [ ...turns , replyTurn ] } ,
389+ createCapabilities ( ) ,
390+ ) ;
391+ return ( Array . isArray ( actions ) ? actions : [ actions ] ) as ReactorAction [ ] ;
392+ } ;
393+ const checklist = "\n✓ every page opened with no errors" . repeat ( 40 ) ;
394+
395+ const passed = await decideTrimmed (
396+ `check passed: built, started, and opened / at 1280 and 390 px with no errors${ checklist } ` ,
397+ true ,
398+ ) ;
399+ expect ( passed . some ( ( action ) => action . type === "reply" ) ) . toBe ( true ) ;
400+
401+ const failed = await decideTrimmed (
402+ `check failed: 1 problem(s) across 1 page(s)${ checklist } ` ,
403+ false ,
404+ ) ;
405+ expect ( failed . some ( ( action ) => action . type === "reply" ) ) . toBe ( false ) ;
406+ expect ( failed . some ( ( action ) => action . type === "compact" ) ) . toBe ( true ) ;
407+ } ) ;
408+
298409test ( "check_design validates DESIGN.md and .dark in styles.css and auto-files the design option on pass" , async ( ) => {
299410 const starter = designStarterFiles ( ) ;
300411 const modernSleek = designThemes ( ) [ "modern-sleek" ] ! ;
0 commit comments