fix(test): harden preload cleanup against Windows EBUSY (#14895)

This commit is contained in:
Luke Parker
2026-02-24 21:59:14 +10:00
committed by GitHub
parent 79254c1020
commit a292eddeb5
2 changed files with 31 additions and 3 deletions

View File

@@ -33,6 +33,10 @@ export namespace Database {
type Journal = { sql: string; timestamp: number }[]
const state = {
sqlite: undefined as BunDatabase | undefined,
}
function time(tag: string) {
const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(tag)
if (!match) return 0
@@ -69,6 +73,7 @@ export namespace Database {
log.info("opening database", { path: path.join(Global.Path.data, "opencode.db") })
const sqlite = new BunDatabase(path.join(Global.Path.data, "opencode.db"), { create: true })
state.sqlite = sqlite
sqlite.run("PRAGMA journal_mode = WAL")
sqlite.run("PRAGMA synchronous = NORMAL")
@@ -95,6 +100,14 @@ export namespace Database {
return db
})
export function close() {
const sqlite = state.sqlite
if (!sqlite) return
sqlite.close()
state.sqlite = undefined
Client.reset()
}
export type TxOrDb = Transaction | Client
const ctx = Context.create<{