65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { Instance } from "../../src/project/instance"
|
|
import { Project } from "../../src/project/project"
|
|
import { Session } from "../../src/session"
|
|
import { Log } from "../../src/util/log"
|
|
import { tmpdir } from "../fixture/fixture"
|
|
|
|
Log.init({ print: false })
|
|
|
|
describe("Session.listGlobal", () => {
|
|
test("lists sessions across projects with project metadata", async () => {
|
|
await using first = await tmpdir({ git: true })
|
|
await using second = await tmpdir({ git: true })
|
|
|
|
const firstSession = await Instance.provide({
|
|
directory: first.path,
|
|
fn: async () => Session.create({ title: "first-session" }),
|
|
})
|
|
const secondSession = await Instance.provide({
|
|
directory: second.path,
|
|
fn: async () => Session.create({ title: "second-session" }),
|
|
})
|
|
|
|
const sessions = [...Session.listGlobal({ limit: 200 })]
|
|
const ids = sessions.map((session) => session.id)
|
|
|
|
expect(ids).toContain(firstSession.id)
|
|
expect(ids).toContain(secondSession.id)
|
|
|
|
const firstProject = Project.get(firstSession.projectID)
|
|
const secondProject = Project.get(secondSession.projectID)
|
|
|
|
const firstItem = sessions.find((session) => session.id === firstSession.id)
|
|
const secondItem = sessions.find((session) => session.id === secondSession.id)
|
|
|
|
expect(firstItem?.project?.id).toBe(firstProject?.id)
|
|
expect(firstItem?.project?.worktree).toBe(firstProject?.worktree)
|
|
expect(secondItem?.project?.id).toBe(secondProject?.id)
|
|
expect(secondItem?.project?.worktree).toBe(secondProject?.worktree)
|
|
})
|
|
|
|
test("excludes archived sessions by default", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const archived = await Instance.provide({
|
|
directory: tmp.path,
|
|
fn: async () => Session.create({ title: "archived-session" }),
|
|
})
|
|
|
|
await Instance.provide({
|
|
directory: tmp.path,
|
|
fn: async () => Session.setArchived({ sessionID: archived.id, time: Date.now() }),
|
|
})
|
|
|
|
const sessions = [...Session.listGlobal({ limit: 200 })]
|
|
const ids = sessions.map((session) => session.id)
|
|
|
|
expect(ids).not.toContain(archived.id)
|
|
|
|
const allSessions = [...Session.listGlobal({ limit: 200, archived: true })]
|
|
const allIds = allSessions.map((session) => session.id)
|
|
|
|
expect(allIds).toContain(archived.id)
|
|
})
|
|
})
|