codemode.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect } from "bun:test"
  2. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  3. import { Location } from "@opencode-ai/core/location"
  4. import { AbsolutePath } from "@opencode-ai/core/schema"
  5. import { Tool } from "@opencode-ai/core/tool"
  6. import { Effect, Schema } from "effect"
  7. import { it } from "./lib/effect"
  8. describe("CodeMode", () => {
  9. it.effect("owns registrations, execute, and catalog materialization", () =>
  10. Effect.gen(function* () {
  11. const tools = yield* Tool.Service
  12. yield* tools.transform((draft) =>
  13. draft.add({
  14. name: "echo",
  15. description: "Echo text",
  16. input: Schema.Struct({ text: Schema.String }),
  17. output: Schema.String,
  18. options: { pinned: true },
  19. execute: ({ text }) => Effect.succeed({ output: text }),
  20. }),
  21. )
  22. const snapshot = yield* tools.snapshot()
  23. expect(snapshot.definitions.some((tool) => tool.name === "execute")).toBe(true)
  24. expect(snapshot.codeModeCatalog).toStrictEqual([
  25. {
  26. path: "echo",
  27. description: "Echo text",
  28. signature: "tools.echo(input: {\n text: string,\n}): Promise<string>",
  29. pinned: true,
  30. },
  31. ])
  32. }).pipe(
  33. Effect.scoped,
  34. Effect.provide(
  35. AppNodeBuilder.build(Tool.node, [
  36. [Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
  37. ]),
  38. ),
  39. ),
  40. )
  41. })