command.test.ts 1.6 KB

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