plugin.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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("reconciles transformed plugins", () =>
  11. Effect.gen(function* () {
  12. const plugins = yield* PluginV2.Service
  13. const agents = yield* AgentV2.Service
  14. let description = "first"
  15. const registration = yield* plugins.transform((draft) => {
  16. draft.add(
  17. define({
  18. id: "managed",
  19. effect: (ctx) =>
  20. ctx.agent
  21. .transform((agents) =>
  22. agents.update("configured", (agent) => {
  23. agent.description = description
  24. }),
  25. )
  26. .pipe(Effect.asVoid),
  27. }),
  28. )
  29. })
  30. expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("first")
  31. description = "second"
  32. yield* plugins.reload()
  33. expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("second")
  34. yield* registration.dispose
  35. expect(yield* agents.get(AgentV2.ID.make("configured"))).toBeUndefined()
  36. }),
  37. )
  38. })