test: use Effect file services in migrated tests (#27154)
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { afterEach, expect } from "bun:test"
|
||||
import { $ } from "bun"
|
||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||
import fs from "fs/promises"
|
||||
import path from "path"
|
||||
import { Effect, Fiber } from "effect"
|
||||
import { Effect, Fiber, Layer } from "effect"
|
||||
import { Snapshot } from "../../src/snapshot"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { disposeAllInstances, provideInstance, TestInstance, tmpdirScoped } from "../fixture/fixture"
|
||||
import { testEffect } from "../lib/effect"
|
||||
|
||||
const it = testEffect(Snapshot.defaultLayer)
|
||||
const it = testEffect(Layer.mergeAll(Snapshot.defaultLayer, AppFileSystem.defaultLayer))
|
||||
|
||||
// Git always outputs /-separated paths internally. Snapshot.patch() joins them
|
||||
// with path.join (which produces \ on Windows) then normalizes back to /.
|
||||
@@ -27,17 +27,13 @@ const exec = (cwd: string, command: string[]) =>
|
||||
if (code !== 0) throw new Error(`${command.join(" ")} failed: ${await new Response(proc.stderr).text()}`)
|
||||
})
|
||||
|
||||
const write = (file: string, content: string | Uint8Array) => Effect.promise(() => Filesystem.write(file, content))
|
||||
const readText = (file: string) => Effect.promise(() => fs.readFile(file, "utf-8"))
|
||||
const exists = (file: string) =>
|
||||
Effect.promise(() =>
|
||||
fs
|
||||
.access(file)
|
||||
.then(() => true)
|
||||
.catch(() => false),
|
||||
)
|
||||
const mkdirp = (dir: string) => Effect.promise(() => fs.mkdir(dir, { recursive: true }))
|
||||
const rm = (file: string) => Effect.promise(() => fs.rm(file, { recursive: true, force: true }))
|
||||
const write = (file: string, content: string | Uint8Array) =>
|
||||
AppFileSystem.Service.use((fs) => fs.writeWithDirs(file, content))
|
||||
const readText = (file: string) => AppFileSystem.Service.use((fs) => fs.readFileString(file))
|
||||
const exists = (file: string) => AppFileSystem.Service.use((fs) => fs.existsSafe(file))
|
||||
const mkdirp = (dir: string) => AppFileSystem.Service.use((fs) => fs.ensureDir(dir))
|
||||
const rm = (file: string) =>
|
||||
AppFileSystem.Service.use((fs) => fs.remove(file, { recursive: true, force: true }).pipe(Effect.ignore))
|
||||
|
||||
const initialize = Effect.fn("SnapshotTest.initialize")(function* (dir: string) {
|
||||
const unique = Math.random().toString(36).slice(2)
|
||||
|
||||
Reference in New Issue
Block a user