plugin-agent-regression.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { expect } from "bun:test"
  2. import { AppFileSystem } from "@opencode-ai/core/filesystem"
  3. import { Effect, Layer } from "effect"
  4. import path from "path"
  5. import { pathToFileURL } from "url"
  6. import { Agent } from "../../src/agent/agent"
  7. import { Bus } from "../../src/bus"
  8. import { Config } from "../../src/config/config"
  9. import { Env } from "../../src/env"
  10. import { RuntimeFlags } from "../../src/effect/runtime-flags"
  11. import { Plugin } from "../../src/plugin"
  12. import { AccountTest } from "../fake/account"
  13. import { AuthTest } from "../fake/auth"
  14. import { NpmTest } from "../fake/npm"
  15. import { ProviderTest } from "../fake/provider"
  16. import { SkillTest } from "../fake/skill"
  17. import { testEffect } from "../lib/effect"
  18. import { PLUGIN_AGENT } from "../fixture/agent-plugin.constants"
  19. // `it.instance` skips InstanceBootstrap so FileWatcher / LSP / MCP don't spin
  20. // up — those services hang during scope teardown on Windows and aren't needed
  21. // to verify plugin → config hook → Agent.list.
  22. const pluginUrl = pathToFileURL(path.join(import.meta.dir, "..", "fixture", "agent-plugin.ts")).href
  23. const provider = ProviderTest.fake()
  24. const configLayer = Config.layer.pipe(
  25. Layer.provide(AppFileSystem.defaultLayer),
  26. Layer.provide(Env.defaultLayer),
  27. Layer.provide(AuthTest.empty),
  28. Layer.provide(AccountTest.empty),
  29. Layer.provide(NpmTest.noop),
  30. )
  31. const pluginLayer = Plugin.layer.pipe(
  32. Layer.provide(Bus.layer),
  33. Layer.provide(configLayer),
  34. Layer.provide(RuntimeFlags.layer({ disableDefaultPlugins: true })),
  35. )
  36. const agentLayer = Agent.layer.pipe(
  37. Layer.provide(configLayer),
  38. Layer.provide(AuthTest.empty),
  39. Layer.provide(SkillTest.empty),
  40. Layer.provide(provider.layer),
  41. Layer.provide(pluginLayer),
  42. )
  43. const it = testEffect(Layer.mergeAll(agentLayer, pluginLayer))
  44. it.instance(
  45. "plugin-registered agents appear in Agent.list",
  46. () =>
  47. Effect.gen(function* () {
  48. yield* Plugin.Service.use((p) => p.init())
  49. const agents = yield* Agent.Service.use((svc) => svc.list())
  50. const added = agents.find((agent) => agent.name === PLUGIN_AGENT.name)
  51. expect(added?.description).toBe(PLUGIN_AGENT.description)
  52. expect(added?.mode).toBe(PLUGIN_AGENT.mode)
  53. }),
  54. { config: { plugin: [pluginUrl] } },
  55. )