refactor(core): resolve database and websearch config through Effect Config
This commit is contained in:
@@ -35,7 +35,7 @@ const QueryCommand = effectCmd({
|
||||
}
|
||||
return
|
||||
}
|
||||
const child = spawn("sqlite3", [Database.path()], {
|
||||
const child = spawn("sqlite3", [yield* Database.configuredPath], {
|
||||
stdio: "inherit",
|
||||
})
|
||||
yield* Effect.promise(() => new Promise((resolve) => child.on("close", resolve)))
|
||||
@@ -47,7 +47,7 @@ const PathCommand = effectCmd({
|
||||
describe: "print the database path",
|
||||
instance: false,
|
||||
handler: Effect.fn("Cli.db.path")(function* () {
|
||||
console.log(Database.path())
|
||||
console.log(yield* Database.configuredPath)
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { rm } from "fs/promises"
|
||||
import { Database } from "@opencode-ai/core/database/database"
|
||||
import { Effect } from "effect"
|
||||
import { disposeAllInstances } from "./fixture"
|
||||
|
||||
export async function resetDatabase() {
|
||||
await disposeAllInstances().catch(() => undefined)
|
||||
const dbPath = Database.path()
|
||||
const dbPath = await Effect.runPromise(Database.configuredPath)
|
||||
await rm(dbPath, { force: true }).catch(() => undefined)
|
||||
await rm(`${dbPath}-wal`, { force: true }).catch(() => undefined)
|
||||
await rm(`${dbPath}-shm`, { force: true }).catch(() => undefined)
|
||||
|
||||
@@ -18,8 +18,10 @@ const preserveExerciseDatabase = !!process.env.OPENCODE_HTTPAPI_EXERCISE_DB
|
||||
export const exerciseDatabasePath =
|
||||
process.env.OPENCODE_HTTPAPI_EXERCISE_DB ??
|
||||
path.join(process.env.TMPDIR ?? "/tmp", `opencode-httpapi-exercise-${process.pid}.db`)
|
||||
// Must run before the first Effect Config read anywhere in the process: the
|
||||
// default ConfigProvider snapshots process.env on first use, so a Config read
|
||||
// during an earlier module import would freeze the wrong database path.
|
||||
process.env.OPENCODE_DB = exerciseDatabasePath
|
||||
Flag.OPENCODE_DB = exerciseDatabasePath
|
||||
|
||||
export const original = {
|
||||
OPENCODE_SERVER_PASSWORD: Flag.OPENCODE_SERVER_PASSWORD,
|
||||
|
||||
Reference in New Issue
Block a user