mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-12 11:48:26 +00:00
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
78 lines
3 KiB
TypeScript
78 lines
3 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Effect, Exit, Layer, Scope } from "effect"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { Global } from "@opencode-ai/core/global"
|
|
import { Reference } from "@opencode-ai/core/reference"
|
|
import { Repository } from "@opencode-ai/core/repository"
|
|
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
|
import { it } from "./lib/effect"
|
|
|
|
const cache = Layer.mock(RepositoryCache.Service, {
|
|
ensure: () => Effect.die("unexpected Git materialization"),
|
|
})
|
|
const referenceLayer = AppNodeBuilder.build(Reference.node, [[RepositoryCache.node, cache]])
|
|
|
|
describe("Reference", () => {
|
|
it.effect("registers normalized sources for the owning scope", () =>
|
|
Effect.gen(function* () {
|
|
const references = yield* Reference.Service
|
|
const scope = yield* Scope.make()
|
|
const path = AbsolutePath.make("/docs")
|
|
const source = Reference.LocalSource.make({
|
|
type: "local",
|
|
path,
|
|
description: "Use for API documentation",
|
|
hidden: true,
|
|
})
|
|
yield* references.transform((editor) => editor.add("docs", source)).pipe(Scope.provide(scope))
|
|
|
|
expect(yield* references.list()).toEqual([
|
|
new Reference.Info({ name: "docs", path, description: "Use for API documentation", hidden: true, source }),
|
|
])
|
|
|
|
yield* Scope.close(scope, Exit.void)
|
|
expect(yield* references.list()).toEqual([])
|
|
}).pipe(Effect.provide(referenceLayer)),
|
|
)
|
|
|
|
it.effect("derives Git paths without exposing cache operations", () =>
|
|
Effect.gen(function* () {
|
|
const references = yield* Reference.Service
|
|
const repository = Repository.parseRemote("owner/repo")
|
|
const source = Reference.GitSource.make({ type: "git", repository: "owner/repo", branch: "main" })
|
|
yield* references.transform((editor) => editor.add("sdk", source))
|
|
|
|
expect(yield* references.list()).toEqual([
|
|
new Reference.Info({
|
|
name: "sdk",
|
|
path: AbsolutePath.make(Repository.cachePath(Global.Path.repos, repository)),
|
|
source,
|
|
}),
|
|
])
|
|
}).pipe(Effect.scoped, Effect.provide(referenceLayer)),
|
|
)
|
|
|
|
it.effect("preserves configured Git descriptions", () =>
|
|
Effect.gen(function* () {
|
|
const references = yield* Reference.Service
|
|
const repository = Repository.parseRemote("owner/repo")
|
|
const source = Reference.GitSource.make({
|
|
type: "git",
|
|
repository: "owner/repo",
|
|
description: "Use for SDK implementation details",
|
|
})
|
|
yield* references.transform((editor) => editor.add("sdk", source))
|
|
|
|
expect(yield* references.list()).toEqual([
|
|
new Reference.Info({
|
|
name: "sdk",
|
|
path: AbsolutePath.make(Repository.cachePath(Global.Path.repos, repository)),
|
|
description: "Use for SDK implementation details",
|
|
source,
|
|
}),
|
|
])
|
|
}).pipe(Effect.scoped, Effect.provide(referenceLayer)),
|
|
)
|
|
})
|