|
|
@@ -18,6 +18,8 @@ const it = testEffect(PluginTestLayer)
|
|
|
|
|
|
class Secret extends Context.Service<Secret, string>()("@opencode/test/PluginSecret") {}
|
|
|
|
|
|
+const versioned = <R>(plugin: EffectPlugin.Plugin<R>, version = "1") => ({ ...plugin, version })
|
|
|
+
|
|
|
describe("PluginV2", () => {
|
|
|
it.live("exposes public events through the plugin context", () =>
|
|
|
Effect.gen(function* () {
|
|
|
@@ -37,15 +39,18 @@ describe("PluginV2", () => {
|
|
|
}),
|
|
|
)
|
|
|
|
|
|
- it.effect("replaces plugins by ID", () =>
|
|
|
+ it.effect("replaces plugins by ID and version", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugins = yield* PluginV2.Service
|
|
|
const agents = yield* AgentV2.Service
|
|
|
const events = yield* EventV2.Service
|
|
|
let description = "first"
|
|
|
- const updated = yield* events
|
|
|
- .subscribe(Plugin.Event.Updated)
|
|
|
- .pipe(Stream.take(2), Stream.runCollect, Effect.forkScoped({ startImmediately: true }))
|
|
|
+ let updates = 0
|
|
|
+ const unsubscribe = yield* events.listen((event) =>
|
|
|
+ Effect.sync(() => {
|
|
|
+ if (event.type === Plugin.Event.Updated.type) updates++
|
|
|
+ }),
|
|
|
+ )
|
|
|
|
|
|
const managed = () =>
|
|
|
EffectPlugin.define({
|
|
|
@@ -60,17 +65,23 @@ describe("PluginV2", () => {
|
|
|
.pipe(Effect.asVoid),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([managed()])
|
|
|
+ yield* plugins.activate([versioned(managed(), "1")])
|
|
|
|
|
|
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("first")
|
|
|
|
|
|
description = "second"
|
|
|
- yield* plugins.activate([managed()])
|
|
|
+ yield* plugins.activate([versioned(managed(), "2")])
|
|
|
+ expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("second")
|
|
|
+
|
|
|
+ description = "third"
|
|
|
+ yield* plugins.activate([versioned(managed(), "2")])
|
|
|
+ expect(updates).toBe(2)
|
|
|
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("second")
|
|
|
- expect(yield* Fiber.join(updated)).toHaveLength(2)
|
|
|
|
|
|
yield* plugins.activate([])
|
|
|
expect(yield* agents.get(AgentV2.ID.make("configured"))).toBeUndefined()
|
|
|
+ expect(updates).toBe(3)
|
|
|
+ yield* unsubscribe
|
|
|
}),
|
|
|
)
|
|
|
|
|
|
@@ -79,12 +90,12 @@ describe("PluginV2", () => {
|
|
|
const plugins = yield* PluginV2.Service
|
|
|
const active = Plugin.ID.make("active")
|
|
|
const duplicate = "duplicate"
|
|
|
- yield* plugins.activate([{ id: active, effect: () => Effect.void }])
|
|
|
+ yield* plugins.activate([{ id: active, version: "1", effect: () => Effect.void }])
|
|
|
|
|
|
const result = yield* plugins
|
|
|
.activate([
|
|
|
- { id: duplicate, effect: () => Effect.void },
|
|
|
- { id: duplicate, effect: () => Effect.void },
|
|
|
+ { id: duplicate, version: "1", effect: () => Effect.void },
|
|
|
+ { id: duplicate, version: "1", effect: () => Effect.void },
|
|
|
])
|
|
|
.pipe(Effect.exit)
|
|
|
|
|
|
@@ -117,12 +128,12 @@ describe("PluginV2", () => {
|
|
|
},
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([good, bad])
|
|
|
+ yield* plugins.activate([versioned(good), versioned(bad)])
|
|
|
expect(yield* plugins.list()).toEqual([{ id: Plugin.ID.make("good") }])
|
|
|
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("loaded")
|
|
|
|
|
|
fail = false
|
|
|
- yield* plugins.activate([good, bad])
|
|
|
+ yield* plugins.activate([versioned(good), versioned(bad, "2")])
|
|
|
expect(yield* plugins.list()).toEqual([{ id: Plugin.ID.make("good") }, { id: Plugin.ID.make("bad") }])
|
|
|
}),
|
|
|
)
|
|
|
@@ -155,8 +166,8 @@ describe("PluginV2", () => {
|
|
|
}),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([previous])
|
|
|
- yield* plugins.activate([replacement])
|
|
|
+ yield* plugins.activate([versioned(previous)])
|
|
|
+ yield* plugins.activate([versioned(replacement, "2")])
|
|
|
|
|
|
expect(yield* plugins.list()).toEqual([{ id: Plugin.ID.make("managed") }])
|
|
|
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("previous")
|
|
|
@@ -187,8 +198,8 @@ describe("PluginV2", () => {
|
|
|
effect: () => Effect.die(new Error("replacement failed")),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([previous])
|
|
|
- yield* plugins.activate([replacement])
|
|
|
+ yield* plugins.activate([versioned(previous)])
|
|
|
+ yield* plugins.activate([versioned(replacement, "2")])
|
|
|
|
|
|
expect(yield* plugins.list()).toEqual([])
|
|
|
expect(yield* agents.get(AgentV2.ID.make("configured"))).toBeUndefined()
|
|
|
@@ -202,6 +213,7 @@ describe("PluginV2", () => {
|
|
|
yield* plugins.activate(
|
|
|
["first", "second"].map((id) => ({
|
|
|
id,
|
|
|
+ version: "1",
|
|
|
effect: () => Effect.addFinalizer(() => Effect.sync(() => closed.push(id))),
|
|
|
})),
|
|
|
)
|
|
|
@@ -225,7 +237,7 @@ describe("PluginV2", () => {
|
|
|
),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([plugin]).pipe(Effect.provideService(Secret, "secret"))
|
|
|
+ yield* plugins.activate([versioned(plugin)]).pipe(Effect.provideService(Secret, "secret"))
|
|
|
|
|
|
expect(visible).toBe(false)
|
|
|
}),
|
|
|
@@ -253,7 +265,7 @@ describe("PluginV2", () => {
|
|
|
.pipe(Effect.orDie),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([plugin])
|
|
|
+ yield* plugins.activate([versioned(plugin)])
|
|
|
expect((yield* registry.materialize()).definitions.map((tool) => tool.name)).toContain("plugin_tool")
|
|
|
|
|
|
yield* plugins.activate([])
|
|
|
@@ -284,7 +296,7 @@ describe("PluginV2", () => {
|
|
|
.pipe(Effect.orDie),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([plugin])
|
|
|
+ yield* plugins.activate([versioned(plugin)])
|
|
|
|
|
|
expect((yield* registry.materialize()).definitions.map((tool) => tool.name)).toEqual([
|
|
|
"plain",
|
|
|
@@ -343,7 +355,7 @@ describe("PluginV2", () => {
|
|
|
}),
|
|
|
})
|
|
|
|
|
|
- yield* plugins.activate([plugin])
|
|
|
+ yield* plugins.activate([versioned(plugin)])
|
|
|
|
|
|
const materialized = yield* registry.materialize()
|
|
|
const settlement = yield* materialized.settle({
|