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
4 changed files with 65 additions and 52 deletions
+3
View File
@@ -9,6 +9,7 @@ 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
@@ -567,3 +568,5 @@ export const locationLayer = Layer.effect(
})
}),
)
export const node = LayerNode.make(locationLayer, [Credential.node, EventV2.node])
@@ -4,7 +4,6 @@ import { Context, Effect, Layer, Scope } from "effect"
import { enableMapSet } from "immer"
import { State } from "../state"
import { Tool } from "./tool"
import { LayerNode } from "../effect/layer-node"
type Data = {
readonly entries: Map<string, Entry>
@@ -57,5 +56,3 @@ export const layer = Layer.effect(
})
}),
)
export const node = LayerNode.make(layer, [])
+43 -35
View File
@@ -4,17 +4,21 @@ 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 layer = Integration.locationLayer.pipe(
Layer.provide(EventV2.defaultLayer),
Layer.provide(
Layer.mock(Credential.Service)({
create: () => Effect.die("unexpected credential creation"),
list: () => Effect.succeed([]),
}),
),
)
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([]),
}),
),
],
})
function connectionLayer(
created: Array<{
@@ -23,24 +27,26 @@ function connectionLayer(
value: Credential.Info
}>,
) {
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([]),
}),
),
)
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([]),
}),
),
],
})
}
describe("Integration", () => {
@@ -357,14 +363,16 @@ describe("Integration", () => {
value: new Credential.Key({ type: "key", key: "b" }),
},
]
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))),
}),
),
)
const projectionLayer = LayerNode.buildLayer(root, {
replacements: [
LayerNode.replace(
Credential.node,
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
+19 -14
View File
@@ -4,7 +4,6 @@ import { describe, expect } from "bun:test"
import { Effect, Equal, Hash, Layer, Schema } from "effect"
import { Tool } from "@opencode-ai/core/public"
import { Catalog } from "@opencode-ai/core/catalog"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { LocationServiceMap } from "@opencode-ai/core/location-layer"
import { Location } from "@opencode-ai/core/location"
import { PluginBoot } from "@opencode-ai/core/plugin/boot"
@@ -25,20 +24,26 @@ import { Reference } from "../src/reference"
import { ToolRegistry } from "../src/tool/registry"
import { ApplicationTools } from "../src/tool/application-tools"
const locationServices = LayerNode.make(LocationServiceMap.layer, [
ApplicationTools.node,
Project.node,
EventV2.node,
Credential.node,
Npm.node,
ModelsDev.node,
FSUtil.node,
Global.node,
])
const applicationTools = ApplicationTools.layer
const it = testEffect(
LayerNode.buildLayer(LayerNode.group([ApplicationTools.node, Database.node, EventV2.node, locationServices]), {
replacements: [LayerNode.replace(Database.node, Database.layerFromPath(":memory:").pipe(Layer.fresh))],
}),
Layer.merge(
Layer.mergeAll(applicationTools, Database.defaultLayer, EventV2.defaultLayer),
LocationServiceMap.layer.pipe(
Layer.provide(applicationTools),
Layer.provide(
Layer.mergeAll(
Project.defaultLayer,
EventV2.defaultLayer,
Credential.defaultLayer,
Credential.layer.pipe(Layer.provide(Database.layerFromPath(":memory:").pipe(Layer.fresh))),
Npm.defaultLayer,
ModelsDev.defaultLayer,
FSUtil.defaultLayer,
Global.defaultLayer,
),
),
),
),
)
describe("LocationServiceMap", () => {