From 4ff0fbc043cfcfab79e9f78d8de7a4015468973f Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Tue, 31 Mar 2026 16:10:32 -0400 Subject: [PATCH] fix: retry scoped tempdir cleanup on windows --- packages/opencode/test/fixture/fixture.ts | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/opencode/test/fixture/fixture.ts b/packages/opencode/test/fixture/fixture.ts index 54578f560b..a50e0c4f61 100644 --- a/packages/opencode/test/fixture/fixture.ts +++ b/packages/opencode/test/fixture/fixture.ts @@ -2,7 +2,7 @@ import { $ } from "bun" import * as fs from "fs/promises" import os from "os" import path from "path" -import { Effect, FileSystem, ServiceMap } from "effect" +import { Effect, ServiceMap } from "effect" import type * as PlatformError from "effect/PlatformError" import type * as Scope from "effect/Scope" import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process" @@ -82,9 +82,17 @@ export async function tmpdir(options?: TmpDirOptions) { /** Effectful scoped tmpdir. Cleaned up when the scope closes. Make sure these stay in sync */ export function tmpdirScoped(options?: { git?: boolean; config?: Partial }) { return Effect.gen(function* () { - const fs = yield* FileSystem.FileSystem const spawner = yield* ChildProcessSpawner.ChildProcessSpawner - const dir = yield* fs.makeTempDirectoryScoped({ prefix: "opencode-test-" }) + const dirpath = sanitizePath(path.join(os.tmpdir(), "opencode-test-" + Math.random().toString(36).slice(2))) + yield* Effect.promise(() => fs.mkdir(dirpath, { recursive: true })) + const dir = sanitizePath(yield* Effect.promise(() => fs.realpath(dirpath))) + + yield* Effect.addFinalizer(() => + Effect.promise(async () => { + if (options?.git) await stop(dir).catch(() => undefined) + await clean(dir).catch(() => undefined) + }), + ) const git = (...args: string[]) => spawner.spawn(ChildProcess.make("git", args, { cwd: dir })).pipe(Effect.flatMap((handle) => handle.exitCode)) @@ -98,9 +106,11 @@ export function tmpdirScoped(options?: { git?: boolean; config?: Partial + fs.writeFile( + path.join(dir, "opencode.json"), + JSON.stringify({ $schema: "https://opencode.ai/config.json", ...options.config }), + ), ) } @@ -150,7 +160,7 @@ export function provideTmpdirServer( ): Effect.Effect< A, E | PlatformError.PlatformError, - R | TestLLMServer | FileSystem.FileSystem | ChildProcessSpawner.ChildProcessSpawner | Scope.Scope + R | TestLLMServer | ChildProcessSpawner.ChildProcessSpawner | Scope.Scope > { return Effect.gen(function* () { const llm = yield* TestLLMServer