소스 검색

refactor(snapshot): remove async facade exports (#22370)

Kit Langton 5 일 전
부모
커밋
f40209bdfb

+ 4 - 3
packages/opencode/src/cli/cmd/debug/snapshot.ts

@@ -1,3 +1,4 @@
+import { AppRuntime } from "@/effect/app-runtime"
 import { Snapshot } from "../../../snapshot"
 import { bootstrap } from "../../bootstrap"
 import { cmd } from "../cmd"
@@ -14,7 +15,7 @@ const TrackCommand = cmd({
   describe: "track current snapshot state",
   async handler() {
     await bootstrap(process.cwd(), async () => {
-      console.log(await Snapshot.track())
+      console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.track())))
     })
   },
 })
@@ -30,7 +31,7 @@ const PatchCommand = cmd({
     }),
   async handler(args) {
     await bootstrap(process.cwd(), async () => {
-      console.log(await Snapshot.patch(args.hash))
+      console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.patch(args.hash))))
     })
   },
 })
@@ -46,7 +47,7 @@ const DiffCommand = cmd({
     }),
   async handler(args) {
     await bootstrap(process.cwd(), async () => {
-      console.log(await Snapshot.diff(args.hash))
+      console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.diff(args.hash))))
     })
   },
 })

+ 0 - 31
packages/opencode/src/snapshot/index.ts

@@ -5,7 +5,6 @@ import path from "path"
 import z from "zod"
 import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
 import { InstanceState } from "@/effect/instance-state"
-import { makeRuntime } from "@/effect/run-service"
 import { AppFileSystem } from "@/filesystem"
 import { Hash } from "@/util/hash"
 import { Config } from "../config/config"
@@ -770,34 +769,4 @@ export namespace Snapshot {
     Layer.provide(AppFileSystem.defaultLayer),
     Layer.provide(Config.defaultLayer),
   )
-
-  const { runPromise } = makeRuntime(Service, defaultLayer)
-
-  export async function init() {
-    return runPromise((svc) => svc.init())
-  }
-
-  export async function track() {
-    return runPromise((svc) => svc.track())
-  }
-
-  export async function patch(hash: string) {
-    return runPromise((svc) => svc.patch(hash))
-  }
-
-  export async function restore(snapshot: string) {
-    return runPromise((svc) => svc.restore(snapshot))
-  }
-
-  export async function revert(patches: Patch[]) {
-    return runPromise((svc) => svc.revert(patches))
-  }
-
-  export async function diff(hash: string) {
-    return runPromise((svc) => svc.diff(hash))
-  }
-
-  export async function diffFull(from: string, to: string) {
-    return runPromise((svc) => svc.diffFull(from, to))
-  }
 }

+ 10 - 7
packages/opencode/test/server/project-init-git.test.ts

@@ -1,4 +1,5 @@
 import { afterEach, describe, expect, spyOn, test } from "bun:test"
+import { Effect } from "effect"
 import path from "path"
 import { GlobalBus } from "../../src/bus/global"
 import { Snapshot } from "../../src/snapshot"
@@ -8,7 +9,7 @@ import { Server } from "../../src/server/server"
 import { Filesystem } from "../../src/util/filesystem"
 import { Log } from "../../src/util/log"
 import { resetDatabase } from "../fixture/db"
-import { tmpdir } from "../fixture/fixture"
+import { provideInstance, tmpdir } from "../fixture/fixture"
 
 Log.init({ print: false })
 
@@ -60,12 +61,14 @@ describe("project.initGit endpoint", () => {
         worktree: tmp.path,
       })
 
-      await Instance.provide({
-        directory: tmp.path,
-        fn: async () => {
-          expect(await Snapshot.track()).toBeTruthy()
-        },
-      })
+      expect(
+        await Effect.runPromise(
+          Snapshot.Service.use((svc) => svc.track()).pipe(
+            provideInstance(tmp.path),
+            Effect.provide(Snapshot.defaultLayer),
+          ),
+        ),
+      ).toBeTruthy()
     } finally {
       await Instance.disposeAll()
       reloadSpy.mockRestore()

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 159 - 139
packages/opencode/test/snapshot/snapshot.test.ts


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.