plugin.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { define } from "@opencode-ai/plugin/v2/effect"
  4. import { AgentV2 } from "@opencode-ai/core/agent"
  5. import { PluginV2 } from "@opencode-ai/core/plugin"
  6. import { testEffect } from "./lib/effect"
  7. import { PluginTestLayer } from "./plugin/fixture"
  8. const it = testEffect(PluginTestLayer)
  9. describe("PluginV2", () => {
  10. it.effect("adds, replaces, and removes plugins", () =>
  11. Effect.gen(function* () {
  12. const plugins = yield* PluginV2.Service
  13. const agents = yield* AgentV2.Service
  14. let description = "first"
  15. const managed = () =>
  16. define({
  17. id: "managed",
  18. effect: (ctx) =>
  19. ctx.agent
  20. .transform((agents) =>
  21. agents.update("configured", (agent) => {
  22. agent.description = description
  23. }),
  24. )
  25. .pipe(Effect.asVoid),
  26. })
  27. yield* plugins.add(PluginV2.ID.make("managed"), managed().effect)
  28. expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("first")
  29. description = "second"
  30. yield* plugins.add(PluginV2.ID.make("managed"), managed().effect)
  31. expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("second")
  32. yield* plugins.remove(PluginV2.ID.make("managed"))
  33. expect(yield* agents.get(AgentV2.ID.make("configured"))).toBeUndefined()
  34. }),
  35. )
  36. })