Compare commits

..
Author SHA1 Message Date
James Long b563a9ca33 test(core): simplify event layer wiring 2026-06-20 21:50:26 -04:00
4 changed files with 59 additions and 58 deletions
-2
View File
@@ -7,7 +7,6 @@ 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"),
@@ -151,4 +150,3 @@ 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
@@ -9,7 +9,6 @@ import { State } from "./state"
import { Identifier } from "./util/identifier"
import { EventV2 } from "./event"
import { IntegrationConnection } from "./integration/connection"
import { LayerNode } from "./effect/layer-node"
export const ID = IntegrationSchema.ID
export type ID = IntegrationSchema.ID
@@ -568,5 +567,3 @@ export const locationLayer = Layer.effect(
})
}),
)
export const node = LayerNode.make(locationLayer, [Credential.node, EventV2.node])
+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),
],
}),
),
)
}),
)
+35 -43
View File
@@ -4,21 +4,17 @@ import * as TestClock from "effect/testing/TestClock"
import { Integration } from "@opencode-ai/core/integration"
import { Credential } from "@opencode-ai/core/credential"
import { EventV2 } from "@opencode-ai/core/event"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { it } from "./lib/effect"
const root = LayerNode.group([Integration.node, EventV2.node])
const layer = LayerNode.buildLayer(root, {
replacements: [
LayerNode.replace(
Credential.node,
Layer.mock(Credential.Service)({
create: () => Effect.die("unexpected credential creation"),
list: () => Effect.succeed([]),
}),
),
],
})
const layer = Integration.locationLayer.pipe(
Layer.provide(EventV2.defaultLayer),
Layer.provide(
Layer.mock(Credential.Service)({
create: () => Effect.die("unexpected credential creation"),
list: () => Effect.succeed([]),
}),
),
)
function connectionLayer(
created: Array<{
@@ -27,26 +23,24 @@ function connectionLayer(
value: Credential.Info
}>,
) {
return LayerNode.buildLayer(root, {
replacements: [
LayerNode.replace(
Credential.node,
Layer.mock(Credential.Service)({
create: (input) =>
Effect.sync(() => {
created.push(input)
return new Credential.Stored({
id: Credential.ID.create(),
integrationID: input.integrationID,
label: input.label ?? "default",
value: input.value,
})
}),
list: () => Effect.succeed([]),
}),
),
],
})
return Integration.locationLayer.pipe(
Layer.provideMerge(EventV2.defaultLayer),
Layer.provide(
Layer.mock(Credential.Service)({
create: (input) =>
Effect.sync(() => {
created.push(input)
return new Credential.Stored({
id: Credential.ID.create(),
integrationID: input.integrationID,
label: input.label ?? "default",
value: input.value,
})
}),
list: () => Effect.succeed([]),
}),
),
)
}
describe("Integration", () => {
@@ -363,16 +357,14 @@ describe("Integration", () => {
value: new Credential.Key({ type: "key", key: "b" }),
},
]
const projectionLayer = LayerNode.buildLayer(root, {
replacements: [
LayerNode.replace(
Credential.node,
Layer.mock(Credential.Service)({
list: () => Effect.succeed(rows.map((row) => new Credential.Stored(row))),
}),
),
],
})
const projectionLayer = Integration.locationLayer.pipe(
Layer.provide(EventV2.defaultLayer),
Layer.provide(
Layer.mock(Credential.Service)({
list: () => Effect.succeed(rows.map((row) => new Credential.Stored(row))),
}),
),
)
return Effect.acquireUseRelease(
Effect.sync(() => {
const previous = process.env.INTEGRATION_TEST_ACME_KEY