command.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { CommandV2 } from "@opencode-ai/core/command"
  4. import { ModelV2 } from "@opencode-ai/core/model"
  5. import { ProviderV2 } from "@opencode-ai/core/provider"
  6. import { testEffect } from "./lib/effect"
  7. const it = testEffect(CommandV2.locationLayer)
  8. describe("CommandV2", () => {
  9. it.effect("applies command transforms and preserves later overrides", () =>
  10. Effect.gen(function* () {
  11. const command = yield* CommandV2.Service
  12. yield* command.transform((editor) => {
  13. editor.update("review", (command) => {
  14. command.template = "First"
  15. command.description = "Review code"
  16. })
  17. editor.update("review", (command) => {
  18. command.template = "Second"
  19. command.model = {
  20. id: ModelV2.ID.make("claude"),
  21. providerID: ProviderV2.ID.make("anthropic"),
  22. variant: ModelV2.VariantID.make("high"),
  23. }
  24. })
  25. })
  26. expect(yield* command.get("review")).toEqual(
  27. new CommandV2.Info({
  28. name: "review",
  29. template: "Second",
  30. description: "Review code",
  31. model: {
  32. id: ModelV2.ID.make("claude"),
  33. providerID: ProviderV2.ID.make("anthropic"),
  34. variant: ModelV2.VariantID.make("high"),
  35. },
  36. }),
  37. )
  38. expect(yield* command.list()).toEqual([
  39. new CommandV2.Info({
  40. name: "review",
  41. template: "Second",
  42. description: "Review code",
  43. model: {
  44. id: ModelV2.ID.make("claude"),
  45. providerID: ProviderV2.ID.make("anthropic"),
  46. variant: ModelV2.VariantID.make("high"),
  47. },
  48. }),
  49. ])
  50. }),
  51. )
  52. })