feat(core): refactor project copies for v2 (#31943)
This commit is contained in:
parent
8d97c8d412
commit
c2e6b18076
33 changed files with 1461 additions and 829 deletions
|
|
@ -26,7 +26,7 @@ function directories(projectID: ProjectV2.ID) {
|
|||
Effect.orDie,
|
||||
Effect.map((rows) =>
|
||||
rows
|
||||
.map((row) => ({ directory: row.directory, type: row.type }))
|
||||
.map((row) => ({ directory: row.directory, strategy: row.strategy ?? undefined }))
|
||||
.toSorted((a, b) => a.directory.localeCompare(b.directory)),
|
||||
),
|
||||
),
|
||||
|
|
@ -41,7 +41,9 @@ describe("Project directory persistence", () => {
|
|||
|
||||
const result = yield* project.fromDirectory(tmp)
|
||||
|
||||
expect(yield* directories(result.project.id)).toEqual([{ directory: tmp, type: "main" }])
|
||||
expect(yield* directories(result.project.id)).toEqual([
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +56,9 @@ describe("Project directory persistence", () => {
|
|||
const next = yield* project.fromDirectory(tmp)
|
||||
|
||||
expect(next.project.id).toBe(result.project.id)
|
||||
expect(yield* directories(result.project.id)).toEqual([{ directory: tmp, type: "main" }])
|
||||
expect(yield* directories(result.project.id)).toEqual([
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -73,8 +77,8 @@ describe("Project directory persistence", () => {
|
|||
|
||||
expect(yield* directories(main.project.id)).toEqual(
|
||||
[
|
||||
{ directory: tmp, type: "main" as const },
|
||||
{ directory: worktree, type: "git_worktree" as const },
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
{ directory: AbsolutePath.make(worktree), strategy: undefined },
|
||||
].toSorted((a, b) => a.directory.localeCompare(b.directory)),
|
||||
)
|
||||
}),
|
||||
|
|
@ -92,7 +96,9 @@ describe("Project directory persistence", () => {
|
|||
|
||||
const result = yield* project.fromDirectory(worktree)
|
||||
|
||||
expect(yield* directories(result.project.id)).toEqual([{ directory: worktree, type: "git_worktree" }])
|
||||
expect(yield* directories(result.project.id)).toEqual([
|
||||
{ directory: AbsolutePath.make(worktree), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -113,8 +119,8 @@ describe("Project directory persistence", () => {
|
|||
|
||||
expect(yield* directories(main.project.id)).toEqual(
|
||||
[
|
||||
{ directory: tmp, type: "main" as const },
|
||||
{ directory: clone, type: "root" as const },
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
{ directory: AbsolutePath.make(clone), strategy: undefined },
|
||||
].toSorted((a, b) => a.directory.localeCompare(b.directory)),
|
||||
)
|
||||
}),
|
||||
|
|
@ -134,7 +140,9 @@ describe("Project directory persistence", () => {
|
|||
|
||||
const result = yield* project.fromDirectory(worktree)
|
||||
|
||||
expect(yield* directories(result.project.id)).toEqual([{ directory: worktree, type: "git_worktree" }])
|
||||
expect(yield* directories(result.project.id)).toEqual([
|
||||
{ directory: AbsolutePath.make(worktree), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -163,7 +171,35 @@ describe("Project directory persistence", () => {
|
|||
|
||||
yield* project.fromDirectory(tmp)
|
||||
|
||||
expect(yield* directories(remoteID)).toEqual([{ directory: tmp, type: "main" }])
|
||||
expect(yield* directories(remoteID)).toEqual([
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("clears stale directories when the project id changes", () =>
|
||||
Effect.gen(function* () {
|
||||
const tmp = yield* tmpdirScoped({ git: true })
|
||||
const project = yield* Project.Service
|
||||
const original = yield* project.fromDirectory(tmp)
|
||||
const stale = AbsolutePath.make(tmp + "-stale-checkout")
|
||||
const { db } = yield* Database.Service
|
||||
yield* db
|
||||
.insert(ProjectDirectoryTable)
|
||||
.values({ project_id: original.project.id, directory: stale })
|
||||
.run()
|
||||
.pipe(Effect.orDie)
|
||||
const remoteID = ProjectV2.ID.make(Hash.fast("git-remote:github.com/project-directory-test/migration"))
|
||||
yield* Effect.promise(() =>
|
||||
$`git remote add origin git@github.com:project-directory-test/migration.git`.cwd(tmp).quiet(),
|
||||
)
|
||||
|
||||
yield* project.fromDirectory(tmp)
|
||||
|
||||
expect(yield* directories(original.project.id)).toEqual([])
|
||||
expect(yield* directories(remoteID)).toEqual([
|
||||
{ directory: AbsolutePath.make(tmp), strategy: undefined },
|
||||
])
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import { NodePath } from "@effect/platform-node"
|
|||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||
import { AppProcess } from "@opencode-ai/core/process"
|
||||
import { ProjectV2 } from "@opencode-ai/core/project"
|
||||
import { ProjectCopy } from "@opencode-ai/core/project/copy"
|
||||
import { ProjectDirectories } from "@opencode-ai/core/project/directories"
|
||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||
import { testEffect } from "../lib/effect"
|
||||
import { RuntimeFlags } from "@/effect/runtime-flags"
|
||||
|
|
@ -73,7 +73,7 @@ function projectLayerWithFailure(failArg: string) {
|
|||
Layer.provide(AppProcess.layer.pipe(Layer.provide(mockGitFailure(failArg)))),
|
||||
Layer.provide(mockGitFailure(failArg)),
|
||||
Layer.provide(ProjectV2.defaultLayer),
|
||||
Layer.provide(ProjectCopy.defaultLayer),
|
||||
Layer.provide(ProjectDirectories.defaultLayer),
|
||||
Layer.provide(EventV2Bridge.defaultLayer),
|
||||
Layer.provide(FSUtil.defaultLayer),
|
||||
Layer.provide(NodePath.layer),
|
||||
|
|
@ -86,7 +86,7 @@ function projectLayerWithRuntimeFlags(flags: Parameters<typeof RuntimeFlags.laye
|
|||
return Project.layer.pipe(
|
||||
Layer.provide(EventV2Bridge.defaultLayer),
|
||||
Layer.provide(ProjectV2.defaultLayer),
|
||||
Layer.provide(ProjectCopy.defaultLayer),
|
||||
Layer.provide(ProjectDirectories.defaultLayer),
|
||||
Layer.provide(AppProcess.defaultLayer),
|
||||
Layer.provide(FSUtil.defaultLayer),
|
||||
Layer.provide(NodePath.layer),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue