refactor(flags): move channel db flag to runtime flags (#27615)

This commit is contained in:
Shoubhit Dash
2026-05-15 04:09:10 +05:30
committed by GitHub
parent cb4f5cdea9
commit fc34c74567
8 changed files with 93 additions and 52 deletions

View File

@@ -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 }))),
)
})