refactor(opencode): roll out serviceUse proxy across 14 services + tests (#28576)
This commit is contained in:
@@ -13,7 +13,7 @@ const it = testEffect(Layer.mergeAll(SessionNs.defaultLayer, Project.defaultLaye
|
||||
|
||||
const withSession = (input?: Parameters<SessionNs.Interface["create"]>[0]) =>
|
||||
Effect.acquireRelease(
|
||||
SessionNs.Service.use((session) => session.create(input)),
|
||||
SessionNs.use.create(input),
|
||||
(created) => SessionNs.Service.use((session) => session.remove(created.id).pipe(Effect.ignore)),
|
||||
)
|
||||
|
||||
@@ -34,8 +34,8 @@ describe("session.listGlobal", () => {
|
||||
expect(ids).toContain(firstSession.id)
|
||||
expect(ids).toContain(secondSession.id)
|
||||
|
||||
const firstProject = yield* Project.Service.use((project) => project.get(firstSession.projectID))
|
||||
const secondProject = yield* Project.Service.use((project) => project.get(secondSession.projectID))
|
||||
const firstProject = yield* Project.use.get(firstSession.projectID)
|
||||
const secondProject = yield* Project.use.get(secondSession.projectID)
|
||||
|
||||
const firstItem = sessions.find((session) => session.id === firstSession.id)
|
||||
const secondItem = sessions.find((session) => session.id === secondSession.id)
|
||||
|
||||
@@ -31,7 +31,7 @@ function request(path: string, directory: string, init: RequestInit = {}) {
|
||||
}
|
||||
|
||||
function createSession(input?: Session.CreateInput) {
|
||||
return Session.Service.use((svc) => svc.create(input))
|
||||
return Session.use.create(input)
|
||||
}
|
||||
|
||||
function json<T>(response: Response) {
|
||||
|
||||
@@ -74,7 +74,7 @@ const createLocalWorkspace = (input: { projectID: Project.Info["id"]; type: stri
|
||||
projectID: input.projectID,
|
||||
})
|
||||
}),
|
||||
(info) => Workspace.Service.use((workspace) => workspace.remove(info.id)).pipe(Effect.ignore),
|
||||
(info) => Workspace.use.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
const probeInstanceContext = Effect.gen(function* () {
|
||||
|
||||
@@ -52,7 +52,7 @@ function pathFor(path: string, params: Record<string, string>) {
|
||||
}
|
||||
|
||||
function createSession(input?: Session.CreateInput) {
|
||||
return Session.Service.use((svc) => svc.create(input))
|
||||
return Session.use.create(input)
|
||||
}
|
||||
|
||||
function createTextMessage(sessionID: SessionIDType, text: string) {
|
||||
@@ -101,7 +101,7 @@ const createLocalWorkspace = (input: { projectID: Project.Info["id"]; type: stri
|
||||
}),
|
||||
)
|
||||
}),
|
||||
(info) => Workspace.Service.use((svc) => svc.remove(info.id)).pipe(Effect.ignore),
|
||||
(info) => Workspace.use.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
const insertLegacyAssistantMessage = (sessionID: SessionIDType, time = 1) =>
|
||||
|
||||
@@ -36,7 +36,7 @@ describe("sync HttpApi", () => {
|
||||
const tmp = yield* TestInstance
|
||||
const headers = { "x-opencode-directory": tmp.directory, "content-type": "application/json" }
|
||||
const info = spyOn(Log.create({ service: "server.sync" }), "info")
|
||||
const session = yield* Session.Service.use((svc) => svc.create({ title: "sync" }))
|
||||
const session = yield* Session.use.create({ title: "sync" })
|
||||
|
||||
const started = yield* Effect.promise(() =>
|
||||
Promise.resolve(app().request(SyncPaths.start, { method: "POST", headers })),
|
||||
|
||||
@@ -128,7 +128,7 @@ const createWorkspace = (input: { projectID: Project.Info["id"]; type: string; a
|
||||
projectID: input.projectID,
|
||||
})
|
||||
}),
|
||||
(info) => Workspace.Service.use((workspace) => workspace.remove(info.id)).pipe(Effect.ignore),
|
||||
(info) => Workspace.use.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
const createRemoteWorkspace = (input: {
|
||||
|
||||
@@ -208,7 +208,7 @@ describe("workspace HttpApi", () => {
|
||||
const workspace = (yield* Effect.promise(() => created.json())) as Workspace.Info
|
||||
expect(workspace).toMatchObject({ type: "local-test", name: "local-test" })
|
||||
|
||||
const session = yield* Session.Service.use((svc) => svc.create({})).pipe(provideInstance(dir))
|
||||
const session = yield* Session.use.create({}).pipe(provideInstance(dir))
|
||||
const warped = yield* request(WorkspacePaths.warp, dir, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
@@ -424,7 +424,7 @@ describe("workspace HttpApi", () => {
|
||||
body: JSON.stringify({ type: "remote-session-target", branch: null }),
|
||||
})
|
||||
const workspace = (yield* Effect.promise(() => created.json())) as Workspace.Info
|
||||
const session = yield* Session.Service.use((svc) => svc.create()).pipe(
|
||||
const session = yield* Session.use.create().pipe(
|
||||
Effect.provideService(WorkspaceRef, workspace.id),
|
||||
provideInstance(dir),
|
||||
)
|
||||
|
||||
@@ -83,7 +83,7 @@ describe("project.initGit endpoint", () => {
|
||||
worktree: tmp.directory,
|
||||
})
|
||||
|
||||
const ctx = yield* InstanceStore.Service.use((store) => store.reload({ directory: tmp.directory }))
|
||||
const ctx = yield* InstanceStore.use.reload({ directory: tmp.directory })
|
||||
const tracked = yield* Snapshot.Service.use((snapshot) => snapshot.track()).pipe(
|
||||
Effect.provideService(InstanceRef, ctx),
|
||||
)
|
||||
|
||||
@@ -22,8 +22,8 @@ describe("session action routes", () => {
|
||||
Effect.gen(function* () {
|
||||
const test = yield* TestInstance
|
||||
const session = yield* Effect.acquireRelease(
|
||||
SessionNs.Service.use((svc) => svc.create({})),
|
||||
(created) => SessionNs.Service.use((svc) => svc.remove(created.id)).pipe(Effect.ignore),
|
||||
SessionNs.use.create({}),
|
||||
(created) => SessionNs.use.remove(created.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
const res = yield* Effect.promise(() =>
|
||||
|
||||
@@ -35,8 +35,8 @@ function pathFor(template: string, params: Record<string, string>) {
|
||||
|
||||
const withSession = (input?: Parameters<Session.Interface["create"]>[0]) =>
|
||||
Effect.acquireRelease(
|
||||
Session.Service.use((session) => session.create(input)),
|
||||
(created) => Session.Service.use((session) => session.remove(created.id)).pipe(Effect.ignore),
|
||||
Session.use.create(input),
|
||||
(created) => Session.use.remove(created.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
describe("session diff with missing patch (#26574)", () => {
|
||||
|
||||
@@ -28,7 +28,7 @@ const it = testEffect(
|
||||
|
||||
const withSession = (input?: Parameters<SessionNs.Interface["create"]>[0]) =>
|
||||
Effect.acquireRelease(
|
||||
SessionNs.Service.use((session) => session.create(input)),
|
||||
SessionNs.use.create(input),
|
||||
(created) => SessionNs.Service.use((session) => session.remove(created.id).pipe(Effect.ignore)),
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ describe("session.list", () => {
|
||||
provideInstance(path.join(test.directory, "packages", "app")),
|
||||
)
|
||||
|
||||
const ids = (yield* SessionNs.Service.use((session) => session.list())).map((session) => session.id)
|
||||
const ids = (yield* SessionNs.use.list()).map((session) => session.id)
|
||||
expect(ids).toContain(root.id)
|
||||
expect(ids).toContain(parent.id)
|
||||
expect(ids).toContain(current.id)
|
||||
@@ -179,7 +179,7 @@ describe("session.list", () => {
|
||||
const root = yield* withSession({ title: "root-session" })
|
||||
const child = yield* withSession({ title: "child-session", parentID: root.id })
|
||||
|
||||
const sessions = yield* SessionNs.Service.use((session) => session.list({ roots: true }))
|
||||
const sessions = yield* SessionNs.use.list({ roots: true })
|
||||
const ids = sessions.map((session) => session.id)
|
||||
|
||||
expect(ids).toContain(root.id)
|
||||
@@ -206,7 +206,7 @@ describe("session.list", () => {
|
||||
yield* withSession({ title: "unique-search-term-abc" })
|
||||
yield* withSession({ title: "other-session-xyz" })
|
||||
|
||||
const sessions = yield* SessionNs.Service.use((session) => session.list({ search: "unique-search" }))
|
||||
const sessions = yield* SessionNs.use.list({ search: "unique-search" })
|
||||
const titles = sessions.map((session) => session.title)
|
||||
|
||||
expect(titles).toContain("unique-search-term-abc")
|
||||
@@ -223,7 +223,7 @@ describe("session.list", () => {
|
||||
yield* withSession({ title: "session-2" })
|
||||
yield* withSession({ title: "session-3" })
|
||||
|
||||
const sessions = yield* SessionNs.Service.use((session) => session.list({ limit: 2 }))
|
||||
const sessions = yield* SessionNs.use.list({ limit: 2 })
|
||||
expect(sessions.length).toBe(2)
|
||||
}),
|
||||
{ git: true },
|
||||
|
||||
@@ -40,8 +40,8 @@ const withoutWatcher = <A, E, R>(effect: Effect.Effect<A, E, R>) => {
|
||||
}
|
||||
|
||||
const sessionScoped = Effect.acquireRelease(
|
||||
SessionNs.Service.use((svc) => svc.create({})),
|
||||
(session) => SessionNs.Service.use((svc) => svc.remove(session.id)).pipe(Effect.ignore),
|
||||
SessionNs.use.create({}),
|
||||
(session) => SessionNs.use.remove(session.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
const fill = Effect.fn("SessionMessagesTest.fill")(function* (
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("tui.selectSession endpoint", () => {
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const tmp = yield* TestInstance
|
||||
const session = yield* Session.Service.use((svc) => svc.create({}))
|
||||
const session = yield* Session.use.create({})
|
||||
|
||||
const app = Server.Default().app
|
||||
const response = yield* Effect.promise(() =>
|
||||
|
||||
Reference in New Issue
Block a user