8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
109 lines
3.2 KiB
TypeScript
109 lines
3.2 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Effect } from "effect"
|
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
|
import { Npm } from "@opencode-ai/core/npm"
|
|
import path from "path"
|
|
import { pathToFileURL } from "url"
|
|
import { Account } from "../../src/account/account"
|
|
import { Auth } from "../../src/auth"
|
|
import { RuntimeFlags } from "../../src/effect/runtime-flags"
|
|
import { Plugin } from "../../src/plugin/index"
|
|
|
|
import { TestInstance } from "../fixture/fixture"
|
|
import { testEffect } from "../lib/effect"
|
|
import { AccountTest } from "../fake/account"
|
|
import { AuthTest } from "../fake/auth"
|
|
import { NpmTest } from "../fake/npm"
|
|
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
import { ModelV2 } from "@opencode-ai/core/model"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
|
|
const it = testEffect(
|
|
AppNodeBuilder.build(LayerNode.group([Plugin.node, CrossSpawnSpawner.node]), [
|
|
[Auth.node, AuthTest.empty],
|
|
[Account.node, AccountTest.empty],
|
|
[Npm.node, NpmTest.noop],
|
|
[RuntimeFlags.node, RuntimeFlags.layer({ disableDefaultPlugins: true })],
|
|
]),
|
|
)
|
|
const systemHook = "experimental.chat.system.transform"
|
|
|
|
function withProject<A, E, R>(source: string, self: Effect.Effect<A, E, R>) {
|
|
return Effect.gen(function* () {
|
|
const test = yield* TestInstance
|
|
const file = path.join(test.directory, "plugin.ts")
|
|
yield* Effect.all(
|
|
[
|
|
Effect.promise(() => Bun.write(file, source)),
|
|
Effect.promise(() =>
|
|
Bun.write(
|
|
path.join(test.directory, "opencode.json"),
|
|
JSON.stringify(
|
|
{
|
|
$schema: "https://opencode.ai/config.json",
|
|
plugin: [pathToFileURL(file).href],
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
{ discard: true, concurrency: 2 },
|
|
)
|
|
return yield* self
|
|
})
|
|
}
|
|
|
|
const triggerSystemTransform = Effect.fn("PluginTriggerTest.triggerSystemTransform")(function* () {
|
|
const plugin = yield* Plugin.Service
|
|
const out = { system: [] as string[] }
|
|
yield* plugin.trigger(
|
|
systemHook,
|
|
{
|
|
model: {
|
|
providerID: ProviderV2.ID.anthropic,
|
|
modelID: ModelV2.ID.make("claude-sonnet-4-6"),
|
|
},
|
|
},
|
|
out,
|
|
)
|
|
return out.system
|
|
})
|
|
|
|
describe("plugin.trigger", () => {
|
|
it.instance("runs synchronous hooks without crashing", () =>
|
|
withProject(
|
|
[
|
|
"export default async () => ({",
|
|
` ${JSON.stringify(systemHook)}: (_input, output) => {`,
|
|
' output.system.unshift("sync")',
|
|
" },",
|
|
"})",
|
|
"",
|
|
].join("\n"),
|
|
Effect.gen(function* () {
|
|
expect(yield* triggerSystemTransform()).toEqual(["sync"])
|
|
}),
|
|
),
|
|
)
|
|
|
|
it.instance("awaits asynchronous hooks", () =>
|
|
withProject(
|
|
[
|
|
"export default async () => ({",
|
|
` ${JSON.stringify(systemHook)}: async (_input, output) => {`,
|
|
" await Bun.sleep(1)",
|
|
' output.system.unshift("async")',
|
|
" },",
|
|
"})",
|
|
"",
|
|
].join("\n"),
|
|
Effect.gen(function* () {
|
|
expect(yield* triggerSystemTransform()).toEqual(["async"])
|
|
}),
|
|
),
|
|
)
|
|
})
|