@@ -1156,3 +1156,43 @@ describe("formatWarpGrepResult edge cases", () => {
11561156 expect ( result ) . toBe ( "Search failed: timeout after 60s" ) ;
11571157 } ) ;
11581158} ) ;
1159+
1160+ describe ( "warpgrep_codebase_search result handling" , ( ) => {
1161+ test ( "awaits the async generator return value (Bun compatibility)" , async ( ) => {
1162+ const fakeResult = {
1163+ success : true ,
1164+ contexts : [
1165+ { file : "src/auth.ts" , content : "code" , lines : [ [ 1 , 5 ] ] as Array < [ number , number ] > } ,
1166+ ] ,
1167+ summary : "found auth" ,
1168+ } ;
1169+
1170+ const original = WarpGrepClient . prototype . execute ;
1171+ // Async generator that returns a result via `return` (not yield).
1172+ // In Bun, `return value` in an async generator may not auto-await,
1173+ // so the plugin must explicitly await the final .next() value.
1174+ WarpGrepClient . prototype . execute = async function * ( ) : AsyncGenerator {
1175+ return fakeResult ;
1176+ } as any ;
1177+
1178+ try {
1179+ const { default : MorphPlugin } = await importPluginWithEnv ( {
1180+ MORPH_API_KEY : "sk-test-key" ,
1181+ } ) ;
1182+ const hooks = await MorphPlugin (
1183+ makePluginInput ( "/tmp/morph-warpgrep-async-test" ) ,
1184+ ) ;
1185+ const output = ( await hooks . tool . warpgrep_codebase_search . execute (
1186+ { search_term : "auth flow" } ,
1187+ makeToolContext ( "/tmp/morph-warpgrep-async-test" ) ,
1188+ ) ) as string ;
1189+
1190+ // Without the `await` fix, `value` is a Promise, `result.success` is
1191+ // undefined, and formatWarpGrepResult returns the generic failure message.
1192+ expect ( output ) . toContain ( "Relevant context found:" ) ;
1193+ expect ( output ) . toContain ( "src/auth.ts" ) ;
1194+ } finally {
1195+ WarpGrepClient . prototype . execute = original ;
1196+ }
1197+ } ) ;
1198+ } ) ;
0 commit comments