Compare commits

..

1 Commits

Author SHA1 Message Date
James Long ad4876d351 test(core): simplify project layer wiring 2026-06-20 21:46:51 -04:00
2 changed files with 15 additions and 40 deletions
+10 -24
View File
@@ -3,7 +3,6 @@ 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"
@@ -18,10 +17,9 @@ const locationLayer = Layer.succeed(
location({ directory: AbsolutePath.make("project"), workspaceID: WorkspaceV2.ID.make("wrk_test") }),
),
)
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 eventLayer = Layer.mergeAll(EventV2.defaultLayer, Database.defaultLayer)
const it = testEffect(eventLayer.pipe(Layer.provideMerge(locationLayer)))
const itWithoutLocation = testEffect(eventLayer)
const Message = EventV2.define({
type: "test.message",
@@ -468,15 +466,12 @@ describe("EventV2", () => {
const continueRead = yield* Deferred.make<void>()
let pause = true
const database = Database.layerFromPath(":memory:")
const customEventNode = LayerNode.make(
EventV2.layerWith({
beforeAggregateRead: () =>
pause
? Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(continueRead)))
: Effect.void,
}),
[Database.node],
)
const eventLayer = EventV2.layerWith({
beforeAggregateRead: () =>
pause
? Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(continueRead)))
: Effect.void,
}).pipe(Layer.provide(database))
yield* Effect.gen(function* () {
const events = yield* EventV2.Service
@@ -493,16 +488,7 @@ 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(
LayerNode.buildLayer(EventV2.node, {
replacements: [
LayerNode.replaceWithNode(EventV2.node, customEventNode),
LayerNode.replace(Database.node, database),
],
}),
),
)
}).pipe(Effect.provide(Layer.mergeAll(database, eventLayer)))
}),
)
+5 -16
View File
@@ -2,30 +2,19 @@ import { describe, expect } from "bun:test"
import { $ } from "bun"
import fs from "fs/promises"
import path from "path"
import { Effect, Layer, Schema } from "effect"
import { Effect, Schema } from "effect"
import { ProjectV2 } from "@opencode-ai/core/project"
import { Database } from "@opencode-ai/core/database/database"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Git } from "@opencode-ai/core/git"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { AbsolutePath } from "@opencode-ai/core/schema"
import { Hash } from "@opencode-ai/core/util/hash"
import { ProjectDirectories } from "@opencode-ai/core/project/directories"
import { tmpdir } from "./fixture/tmpdir"
import { testEffect } from "./lib/effect"
const databaseLayer = Database.layerFromPath(":memory:")
const directoriesLayer = ProjectDirectories.layer.pipe(Layer.provide(databaseLayer))
const it = testEffect(
Layer.mergeAll(
ProjectV2.layer.pipe(
Layer.provide(FSUtil.defaultLayer),
Layer.provide(Git.defaultLayer),
Layer.provide(directoriesLayer),
Layer.provide(databaseLayer),
),
databaseLayer,
directoriesLayer,
),
LayerNode.buildLayer(ProjectV2.node, {
replacements: [LayerNode.replace(Database.node, Database.layerFromPath(":memory:"))],
}),
)
function remoteID(remote: string) {