| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { afterAll, afterEach, describe, expect, test } from "bun:test"
- import { Effect } from "effect"
- import path from "path"
- import { pathToFileURL } from "url"
- import { tmpdir } from "../fixture/fixture"
- const disableDefault = process.env.KILO_DISABLE_DEFAULT_PLUGINS
- process.env.KILO_DISABLE_DEFAULT_PLUGINS = "1"
- const { Plugin } = await import("../../src/plugin/index")
- const { Workspace } = await import("../../src/control-plane/workspace")
- const { Instance } = await import("../../src/project/instance")
- afterEach(async () => {
- await Instance.disposeAll()
- })
- afterAll(() => {
- if (disableDefault === undefined) {
- delete process.env.KILO_DISABLE_DEFAULT_PLUGINS
- return
- }
- process.env.KILO_DISABLE_DEFAULT_PLUGINS = disableDefault
- })
- describe("plugin.workspace", () => {
- test("plugin can install a workspace adaptor", async () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const type = `plug-${Math.random().toString(36).slice(2)}`
- const file = path.join(dir, "plugin.ts")
- const mark = path.join(dir, "created.json")
- const space = path.join(dir, "space")
- await Bun.write(
- file,
- [
- "export default async ({ experimental_workspace }) => {",
- ` experimental_workspace.register(${JSON.stringify(type)}, {`,
- ' name: "plug",',
- ' description: "plugin workspace adaptor",',
- " configure(input) {",
- ` return { ...input, name: \"plug\", branch: \"plug/main\", directory: ${JSON.stringify(space)} }`,
- " },",
- " async create(input) {",
- ` await Bun.write(${JSON.stringify(mark)}, JSON.stringify(input))`,
- " },",
- " async remove() {},",
- " target(input) {",
- ' return { type: "local", directory: input.directory }',
- " },",
- " })",
- " return {}",
- "}",
- "",
- ].join("\n"),
- )
- await Bun.write(
- path.join(dir, "opencode.json"),
- JSON.stringify(
- {
- $schema: "https://opencode.ai/config.json",
- plugin: [pathToFileURL(file).href],
- },
- null,
- 2,
- ),
- )
- return { mark, space, type }
- },
- })
- const info = await Instance.provide({
- directory: tmp.path,
- fn: async () =>
- Effect.gen(function* () {
- const plugin = yield* Plugin.Service
- yield* plugin.init()
- return Workspace.create({
- type: tmp.extra.type,
- branch: null,
- extra: { key: "value" },
- projectID: Instance.project.id,
- })
- }).pipe(Effect.provide(Plugin.defaultLayer), Effect.runPromise),
- })
- expect(info.type).toBe(tmp.extra.type)
- expect(info.name).toBe("plug")
- expect(info.branch).toBe("plug/main")
- expect(info.directory).toBe(tmp.extra.space)
- expect(info.extra).toEqual({ key: "value" })
- expect(JSON.parse(await Bun.file(tmp.extra.mark).text())).toMatchObject({
- type: tmp.extra.type,
- name: "plug",
- branch: "plug/main",
- directory: tmp.extra.space,
- extra: { key: "value" },
- })
- })
- })
|