66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { Effect, Layer } from "effect"
|
|
import { Database } from "@opencode-ai/core/database/database"
|
|
import { EventV2 } from "@opencode-ai/core/event"
|
|
import { Location } from "@opencode-ai/core/location"
|
|
import { ProjectV2 } from "@opencode-ai/core/project"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { SessionV2 } from "@opencode-ai/core/session"
|
|
import { SessionProjector } from "@opencode-ai/core/session/projector"
|
|
import { SessionExecution } from "@opencode-ai/core/session/execution"
|
|
import { SessionStore } from "@opencode-ai/core/session/store"
|
|
import { locationServiceMapLayer } from "@opencode-ai/core/location-services"
|
|
import { testEffect } from "./lib/effect"
|
|
|
|
const location = Location.Ref.make({ directory: AbsolutePath.make("/project") })
|
|
const awaited: SessionV2.ID[] = []
|
|
const projects = Layer.succeed(
|
|
ProjectV2.Service,
|
|
ProjectV2.Service.of({
|
|
resolve: (directory) => Effect.succeed({ id: ProjectV2.ID.global, directory }),
|
|
directories: () => Effect.succeed([]),
|
|
commit: () => Effect.void,
|
|
}),
|
|
)
|
|
const execution = Layer.succeed(
|
|
SessionExecution.Service,
|
|
SessionExecution.Service.of({
|
|
active: Effect.succeed(new Set()),
|
|
resume: () => Effect.void,
|
|
wake: () => Effect.void,
|
|
interrupt: () => Effect.void,
|
|
awaitIdle: (sessionID) => Effect.sync(() => awaited.push(sessionID)),
|
|
}),
|
|
)
|
|
const sessions = SessionV2.layer.pipe(
|
|
Layer.provide(locationServiceMapLayer),
|
|
Layer.provide(EventV2.defaultLayer),
|
|
Layer.provide(Database.defaultLayer),
|
|
Layer.provide(SessionStore.defaultLayer),
|
|
Layer.provide(projects),
|
|
Layer.provide(execution),
|
|
)
|
|
const it = testEffect(
|
|
Layer.mergeAll(
|
|
Database.defaultLayer,
|
|
EventV2.defaultLayer,
|
|
projects,
|
|
SessionProjector.defaultLayer,
|
|
SessionStore.defaultLayer,
|
|
sessions,
|
|
),
|
|
)
|
|
|
|
describe("SessionV2.wait", () => {
|
|
it.effect("delegates to SessionExecution.awaitIdle", () =>
|
|
Effect.gen(function* () {
|
|
awaited.length = 0
|
|
const sessions = yield* SessionV2.Service
|
|
const session = yield* sessions.create({ location })
|
|
|
|
yield* sessions.wait(session.id)
|
|
|
|
expect(awaited).toEqual([session.id])
|
|
}),
|
|
)
|
|
})
|