mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 03:24:54 +00:00
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Bus } from "@opencode/core/bus"
|
|
import { Config } from "@opencode/core/config"
|
|
import { ConfigSessionSearchPlugin } from "@opencode/core/config/plugin/session-search"
|
|
import { Plugin } from "@opencode/core/plugin"
|
|
import { PluginHost } from "@opencode/core/plugin/host"
|
|
import { SessionSearchBuild } from "@opencode/core/session/search-build"
|
|
import { Document, Event, Info } from "@opencode/schema/config"
|
|
import { ConfigExperimental } from "@opencode/schema/config/experimental"
|
|
import { Effect, Layer } from "effect"
|
|
import { it } from "../lib/effect"
|
|
import { drain } from "../lib/clock"
|
|
import { PluginTestLayer } from "../plugin/fixture"
|
|
|
|
const documents = (on: boolean) => [
|
|
new Document({ type: "document", info: new Info({ experimental: new ConfigExperimental.Info({ sqlite_fts: on }) }) }),
|
|
]
|
|
|
|
describe("ConfigSessionSearchPlugin.Plugin", () => {
|
|
it.effect("starts the build once the location's config turns sqlite_fts on", () => {
|
|
const starts = { count: 0 }
|
|
const build = Layer.succeed(
|
|
SessionSearchBuild.Service,
|
|
SessionSearchBuild.Service.of({
|
|
start: Effect.sync(() => starts.count++),
|
|
run: Effect.void,
|
|
}),
|
|
)
|
|
return Effect.gen(function* () {
|
|
const bus = yield* Bus.Service
|
|
const config = yield* Config.Test
|
|
const plugins = yield* Plugin.Service
|
|
yield* config.setEntries(documents(false))
|
|
yield* ConfigSessionSearchPlugin.Plugin.effect(yield* PluginHost.make(plugins, "test"))
|
|
expect(starts.count).toBe(0)
|
|
|
|
yield* config.setEntries(documents(true))
|
|
yield* bus.publish(Event.Updated, {})
|
|
yield* drain
|
|
expect(starts.count).toBe(1)
|
|
yield* bus.publish(Event.Updated, {})
|
|
yield* drain
|
|
expect(starts.count).toBe(1)
|
|
}).pipe(Effect.scoped, Effect.provide(build), Effect.provide(PluginTestLayer))
|
|
})
|
|
|
|
it.effect("starts the build immediately when sqlite_fts is already on at load", () => {
|
|
const starts = { count: 0 }
|
|
const build = Layer.succeed(
|
|
SessionSearchBuild.Service,
|
|
SessionSearchBuild.Service.of({
|
|
start: Effect.sync(() => starts.count++),
|
|
run: Effect.void,
|
|
}),
|
|
)
|
|
return Effect.gen(function* () {
|
|
const config = yield* Config.Test
|
|
const plugins = yield* Plugin.Service
|
|
yield* config.setEntries(documents(true))
|
|
yield* ConfigSessionSearchPlugin.Plugin.effect(yield* PluginHost.make(plugins, "test"))
|
|
expect(starts.count).toBe(1)
|
|
}).pipe(Effect.scoped, Effect.provide(build), Effect.provide(PluginTestLayer))
|
|
})
|
|
})
|