Compare commits

..

1 Commits

Author SHA1 Message Date
James Long b563a9ca33 test(core): simplify event layer wiring 2026-06-20 21:50:26 -04:00
3 changed files with 36 additions and 21 deletions
-2
View File
@@ -1,6 +1,5 @@
import path from "path"
import { Context, Effect, Layer, Schema } from "effect"
import { LayerNode } from "./effect/layer-node"
import { FSUtil } from "./fs-util"
import { Git } from "./git"
import { Global } from "./global"
@@ -259,7 +258,6 @@ export const defaultLayer: Layer.Layer<Service> = layer.pipe(
Layer.provide(Git.defaultLayer),
Layer.provide(Global.defaultLayer),
)
export const node = LayerNode.make(layer, [FSUtil.node, Git.node, EffectFlock.node, Global.node])
function statusForRepository(input: { reuse: boolean; refresh?: boolean; branchMatches?: boolean }) {
if (!input.reuse) return "cloned" as const
+24 -10
View File
@@ -3,6 +3,7 @@ import { Cause, DateTime, Deferred, Effect, Exit, Fiber, Layer, Schema, Stream }
import { EventV2 } from "@opencode-ai/core/event"
import { Database } from "@opencode-ai/core/database/database"
import { EventSequenceTable, EventTable } from "@opencode-ai/core/event/sql"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { Location } from "@opencode-ai/core/location"
import { AbsolutePath } from "@opencode-ai/core/schema"
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
@@ -17,9 +18,10 @@ const locationLayer = Layer.succeed(
location({ directory: AbsolutePath.make("project"), workspaceID: WorkspaceV2.ID.make("wrk_test") }),
),
)
const eventLayer = Layer.mergeAll(EventV2.defaultLayer, Database.defaultLayer)
const it = testEffect(eventLayer.pipe(Layer.provideMerge(locationLayer)))
const itWithoutLocation = testEffect(eventLayer)
const locationNode = LayerNode.make(locationLayer, [])
const eventNode = LayerNode.group([EventV2.node, Database.node])
const it = testEffect(LayerNode.buildLayer(LayerNode.group([eventNode, locationNode])))
const itWithoutLocation = testEffect(LayerNode.buildLayer(eventNode))
const Message = EventV2.define({
type: "test.message",
@@ -466,12 +468,15 @@ describe("EventV2", () => {
const continueRead = yield* Deferred.make<void>()
let pause = true
const database = Database.layerFromPath(":memory:")
const eventLayer = EventV2.layerWith({
beforeAggregateRead: () =>
pause
? Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(continueRead)))
: Effect.void,
}).pipe(Layer.provide(database))
const customEventNode = LayerNode.make(
EventV2.layerWith({
beforeAggregateRead: () =>
pause
? Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(continueRead)))
: Effect.void,
}),
[Database.node],
)
yield* Effect.gen(function* () {
const events = yield* EventV2.Service
@@ -488,7 +493,16 @@ describe("EventV2", () => {
expect(Array.from(yield* Fiber.join(fiber)).map((event) => [event.cursor, event.event.data])).toEqual([
[EventV2.Cursor.make(0), { id: aggregateID, text: "during handoff" }],
])
}).pipe(Effect.provide(Layer.mergeAll(database, eventLayer)))
}).pipe(
Effect.provide(
LayerNode.buildLayer(EventV2.node, {
replacements: [
LayerNode.replaceWithNode(EventV2.node, customEventNode),
LayerNode.replace(Database.node, database),
],
}),
),
)
}),
)
+12 -9
View File
@@ -3,10 +3,12 @@ import fs from "fs/promises"
import path from "path"
import { pathToFileURL } from "url"
import { Effect, Layer } from "effect"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Git } from "@opencode-ai/core/git"
import { Global } from "@opencode-ai/core/global"
import { Repository } from "@opencode-ai/core/repository"
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
import { EffectFlock } from "@opencode-ai/core/util/effect-flock"
import { git, gitRemote } from "./fixture/git"
import { tmpdir } from "./fixture/tmpdir"
import { testEffect } from "./lib/effect"
@@ -87,14 +89,15 @@ describe("RepositoryCache", () => {
})
function cacheLayer(root: string) {
return LayerNode.buildLayer(RepositoryCache.node, {
replacements: [
LayerNode.replace(
Global.node,
Global.layerWith({ state: path.join(root, "state"), repos: path.join(root, "repos") }),
),
],
})
const dependencies = Layer.mergeAll(
Global.layerWith({ state: path.join(root, "state"), repos: path.join(root, "repos") }),
FSUtil.defaultLayer,
)
return RepositoryCache.layer.pipe(
Layer.provide(EffectFlock.layer.pipe(Layer.provide(dependencies))),
Layer.provide(Git.defaultLayer),
Layer.provide(dependencies),
)
}
function withRemote<A, E, R>(body: (fixture: Awaited<ReturnType<typeof gitRemote>>) => Effect.Effect<A, E, R>) {