From 46d48db825d58ef5ae9cc45eaee9b4fb8494c6de Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Mon, 27 Jul 2026 14:16:11 +0200 Subject: [PATCH] fix(cli): close HttpApi exerciser resources --- .../test/server/httpapi-exercise/index.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/opencode/test/server/httpapi-exercise/index.ts b/packages/opencode/test/server/httpapi-exercise/index.ts index f6b32e6765..ef92a238b5 100644 --- a/packages/opencode/test/server/httpapi-exercise/index.ts +++ b/packages/opencode/test/server/httpapi-exercise/index.ts @@ -17,7 +17,7 @@ * - `.json(...)` / `.jsonEffect(...)` assert response shape and optional side effects. * - `.mutating()` tells the runner to reset isolated state after destructive routes. */ -import { Effect } from "effect" +import { Effect, Layer } from "effect" // kilocode_change import { OpenApi } from "effect/unstable/httpapi" import { TestLLMServer } from "../../lib/llm-server" import path from "path" @@ -1670,7 +1670,16 @@ const llmScenarios = new Set([ ]) const main = Effect.gen(function* () { - yield* Effect.addFinalizer(() => Effect.promise(() => disposeApps()).pipe(Effect.andThen(cleanupExercisePaths))) + // kilocode_change start - dispose final non-mutating instances so shared test scopes can close + yield* Effect.addFinalizer(() => + Effect.gen(function* () { + yield* Effect.promise(() => disposeApps()) + const modules = yield* Effect.promise(() => runtime()) + yield* Effect.promise(() => modules.disposeAllInstances()) + yield* cleanupExercisePaths + }), + ) + // kilocode_change end const options = parseOptions(Bun.argv.slice(2)) const modules = yield* Effect.promise(() => runtime()) const effectRoutes = routeKeys(OpenApi.fromApi(modules.PublicApi)) @@ -1712,10 +1721,17 @@ const main = Effect.gen(function* () { return undefined }) -Effect.runPromise(main.pipe(Effect.provide(TestLLMServer.layer), Effect.scoped)).then( +// kilocode_change start - route-only coverage must not acquire a listening fake LLM server +const llm = + parseOptions(Bun.argv.slice(2)).mode === "coverage" + ? Layer.mock(TestLLMServer)({ url: "http://coverage.invalid" }) + : TestLLMServer.layer + +Effect.runPromise(main.pipe(Effect.provide(llm), Effect.scoped)).then( () => process.exit(0), (error: unknown) => { console.error(`${color.red}${message(error)}${color.reset}`) process.exit(1) }, ) +// kilocode_change end