Skip to content

Commit ca62001

Browse files
authored
refactor: remove vcs async facade exports (#22304)
1 parent 7239b38 commit ca62001

3 files changed

Lines changed: 89 additions & 37 deletions

File tree

packages/opencode/src/project/vcs.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import path from "path"
44
import { Bus } from "@/bus"
55
import { BusEvent } from "@/bus/bus-event"
66
import { InstanceState } from "@/effect/instance-state"
7-
import { makeRuntime } from "@/effect/run-service"
87
import { AppFileSystem } from "@/filesystem"
98
import { FileWatcher } from "@/file/watcher"
109
import { Git } from "@/git"
@@ -231,22 +230,4 @@ export namespace Vcs {
231230
Layer.provide(AppFileSystem.defaultLayer),
232231
Layer.provide(Bus.layer),
233232
)
234-
235-
const { runPromise } = makeRuntime(Service, defaultLayer)
236-
237-
export async function init() {
238-
return runPromise((svc) => svc.init())
239-
}
240-
241-
export async function branch() {
242-
return runPromise((svc) => svc.branch())
243-
}
244-
245-
export async function defaultBranch() {
246-
return runPromise((svc) => svc.defaultBranch())
247-
}
248-
249-
export async function diff(mode: Mode) {
250-
return runPromise((svc) => svc.diff(mode))
251-
}
252233
}

