Compare commits

..

1 Commits

Author SHA1 Message Date
James Long 3eb74673c2 test(core): simplify watcher layer wiring 2026-06-20 21:55:17 -04:00
4 changed files with 31 additions and 24 deletions
-4
View File
@@ -8,7 +8,6 @@ import { Location } from "./location"
import { PositiveInt, RelativePath } from "./schema"
import { FileSystemSearch } from "./filesystem/search"
import { Entry, Match } from "./filesystem/schema"
import { LayerNode } from "./effect/layer-node"
export { Entry, Match, Submatch } from "./filesystem/schema"
export const ReadInput = Schema.Struct({
@@ -127,6 +126,3 @@ const baseLayer = Layer.effect(
export const layer = baseLayer.pipe(Layer.provide(FileSystemSearch.defaultLayer), Layer.provide(FSUtil.defaultLayer))
export const locationLayer = layer
export const node = (location: LayerNode.Node<Location.Service>) =>
LayerNode.make(baseLayer, [FSUtil.node, FileSystemSearch.node(location), location])
-4
View File
@@ -10,7 +10,6 @@ import { Location } from "../location"
import { Ripgrep } from "../ripgrep"
import { RelativePath } from "../schema"
import { Flag } from "../flag/flag"
import { LayerNode } from "../effect/layer-node"
export interface Interface {
readonly find: (input: FileSystem.FindInput) => Effect.Effect<FileSystem.Entry[]>
@@ -236,6 +235,3 @@ export const fffLayer = Layer.effect(
export const defaultLayer = Layer.unwrap(
Effect.sync(() => (Flag.OPENCODE_DISABLE_FFF || !Fff.available() ? ripgrepLayer : fffLayer)),
)
export const node = (location: LayerNode.Node<Location.Service>) =>
LayerNode.make(defaultLayer, [FSUtil.node, Ripgrep.node, location])
+18 -9
View File
@@ -4,6 +4,7 @@ import fs from "fs/promises"
import path from "path"
import { ConfigProvider, Deferred, Duration, Effect, Fiber, Layer, Option, Stream } from "effect"
import { Config } from "@opencode-ai/core/config"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { EventV2 } from "@opencode-ai/core/event"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Watcher } from "@opencode-ai/core/filesystem/watcher"
@@ -18,7 +19,8 @@ const describeWatcher = Watcher.hasNativeBinding() && !process.env.CI ? describe
type WatcherEvent = { file: string; event: "add" | "change" | "unlink" }
const it = testEffect(Layer.mergeAll(FSUtil.defaultLayer, EventV2.defaultLayer))
const root = LayerNode.group([FSUtil.node, EventV2.node])
const it = testEffect(LayerNode.buildLayer(root))
const configLayer = Layer.succeed(
Config.Service,
@@ -26,6 +28,7 @@ const configLayer = Layer.succeed(
entries: () => Effect.succeed([]),
}),
)
const configNode = LayerNode.make(configLayer, [])
const flagsLayer = ConfigProvider.layer(
ConfigProvider.fromUnknown({
@@ -35,15 +38,21 @@ const flagsLayer = ConfigProvider.layer(
)
function provide(directory: string, vcs?: Location.Interface["vcs"]) {
const locationLayer = Layer.succeed(
Location.Service,
Location.Service.of(location({ directory: AbsolutePath.make(directory) }, { vcs })),
const locationNode = LayerNode.make(
Layer.succeed(
Location.Service,
Location.Service.of(location({ directory: AbsolutePath.make(directory) }, { vcs })),
),
[],
)
return Effect.provide(
Watcher.layer.pipe(
Layer.provide(configLayer),
Layer.provide(Git.defaultLayer),
Layer.provide(locationLayer),
LayerNode.buildLayer(
LayerNode.group([
LayerNode.make(Watcher.layer, [configNode, EventV2.node, FSUtil.node, Git.node, locationNode]),
root,
]),
{ replacements: [LayerNode.replace(configNode, configLayer)] },
).pipe(
Layer.provide(flagsLayer),
),
)
@@ -196,7 +205,7 @@ describeWatcher("Watcher", () => {
yield* noUpdate((event) => event.file === file, fs.writeFileString(file, "gone")).pipe(
Effect.provideService(EventV2.Service, events),
)
}).pipe(Effect.provide(Layer.mergeAll(FSUtil.defaultLayer, EventV2.defaultLayer))),
}).pipe(Effect.provide(LayerNode.buildLayer(root))),
)
it.live("ignores .git/index changes", () =>
+13 -7
View File
@@ -2,21 +2,27 @@ import fs from "fs/promises"
import path from "path"
import { describe, expect } from "bun:test"
import { Effect, Exit, Layer } from "effect"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { FileSystem } from "@opencode-ai/core/filesystem"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Location } from "@opencode-ai/core/location"
import { Ripgrep } from "@opencode-ai/core/ripgrep"
import { AbsolutePath, RelativePath } from "@opencode-ai/core/schema"
import { location } from "./fixture/location"
import { tmpdir } from "./fixture/tmpdir"
import { it } from "./lib/effect"
const provide = (directory: string) => {
const activeLocation = LayerNode.make(
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
[],
const provide = (directory: string) =>
Effect.provide(
FileSystem.layer.pipe(
Layer.provide(
Layer.mergeAll(
FSUtil.defaultLayer,
Ripgrep.defaultLayer,
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
),
),
),
)
return Effect.provide(LayerNode.buildLayer(FileSystem.node(activeLocation)))
}
const withTmp = <A, E, R>(f: (directory: string) => Effect.Effect<A, E, R>) =>
Effect.acquireRelease(