a5b1dc081d
compliance-close / close-non-compliant (push) Has been cancelled
beta / sync (push) Has been cancelled
docs-update / update-docs (push) Has been cancelled
deploy / deploy (push) Has been cancelled
docs-locale-sync / sync-locales (push) Has been cancelled
generate / generate (push) Has been cancelled
nix-eval / nix-eval (push) Has been cancelled
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Has been cancelled
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Has been cancelled
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Has been cancelled
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Has been cancelled
publish / version (push) Has been cancelled
storybook / storybook build (push) Has been cancelled
test / unit (linux) (push) Has been cancelled
test / unit (windows) (push) Has been cancelled
test / e2e (linux) (push) Has been cancelled
test / e2e (windows) (push) Has been cancelled
typecheck / typecheck (push) Has been cancelled
nix-hashes / update-hashes (push) Has been cancelled
publish / build-cli (push) Has been cancelled
publish / sign-cli-windows (push) Has been cancelled
publish / build-tauri (map[host:blacksmith-4vcpu-ubuntu-2404 target:x86_64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-tauri (map[host:blacksmith-4vcpu-windows-2025 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
publish / build-tauri (map[host:blacksmith-8vcpu-ubuntu-2404-arm target:aarch64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
publish / build-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
publish / build-tauri (map[host:windows-2025 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:aarch64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Has been cancelled
publish / build-electron (map[host:macos-latest platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[host:macos-latest platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
publish / publish (push) Has been cancelled
stats / stats (push) Has been cancelled
daily-pr-recap / pr-recap (push) Has been cancelled
daily-issues-recap / daily-recap (push) Has been cancelled
close-issues / close (push) Has been cancelled
close-stale-prs / close-stale-prs (push) Has been cancelled
112 lines
2.7 KiB
TypeScript
112 lines
2.7 KiB
TypeScript
import { afterAll, afterEach, describe, expect, test } from "bun:test"
|
|
import path from "path"
|
|
import { pathToFileURL } from "url"
|
|
import { tmpdir } from "../fixture/fixture"
|
|
|
|
const disableDefault = process.env.OPENCODE_DISABLE_DEFAULT_PLUGINS
|
|
process.env.OPENCODE_DISABLE_DEFAULT_PLUGINS = "1"
|
|
|
|
const { Plugin } = await import("../../src/plugin/index")
|
|
const { Instance } = await import("../../src/project/instance")
|
|
|
|
afterEach(async () => {
|
|
await Instance.disposeAll()
|
|
})
|
|
|
|
afterAll(() => {
|
|
if (disableDefault === undefined) {
|
|
delete process.env.OPENCODE_DISABLE_DEFAULT_PLUGINS
|
|
return
|
|
}
|
|
process.env.OPENCODE_DISABLE_DEFAULT_PLUGINS = disableDefault
|
|
})
|
|
|
|
async function project(source: string) {
|
|
return tmpdir({
|
|
init: async (dir) => {
|
|
const file = path.join(dir, "plugin.ts")
|
|
await Bun.write(file, source)
|
|
await Bun.write(
|
|
path.join(dir, "opencode.json"),
|
|
JSON.stringify(
|
|
{
|
|
$schema: "https://opencode.ai/config.json",
|
|
plugin: [pathToFileURL(file).href],
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
},
|
|
})
|
|
}
|
|
|
|
describe("plugin.trigger", () => {
|
|
test("runs synchronous hooks without crashing", async () => {
|
|
await using tmp = await project(
|
|
[
|
|
"export default async () => ({",
|
|
' "experimental.chat.system.transform": (_input, output) => {',
|
|
' output.system.unshift("sync")',
|
|
" },",
|
|
"})",
|
|
"",
|
|
].join("\n"),
|
|
)
|
|
|
|
const out = await Instance.provide({
|
|
directory: tmp.path,
|
|
fn: async () => {
|
|
const out = { system: [] as string[] }
|
|
await Plugin.trigger(
|
|
"experimental.chat.system.transform",
|
|
{
|
|
model: {
|
|
providerID: "anthropic",
|
|
modelID: "claude-sonnet-4-6",
|
|
} as any,
|
|
},
|
|
out,
|
|
)
|
|
return out
|
|
},
|
|
})
|
|
|
|
expect(out.system).toEqual(["sync"])
|
|
})
|
|
|
|
test("awaits asynchronous hooks", async () => {
|
|
await using tmp = await project(
|
|
[
|
|
"export default async () => ({",
|
|
' "experimental.chat.system.transform": async (_input, output) => {',
|
|
" await Bun.sleep(1)",
|
|
' output.system.unshift("async")',
|
|
" },",
|
|
"})",
|
|
"",
|
|
].join("\n"),
|
|
)
|
|
|
|
const out = await Instance.provide({
|
|
directory: tmp.path,
|
|
fn: async () => {
|
|
const out = { system: [] as string[] }
|
|
await Plugin.trigger(
|
|
"experimental.chat.system.transform",
|
|
{
|
|
model: {
|
|
providerID: "anthropic",
|
|
modelID: "claude-sonnet-4-6",
|
|
} as any,
|
|
},
|
|
out,
|
|
)
|
|
return out
|
|
},
|
|
})
|
|
|
|
expect(out.system).toEqual(["async"])
|
|
})
|
|
})
|