refactor(core): move database schema ownership (#29068)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,16 +2,19 @@ import { afterEach, expect } from "bun:test"
|
||||
import { Cause, Effect, Exit, Fiber, Layer, Queue } from "effect"
|
||||
import { Question } from "../../src/question"
|
||||
import { InstanceRef } from "../../src/effect/instance-ref"
|
||||
import { InstanceRuntime } from "../../src/project/instance-runtime"
|
||||
import { InstanceStore } from "../../src/project/instance-store"
|
||||
import { QuestionID } from "../../src/question/schema"
|
||||
import { disposeAllInstances, provideInstance, reloadTestInstance, tmpdirScoped } from "../fixture/fixture"
|
||||
import { disposeAllInstances, provideInstance, testInstanceStoreLayer, tmpdirScoped } from "../fixture/fixture"
|
||||
import { SessionID } from "../../src/session/schema"
|
||||
import { testEffect } from "../lib/effect"
|
||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||
import { Bus } from "../../src/bus"
|
||||
import { EventV2Bridge } from "../../src/event-v2-bridge"
|
||||
|
||||
const it = testEffect(
|
||||
Layer.mergeAll(Question.layer.pipe(Layer.provideMerge(Bus.layer)), CrossSpawnSpawner.defaultLayer),
|
||||
Layer.mergeAll(Question.layer.pipe(Layer.provideMerge(EventV2Bridge.defaultLayer)), CrossSpawnSpawner.defaultLayer),
|
||||
)
|
||||
const lifecycle = testEffect(
|
||||
Layer.mergeAll(Question.layer.pipe(Layer.provideMerge(EventV2Bridge.defaultLayer)), CrossSpawnSpawner.defaultLayer, testInstanceStoreLayer),
|
||||
)
|
||||
|
||||
const askEffect = Effect.fn("QuestionTest.ask")(function* (input: {
|
||||
@@ -49,10 +52,13 @@ const rejectAll = Effect.gen(function* () {
|
||||
|
||||
const waitForPending = Effect.fn("QuestionTest.waitForPending")(function* (count: number) {
|
||||
const question = yield* Question.Service
|
||||
const bus = yield* Bus.Service
|
||||
const events = yield* EventV2Bridge.Service
|
||||
const asked = yield* Queue.unbounded<void>()
|
||||
const off = yield* bus.subscribeCallback(Question.Event.Asked, () => Queue.offerUnsafe(asked, undefined))
|
||||
yield* Effect.addFinalizer(() => Effect.sync(off))
|
||||
const off = yield* events.listen((event) => {
|
||||
if (event.type === Question.Event.Asked.type) Queue.offerUnsafe(asked, undefined)
|
||||
return Effect.void
|
||||
})
|
||||
yield* Effect.addFinalizer(() => off)
|
||||
|
||||
for (;;) {
|
||||
const pending = yield* question.list()
|
||||
@@ -361,7 +367,7 @@ it.instance(
|
||||
{ git: true },
|
||||
)
|
||||
|
||||
it.live("questions stay isolated by directory", () =>
|
||||
lifecycle.live("questions stay isolated by directory", () =>
|
||||
Effect.gen(function* () {
|
||||
const one = yield* tmpdirScoped({ git: true })
|
||||
const two = yield* tmpdirScoped({ git: true })
|
||||
@@ -404,7 +410,7 @@ it.live("questions stay isolated by directory", () =>
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("pending question rejects on instance dispose", () =>
|
||||
lifecycle.live("pending question rejects on instance dispose", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const fiber = yield* askEffect({
|
||||
@@ -423,7 +429,7 @@ it.live("pending question rejects on instance dispose", () =>
|
||||
return yield* InstanceRef
|
||||
}).pipe(provideInstance(dir))
|
||||
if (!ctx) return yield* Effect.die(new Error("missing test instance"))
|
||||
yield* Effect.promise(() => InstanceRuntime.disposeInstance(ctx))
|
||||
yield* InstanceStore.Service.use((store) => store.dispose(ctx))
|
||||
|
||||
const exit = yield* Fiber.await(fiber)
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
@@ -431,7 +437,7 @@ it.live("pending question rejects on instance dispose", () =>
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("pending question rejects on instance reload", () =>
|
||||
lifecycle.live("pending question rejects on instance reload", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const fiber = yield* askEffect({
|
||||
@@ -446,7 +452,7 @@ it.live("pending question rejects on instance reload", () =>
|
||||
}).pipe(provideInstance(dir), Effect.forkScoped)
|
||||
|
||||
expect(yield* waitForPending(1).pipe(provideInstance(dir))).toHaveLength(1)
|
||||
yield* Effect.promise(() => reloadTestInstance({ directory: dir }))
|
||||
yield* InstanceStore.Service.use((store) => store.reload({ directory: dir }))
|
||||
|
||||
const exit = yield* Fiber.await(fiber)
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
|
||||
Reference in New Issue
Block a user