summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-05-03 18:07:10 -0400
committerGitHub <[email protected]>2026-05-03 22:07:10 +0000
commitc2b1974dddd51a08f2e995743aa9d377e0046fdf (patch)
tree8fc047802f2203dcb0bb91d27b92eaf5940a9d5d
parentca6150d6f092cc8761d6072b0b07b6a7de8748cf (diff)
downloadopencode-c2b1974dddd51a08f2e995743aa9d377e0046fdf.tar.gz
opencode-c2b1974dddd51a08f2e995743aa9d377e0046fdf.zip
Effectify plugin agent regression test (#25646)
-rw-r--r--packages/opencode/test/agent/plugin-agent-regression.test.ts105
1 files changed, 59 insertions, 46 deletions
diff --git a/packages/opencode/test/agent/plugin-agent-regression.test.ts b/packages/opencode/test/agent/plugin-agent-regression.test.ts
index 72e538aa3..3ac923c43 100644
--- a/packages/opencode/test/agent/plugin-agent-regression.test.ts
+++ b/packages/opencode/test/agent/plugin-agent-regression.test.ts
@@ -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 { pathToFileURL } from "url"
-import { AppRuntime } from "../../src/effect/app-runtime"
import { Agent } from "../../src/agent/agent"
-import { Instance } from "../../src/project/instance"
-import { WithInstance } from "../../src/project/with-instance"
-import { disposeAllInstances, tmpdir } from "../fixture/fixture"
+import { InstanceRef } from "../../src/effect/instance-ref"
+import { InstanceLayer } from "../../src/project/instance-layer"
+import { InstanceStore } from "../../src/project/instance-store"
+import { tmpdirScoped } from "../fixture/fixture"
+import { testEffect } from "../lib/effect"
-afterEach(async () => {
- await disposeAllInstances()
-})
+const pluginAgent = {
+ 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 () => {
- await using tmp = await tmpdir({
- init: async (dir) => {
- const pluginFile = path.join(dir, "plugin.ts")
- await Bun.write(
- pluginFile,
- [
- "export default async () => ({",
- " config: async (cfg) => {",
- " cfg.agent = cfg.agent ?? {}",
- " cfg.agent.plugin_added = {",
- ' description: "Added by a plugin via the config hook",',
- ' mode: "subagent",',
- " }",
- " },",
- "})",
- "",
- ].join("\n"),
- )
- await Bun.write(
- path.join(dir, "opencode.json"),
- JSON.stringify({
- $schema: "https://opencode.ai/config.json",
- plugin: [pathToFileURL(pluginFile).href],
- }),
- )
- },
- })
+const it = testEffect(Layer.mergeAll(Agent.defaultLayer, InstanceLayer.layer, CrossSpawnSpawner.defaultLayer))
- await WithInstance.provide({
- directory: tmp.path,
- fn: async () => {
- const agents = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.list()))
- const added = agents.find((agent) => agent.name === "plugin_added")
- expect(added?.description).toBe("Added by a plugin via the config hook")
- expect(added?.mode).toBe("subagent")
- },
- })
-})
+it.live("plugin-registered agents appear in Agent.list", () =>
+ Effect.gen(function* () {
+ const dir = yield* tmpdirScoped()
+ const pluginFile = path.join(dir, "plugin.ts")
+
+ yield* Effect.promise(async () => {
+ await Promise.all([
+ Bun.write(
+ pluginFile,
+ [
+ "export default async () => ({",
+ " config: async (cfg) => {",
+ " cfg.agent = cfg.agent ?? {}",
+ ` cfg.agent[${JSON.stringify(pluginAgent.name)}] = {`,
+ ` description: ${JSON.stringify(pluginAgent.description)},`,
+ ` mode: ${JSON.stringify(pluginAgent.mode)},`,
+ " }",
+ " },",
+ "})",
+ "",
+ ].join("\n"),
+ ),
+ Bun.write(
+ path.join(dir, "opencode.json"),
+ JSON.stringify({
+ $schema: "https://opencode.ai/config.json",
+ plugin: [pathToFileURL(pluginFile).href],
+ }),
+ ),
+ ])
+ })
+
+ const agents = yield* InstanceStore.Service.use((store) =>
+ Effect.gen(function* () {
+ const ctx = yield* store.load({ directory: dir })
+ yield* Effect.addFinalizer(() => store.dispose(ctx).pipe(Effect.ignore))
+ return yield* Agent.Service.use((svc) => svc.list()).pipe(Effect.provideService(InstanceRef, ctx))
+ }),
+ )
+ const added = agents.find((agent) => agent.name === pluginAgent.name)
+
+ expect(added?.description).toBe(pluginAgent.description)
+ expect(added?.mode).toBe(pluginAgent.mode)
+ }),
+)