Skip to content

Commit c2b1974

Browse files
authored
Effectify plugin agent regression test (#25646)
1 parent ca6150d commit c2b1974

1 file changed

Lines changed: 59 additions & 46 deletions

File tree

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,65 @@
1-
import { afterEach, expect, test } from "bun:test"
1+
import { expect } from "bun:test"
2+
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
3+
import { Effect, Layer } from "effect"
24
import path from "path"
35
import { pathToFileURL } from "url"
4-
import { AppRuntime } from "../../src/effect/app-runtime"
56
import { Agent } from "../../src/agent/agent"
6-
import { Instance } from "../../src/project/instance"
7-
import { WithInstance } from "../../src/project/with-instance"
8-
import { disposeAllInstances, tmpdir } from "../fixture/fixture"
7+
import { InstanceRef } from "../../src/effect/instance-ref"
8+
import { InstanceLayer } from "../../src/project/instance-layer"
9+
import { InstanceStore } from "../../src/project/instance-store"
10+
import { tmpdirScoped } from "../fixture/fixture"
11+
import { testEffect } from "../lib/effect"
912

10-
afterEach(async () => {
11-
await disposeAllInstances()
12-
})
13+
const pluginAgent = {
14+
name: "plugin_added",
15+
description: "Added by a plugin via the config hook",
16+
mode: "subagent",
17+
} as const
1318

14-
test("plugin-registered agents appear in Agent.list", async () => {
15-
await using tmp = await tmpdir({
16-
init: async (dir) => {
17-
const pluginFile = path.join(dir, "plugin.ts")
18-
await Bun.write(
19-
pluginFile,
20-
[
21-
"export default async () => ({",
22-
" config: async (cfg) => {",
23-
" cfg.agent = cfg.agent ?? {}",
24-
" cfg.agent.plugin_added = {",
25-
' description: "Added by a plugin via the config hook",',
26-
' mode: "subagent",',
27-
" }",
28-
" },",
29-
"})",
30-
"",
31-
].join("\n"),
32-
)
33-
await Bun.write(
34-
path.join(dir, "opencode.json"),
35-
JSON.stringify({
36-
$schema: "https://opencode.ai/config.json",
37-
plugin: [pathToFileURL(pluginFile).href],
38-
}),
39-
)
40-
},
41-
})
19+
const it = testEffect(Layer.mergeAll(Agent.defaultLayer, InstanceLayer.layer, CrossSpawnSpawner.defaultLayer))
4220

43-
await WithInstance.provide({
44-
directory: tmp.path,
45-
fn: async () => {
46-
const agents = await AppRuntime.runPromise(Agent.Service.use((svc) => svc.list()))
47-
const added = agents.find((agent) => agent.name === "plugin_added")
48-
expect(added?.description).toBe("Added by a plugin via the config hook")
49-
expect(added?.mode).toBe("subagent")
50-
},
51-
})
52-
})
21+
it.live("plugin-registered agents appear in Agent.list", () =>
22+
Effect.gen(function* () {
23+
const dir = yield* tmpdirScoped()
24+
const pluginFile = path.join(dir, "plugin.ts")
25+
26+
yield* Effect.promise(async () => {
27+
await Promise.all([
28+
Bun.write(
29+
pluginFile,
30+
[
31+
"export default async () => ({",
32+
" config: async (cfg) => {",
33+
" cfg.agent = cfg.agent ?? {}",
34+
` cfg.agent[${JSON.stringify(pluginAgent.name)}] = {`,
35+
` description: ${JSON.stringify(pluginAgent.description)},`,
36+
` mode: ${JSON.stringify(pluginAgent.mode)},`,
37+
" }",
38+
" },",
39+
"})",
40+
"",
41+
].join("\n"),
42+
),
43+
Bun.write(
44+
path.join(dir, "opencode.json"),
45+
JSON.stringify({
46+
$schema: "https://opencode.ai/config.json",
47+
plugin: [pathToFileURL(pluginFile).href],
48+
}),
49+
),
50+
])
51+
})
52+
53+
const agents = yield* InstanceStore.Service.use((store) =>
54+
Effect.gen(function* () {
55+
const ctx = yield* store.load({ directory: dir })
56+
yield* Effect.addFinalizer(() => store.dispose(ctx).pipe(Effect.ignore))
57+
return yield* Agent.Service.use((svc) => svc.list()).pipe(Effect.provideService(InstanceRef, ctx))
58+
}),
59+
)
60+
const added = agents.find((agent) => agent.name === pluginAgent.name)
61+
62+
expect(added?.description).toBe(pluginAgent.description)
63+
expect(added?.mode).toBe(pluginAgent.mode)
64+
}),
65+
)

0 commit comments

Comments
 (0)