mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-28 07:15:10 +00:00
refactor(flags): move channel db flag to runtime flags (#27615)
This commit is contained in:
@@ -1,14 +1,29 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { describe, expect } from "bun:test"
|
||||
import path from "path"
|
||||
import { Effect } from "effect"
|
||||
import { Global } from "@opencode-ai/core/global"
|
||||
import { InstallationChannel } from "@opencode-ai/core/installation/version"
|
||||
import { RuntimeFlags } from "@/effect/runtime-flags"
|
||||
import { Database } from "@/storage/db"
|
||||
import { it } from "../lib/effect"
|
||||
|
||||
describe("Database.Path", () => {
|
||||
test("returns database path for the current channel", () => {
|
||||
const expected = ["latest", "beta"].includes(InstallationChannel)
|
||||
? path.join(Global.Path.data, "opencode.db")
|
||||
: path.join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
|
||||
expect(Database.getChannelPath()).toBe(expected)
|
||||
})
|
||||
describe("Database.getChannelPath", () => {
|
||||
it.effect("returns database path for the current channel", () =>
|
||||
Effect.gen(function* () {
|
||||
const flags = yield* RuntimeFlags.Service
|
||||
const expected = ["latest", "beta", "prod"].includes(InstallationChannel)
|
||||
? path.join(Global.Path.data, "opencode.db")
|
||||
: path.join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
|
||||
|
||||
expect(Database.getChannelPath(flags)).toBe(expected)
|
||||
}).pipe(Effect.provide(RuntimeFlags.layer())),
|
||||
)
|
||||
|
||||
it.effect("uses the shared database path when channel databases are disabled", () =>
|
||||
Effect.gen(function* () {
|
||||
const flags = yield* RuntimeFlags.Service
|
||||
|
||||
expect(Database.getChannelPath(flags)).toBe(path.join(Global.Path.data, "opencode.db"))
|
||||
}).pipe(Effect.provide(RuntimeFlags.layer({ disableChannelDb: true }))),
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user