Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/test/process/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve) => setTimeout(resolve, 10))
}
await new Promise<void>((resolve) => setTimeout(resolve, 10))
}
})

Expand Down
49 changes: 26 additions & 23 deletions packages/core/test/project-copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand Down
Loading