db.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829
  1. import { describe, expect } from "bun:test"
  2. import path from "path"
  3. import { Effect } from "effect"
  4. import { Global } from "@opencode-ai/core/global"
  5. import { InstallationChannel } from "@opencode-ai/core/installation/version"
  6. import { RuntimeFlags } from "@/effect/runtime-flags"
  7. import { Database } from "@/storage/db"
  8. import { it } from "../lib/effect"
  9. describe("Database.getChannelPath", () => {
  10. it.effect("returns database path for the current channel", () =>
  11. Effect.gen(function* () {
  12. const flags = yield* RuntimeFlags.Service
  13. const expected = ["latest", "beta", "prod"].includes(InstallationChannel)
  14. ? path.join(Global.Path.data, "opencode.db")
  15. : path.join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
  16. expect(Database.getChannelPath(flags)).toBe(expected)
  17. }).pipe(Effect.provide(RuntimeFlags.layer())),
  18. )
  19. it.effect("uses the shared database path when channel databases are disabled", () =>
  20. Effect.gen(function* () {
  21. const flags = yield* RuntimeFlags.Service
  22. expect(Database.getChannelPath(flags)).toBe(path.join(Global.Path.data, "opencode.db"))
  23. }).pipe(Effect.provide(RuntimeFlags.layer({ disableChannelDb: true }))),
  24. )
  25. })