diff --git a/packages/opencode/script/seed-e2e.ts b/packages/opencode/script/seed-e2e.ts index f34dd051db..fc3573548d 100644 --- a/packages/opencode/script/seed-e2e.ts +++ b/packages/opencode/script/seed-e2e.ts @@ -11,46 +11,52 @@ const seed = async () => { const { Instance } = await import("../src/project/instance") const { InstanceBootstrap } = await import("../src/project/bootstrap") const { Config } = await import("../src/config/config") + const { disposeRuntime } = await import("../src/effect/runtime") const { Session } = await import("../src/session") const { MessageID, PartID } = await import("../src/session/schema") const { Project } = await import("../src/project/project") const { ModelID, ProviderID } = await import("../src/provider/schema") const { ToolRegistry } = await import("../src/tool/registry") - await Instance.provide({ - directory: dir, - init: InstanceBootstrap, - fn: async () => { - await Config.waitForDependencies() - await ToolRegistry.ids() + try { + await Instance.provide({ + directory: dir, + init: InstanceBootstrap, + fn: async () => { + await Config.waitForDependencies() + await ToolRegistry.ids() - const session = await Session.create({ title }) - const messageID = MessageID.ascending() - const partID = PartID.ascending() - const message = { - id: messageID, - sessionID: session.id, - role: "user" as const, - time: { created: now }, - agent: "build", - model: { - providerID: ProviderID.make(providerID), - modelID: ModelID.make(modelID), - }, - } - const part = { - id: partID, - sessionID: session.id, - messageID, - type: "text" as const, - text, - time: { start: now }, - } - await Session.updateMessage(message) - await Session.updatePart(part) - await Project.update({ projectID: Instance.project.id, name: "E2E Project" }) - }, - }) + const session = await Session.create({ title }) + const messageID = MessageID.ascending() + const partID = PartID.ascending() + const message = { + id: messageID, + sessionID: session.id, + role: "user" as const, + time: { created: now }, + agent: "build", + model: { + providerID: ProviderID.make(providerID), + modelID: ModelID.make(modelID), + }, + } + const part = { + id: partID, + sessionID: session.id, + messageID, + type: "text" as const, + text, + time: { start: now }, + } + await Session.updateMessage(message) + await Session.updatePart(part) + await Project.update({ projectID: Instance.project.id, name: "E2E Project" }) + }, + }) + } finally { + await Instance.disposeAll().catch(() => {}) + await disposeRuntime().catch(() => {}) + } } await seed() diff --git a/packages/opencode/src/effect/runtime.ts b/packages/opencode/src/effect/runtime.ts index 5a9e68d1e5..4d3e788bba 100644 --- a/packages/opencode/src/effect/runtime.ts +++ b/packages/opencode/src/effect/runtime.ts @@ -15,3 +15,7 @@ export const runtime = ManagedRuntime.make( export function runPromiseInstance(effect: Effect.Effect) { return runtime.runPromise(effect.pipe(Effect.provide(Instances.get(Instance.directory)))) } + +export function disposeRuntime() { + return runtime.dispose() +}