command.test.ts 1.8 KB

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