cloudaxe-opencode/packages/opencode/test/fixture/tui-runtime.ts

32 lines
958 B
TypeScript
Raw Normal View History

2026-03-27 14:00:26 +00:00
import { spyOn } from "bun:test"
import path from "path"
2026-04-16 06:03:03 +00:00
import { TuiConfig } from "../../src/cli/cmd/tui/config/tui"
2026-03-27 14:00:26 +00:00
type PluginSpec = string | [string, Record<string, unknown>]
2026-04-16 06:03:03 +00:00
export function mockTuiRuntime(dir: string, plugin: PluginSpec[], opts?: { plugin_enabled?: Record<string, boolean> }) {
2026-03-27 14:00:26 +00:00
process.env.OPENCODE_PLUGIN_META_FILE = path.join(dir, "plugin-meta.json")
const plugin_origins = plugin.map((spec) => ({
spec,
scope: "local" as const,
source: path.join(dir, "tui.json"),
}))
2026-03-27 14:00:26 +00:00
const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue()
const cwd = spyOn(process, "cwd").mockImplementation(() => dir)
2026-04-16 06:03:03 +00:00
const config: TuiConfig.Info = {
plugin,
plugin_origins,
...(opts?.plugin_enabled && { plugin_enabled: opts.plugin_enabled }),
}
return {
config,
restore: () => {
cwd.mockRestore()
wait.mockRestore()
delete process.env.OPENCODE_PLUGIN_META_FILE
},
2026-03-27 14:00:26 +00:00
}
}