fix tests

This commit is contained in:
James Long 2026-05-08 11:02:57 -04:00
commit ed6140af9e
2 changed files with 26 additions and 43 deletions

View file

@ -25,23 +25,4 @@ describe("recentConnectedWorkspaces", () => {
expect(recent.map((workspace) => workspace.id)).toEqual(["wrk_a", "wrk_d", "wrk_e"]) expect(recent.map((workspace) => workspace.id)).toEqual(["wrk_a", "wrk_d", "wrk_e"])
}) })
test("omits the active workspace before limiting recent workspaces", () => {
const workspaces = [
{ id: "wrk_a", name: "alpha", timeUsed: 400 },
{ id: "wrk_b", name: "beta", timeUsed: 300 },
{ id: "wrk_c", name: "gamma", timeUsed: 200 },
{ id: "wrk_d", name: "delta", timeUsed: 100 },
]
const { recent, hasMore } = recentConnectedWorkspaces({
workspaces,
status: () => "connected",
limit: 3,
omitWorkspaceID: "wrk_a",
})
expect(recent.map((workspace) => workspace.id)).toEqual(["wrk_b", "wrk_c", "wrk_d"])
expect(hasMore).toBe(false)
})
}) })

View file

@ -469,7 +469,15 @@ describe("workspace CRUD", () => {
expect(recorded.calls.configure).toHaveLength(1) expect(recorded.calls.configure).toHaveLength(1)
expect(recorded.calls.configure[0]).toMatchObject({ id: workspaceID, type, directory: null }) expect(recorded.calls.configure[0]).toMatchObject({ id: workspaceID, type, directory: null })
expect(recorded.calls.create).toHaveLength(1) expect(recorded.calls.create).toHaveLength(1)
expect(recorded.calls.create[0].info).toEqual(info) expect(recorded.calls.create[0].info).toEqual({
id: workspaceID,
type,
branch: "configured-branch",
name: "Configured Name",
directory: targetDir,
extra: { configured: true },
projectID: Instance.project.id,
})
expect(JSON.parse(recorded.calls.create[0].env.OPENCODE_AUTH_CONTENT ?? "{}")).toEqual({ expect(JSON.parse(recorded.calls.create[0].env.OPENCODE_AUTH_CONTENT ?? "{}")).toEqual({
test: { type: "api", key: "secret" }, test: { type: "api", key: "secret" },
}) })
@ -953,35 +961,29 @@ describe("workspace sync state", () => {
}) })
}) })
test("startWorkspaceSyncing starts only workspaces with sessions", async () => { test("startWorkspaceSyncing starts all workspaces", async () => {
await withInstance(async (dir) => { await withInstance(async (dir) => {
const withSessionType = unique("with-session") const firstType = unique("first")
const withoutSessionType = unique("without-session") const secondType = unique("second")
const withSession = workspaceInfo(Instance.project.id, withSessionType) const first = workspaceInfo(Instance.project.id, firstType)
const withoutSession = workspaceInfo(Instance.project.id, withoutSessionType) const second = workspaceInfo(Instance.project.id, secondType)
const withSessionDir = path.join(dir, "with-session") await fs.mkdir(path.join(dir, "first"), { recursive: true })
const withoutSessionDir = path.join(dir, "without-session") await fs.mkdir(path.join(dir, "second"), { recursive: true })
await fs.mkdir(withSessionDir, { recursive: true }) insertWorkspace(first)
await fs.mkdir(withoutSessionDir, { recursive: true }) insertWorkspace(second)
insertWorkspace(withSession) registerAdapter(Instance.project.id, firstType, localAdapter(path.join(dir, "first")).adapter)
insertWorkspace(withoutSession) registerAdapter(Instance.project.id, secondType, localAdapter(path.join(dir, "second")).adapter)
registerAdapter(Instance.project.id, withSessionType, localAdapter(withSessionDir).adapter)
registerAdapter(Instance.project.id, withoutSessionType, localAdapter(withoutSessionDir).adapter)
attachSessionToWorkspace(
(await AppRuntime.runPromise(SessionNs.Service.use((svc) => svc.create({})))).id,
withSession.id,
)
startWorkspaceSyncing(Instance.project.id) startWorkspaceSyncing(Instance.project.id)
await eventually(() => await eventually(() =>
workspaceStatus().then((status) => workspaceStatus().then((status) => {
expect(status.find((item) => item.workspaceID === withSession.id)?.status).toBe("connected"), expect(status.find((item) => item.workspaceID === first.id)?.status).toBe("connected")
), expect(status.find((item) => item.workspaceID === second.id)?.status).toBe("connected")
}),
) )
expect((await workspaceStatus()).find((item) => item.workspaceID === withoutSession.id)?.status).toBeUndefined() await removeWorkspace(first.id)
await removeWorkspace(withSession.id) await removeWorkspace(second.id)
await removeWorkspace(withoutSession.id)
}) })
}) })