codemode.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. execute: ({ text }) => Effect.succeed({ output: text }),
  19. }),
  20. )
  21. const snapshot = yield* tools.snapshot()
  22. expect(snapshot.definitions.some((tool) => tool.name === "execute")).toBe(true)
  23. expect(snapshot.codeModeCatalog).toStrictEqual([
  24. {
  25. path: "echo",
  26. description: "Echo text",
  27. signature: "tools.echo(input: {\n text: string,\n}): Promise<string>",
  28. },
  29. ])
  30. }).pipe(
  31. Effect.scoped,
  32. Effect.provide(
  33. AppNodeBuilder.build(Tool.node, [
  34. [Location.node, Location.boundNode({ directory: AbsolutePath.make("/project") })],
  35. ]),
  36. ),
  37. ),
  38. )
  39. })