Răsfoiți Sursa

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.
Kit Langton 5 zile în urmă
părinte
comite
7bdb4e6280
1 a modificat fișierele cu 5 adăugiri și 13 ștergeri
  1. 5 13
      packages/opencode/test/tool/webfetch.test.ts

+ 5 - 13
packages/opencode/test/tool/webfetch.test.ts

@@ -26,9 +26,10 @@ async function withFetch(fetch: (req: Request) => Response | Promise<Response>,
   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("<svg")
             expect(result.attachments).toBeUndefined()
           },
@@ -97,10 +92,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("/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()
           },