Files
kilocode/packages/kilo-vscode/tests/unit/agent-project-reactivate.test.ts
T
marius-kilocode 9bbf2dab10 refactor(agent-manager): move project domain into src/agent-manager/project
The project-domain modules sat flat in src/agent-manager next to the
shared capability layer (GitOps, WorktreeStateManager, pollers, diff
helpers), which made the layering invisible: anything could import
anything and the folder gave no hint about what belongs to per-project
state versus shared infrastructure.

Moves the files whose entire reason to exist is per-project state and
routing into src/agent-manager/project/: context (split from the old
project-context.ts into context.ts for the single-project scope and
contexts.ts for the panel-level coordinator), init, paths, registry,
route, scope, pollers, messages, session-view, state-gate, and wiring.
Shared capabilities stay at the parent level; the domain imports them
across the boundary (../GitOps etc.), the same pattern the webview
project/ directory already uses. Rename-only aside from the context
split and import path updates; no barrel module.
2026-07-30 10:32:36 +02:00

55 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "bun:test"
import { ProjectContext, type ProjectContextDeps } from "../../src/agent-manager/project/context"
import { reactivateProject } from "../../src/agent-manager/project/init"
import type { WorktreeStateManager } from "../../src/agent-manager/WorktreeStateManager"
const ROOT = "/repo/main"
function fakeState(): WorktreeStateManager {
return {
getWorktrees: () => [],
getSessions: () => [],
flush: async () => {},
} as unknown as WorktreeStateManager
}
function makeContext(): ProjectContext {
const deps: ProjectContextDeps = { log: () => {}, state: () => fakeState() }
const ctx = new ProjectContext("prj-test", ROOT, false, deps)
ctx.stateManager()
return ctx
}
describe("reactivateProject", () => {
it("returns false for a cold context that never initialized", () => {
const ctx = makeContext()
const pushed: string[] = []
expect(reactivateProject(ctx, undefined, () => pushed.push(ctx.id))).toBe(false)
expect(pushed).toHaveLength(0)
})
it("re-registers and pushes in-memory state for a ready context", async () => {
const ctx = makeContext()
await ctx.ensureReady(async () => ({ ok: true, refsFixed: 0 }))
const registered = new Map<string, string>()
const pushed: string[] = []
const ok = reactivateProject(
ctx,
{
setSessionDirectory: (id, dir) => registered.set(id, dir),
trackSession: () => {},
},
() => pushed.push(ctx.id),
)
expect(ok).toBe(true)
expect(pushed).toEqual(["prj-test"])
})
it("returns false after the context is suspended", async () => {
const ctx = makeContext()
await ctx.ensureReady(async () => ({ ok: true, refsFixed: 0 }))
ctx.suspend()
expect(reactivateProject(ctx, undefined, () => {})).toBe(false)
})
})