command.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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: {
  25. list: () => Effect.die("unused command.list"),
  26. transform: command.transform,
  27. reload: command.reload,
  28. },
  29. }),
  30. ).pipe(
  31. Effect.provideService(
  32. Location.Service,
  33. Location.Service.of(location({ directory }, { projectDirectory: project })),
  34. ),
  35. )
  36. expect(yield* command.get("init")).toMatchObject({
  37. name: "init",
  38. description: "guided AGENTS.md setup",
  39. })
  40. expect((yield* command.get("init"))?.template).toContain("`/repo`")
  41. expect(yield* command.get("review")).toMatchObject({
  42. name: "review",
  43. description: "review changes [commit|branch|pr], defaults to uncommitted",
  44. })
  45. }),
  46. )
  47. })