test(core): add CodeMode search fixture catalog

This commit is contained in:
Aiden Cline 2026-07-10 23:20:55 +00:00 committed by 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
commit 180109d8b6
4 changed files with 409 additions and 0 deletions

View file

@ -550,6 +550,7 @@ describe("LocationServiceMap", () => {
expect(blockedState.providers.some((provider) => provider.id === allowedID)).toBe(false)
expect(blockedState.tools.map((tool) => tool.name).sort()).toEqual([
"edit",
"execute",
"glob",
"grep",
"patch",
@ -567,6 +568,7 @@ describe("LocationServiceMap", () => {
expect(allowedState.providers.some((provider) => provider.id === blockedID)).toBe(false)
expect(allowedState.tools.map((tool) => tool.name).sort()).toEqual([
"edit",
"execute",
"glob",
"grep",
"patch",

View file

@ -0,0 +1,50 @@
import { expect } from "bun:test"
import { AgentV2 } from "@opencode-ai/core/agent"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { SessionV2 } from "@opencode-ai/core/session"
import { SessionMessage } from "@opencode-ai/core/session/message"
import { ToolOutputStore } from "@opencode-ai/core/tool-output-store"
import { ToolRegistry } from "@opencode-ai/core/tool/registry"
import { SearchFixtureTool } from "@opencode-ai/core/tool/search-fixture"
import { Effect, Layer } from "effect"
import { testEffect } from "./lib/effect"
import { registerToolPlugin } from "./lib/tool"
const outputStore = Layer.mock(ToolOutputStore.Service, {
bound: (input) => Effect.succeed({ output: input.output, outputPaths: [] }),
})
const it = testEffect(AppNodeBuilder.build(ToolRegistry.node, [[ToolOutputStore.node, outputStore]]))
it.effect("registers 200 searchable no-op tools across namespaces", () =>
Effect.gen(function* () {
expect(SearchFixtureTool.catalog).toHaveLength(20)
expect(SearchFixtureTool.catalog.flatMap((group) => group.operations)).toHaveLength(200)
yield* registerToolPlugin(SearchFixtureTool.Plugin)
const registry = yield* ToolRegistry.Service
const tools = yield* registry.materialize()
expect(tools.definitions.map((tool) => tool.name)).toEqual(["execute"])
const invoke = (code: string, id: string) =>
tools.settle({
sessionID: SessionV2.ID.make("ses_search_fixture"),
agent: AgentV2.ID.make("build"),
assistantMessageID: SessionMessage.ID.make("msg_search_fixture"),
call: { type: "tool-call", id, name: "execute", input: { code } },
})
const searched = yield* invoke(
'return await tools.$codemode.search({ query: "refund payment", namespace: "stripe" })',
"call_search_fixture",
)
expect(searched.result.type).toBe("text")
if (searched.result.type !== "text") return
expect(JSON.parse(String(searched.result.value)).items[0]).toMatchObject({
path: "tools.stripe.refund_payment",
description: "Refund payment in Stripe.",
})
const completed = yield* invoke("return await tools.stripe.refund_payment({})", "call_run_fixture")
expect(completed.result).toEqual({ type: "text", value: "Completed refund payment." })
}),
)