command.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(
  14. Location.Service,
  15. Location.Service.of(location({ directory }, { projectDirectory: project })),
  16. )
  17. const it = testEffect(AppNodeBuilder.build(CommandV2.node, [[Location.node, locationLayer]]))
  18. describe("CommandPlugin.Plugin", () => {
  19. it.effect("registers built-in init and review commands", () =>
  20. Effect.gen(function* () {
  21. const command = yield* CommandV2.Service
  22. yield* CommandPlugin.Plugin.effect(
  23. host({
  24. command: { transform: command.transform, reload: command.reload },
  25. }),
  26. ).pipe(
  27. Effect.provideService(
  28. Location.Service,
  29. Location.Service.of(location({ directory }, { projectDirectory: project })),
  30. ),
  31. )
  32. expect(yield* command.get("init")).toMatchObject({
  33. name: "init",
  34. description: "guided AGENTS.md setup",
  35. })
  36. expect((yield* command.get("init"))?.template).toContain("`/repo`")
  37. expect(yield* command.get("review")).toMatchObject({
  38. name: "review",
  39. description: "review changes [commit|branch|pr], defaults to uncommitted",
  40. subtask: true,
  41. })
  42. }),
  43. )
  44. })