Effectify plugin agent regression test (#25646)

This commit is contained in:
Kit Langton
2026-05-03 22:07:10 +00:00
committed by GitHub
parent ca6150d6f0
commit c2b1974ddd
@@ -1,52 +1,65 @@
import { afterEach, expect, test } from "bun:test" import { expect } from "bun:test"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
import { Effect, Layer } from "effect"
import path from "path" import path from "path"
import { pathToFileURL } from "url" import { pathToFileURL } from "url"
import { AppRuntime } from "../../src/effect/app-runtime"
import { Agent } from "../../src/agent/agent" import { Agent } from "../../src/agent/agent"
import { Instance } from "../../src/project/instance" import { InstanceRef } from "../../src/effect/instance-ref"
import { WithInstance } from "../../src/project/with-instance" import { InstanceLayer } from "../../src/project/instance-layer"
import { disposeAllInstances, tmpdir } from "../fixture/fixture" import { InstanceStore } from "../../src/project/instance-store"
import { tmpdirScoped } from "../fixture/fixture"
import { testEffect } from "../lib/effect"
afterEach(async () => { const pluginAgent = {
await disposeAllInstances() name: "plugin_added",
}) description: "Added by a plugin via the config hook",
mode: "subagent",
} as const
test("plugin-registered agents appear in Agent.list", async () => { const it = testEffect(Layer.mergeAll(Agent.defaultLayer, InstanceLayer.layer, CrossSpawnSpawner.defaultLayer))
await using tmp = await tmpdir({
init: async (dir) => { it.live("plugin-registered agents appear in Agent.list", () =>
Effect.gen(function* () {
const dir = yield* tmpdirScoped()
const pluginFile = path.join(dir, "plugin.ts") const pluginFile = path.join(dir, "plugin.ts")
await Bun.write(
yield* Effect.promise(async () => {
await Promise.all([
Bun.write(
pluginFile, pluginFile,
[ [
"export default async () => ({", "export default async () => ({",
" config: async (cfg) => {", " config: async (cfg) => {",
" cfg.agent = cfg.agent ?? {}", " cfg.agent = cfg.agent ?? {}",
" cfg.agent.plugin_added = {", ` cfg.agent[${JSON.stringify(pluginAgent.name)}] = {`,
' description: "Added by a plugin via the config hook",', ` description: ${JSON.stringify(pluginAgent.description)},`,
' mode: "subagent",', ` mode: ${JSON.stringify(pluginAgent.mode)},`,
" }", " }",
" },", " },",
"})", "})",
"", "",
].join("\n"), ].join("\n"),
) ),
await Bun.write( Bun.write(
path.join(dir, "opencode.json"), path.join(dir, "opencode.json"),
JSON.stringify({ JSON.stringify({
$schema: "https://opencode.ai/config.json", $schema: "https://opencode.ai/config.json",
plugin: [pathToFileURL(pluginFile).href], plugin: [pathToFileURL(pluginFile).href],
}), }),
) ),
}, ])
}) })
await WithInstance.provide({ const agents = yield* InstanceStore.Service.use((store) =>
directory: tmp.path, Effect.gen(function* () {
fn: async () => { const ctx = yield* store.load({ directory: dir })
const agents = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.list())) yield* Effect.addFinalizer(() => store.dispose(ctx).pipe(Effect.ignore))
const added = agents.find((agent) => agent.name === "plugin_added") return yield* Agent.Service.use((svc) => svc.list()).pipe(Effect.provideService(InstanceRef, ctx))
expect(added?.description).toBe("Added by a plugin via the config hook") }),
expect(added?.mode).toBe("subagent") )
}, const added = agents.find((agent) => agent.name === pluginAgent.name)
})
}) expect(added?.description).toBe(pluginAgent.description)
expect(added?.mode).toBe(pluginAgent.mode)
}),
)