|
1 | 1 | import { describe, expect } from "bun:test" |
2 | | -import { Effect, Exit, Scope } from "effect" |
| 2 | +import { Effect, Exit, Fiber, Layer, Scope, Stream } from "effect" |
3 | 3 | import { AgentV2 } from "@opencode-ai/core/agent" |
| 4 | +import { EventV2 } from "@opencode-ai/core/event" |
4 | 5 | import { Location } from "@opencode-ai/core/location" |
5 | 6 | import { AgentPlugin } from "@opencode-ai/core/plugin/agent" |
6 | 7 | import { AbsolutePath } from "@opencode-ai/core/schema" |
7 | 8 | import { location } from "./fixture/location" |
8 | 9 | import { testEffect } from "./lib/effect" |
9 | 10 | import { agentHost, host } from "./plugin/host" |
10 | 11 |
|
11 | | -const it = testEffect(AgentV2.locationLayer) |
| 12 | +const testLocation = location({ directory: AbsolutePath.make("/project") }) |
| 13 | +const locationLayer = Layer.succeed(Location.Service, Location.Service.of(testLocation)) |
| 14 | + |
| 15 | +const it = testEffect( |
| 16 | + AgentV2.locationLayer.pipe( |
| 17 | + Layer.provideMerge(EventV2.defaultLayer), |
| 18 | + Layer.provideMerge(locationLayer), |
| 19 | + ), |
| 20 | +) |
12 | 21 |
|
13 | 22 | describe("AgentV2", () => { |
| 23 | + it.effect("publishes an updated event after agent changes", () => |
| 24 | + Effect.gen(function* () { |
| 25 | + const agent = yield* AgentV2.Service |
| 26 | + const events = yield* EventV2.Service |
| 27 | + const updated = yield* events |
| 28 | + .subscribe(AgentV2.Event.Updated) |
| 29 | + .pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped) |
| 30 | + yield* Effect.yieldNow |
| 31 | + |
| 32 | + yield* agent.transform((editor) => editor.update(AgentV2.ID.make("reviewer"), () => {})) |
| 33 | + |
| 34 | + expect(yield* Fiber.join(updated)).toMatchObject([{ location: { directory: testLocation.directory } }]) |
| 35 | + }), |
| 36 | + ) |
| 37 | + |
14 | 38 | it.effect("starts without agents", () => |
15 | 39 | Effect.gen(function* () { |
16 | 40 | const agent = yield* AgentV2.Service |
|
0 commit comments