reference-guidance.test.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { describe, expect } from "bun:test"
  2. import { Effect, Layer } from "effect"
  3. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  4. import { AbsolutePath } from "@opencode-ai/core/schema"
  5. import { Reference } from "@opencode-ai/core/reference"
  6. import { ReferenceGuidance } from "@opencode-ai/core/reference/guidance"
  7. import { SystemContext } from "@opencode-ai/core/system-context/index"
  8. import { it } from "./lib/effect"
  9. const guidanceLayer = (referenceLayer: Layer.Layer<Reference.Service>) =>
  10. AppNodeBuilder.build(ReferenceGuidance.node, [[Reference.node, referenceLayer]])
  11. describe("ReferenceGuidance", () => {
  12. it.effect("lists available references in the system context", () =>
  13. Effect.gen(function* () {
  14. const guidance = yield* ReferenceGuidance.Service
  15. const generation = yield* SystemContext.initialize(yield* guidance.load())
  16. expect(generation.baseline).toContain("<available_references>")
  17. expect(generation.baseline).toContain("<name>docs</name>")
  18. expect(generation.baseline).toContain("<path>/docs</path>")
  19. expect(generation.baseline).toContain("<description>Use for product documentation</description>")
  20. }).pipe(
  21. Effect.provide(
  22. guidanceLayer(
  23. Layer.mock(Reference.Service, {
  24. list: () =>
  25. Effect.succeed([
  26. new Reference.Info({
  27. name: "docs",
  28. path: AbsolutePath.make("/docs"),
  29. description: "Use for product documentation",
  30. source: Reference.LocalSource.make({
  31. type: "local",
  32. path: AbsolutePath.make("/docs"),
  33. description: "Use for product documentation",
  34. }),
  35. }),
  36. ]),
  37. }),
  38. ),
  39. ),
  40. ),
  41. )
  42. it.effect("omits guidance when no references are available", () =>
  43. Effect.gen(function* () {
  44. const guidance = yield* ReferenceGuidance.Service
  45. const generation = yield* SystemContext.initialize(yield* guidance.load())
  46. expect(generation.baseline).toBe("")
  47. }).pipe(Effect.provide(guidanceLayer(Layer.mock(Reference.Service, { list: () => Effect.succeed([]) })))),
  48. )
  49. it.effect("omits references without descriptions", () =>
  50. Effect.gen(function* () {
  51. const guidance = yield* ReferenceGuidance.Service
  52. const generation = yield* SystemContext.initialize(yield* guidance.load())
  53. expect(generation.baseline).toBe("")
  54. }).pipe(
  55. Effect.provide(
  56. guidanceLayer(
  57. Layer.mock(Reference.Service, {
  58. list: () =>
  59. Effect.succeed([
  60. new Reference.Info({
  61. name: "docs",
  62. path: AbsolutePath.make("/docs"),
  63. source: Reference.LocalSource.make({ type: "local", path: AbsolutePath.make("/docs") }),
  64. }),
  65. ]),
  66. }),
  67. ),
  68. ),
  69. ),
  70. )
  71. })