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
6 changed files with 60 additions and 55 deletions
-3
View File
@@ -24,7 +24,6 @@ import { ConfigToolOutput } from "./config/tool-output"
import { ConfigWatcher } from "./config/watcher" import { ConfigWatcher } from "./config/watcher"
import { ConfigV1 } from "./v1/config/config" import { ConfigV1 } from "./v1/config/config"
import { ConfigMigrateV1 } from "./v1/config/migrate" import { ConfigMigrateV1 } from "./v1/config/migrate"
import { LayerNode } from "./effect/layer-node"
export class Info extends Schema.Class<Info>("Config.Info")({ export class Info extends Schema.Class<Info>("Config.Info")({
$schema: Schema.optional(Schema.String).annotate({ $schema: Schema.optional(Schema.String).annotate({
@@ -219,5 +218,3 @@ export const layer = Layer.effect(
) )
export const locationLayer = layer.pipe(Layer.provideMerge(Policy.locationLayer)) export const locationLayer = layer.pipe(Layer.provideMerge(Policy.locationLayer))
export const node = (location: LayerNode.Node<Location.Service>, policy = Policy.node(location)) =>
LayerNode.make(layer, [FSUtil.node, Global.node, location, policy])
+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])
-2
View File
@@ -3,7 +3,6 @@ export * as Policy from "./policy"
import { Context, Effect as EffectRuntime, Layer, Schema } from "effect" import { Context, Effect as EffectRuntime, Layer, Schema } from "effect"
import { Wildcard } from "./util/wildcard" import { Wildcard } from "./util/wildcard"
import { Location } from "./location" import { Location } from "./location"
import { LayerNode } from "./effect/layer-node"
export const Effect = Schema.Literals(["allow", "deny"]).annotate({ identifier: "Policy.Effect" }) export const Effect = Schema.Literals(["allow", "deny"]).annotate({ identifier: "Policy.Effect" })
export type Effect = typeof Effect.Type export type Effect = typeof Effect.Type
@@ -45,4 +44,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, [location])
+6 -9
View File
@@ -5,9 +5,9 @@ import { Effect, Layer, Schema } from "effect"
import { FastCheck } from "effect/testing" import { FastCheck } from "effect/testing"
import { Config } from "@opencode-ai/core/config" import { Config } from "@opencode-ai/core/config"
import { ConfigProvider } from "@opencode-ai/core/config/provider" import { ConfigProvider } from "@opencode-ai/core/config/provider"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { ConfigMigrateV1 } from "@opencode-ai/core/v1/config/migrate" import { ConfigMigrateV1 } from "@opencode-ai/core/v1/config/migrate"
import { ConfigV1 } from "@opencode-ai/core/v1/config/config" import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Global } from "@opencode-ai/core/global" import { Global } from "@opencode-ai/core/global"
import { Location } from "@opencode-ai/core/location" import { Location } from "@opencode-ai/core/location"
import { Policy } from "@opencode-ai/core/policy" import { Policy } from "@opencode-ai/core/policy"
@@ -25,7 +25,10 @@ function testLayer(
projectDirectory = directory, projectDirectory = directory,
vcs?: Project.Vcs, vcs?: Project.Vcs,
) { ) {
const locationNode = LayerNode.make( return Config.locationLayer.pipe(
Layer.provide(FSUtil.defaultLayer),
Layer.provide(Global.layerWith({ config: globalDirectory })),
Layer.provide(
Layer.succeed( Layer.succeed(
Location.Service, Location.Service,
Location.Service.of( Location.Service.of(
@@ -35,14 +38,8 @@ function testLayer(
), ),
), ),
), ),
[], ),
) )
const policyNode = Policy.node(locationNode)
return LayerNode.buildLayer(LayerNode.group([Config.node(locationNode, policyNode), policyNode, locationNode]), {
replacements: [
LayerNode.replace(Global.node, Global.layerWith({ config: globalDirectory })),
],
})
} }
const provider = { const provider = {
+20 -12
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: [
LayerNode.replace(
Credential.node,
Layer.mock(Credential.Service)({ Layer.mock(Credential.Service)({
create: () => Effect.die("unexpected credential creation"), create: () => Effect.die("unexpected credential creation"),
list: () => Effect.succeed([]), list: () => Effect.succeed([]),
}), }),
), ),
) ],
})
function connectionLayer( function connectionLayer(
created: Array<{ created: Array<{
@@ -23,9 +27,10 @@ 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(
Credential.node,
Layer.mock(Credential.Service)({ Layer.mock(Credential.Service)({
create: (input) => create: (input) =>
Effect.sync(() => { Effect.sync(() => {
@@ -40,7 +45,8 @@ function connectionLayer(
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(
Credential.node,
Layer.mock(Credential.Service)({ Layer.mock(Credential.Service)({
list: () => Effect.succeed(rows.map((row) => new Credential.Stored(row))), 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