+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
102 lines
3.2 KiB
TypeScript
102 lines
3.2 KiB
TypeScript
import { expect } from "bun:test"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Context, Deferred, Effect, Fiber, Layer, Logger } from "effect"
|
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
|
import { AppLayer } from "../../src/effect/app-runtime"
|
|
import { EffectBridge } from "@/effect/bridge"
|
|
import { InstanceRef } from "../../src/effect/instance-ref"
|
|
import * as Observability from "@opencode-ai/core/observability"
|
|
import { attach } from "../../src/effect/run-service"
|
|
import { TestInstance } from "../fixture/fixture"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
const observabilityLayer = LayerNode.compile(Observability.node)
|
|
const it = testEffect(LayerNode.compile(CrossSpawnSpawner.node))
|
|
|
|
function check(loggers: ReadonlySet<Logger.Logger<unknown, any>>) {
|
|
return {
|
|
tracerLogger: loggers.has(Logger.tracerLogger),
|
|
size: loggers.size,
|
|
}
|
|
}
|
|
|
|
it.live("makeRuntime installs the observability logger", () =>
|
|
Effect.gen(function* () {
|
|
class Dummy extends Context.Service<Dummy, { readonly current: () => Effect.Effect<ReturnType<typeof check>> }>()(
|
|
"@test/Dummy",
|
|
) {}
|
|
|
|
const layer = Layer.effect(
|
|
Dummy,
|
|
Effect.gen(function* () {
|
|
return Dummy.of({
|
|
current: () => Effect.map(Effect.service(Logger.CurrentLoggers), check),
|
|
})
|
|
}),
|
|
)
|
|
|
|
const current = yield* Dummy.use((svc) => svc.current()).pipe(
|
|
Effect.provide(Layer.provideMerge(layer, observabilityLayer)),
|
|
)
|
|
|
|
expect(current.size).toBeGreaterThan(0)
|
|
}),
|
|
)
|
|
|
|
it.live("AppLayer also installs the observability logger", () =>
|
|
Effect.gen(function* () {
|
|
const current = yield* Effect.map(Effect.service(Logger.CurrentLoggers), check).pipe(Effect.provide(AppLayer))
|
|
|
|
expect(current.size).toBeGreaterThan(0)
|
|
}),
|
|
)
|
|
|
|
it.instance(
|
|
"attach preserves InstanceRef from the current fiber context",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const test = yield* TestInstance
|
|
const current = yield* attach(
|
|
Effect.gen(function* () {
|
|
return (yield* InstanceRef)?.directory
|
|
}),
|
|
)
|
|
|
|
expect(current).toBe(test.directory)
|
|
}),
|
|
{ git: true },
|
|
)
|
|
|
|
it.instance(
|
|
"EffectBridge preserves logger and instance context across async boundaries",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const test = yield* TestInstance
|
|
const bridge = yield* EffectBridge.make()
|
|
const started = yield* Deferred.make<void>()
|
|
|
|
const fiber = yield* Effect.gen(function* () {
|
|
yield* Deferred.succeed(started, undefined)
|
|
return yield* Effect.promise(() =>
|
|
Promise.resolve().then(() =>
|
|
bridge.promise(
|
|
Effect.gen(function* () {
|
|
return {
|
|
directory: (yield* InstanceRef)?.directory,
|
|
...check(yield* Effect.service(Logger.CurrentLoggers)),
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
}).pipe(Effect.forkScoped)
|
|
|
|
yield* Deferred.await(started)
|
|
const result = yield* Fiber.join(fiber)
|
|
|
|
expect(result.directory).toBe(test.directory)
|
|
expect(result.size).toBeGreaterThan(0)
|
|
}).pipe(Effect.provide(observabilityLayer)),
|
|
{ git: true },
|
|
)
|