diff --git a/packages/core/test/process/process.test.ts b/packages/core/test/process/process.test.ts index 82b6dc4717a3..28d1efb16035 100644 --- a/packages/core/test/process/process.test.ts +++ b/packages/core/test/process/process.test.ts @@ -18,11 +18,13 @@ const waitForFile = (file: string) => Effect.promise(async () => { while (true) { try { - return await fs.readFile(file, "utf8") + const content = await fs.readFile(file, "utf8") + // Retry empty reads: the path can appear before write contents are visible. + if (content !== "") return content } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error - await new Promise((resolve) => setTimeout(resolve, 10)) } + await new Promise((resolve) => setTimeout(resolve, 10)) } }) diff --git a/packages/core/test/project-copy.test.ts b/packages/core/test/project-copy.test.ts index d37f6302074a..a47508e92424 100644 --- a/packages/core/test/project-copy.test.ts +++ b/packages/core/test/project-copy.test.ts @@ -333,29 +333,32 @@ describe("ProjectCopy", () => { }), ) - it.live("refresh ignores stale git worktree registrations", () => - Effect.gen(function* () { - const input = yield* setup() - const copy = yield* ProjectCopy.Service - const stale = abs(`${input.root.path}-copy-stale`) - const target = abs(`${input.root.path}-copy-after-stale`) - yield* Effect.addFinalizer(() => - Effect.promise(() => fs.rm(target, { recursive: true, force: true })).pipe(Effect.ignore), - ) - yield* Effect.promise(() => $`git worktree add --detach ${stale} HEAD`.cwd(input.root.path).quiet()) - yield* Effect.promise(() => fs.rm(stale, { recursive: true, force: true })) - yield* Effect.promise(() => $`git worktree add --detach ${target} HEAD`.cwd(input.root.path).quiet()) - - yield* copy.refresh({ projectID: input.projectID }) - - const discovered = abs(yield* Effect.promise(() => fs.realpath(target))) - expect(yield* stored(input.projectID)).toEqual( - [ - { directory: input.sourceDirectory, strategy: null }, - { directory: discovered, strategy: "git_worktree" }, - ].toSorted((a, b) => a.directory.localeCompare(b.directory)), - ) - }), + it.live( + "refresh ignores stale git worktree registrations", + () => + Effect.gen(function* () { + const input = yield* setup() + const copy = yield* ProjectCopy.Service + const stale = abs(`${input.root.path}-copy-stale`) + const target = abs(`${input.root.path}-copy-after-stale`) + yield* Effect.addFinalizer(() => + Effect.promise(() => fs.rm(target, { recursive: true, force: true })).pipe(Effect.ignore), + ) + yield* Effect.promise(() => $`git worktree add --detach ${stale} HEAD`.cwd(input.root.path).quiet()) + yield* Effect.promise(() => fs.rm(stale, { recursive: true, force: true })) + yield* Effect.promise(() => $`git worktree add --detach ${target} HEAD`.cwd(input.root.path).quiet()) + + yield* copy.refresh({ projectID: input.projectID }) + + const discovered = abs(yield* Effect.promise(() => fs.realpath(target))) + expect(yield* stored(input.projectID)).toEqual( + [ + { directory: input.sourceDirectory, strategy: null }, + { directory: discovered, strategy: "git_worktree" }, + ].toSorted((a, b) => a.directory.localeCompare(b.directory)), + ) + }), + 15_000, ) it.live("refresh ignores existing directories that are no longer git checkouts", () =>