command.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect } from "bun:test"
  2. import { Effect, Layer } from "effect"
  3. import { CommandV2 } from "@opencode-ai/core/command"
  4. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  5. import { Location } from "@opencode-ai/core/location"
  6. import { CommandPlugin } from "@opencode-ai/core/plugin/command"
  7. import { AbsolutePath } from "@opencode-ai/core/schema"
  8. import { location } from "../fixture/location"
  9. import { testEffect } from "../lib/effect"
  10. import { host } from "./host"
  11. const directory = AbsolutePath.make("/repo/packages/app")
  12. const project = AbsolutePath.make("/repo")
  13. const locationLayer = Layer.succeed(Location.Service, Location.Service.of(location({ directory }, { projectDirectory: project })))
  14. const it = testEffect(
  15. AppNodeBuilder.build(CommandV2.node, [[Location.node, locationLayer]]),
  16. )
  17. describe("CommandPlugin.Plugin", () => {
  18. it.effect("registers built-in init and review commands", () =>
  19. Effect.gen(function* () {
  20. const command = yield* CommandV2.Service
  21. yield* CommandPlugin.Plugin.effect(
  22. host({
  23. command: { transform: command.transform, reload: command.reload },
  24. }),
  25. ).pipe(
  26. Effect.provideService(
  27. Location.Service,
  28. Location.Service.of(location({ directory }, { projectDirectory: project })),
  29. ),
  30. )
  31. expect(yield* command.get("init")).toMatchObject({
  32. name: "init",
  33. description: "guided AGENTS.md setup",
  34. })
  35. expect((yield* command.get("init"))?.template).toContain("`/repo`")
  36. expect(yield* command.get("review")).toMatchObject({
  37. name: "review",
  38. description: "review changes [commit|branch|pr], defaults to uncommitted",
  39. subtask: true,
  40. })
  41. }),
  42. )
  43. })