packages/opencode/src/server/instance/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describeRoute, resolver, validator } from "hono-openapi"
22
import { Hono } from "hono"
33
import type { UpgradeWebSocket } from "hono/ws"
4+
import { Effect } from "effect"
45
import z from "zod"
56
import { Format } from "../../format"
67
import { TuiRoutes } from "./tui"
@@ -120,11 +121,17 @@ export const InstanceRoutes = (upgrade: UpgradeWebSocket): Hono =>
120121
},
121122
}),
122123
async (c) => {
123-
const [branch, default_branch] = await Promise.all([Vcs.branch(), Vcs.defaultBranch()])
124-
return c.json({
125-
branch,
126-
default_branch,
127-
})
124+
return c.json(
125+
await AppRuntime.runPromise(
126+
Effect.gen(function* () {
127+
const vcs = yield* Vcs.Service
128+
const [branch, default_branch] = yield* Effect.all([vcs.branch(), vcs.defaultBranch()], {
129+
concurrency: 2,
130+
})
131+
return { branch, default_branch }
132+
}),
133+
),
134+
)
128135
},
129136
)
130137
.get(
@@ -151,7 +158,14 @@ export const InstanceRoutes = (upgrade: UpgradeWebSocket): Hono =>
151158
}),
152159
),
153160
async (c) => {
154-
return c.json(await Vcs.diff(c.req.valid("query").mode))
161+
return c.json(
162+
await AppRuntime.runPromise(
163+
Effect.gen(function* () {
164+
const vcs = yield* Vcs.Service
165+
return yield* vcs.diff(c.req.valid("query").mode)
166+
}),
167+
),
168+
)
155169
},
156170
)
157171
.get(

packages/opencode/test/project/vcs.test.ts

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { $ } from "bun"
22
import { afterEach, describe, expect, test } from "bun:test"
3+
import { Effect } from "effect"
34
import fs from "fs/promises"
45
import path from "path"
56
import { tmpdir } from "../fixture/fixture"
@@ -20,8 +21,14 @@ async function withVcs(directory: string, body: () => Promise<void>) {
2021
return Instance.provide({
2122
directory,
2223
fn: async () => {
23-
void AppRuntime.runPromise(FileWatcher.Service.use((svc) => svc.init()))
24-
Vcs.init()
24+
await AppRuntime.runPromise(
25+
Effect.gen(function* () {
26+
const watcher = yield* FileWatcher.Service
27+
const vcs = yield* Vcs.Service
28+
yield* watcher.init()
29+
yield* vcs.init()
30+
}),
31+
)
2532
await Bun.sleep(500)
2633
await body()
2734
},
@@ -32,7 +39,12 @@ function withVcsOnly(directory: string, body: () => Promise<void>) {
3239
return Instance.provide({
3340
directory,
3441
fn: async () => {
35-
Vcs.init()
42+
await AppRuntime.runPromise(
43+
Effect.gen(function* () {
44+
const vcs = yield* Vcs.Service
45+
yield* vcs.init()
46+
}),
47+
)
3648
await body()
3749
},
3850
})
@@ -80,7 +92,12 @@ describeVcs("Vcs", () => {
8092
await using tmp = await tmpdir({ git: true })
8193

8294
await withVcs(tmp.path, async () => {
83-
const branch = await Vcs.branch()
95+
const branch = await AppRuntime.runPromise(
96+
Effect.gen(function* () {
97+
const vcs = yield* Vcs.Service
98+
return yield* vcs.branch()
99+
}),
100+
)
84101
expect(branch).toBeDefined()
85102
expect(typeof branch).toBe("string")
86103
})
@@ -90,7 +107,12 @@ describeVcs("Vcs", () => {
90107
await using tmp = await tmpdir()
91108

92109
await withVcs(tmp.path, async () => {
93-
const branch = await Vcs.branch()
110+
const branch = await AppRuntime.runPromise(
111+
Effect.gen(function* () {
112+
const vcs = yield* Vcs.Service
113+
return yield* vcs.branch()
114+
}),
115+
)
94116
expect(branch).toBeUndefined()
95117
})
96118
})
@@ -123,7 +145,12 @@ describeVcs("Vcs", () => {
123145
await fs.writeFile(head, `ref: refs/heads/${branch}\n`)
124146

125147
await pending
126-
const current = await Vcs.branch()
148+
const current = await AppRuntime.runPromise(
149+
Effect.gen(function* () {
150+
const vcs = yield* Vcs.Service
151+
return yield* vcs.branch()
152+
}),
153+
)
127154
expect(current).toBe(branch)
128155
})
129156
})
@@ -139,7 +166,12 @@ describe("Vcs diff", () => {
139166
await $`git branch -M main`.cwd(tmp.path).quiet()
140167

141168
await withVcsOnly(tmp.path, async () => {
142-
const branch = await Vcs.defaultBranch()
169+
const branch = await AppRuntime.runPromise(
170+
Effect.gen(function* () {
171+
const vcs = yield* Vcs.Service
172+
return yield* vcs.defaultBranch()
173+
}),
174+
)
143175
expect(branch).toBe("main")
144176
})
145177
})
@@ -150,7 +182,12 @@ describe("Vcs diff", () => {
150182
await $`git config init.defaultBranch trunk`.cwd(tmp.path).quiet()
151183

152184
await withVcsOnly(tmp.path, async () => {
153-
const branch = await Vcs.defaultBranch()
185+
const branch = await AppRuntime.runPromise(
186+
Effect.gen(function* () {
187+
const vcs = yield* Vcs.Service
188+
return yield* vcs.defaultBranch()
189+
}),
190+
)
154191
expect(branch).toBe("trunk")
155192
})
156193
})
@@ -163,7 +200,12 @@ describe("Vcs diff", () => {
163200
await $`git worktree add -b feature/test ${dir} HEAD`.cwd(tmp.path).quiet()
164201

165202
await withVcsOnly(dir, async () => {
166-
const [branch, base] = await Promise.all([Vcs.branch(), Vcs.defaultBranch()])
203+
const [branch, base] = await AppRuntime.runPromise(
204+
Effect.gen(function* () {
205+
const vcs = yield* Vcs.Service
206+
return yield* Effect.all([vcs.branch(), vcs.defaultBranch()], { concurrency: 2 })
207+
}),
208+
)
167209
expect(branch).toBe("feature/test")
168210
expect(base).toBe("main")
169211
})
@@ -177,7 +219,12 @@ describe("Vcs diff", () => {
177219
await fs.writeFile(path.join(tmp.path, "file.txt"), "changed\n", "utf-8")
178220

179221
await withVcsOnly(tmp.path, async () => {
180-
const diff = await Vcs.diff("git")
222+
const diff = await AppRuntime.runPromise(
223+
Effect.gen(function* () {
224+
const vcs = yield* Vcs.Service
225+
return yield* vcs.diff("git")
226+
}),
227+
)
181228
expect(diff).toEqual(
182229
expect.arrayContaining([
183230
expect.objectContaining({
@@ -194,7 +241,12 @@ describe("Vcs diff", () => {
194241
await fs.writeFile(path.join(tmp.path, weird), "hello\n", "utf-8")
195242

196243
await withVcsOnly(tmp.path, async () => {
197-
const diff = await Vcs.diff("git")
244+
const diff = await AppRuntime.runPromise(
245+
Effect.gen(function* () {
246+
const vcs = yield* Vcs.Service
247+
return yield* vcs.diff("git")
248+
}),
249+
)
198250
expect(diff).toEqual(
199251
expect.arrayContaining([
200252
expect.objectContaining({
@@ -215,7 +267,12 @@ describe("Vcs diff", () => {
215267
await $`git commit --no-gpg-sign -m "branch file"`.cwd(tmp.path).quiet()
216268

217269
await withVcsOnly(tmp.path, async () => {
218-
const diff = await Vcs.diff("branch")
270+
const diff = await AppRuntime.runPromise(
271+
Effect.gen(function* () {
272+
const vcs = yield* Vcs.Service
273+
return yield* vcs.diff("branch")
274+
}),
275+
)
219276
expect(diff).toEqual(
220277
expect.arrayContaining([
221278
expect.objectContaining({

0 commit comments

Comments
 (0)