fix: session list on tui

This commit is contained in:
Catriel Müller
2026-06-15 21:08:16 -03:00
parent 8c1cdf53a9
commit e91eef2b38
17 changed files with 226 additions and 45 deletions
@@ -156,4 +156,114 @@ describe("experimental.session.list", () => {
await $`git worktree remove ${worktree}`.cwd(first.path).quiet().nothrow()
}
})
test("current=true narrows worktrees to the directory containing worktree", async () => {
await using first = await tmpdir({ git: true })
const worktree = path.join(first.path, "..", path.basename(first.path) + "-worktree")
try {
await $`git worktree add ${worktree} -b test-branch-current-${Date.now()}`.cwd(first.path).quiet()
try {
const { Server } = await import("../../src/server/server")
const branch = await WithInstance.provide({
directory: worktree,
fn: () => create("worktree-session"),
})
const root = await WithInstance.provide({
directory: first.path,
fn: async () => ({
app: Server.Default().app,
project: await Server.Default().app.request("/project/current", {
headers: { "x-kilo-directory": first.path },
}),
session: await create("root-session"),
}),
})
const app = root.app
const project = await root.project.json()
const cwd = path.join(worktree, "packages", "opencode")
const response = await app.request(
`/experimental/session?projectID=${encodeURIComponent(project.id)}&roots=true&worktrees=true&current=true&directory=${encodeURIComponent(cwd)}`,
{
headers: { "x-kilo-directory": first.path },
},
)
expect(response.status).toBe(200)
const body = await response.json()
const ids = body.map((item: { id: string }) => item.id)
expect(ids).toContain(branch.id)
expect(ids).not.toContain(root.session.id)
} finally {
mock.restore()
}
} finally {
await $`git worktree remove ${worktree}`.cwd(first.path).quiet().nothrow()
}
})
test("current=true excludes Agent Manager worktrees from the root worktree", async () => {
await using first = await tmpdir({ git: true })
const worktree = path.join(first.path, ".kilo", "worktrees", "nested-current")
try {
await $`git worktree add --quiet -b test-branch-nested-current-${Date.now()} ${worktree} HEAD`.cwd(
first.path,
)
try {
const { Server } = await import("../../src/server/server")
const branch = await WithInstance.provide({
directory: worktree,
fn: () => create("worktree-session"),
})
const root = await WithInstance.provide({
directory: first.path,
fn: async () => ({
app: Server.Default().app,
project: await Server.Default().app.request("/project/current", {
headers: { "x-kilo-directory": first.path },
}),
session: await create("root-session"),
}),
})
const app = root.app
const project = await root.project.json()
const all = await app.request(
`/experimental/session?projectID=${encodeURIComponent(project.id)}&roots=true&worktrees=true&directory=${encodeURIComponent(first.path)}`,
{
headers: { "x-kilo-directory": first.path },
},
)
const current = await app.request(
`/experimental/session?projectID=${encodeURIComponent(project.id)}&roots=true&worktrees=true&current=true&directory=${encodeURIComponent(first.path)}`,
{
headers: { "x-kilo-directory": first.path },
},
)
expect(all.status).toBe(200)
expect(current.status).toBe(200)
const allIds = (await all.json()).map((item: { id: string }) => item.id)
const currentIds = (await current.json()).map((item: { id: string }) => item.id)
expect(allIds).toContain(root.session.id)
expect(allIds).toContain(branch.id)
expect(currentIds).toContain(root.session.id)
expect(currentIds).not.toContain(branch.id)
} finally {
mock.restore()
}
} finally {
await $`git worktree remove ${worktree}`.cwd(first.path).quiet().nothrow()
}
})
})