test: migrate app runtime logger effect tests (#27176)
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import { expect } from "bun:test"
|
import { expect } from "bun:test"
|
||||||
import { Context, Effect, Layer, Logger } from "effect"
|
import { Context, Deferred, Effect, Fiber, Layer, Logger } from "effect"
|
||||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||||
import { AppRuntime } from "../../src/effect/app-runtime"
|
import { AppLayer } from "../../src/effect/app-runtime"
|
||||||
import { EffectBridge } from "@/effect/bridge"
|
import { EffectBridge } from "@/effect/bridge"
|
||||||
import { InstanceRef } from "../../src/effect/instance-ref"
|
import { InstanceRef } from "../../src/effect/instance-ref"
|
||||||
import * as EffectLogger from "@opencode-ai/core/effect/logger"
|
import * as EffectLogger from "@opencode-ai/core/effect/logger"
|
||||||
import { makeRuntime } from "../../src/effect/run-service"
|
import * as Observability from "@opencode-ai/core/effect/observability"
|
||||||
import { provideInstance, tmpdirScoped } from "../fixture/fixture"
|
import { attach } from "../../src/effect/run-service"
|
||||||
|
import { TestInstance } from "../fixture/fixture"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const it = testEffect(CrossSpawnSpawner.defaultLayer)
|
const it = testEffect(CrossSpawnSpawner.defaultLayer)
|
||||||
@@ -35,17 +36,8 @@ it.live("makeRuntime installs EffectLogger through Observability.layer", () =>
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const current = yield* Effect.promise(() => makeRuntime(Dummy, layer).runPromise((svc) => svc.current()))
|
const current = yield* Dummy.use((svc) => svc.current()).pipe(
|
||||||
|
Effect.provide(Layer.provideMerge(layer, Observability.layer)),
|
||||||
expect(current.effectLogger).toBe(true)
|
|
||||||
expect(current.defaultLogger).toBe(false)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
it.live("AppRuntime also installs EffectLogger through Observability.layer", () =>
|
|
||||||
Effect.gen(function* () {
|
|
||||||
const current = yield* Effect.promise(() =>
|
|
||||||
AppRuntime.runPromise(Effect.map(Effect.service(Logger.CurrentLoggers), check)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(current.effectLogger).toBe(true)
|
expect(current.effectLogger).toBe(true)
|
||||||
@@ -53,46 +45,61 @@ it.live("AppRuntime also installs EffectLogger through Observability.layer", ()
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live("AppRuntime attaches InstanceRef from ALS", () =>
|
it.live("AppLayer also installs EffectLogger through Observability.layer", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const dir = yield* tmpdirScoped({ git: true })
|
const current = yield* Effect.map(Effect.service(Logger.CurrentLoggers), check).pipe(Effect.provide(AppLayer))
|
||||||
const current = yield* Effect.promise(() =>
|
|
||||||
AppRuntime.runPromise(
|
expect(current.effectLogger).toBe(true)
|
||||||
|
expect(current.defaultLogger).toBe(false)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
it.instance(
|
||||||
|
"attach preserves InstanceRef from the current fiber context",
|
||||||
|
() =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const test = yield* TestInstance
|
||||||
|
const current = yield* attach(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
return (yield* InstanceRef)?.directory
|
return (yield* InstanceRef)?.directory
|
||||||
}),
|
}),
|
||||||
),
|
)
|
||||||
).pipe(provideInstance(dir))
|
|
||||||
|
|
||||||
expect(current).toBe(dir)
|
expect(current).toBe(test.directory)
|
||||||
}),
|
}),
|
||||||
|
{ git: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live("EffectBridge preserves logger and instance context across async boundaries", () =>
|
it.instance(
|
||||||
Effect.gen(function* () {
|
"EffectBridge preserves logger and instance context across async boundaries",
|
||||||
const dir = yield* tmpdirScoped({ git: true })
|
() =>
|
||||||
const result = yield* Effect.promise(() =>
|
Effect.gen(function* () {
|
||||||
AppRuntime.runPromise(
|
const test = yield* TestInstance
|
||||||
Effect.gen(function* () {
|
const bridge = yield* EffectBridge.make()
|
||||||
const bridge = yield* EffectBridge.make()
|
const started = yield* Deferred.make<void>()
|
||||||
return yield* Effect.promise(() =>
|
|
||||||
Promise.resolve().then(() =>
|
const fiber = yield* Effect.gen(function* () {
|
||||||
bridge.promise(
|
yield* Deferred.succeed(started, undefined)
|
||||||
Effect.gen(function* () {
|
return yield* Effect.promise(() =>
|
||||||
return {
|
Promise.resolve().then(() =>
|
||||||
directory: (yield* InstanceRef)?.directory,
|
bridge.promise(
|
||||||
...check(yield* Effect.service(Logger.CurrentLoggers)),
|
Effect.gen(function* () {
|
||||||
}
|
return {
|
||||||
}),
|
directory: (yield* InstanceRef)?.directory,
|
||||||
),
|
...check(yield* Effect.service(Logger.CurrentLoggers)),
|
||||||
|
}
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
}),
|
)
|
||||||
),
|
}).pipe(Effect.forkScoped)
|
||||||
).pipe(provideInstance(dir))
|
|
||||||
|
|
||||||
expect(result.directory).toBe(dir)
|
yield* Deferred.await(started)
|
||||||
expect(result.effectLogger).toBe(true)
|
const result = yield* Fiber.join(fiber)
|
||||||
expect(result.defaultLogger).toBe(false)
|
|
||||||
}),
|
expect(result.directory).toBe(test.directory)
|
||||||
|
expect(result.effectLogger).toBe(true)
|
||||||
|
expect(result.defaultLogger).toBe(false)
|
||||||
|
}).pipe(Effect.provide(Observability.layer)),
|
||||||
|
{ git: true },
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user