Skip to content

Commit 27208e7

Browse files
Merge pull request #25 from fpdy/fix/warpgrep-snapshot-worktree-fallback
fix: await async generator return value in warpgrep_codebase_search (Bun compatibility Issue)
2 parents d7d5446 + 9a8d60a commit 27208e7

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});

index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,11 @@ Get your API key at: https://morphllm.com/dashboard/api-keys`;
10461046
for (;;) {
10471047
const { value, done } = await generator.next();
10481048
if (done) {
1049-
result = value;
1049+
// Bun: morphsdk's async generator returns an unawaited Promise
1050+
// from processAgentResult() via `return promise`. Node.js
1051+
// auto-awaits it per spec, but Bun does not. Explicitly await
1052+
// so the resolved WarpGrepResult is used instead of a Promise.
1053+
result = await value as WarpGrepResult;
10501054
break;
10511055
}
10521056
turnCount = value.turn;

0 commit comments

Comments
 (0)