From 7bdb4e6280aaa620e9ceb6808196d4c9e9cdb20f Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 11 Apr 2026 21:12:33 -0400 Subject: [PATCH] test(webfetch): keep tool execution in scope Execute the webfetch tool inside the same provided Effect scope used for initialization so the HTTP client layer stays alive for the assertions instead of interrupting the test fibers. --- packages/opencode/test/tool/webfetch.test.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/opencode/test/tool/webfetch.test.ts b/packages/opencode/test/tool/webfetch.test.ts index 789d2ca474..7d2ff1dcab 100644 --- a/packages/opencode/test/tool/webfetch.test.ts +++ b/packages/opencode/test/tool/webfetch.test.ts @@ -26,9 +26,10 @@ async function withFetch(fetch: (req: Request) => Response | Promise, await fn(server.url) } -function initTool() { +function exec(args: { url: string; format: "text" | "markdown" | "html" }) { return WebFetchTool.pipe( Effect.flatMap((info) => info.init()), + Effect.flatMap((tool) => tool.execute(args, ctx)), Effect.provide(Layer.mergeAll(FetchHttpClient.layer, Truncate.defaultLayer, Agent.defaultLayer)), Effect.runPromise, ) @@ -43,10 +44,7 @@ describe("tool.webfetch", () => { await Instance.provide({ directory: projectRoot, fn: async () => { - const webfetch = await initTool() - const result = await Effect.runPromise( - webfetch.execute({ url: new URL("/image.png", url).toString(), format: "markdown" }, ctx), - ) + const result = await exec({ url: new URL("/image.png", url).toString(), format: "markdown" }) expect(result.output).toBe("Image fetched successfully") expect(result.attachments).toBeDefined() expect(result.attachments?.length).toBe(1) @@ -74,10 +72,7 @@ describe("tool.webfetch", () => { await Instance.provide({ directory: projectRoot, fn: async () => { - const webfetch = await initTool() - const result = await Effect.runPromise( - webfetch.execute({ url: new URL("/image.svg", url).toString(), format: "html" }, ctx), - ) + const result = await exec({ url: new URL("/image.svg", url).toString(), format: "html" }) expect(result.output).toContain(" { await Instance.provide({ directory: projectRoot, fn: async () => { - const webfetch = await initTool() - const result = await Effect.runPromise( - webfetch.execute({ url: new URL("/file.txt", url).toString(), format: "text" }, ctx), - ) + const result = await exec({ url: new URL("/file.txt", url).toString(), format: "text" }) expect(result.output).toBe("hello from webfetch") expect(result.attachments).toBeUndefined() },