Compare commits

..

1 Commits

Author SHA1 Message Date
James Long b913f8541f test(core): simplify integration layer wiring 2026-06-20 21:53:15 -04:00
5 changed files with 58 additions and 43 deletions
+2
View File
@@ -7,6 +7,7 @@ import { IntegrationSchema } from "./integration/schema"
import { NonNegativeInt, withStatics } from "./schema" import { NonNegativeInt, withStatics } from "./schema"
import { Identifier } from "./util/identifier" import { Identifier } from "./util/identifier"
import { CredentialTable } from "./credential/sql" import { CredentialTable } from "./credential/sql"
import { LayerNode } from "./effect/layer-node"
export const ID = Schema.String.pipe( export const ID = Schema.String.pipe(
Schema.brand("Credential.ID"), Schema.brand("Credential.ID"),
@@ -150,3 +151,4 @@ export const layer = Layer.effect(
) )
export const defaultLayer = layer.pipe(Layer.provide(Database.defaultLayer)) export const defaultLayer = layer.pipe(Layer.provide(Database.defaultLayer))
export const node = LayerNode.make(layer, [Database.node])
+3
View File
@@ -9,6 +9,7 @@ import { State } from "./state"
import { Identifier } from "./util/identifier" import { Identifier } from "./util/identifier"
import { EventV2 } from "./event" import { EventV2 } from "./event"
import { IntegrationConnection } from "./integration/connection" import { IntegrationConnection } from "./integration/connection"
import { LayerNode } from "./effect/layer-node"
export const ID = IntegrationSchema.ID export const ID = IntegrationSchema.ID
export type ID = IntegrationSchema.ID export type ID = IntegrationSchema.ID
@@ -567,3 +568,5 @@ export const locationLayer = Layer.effect(
}) })
}), }),
) )
export const node = LayerNode.make(locationLayer, [Credential.node, EventV2.node])
-3
View File
@@ -2,7 +2,6 @@ export * as LocationMutation from "./location-mutation"
import path from "path" import path from "path"
import { Context, Effect, Layer, Schema } from "effect" import { Context, Effect, Layer, Schema } from "effect"
import { LayerNode } from "./effect/layer-node"
import { FSUtil } from "./fs-util" import { FSUtil } from "./fs-util"
import { Location } from "./location" import { Location } from "./location"
@@ -154,5 +153,3 @@ export const layer = Layer.effect(
) )
export const locationLayer = layer export const locationLayer = layer
export const node = (location: LayerNode.Node<Location.Service>) => LayerNode.make(layer, [FSUtil.node, location])
+43 -35
View File
@@ -4,17 +4,21 @@ import * as TestClock from "effect/testing/TestClock"
import { Integration } from "@opencode-ai/core/integration" import { Integration } from "@opencode-ai/core/integration"
import { Credential } from "@opencode-ai/core/credential" import { Credential } from "@opencode-ai/core/credential"
import { EventV2 } from "@opencode-ai/core/event" import { EventV2 } from "@opencode-ai/core/event"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { it } from "./lib/effect" import { it } from "./lib/effect"
const layer = Integration.locationLayer.pipe( const root = LayerNode.group([Integration.node, EventV2.node])
Layer.provide(EventV2.defaultLayer), const layer = LayerNode.buildLayer(root, {
Layer.provide( replacements: [
Layer.mock(Credential.Service)({ LayerNode.replace(
create: () => Effect.die("unexpected credential creation"), Credential.node,
list: () => Effect.succeed([]), Layer.mock(Credential.Service)({
}), create: () => Effect.die("unexpected credential creation"),
), list: () => Effect.succeed([]),
) }),
),
],
})
function connectionLayer( function connectionLayer(
created: Array<{ created: Array<{
@@ -23,24 +27,26 @@ function connectionLayer(
value: Credential.Info value: Credential.Info
}>, }>,
) { ) {
return Integration.locationLayer.pipe( return LayerNode.buildLayer(root, {
Layer.provideMerge(EventV2.defaultLayer), replacements: [
Layer.provide( LayerNode.replace(
Layer.mock(Credential.Service)({ Credential.node,
create: (input) => Layer.mock(Credential.Service)({
Effect.sync(() => { create: (input) =>
created.push(input) Effect.sync(() => {
return new Credential.Stored({ created.push(input)
id: Credential.ID.create(), return new Credential.Stored({
integrationID: input.integrationID, id: Credential.ID.create(),
label: input.label ?? "default", integrationID: input.integrationID,
value: input.value, label: input.label ?? "default",
}) value: input.value,
}), })
list: () => Effect.succeed([]), }),
}), list: () => Effect.succeed([]),
), }),
) ),
],
})
} }
describe("Integration", () => { describe("Integration", () => {
@@ -357,14 +363,16 @@ describe("Integration", () => {
value: new Credential.Key({ type: "key", key: "b" }), value: new Credential.Key({ type: "key", key: "b" }),
}, },
] ]
const projectionLayer = Integration.locationLayer.pipe( const projectionLayer = LayerNode.buildLayer(root, {
Layer.provide(EventV2.defaultLayer), replacements: [
Layer.provide( LayerNode.replace(
Layer.mock(Credential.Service)({ Credential.node,
list: () => Effect.succeed(rows.map((row) => new Credential.Stored(row))), Layer.mock(Credential.Service)({
}), list: () => Effect.succeed(rows.map((row) => new Credential.Stored(row))),
), }),
) ),
],
})
return Effect.acquireUseRelease( return Effect.acquireUseRelease(
Effect.sync(() => { Effect.sync(() => {
const previous = process.env.INTEGRATION_TEST_ACME_KEY const previous = process.env.INTEGRATION_TEST_ACME_KEY
+10 -5
View File
@@ -2,7 +2,7 @@ import fs from "fs/promises"
import path from "path" import path from "path"
import { describe, expect, test } from "bun:test" import { describe, expect, test } from "bun:test"
import { Effect, Layer, Schema } from "effect" import { Effect, Layer, Schema } from "effect"
import { LayerNode } from "@opencode-ai/core/effect/layer-node" import { FSUtil } from "@opencode-ai/core/fs-util"
import { Location } from "@opencode-ai/core/location" import { Location } from "@opencode-ai/core/location"
import { LocationMutation } from "@opencode-ai/core/location-mutation" import { LocationMutation } from "@opencode-ai/core/location-mutation"
import { AbsolutePath } from "@opencode-ai/core/schema" import { AbsolutePath } from "@opencode-ai/core/schema"
@@ -11,11 +11,16 @@ import { location } from "./fixture/location"
import { it } from "./lib/effect" import { it } from "./lib/effect"
function provide(directory: string) { function provide(directory: string) {
const activeLocation = LayerNode.make( return Effect.provide(
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))), LocationMutation.layer.pipe(
[], Layer.provide(
Layer.mergeAll(
FSUtil.defaultLayer,
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
),
),
),
) )
return Effect.provide(LayerNode.buildLayer(LocationMutation.node(activeLocation)))
} }
function withTmp<A, E, R>(f: (directory: string) => Effect.Effect<A, E, R>) { function withTmp<A, E, R>(f: (directory: string) => Effect.Effect<A, E, R>) {