mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-24 05:14:44 +00:00
Migrate test inits from Promise to Effect (#25377)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { expect } from "bun:test"
|
||||
import { Effect, Layer, Context } from "effect"
|
||||
import { InstanceRef } from "../../src/effect/instance-ref"
|
||||
import { makeRuntime } from "../../src/effect/run-service"
|
||||
import { ProjectID } from "../../src/project/schema"
|
||||
import { it } from "../lib/effect"
|
||||
|
||||
class Shared extends Context.Service<Shared, { readonly id: number }>()("@test/Shared") {}
|
||||
const testDirectory = "/tmp/opencode-test"
|
||||
|
||||
it.live("makeRuntime shares dependent layers through the shared memo map", () =>
|
||||
Effect.gen(function* () {
|
||||
@@ -47,3 +50,40 @@ it.live("makeRuntime shares dependent layers through the shared memo map", () =>
|
||||
expect(n).toBe(1)
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("makeRuntime inherits InstanceRef from the current fiber", () =>
|
||||
Effect.gen(function* () {
|
||||
class NeedsInstance extends Context.Service<
|
||||
NeedsInstance,
|
||||
{ readonly directory: () => Effect.Effect<string | undefined> }
|
||||
>()("@test/NeedsInstance") {}
|
||||
|
||||
const runtime = makeRuntime(
|
||||
NeedsInstance,
|
||||
Layer.succeed(
|
||||
NeedsInstance,
|
||||
NeedsInstance.of({
|
||||
directory: () =>
|
||||
Effect.gen(function* () {
|
||||
return (yield* InstanceRef)?.directory
|
||||
}),
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
const actual = yield* Effect.promise(() => runtime.runPromise((svc) => svc.directory()))
|
||||
|
||||
expect(actual).toBe(testDirectory)
|
||||
}).pipe(
|
||||
Effect.provideService(InstanceRef, {
|
||||
directory: testDirectory,
|
||||
worktree: testDirectory,
|
||||
project: {
|
||||
id: ProjectID.global,
|
||||
worktree: testDirectory,
|
||||
time: { created: 0, updated: 0 },
|
||||
sandboxes: [],
|
||||
},
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user