refactor(opencode): migrate session tests to layer nodes (#34494)
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { setTimeout as sleep } from "node:timers/promises"
|
||||
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
||||
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||
import { EffectFlock } from "@opencode-ai/core/util/effect-flock"
|
||||
import { McpAuth } from "../../src/mcp/auth"
|
||||
|
||||
function authFile() {
|
||||
@@ -11,7 +10,7 @@ function authFile() {
|
||||
let activeWrites = 0
|
||||
let sawOverlap = false
|
||||
|
||||
const layer = Layer.effect(
|
||||
const fsLayer = Layer.effect(
|
||||
FSUtil.Service,
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FSUtil.Service
|
||||
@@ -42,14 +41,14 @@ function authFile() {
|
||||
: fs.writeJson(file, value, mode),
|
||||
})
|
||||
}),
|
||||
).pipe(Layer.provide(LayerNode.compile(FSUtil.node)))
|
||||
).pipe(Layer.provide(AppNodeBuilder.build(FSUtil.node)))
|
||||
|
||||
return { layer, raw: () => raw }
|
||||
return { fsLayer, raw: () => raw }
|
||||
}
|
||||
|
||||
function authService(layer: Layer.Layer<FSUtil.Service>) {
|
||||
function authService(fsLayer: Layer.Layer<FSUtil.Service>) {
|
||||
return McpAuth.Service.use((auth) => Effect.succeed(auth)).pipe(
|
||||
Effect.provide(LayerNode.compile(McpAuth.node, [[FSUtil.node, layer]])),
|
||||
Effect.provide(AppNodeBuilder.build(McpAuth.node, [[FSUtil.node, fsLayer]])),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,8 +57,8 @@ test("serializes concurrent auth file updates across service instances", async (
|
||||
|
||||
await Effect.runPromise(
|
||||
Effect.gen(function* () {
|
||||
const first = yield* authService(file.layer)
|
||||
const second = yield* authService(file.layer)
|
||||
const first = yield* authService(file.fsLayer)
|
||||
const second = yield* authService(file.fsLayer)
|
||||
|
||||
yield* Effect.all(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user