instructions.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect } from "bun:test"
  2. import { AgentV2 } from "@opencode-ai/core/agent"
  3. import { CodeMode } from "@opencode-ai/core/codemode"
  4. import { CodeModeInstructions } from "@opencode-ai/core/codemode/instructions"
  5. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  6. import { Effect, Layer } from "effect"
  7. import { it } from "../lib/effect"
  8. import { readInitial, readUpdate } from "../lib/instructions"
  9. const agent = AgentV2.Info.make(AgentV2.Info.empty(AgentV2.ID.make("build")))
  10. describe("CodeModeInstructions", () => {
  11. it.effect("renders catalog changes and removal", () => {
  12. let catalog: string | undefined = "Initial Code Mode catalog"
  13. const layer = AppNodeBuilder.build(CodeModeInstructions.node, [
  14. [
  15. CodeMode.node,
  16. Layer.mock(CodeMode.Service, {
  17. materialize: () => Effect.succeed({ ...(catalog === undefined ? {} : { instructions: catalog }) }),
  18. register: () => Effect.void,
  19. }),
  20. ],
  21. ])
  22. return Effect.gen(function* () {
  23. const instructions = yield* CodeModeInstructions.Service
  24. const initialized = yield* instructions.load({ id: agent.id, info: agent }).pipe(Effect.flatMap(readInitial))
  25. expect(initialized.text).toBe("Initial Code Mode catalog")
  26. catalog = "Updated Code Mode catalog"
  27. expect(
  28. yield* instructions
  29. .load({ id: agent.id, info: agent })
  30. .pipe(Effect.flatMap((context) => readUpdate(context, initialized))),
  31. ).toMatchObject({
  32. text: "The Code Mode tool catalog has changed. This catalog supersedes the previous Code Mode tool catalog.\n\nUpdated Code Mode catalog",
  33. })
  34. catalog = undefined
  35. expect(
  36. yield* instructions
  37. .load({ id: agent.id, info: agent })
  38. .pipe(Effect.flatMap((context) => readUpdate(context, initialized))),
  39. ).toMatchObject({
  40. text: "Code Mode tools are no longer available. Do not use any previously listed Code Mode tools.",
  41. })
  42. }).pipe(Effect.provide(layer))
  43. })
  44. })