Files
opencode/packages/core/test/reference-guidance.test.ts
+21 8c94e9005f chore: merge dev into v2 (#34788)
Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: Kit Langton <[email protected]>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Affan Ali <[email protected]>
Co-authored-by: affanali2k3 <[email protected]>
Co-authored-by: Frank <[email protected]>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Co-authored-by: Jay V <[email protected]>
Co-authored-by: Dax Raad <[email protected]>
Co-authored-by: Aarav Sareen <[email protected]>
Co-authored-by: OpeOginni <[email protected]>
Co-authored-by: Luke Parker <[email protected]>
Co-authored-by: Ben Guthrie <[email protected]>
Co-authored-by: Dax <[email protected]>
Co-authored-by: Filip <[email protected]>
Co-authored-by: Max Anderson <[email protected]>
Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: Jack <[email protected]>
Co-authored-by: Shoubhit Dash <[email protected]>
Co-authored-by: Dustin Deus <[email protected]>
Co-authored-by: starptech <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Co-authored-by: usrnk1 <[email protected]>
Co-authored-by: Jay <[email protected]>
Co-authored-by: runvip <[email protected]>
Co-authored-by: opencode <[email protected]>
Co-authored-by: Julian Coy <[email protected]>
Co-authored-by: Vladimir Glafirov <[email protected]>
2026-07-01 17:12:00 -04:00

77 lines
2.9 KiB
TypeScript

import { describe, expect } from "bun:test"
import { Effect, Layer } from "effect"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { AbsolutePath } from "@opencode-ai/core/schema"
import { Reference } from "@opencode-ai/core/reference"
import { ReferenceGuidance } from "@opencode-ai/core/reference/guidance"
import { SystemContext } from "@opencode-ai/core/system-context/index"
import { it } from "./lib/effect"
const guidanceLayer = (referenceLayer: Layer.Layer<Reference.Service>) =>
AppNodeBuilder.build(ReferenceGuidance.node, [[Reference.node, referenceLayer]])
describe("ReferenceGuidance", () => {
it.effect("lists available references in the system context", () =>
Effect.gen(function* () {
const guidance = yield* ReferenceGuidance.Service
const generation = yield* SystemContext.initialize(yield* guidance.load())
expect(generation.baseline).toContain("<available_references>")
expect(generation.baseline).toContain("<name>docs</name>")
expect(generation.baseline).toContain("<path>/docs</path>")
expect(generation.baseline).toContain("<description>Use for product documentation</description>")
}).pipe(
Effect.provide(
guidanceLayer(
Layer.mock(Reference.Service, {
list: () =>
Effect.succeed([
new Reference.Info({
name: "docs",
path: AbsolutePath.make("/docs"),
description: "Use for product documentation",
source: Reference.LocalSource.make({
type: "local",
path: AbsolutePath.make("/docs"),
description: "Use for product documentation",
}),
}),
]),
}),
),
),
),
)
it.effect("omits guidance when no references are available", () =>
Effect.gen(function* () {
const guidance = yield* ReferenceGuidance.Service
const generation = yield* SystemContext.initialize(yield* guidance.load())
expect(generation.baseline).toBe("")
}).pipe(Effect.provide(guidanceLayer(Layer.mock(Reference.Service, { list: () => Effect.succeed([]) })))),
)
it.effect("omits references without descriptions", () =>
Effect.gen(function* () {
const guidance = yield* ReferenceGuidance.Service
const generation = yield* SystemContext.initialize(yield* guidance.load())
expect(generation.baseline).toBe("")
}).pipe(
Effect.provide(
guidanceLayer(
Layer.mock(Reference.Service, {
list: () =>
Effect.succeed([
new Reference.Info({
name: "docs",
path: AbsolutePath.make("/docs"),
source: Reference.LocalSource.make({ type: "local", path: AbsolutePath.make("/docs") }),
}),
]),
}),
),
),
),
)
})