refactor(core): resolve database and websearch config through Effect Config
This commit is contained in:
parent
a39db9c6f6
commit
cb32c42e6f
7 changed files with 148 additions and 43 deletions
|
|
@ -1,15 +1,20 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import { afterAll, expect, test } from "bun:test"
|
||||
import { mkdtemp, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { Deferred, Effect, Latch, Option, Schema, Stream } from "effect"
|
||||
import type { OpenCodeEvent } from "../src"
|
||||
|
||||
// The database layer resolves OPENCODE_DB through Effect Config, and the
|
||||
// default ConfigProvider snapshots the process environment on first use, so
|
||||
// database placement is process-wide. Point every embedded host in this file
|
||||
// at one shared temporary database before anything builds a runtime.
|
||||
const databaseDirectory = await mkdtemp(join(tmpdir(), "opencode-embedded-db-"))
|
||||
process.env.OPENCODE_DB = join(databaseDirectory, "opencode.sqlite")
|
||||
afterAll(() => rm(databaseDirectory, { recursive: true, force: true }))
|
||||
|
||||
test("embedded client uses the real router and handlers", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "opencode-embedded-"))
|
||||
const database = Flag.OPENCODE_DB
|
||||
Flag.OPENCODE_DB = join(directory, "opencode.sqlite")
|
||||
const { AbsolutePath, Agent, Location, Model, OpenCode, Prompt, Provider, Session, Tool } = await import("../src")
|
||||
const sessionID = Session.ID.make(`ses_embedded_${crypto.randomUUID()}`)
|
||||
const model = Model.Ref.make({ id: Model.ID.make("embedded"), providerID: Provider.ID.make("test") })
|
||||
|
|
@ -99,15 +104,12 @@ test("embedded client uses the real router and handlers", async () => {
|
|||
})
|
||||
await Effect.runPromise(Effect.scoped(program))
|
||||
} finally {
|
||||
Flag.OPENCODE_DB = database
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test("Location-owned runner events reach the ready global client", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "opencode-embedded-events-"))
|
||||
const database = Flag.OPENCODE_DB
|
||||
Flag.OPENCODE_DB = join(directory, "opencode.sqlite")
|
||||
const { AbsolutePath, Location, OpenCode, Prompt, Session } = await import("../src")
|
||||
const sessionID = Session.ID.make(`ses_embedded_${crypto.randomUUID()}`)
|
||||
|
||||
|
|
@ -138,15 +140,12 @@ test("Location-owned runner events reach the ready global client", async () => {
|
|||
})
|
||||
await Effect.runPromise(Effect.scoped(program))
|
||||
} finally {
|
||||
Flag.OPENCODE_DB = database
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
}, 10_000)
|
||||
|
||||
test("independent embedded hosts do not share live notifications", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "opencode-embedded-hosts-"))
|
||||
const database = Flag.OPENCODE_DB
|
||||
Flag.OPENCODE_DB = join(directory, "opencode.sqlite")
|
||||
const { AbsolutePath, Agent, Location, OpenCode, Session } = await import("../src")
|
||||
const sessionID = Session.ID.make(`ses_embedded_${crypto.randomUUID()}`)
|
||||
|
||||
|
|
@ -181,15 +180,12 @@ test("independent embedded hosts do not share live notifications", async () => {
|
|||
})
|
||||
await Effect.runPromise(Effect.scoped(program))
|
||||
} finally {
|
||||
Flag.OPENCODE_DB = database
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
}, 10_000)
|
||||
|
||||
test("embedded client is available as a Layer service", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "opencode-embedded-layer-"))
|
||||
const database = Flag.OPENCODE_DB
|
||||
Flag.OPENCODE_DB = join(directory, "opencode.sqlite")
|
||||
const { AbsolutePath, Location, OpenCode, Session } = await import("../src")
|
||||
const sessionID = Session.ID.make(`ses_embedded_${crypto.randomUUID()}`)
|
||||
|
||||
|
|
@ -206,7 +202,6 @@ test("embedded client is available as a Layer service", async () => {
|
|||
|
||||
expect(created.id).toBe(sessionID)
|
||||
} finally {
|
||||
Flag.OPENCODE_DB = database
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue