mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 05:52:35 +08:00
Merge pull request #10684 from Kilo-Org/effect-project-facade-10676
refactor(cli): remove Project promise facade
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"
|
||||
import { Database } from "../../src/storage/db"
|
||||
import { SessionImportService } from "../../src/kilocode/session-import/service"
|
||||
import { resetDatabase } from "../fixture/db"
|
||||
import { tmpdir } from "../fixture/fixture"
|
||||
|
||||
let spy: ReturnType<typeof spyOn>
|
||||
|
||||
@@ -76,6 +78,37 @@ function input(force?: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
function project(worktree: string) {
|
||||
return {
|
||||
id: "legacy_project",
|
||||
worktree,
|
||||
timeCreated: 1,
|
||||
timeUpdated: 1,
|
||||
sandboxes: [],
|
||||
}
|
||||
}
|
||||
|
||||
describe("SessionImportService.project", () => {
|
||||
afterEach(async () => {
|
||||
await resetDatabase()
|
||||
})
|
||||
|
||||
test("rejects an empty legacy worktree", async () => {
|
||||
await expect(SessionImportService.project(project(" "))).rejects.toThrow(
|
||||
"Legacy project import requires a non-empty worktree",
|
||||
)
|
||||
})
|
||||
|
||||
test("resolves a valid legacy project through Project.Service", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
|
||||
const result = await SessionImportService.project(project(tmp.path))
|
||||
|
||||
expect(result.ok).toBe(true)
|
||||
expect(result.id).not.toBe("global")
|
||||
})
|
||||
})
|
||||
|
||||
describe("SessionImportService.session", () => {
|
||||
beforeEach(() => {
|
||||
spy = spyOn(Database, "use").mockImplementation((fn: any) => fn(db))
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect } from "bun:test"
|
||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { Git } from "../../src/git"
|
||||
import { InstanceRef } from "../../src/effect/instance-ref"
|
||||
import { WorktreeFamily } from "../../src/kilocode/worktree-family"
|
||||
import { Project } from "../../src/project/project"
|
||||
import { resetDatabase } from "../fixture/db"
|
||||
import { tmpdirScoped } from "../fixture/fixture"
|
||||
import { testEffect } from "../lib/effect"
|
||||
|
||||
const it = testEffect(Layer.mergeAll(Project.defaultLayer, Git.defaultLayer, CrossSpawnSpawner.defaultLayer))
|
||||
|
||||
describe("WorktreeFamily.list", () => {
|
||||
it.live("returns recorded sandboxes when git worktree listing fails", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* Effect.addFinalizer(() => Effect.promise(() => resetDatabase()))
|
||||
const root = yield* tmpdirScoped()
|
||||
const sandbox = yield* tmpdirScoped()
|
||||
const project = yield* Project.Service
|
||||
const info = (yield* project.fromDirectory(root)).project
|
||||
yield* project.addSandbox(info.id, sandbox)
|
||||
|
||||
const dirs = yield* WorktreeFamily.list().pipe(
|
||||
Effect.provideService(InstanceRef, {
|
||||
directory: root,
|
||||
worktree: root,
|
||||
project: { ...info, vcs: "git" },
|
||||
}),
|
||||
)
|
||||
|
||||
expect(dirs).toEqual([root, sandbox])
|
||||
}),
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user