@@ -2,6 +2,7 @@ import { afterAll, describe, expect, setDefaultTimeout, test } from "bun:test"
22import {
33 chmodSync ,
44 copyFileSync ,
5+ cpSync ,
56 existsSync ,
67 mkdirSync ,
78 mkdtempSync ,
@@ -33,32 +34,47 @@ const ROUTE_CONTRACTS = {
3334 "grok-cursor" : { target : "grok" , harness : "cursor-agent" , intermediaries : [ "cursor" ] , model : "cursor-grok-4.6-high" , restriction : "adapter-enforced" } ,
3435} as const
3536const roots : string [ ] = [ ]
37+ const templateRoots : string [ ] = [ ]
38+ let seedCanonical : string | null = null
3639
3740function temp ( prefix : string ) : string {
3841 const dir = mkdtempSync ( path . join ( tmpdir ( ) , prefix ) )
3942 roots . push ( dir )
4043 return dir
4144}
4245
43- afterAll ( ( ) => roots . forEach ( ( dir ) => rmSync ( dir , { recursive : true , force : true } ) ) )
46+ afterAll ( ( ) => {
47+ for ( const dir of [ ...roots , ...templateRoots ] ) rmSync ( dir , { recursive : true , force : true } )
48+ } )
49+
50+ function seedCanonicalRepo ( ) : string {
51+ if ( seedCanonical ) return seedCanonical
52+ const root = mkdtempSync ( path . join ( tmpdir ( ) , "ce-work-route-template-" ) )
53+ templateRoots . push ( root )
54+ const canonical = path . join ( root , "canonical" )
55+ mkdirSync ( canonical )
56+ mkdirSync ( path . join ( canonical , "docs" , "plans" ) , { recursive : true } )
57+ writeFileSync ( path . join ( canonical , "README.md" ) , "seed\n" )
58+ writeFileSync ( path . join ( canonical , "docs" , "plans" , "plan.md" ) , "# Test plan\n" )
59+ spawnSync ( "git" , [ "init" , "-q" , canonical ] )
60+ spawnSync ( "git" , [ "-C" , canonical , "config" , "user.email" , "test@example.com" ] )
61+ spawnSync ( "git" , [ "-C" , canonical , "config" , "user.name" , "Test" ] )
62+ spawnSync ( "git" , [ "-C" , canonical , "add" , "." ] )
63+ spawnSync ( "git" , [ "-C" , canonical , "commit" , "-qm" , "seed" ] )
64+ seedCanonical = canonical
65+ return canonical
66+ }
4467
4568function fixture ( ) {
4669 const root = temp ( "ce-work-route-" )
4770 const canonical = path . join ( root , "canonical" )
4871 const packet = path . join ( root , "packet.md" )
4972 const capture = path . join ( root , "capture" )
5073 const runs = path . join ( root , "runs" )
51- mkdirSync ( canonical )
74+ mkdirSync ( root , { recursive : true } )
5275 mkdirSync ( capture )
5376 writeFileSync ( packet , "Implement U3 only.\n" )
54- spawnSync ( "git" , [ "init" , "-q" , canonical ] )
55- spawnSync ( "git" , [ "-C" , canonical , "config" , "user.email" , "test@example.com" ] )
56- spawnSync ( "git" , [ "-C" , canonical , "config" , "user.name" , "Test" ] )
57- mkdirSync ( path . join ( canonical , "docs" , "plans" ) , { recursive : true } )
58- writeFileSync ( path . join ( canonical , "README.md" ) , "seed\n" )
59- writeFileSync ( path . join ( canonical , "docs" , "plans" , "plan.md" ) , "# Test plan\n" )
60- spawnSync ( "git" , [ "-C" , canonical , "add" , "." ] )
61- spawnSync ( "git" , [ "-C" , canonical , "commit" , "-qm" , "seed" ] )
77+ cpSync ( seedCanonicalRepo ( ) , canonical , { recursive : true } )
6278 return {
6379 root,
6480 canonical,
@@ -520,7 +536,7 @@ describe("ce-work fixed write routes", () => {
520536 const quietBin = temp ( "ce-work-bin-" )
521537 writeFileSync ( path . join ( quietBin , "claude" ) , `#!/bin/sh
522538cat > '${ quiet . capture } /stdin'
523- sleep 2
539+ sleep 1.1
524540exit 7
525541` )
526542 chmodSync ( path . join ( quietBin , "claude" ) , 0o755 )
@@ -882,14 +898,15 @@ printf '%s' '${prefix}${sentinel}${"y".repeat(maxRawBytes)}'
882898 const bin = temp ( "ce-work-bin-" )
883899 writeFileSync ( path . join ( bin , "claude" ) , `#!/bin/sh
884900cat > '${ f . capture } /stdin'
885- python3 -c 'import sys; sys.stdout.buffer.write(b"x" * 8388608 )'
901+ python3 -c 'import sys; sys.stdout.buffer.write(b"x" * 65536 )'
886902` )
887903 chmodSync ( path . join ( bin , "claude" ) , 0o755 )
888904
889905 const result = run ( "claude" , f , {
890906 ...process . env ,
891907 PATH : `${ bin } :${ process . env . PATH } ` ,
892908 CE_WORK_MAX_RAW_BYTES : String ( maxRawBytes ) ,
909+ CE_WORK_ACTIVITY_POLL_SECS : "1" ,
893910 } )
894911
895912 expect ( result . code ) . toBe ( 1 )
0 commit comments