mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Bus } from "@opencode/core/bus"
|
|
import { Config } from "@opencode/core/config"
|
|
import { ConfigWebSearchPlugin } from "@opencode/core/config/plugin/websearch"
|
|
import { Plugin } from "@opencode/core/plugin"
|
|
import { PluginHost } from "@opencode/core/plugin/host"
|
|
import { WebSearch } from "@opencode/core/websearch"
|
|
import { Document, Event, Info } from "@opencode/schema/config"
|
|
import { ConfigWebSearch } from "@opencode/schema/config/websearch"
|
|
import { Effect } from "effect"
|
|
import { waitUntil } from "../lib/eventually"
|
|
import { testEffect } from "../lib/effect"
|
|
import { PluginTestLayer } from "../plugin/fixture"
|
|
|
|
const it = testEffect(PluginTestLayer)
|
|
|
|
describe("ConfigWebSearchPlugin.Plugin", () => {
|
|
it.live("reloads changed default selection", () =>
|
|
Effect.gen(function* () {
|
|
const websearch = yield* WebSearch.Service
|
|
const bus = yield* Bus.Service
|
|
const config = yield* Config.Test
|
|
const plugins = yield* Plugin.Service
|
|
yield* websearch.transform((editor) =>
|
|
editor.add({ id: WebSearch.ID.make("test"), name: "Test", execute: () => Effect.succeed([]) }),
|
|
)
|
|
yield* ConfigWebSearchPlugin.Plugin.effect(yield* PluginHost.make(plugins, "test"))
|
|
|
|
expect((yield* websearch.default().pipe(Effect.flip))._tag).toBe("WebSearch.Disabled")
|
|
|
|
yield* config.setEntries([configured(new ConfigWebSearch.Info({ provider: "random" }))])
|
|
yield* bus.publish(Event.Updated, {})
|
|
yield* waitUntil(
|
|
websearch.default().pipe(
|
|
Effect.map((provider) => provider?.id === WebSearch.ID.make("test")),
|
|
Effect.orElseSucceed(() => false),
|
|
),
|
|
)
|
|
}).pipe(Effect.provide(Config.testLayer([configured(false)]))),
|
|
)
|
|
})
|
|
|
|
function configured(websearch: ConfigWebSearch.Selection): Document {
|
|
return new Document({ type: "document", info: new Info({ websearch }) })
|
|
}
|