Compare commits

..

1 Commits

Author SHA1 Message Date
James Long ed3b2a0d79 test(core): simplify location layer wiring 2026-06-20 22:00:43 -04:00
6 changed files with 39 additions and 51 deletions
+2
View File
@@ -7,6 +7,7 @@ import { IntegrationSchema } from "./integration/schema"
import { NonNegativeInt, withStatics } from "./schema"
import { Identifier } from "./util/identifier"
import { CredentialTable } from "./credential/sql"
import { LayerNode } from "./effect/layer-node"
export const ID = Schema.String.pipe(
Schema.brand("Credential.ID"),
@@ -150,3 +151,4 @@ export const layer = Layer.effect(
)
export const defaultLayer = layer.pipe(Layer.provide(Database.defaultLayer))
export const node = LayerNode.make(layer, [Database.node])
-3
View File
@@ -3,7 +3,6 @@ export * as FileMutation from "./file-mutation"
import { Context, Effect, Layer, Schema } from "effect"
import { dirname } from "path"
import { KeyedMutex } from "./effect/keyed-mutex"
import { LayerNode } from "./effect/layer-node"
import { FSUtil } from "./fs-util"
export interface Target {
@@ -172,8 +171,6 @@ export const layer = Layer.effect(
}),
)
export const node = LayerNode.make(layer, [FSUtil.node])
function splitBom(text: string) {
const stripped = text.replace(/^\uFEFF+/, "")
return { bom: stripped.length !== text.length, text: stripped }
-3
View File
@@ -2,7 +2,6 @@ export * as LocationMutation from "./location-mutation"
import path from "path"
import { Context, Effect, Layer, Schema } from "effect"
import { LayerNode } from "./effect/layer-node"
import { FSUtil } from "./fs-util"
import { Location } from "./location"
@@ -154,5 +153,3 @@ export const layer = Layer.effect(
)
export const locationLayer = layer
export const node = (location: LayerNode.Node<Location.Service>) => LayerNode.make(layer, [FSUtil.node, location])
@@ -4,6 +4,7 @@ import { Context, Effect, Layer, Scope } from "effect"
import { enableMapSet } from "immer"
import { State } from "../state"
import { Tool } from "./tool"
import { LayerNode } from "../effect/layer-node"
type Data = {
readonly entries: Map<string, Entry>
@@ -56,3 +57,5 @@ export const layer = Layer.effect(
})
}),
)
export const node = LayerNode.make(layer, [])
+20 -26
View File
@@ -2,7 +2,6 @@ import fs from "fs/promises"
import path from "path"
import { describe, expect } from "bun:test"
import { Deferred, Effect, Fiber, Layer } from "effect"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { FileMutation } from "@opencode-ai/core/file-mutation"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Location } from "@opencode-ai/core/location"
@@ -12,16 +11,14 @@ import { location } from "./fixture/location"
import { tmpdir } from "./fixture/tmpdir"
import { it } from "./lib/effect"
function provide(directory: string, filesystem?: LayerNode.Replacement<FSUtil.Service>) {
const activeLocation = LayerNode.make(
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
[],
)
return Effect.provide(
LayerNode.buildLayer(LayerNode.group([LocationMutation.node(activeLocation), FileMutation.node]), {
replacements: filesystem ? [filesystem] : [],
}),
function provide(directory: string, filesystem = FSUtil.defaultLayer) {
const activeLocation = Layer.succeed(
Location.Service,
Location.Service.of(location({ directory: AbsolutePath.make(directory) })),
)
const resolution = LocationMutation.layer.pipe(Layer.provide(filesystem), Layer.provide(activeLocation))
const mutation = FileMutation.layer.pipe(Layer.provide(filesystem))
return Effect.provide(Layer.mergeAll(resolution, mutation))
}
function withTmp<A, E, R>(f: (directory: string) => Effect.Effect<A, E, R>) {
@@ -350,20 +347,17 @@ describe("FileMutation", () => {
})
function instrumentWrites(run: <E>(write: Effect.Effect<void, E>, target: string) => Effect.Effect<void, E>) {
return LayerNode.replace(
FSUtil.node,
Layer.effect(
FSUtil.Service,
Effect.gen(function* () {
const filesystem = yield* FSUtil.Service
return FSUtil.Service.of({
...filesystem,
writeWithDirs: (target, content, mode) => run(filesystem.writeWithDirs(target, content, mode), target),
writeFile: (target, content, options) => run(filesystem.writeFile(target, content, options), target),
writeFileString: (target, content, options) =>
run(filesystem.writeFileString(target, content, options), target),
})
}),
).pipe(Layer.provide(LayerNode.buildLayer(FSUtil.node))),
)
return Layer.effect(
FSUtil.Service,
Effect.gen(function* () {
const filesystem = yield* FSUtil.Service
return FSUtil.Service.of({
...filesystem,
writeWithDirs: (target, content, mode) => run(filesystem.writeWithDirs(target, content, mode), target),
writeFile: (target, content, options) => run(filesystem.writeFile(target, content, options), target),
writeFileString: (target, content, options) =>
run(filesystem.writeFileString(target, content, options), target),
})
}),
).pipe(Layer.provide(FSUtil.defaultLayer))
}
+14 -19
View File
@@ -4,6 +4,7 @@ import { describe, expect } from "bun:test"
import { Effect, Equal, Hash, Layer, Schema } from "effect"
import { Tool } from "@opencode-ai/core/public"
import { Catalog } from "@opencode-ai/core/catalog"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { LocationServiceMap } from "@opencode-ai/core/location-layer"
import { Location } from "@opencode-ai/core/location"
import { PluginBoot } from "@opencode-ai/core/plugin/boot"
@@ -24,26 +25,20 @@ import { Reference } from "../src/reference"
import { ToolRegistry } from "../src/tool/registry"
import { ApplicationTools } from "../src/tool/application-tools"
const applicationTools = ApplicationTools.layer
const locationServices = LayerNode.make(LocationServiceMap.layer, [
ApplicationTools.node,
Project.node,
EventV2.node,
Credential.node,
Npm.node,
ModelsDev.node,
FSUtil.node,
Global.node,
])
const it = testEffect(
Layer.merge(
Layer.mergeAll(applicationTools, Database.defaultLayer, EventV2.defaultLayer),
LocationServiceMap.layer.pipe(
Layer.provide(applicationTools),
Layer.provide(
Layer.mergeAll(
Project.defaultLayer,
EventV2.defaultLayer,
Credential.defaultLayer,
Credential.layer.pipe(Layer.provide(Database.layerFromPath(":memory:").pipe(Layer.fresh))),
Npm.defaultLayer,
ModelsDev.defaultLayer,
FSUtil.defaultLayer,
Global.defaultLayer,
),
),
),
),
LayerNode.buildLayer(LayerNode.group([ApplicationTools.node, Database.node, EventV2.node, locationServices]), {
replacements: [LayerNode.replace(Database.node, Database.layerFromPath(":memory:").pipe(Layer.fresh))],
}),
)
describe("LocationServiceMap", () => {