fix tests

This commit is contained in:
James Long
2026-05-08 11:02:57 -04:00
parent 8d63dc34c0
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"])
})
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[0]).toMatchObject({ id: workspaceID, type, directory: null })
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({
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) => {
const withSessionType = unique("with-session")
const withoutSessionType = unique("without-session")
const withSession = workspaceInfo(Instance.project.id, withSessionType)
const withoutSession = workspaceInfo(Instance.project.id, withoutSessionType)
const withSessionDir = path.join(dir, "with-session")
const withoutSessionDir = path.join(dir, "without-session")
await fs.mkdir(withSessionDir, { recursive: true })
await fs.mkdir(withoutSessionDir, { recursive: true })
insertWorkspace(withSession)
insertWorkspace(withoutSession)
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,
)
const firstType = unique("first")
const secondType = unique("second")
const first = workspaceInfo(Instance.project.id, firstType)
const second = workspaceInfo(Instance.project.id, secondType)
await fs.mkdir(path.join(dir, "first"), { recursive: true })
await fs.mkdir(path.join(dir, "second"), { recursive: true })
insertWorkspace(first)
insertWorkspace(second)
registerAdapter(Instance.project.id, firstType, localAdapter(path.join(dir, "first")).adapter)
registerAdapter(Instance.project.id, secondType, localAdapter(path.join(dir, "second")).adapter)
startWorkspaceSyncing(Instance.project.id)
await eventually(() =>
workspaceStatus().then((status) =>
expect(status.find((item) => item.workspaceID === withSession.id)?.status).toBe("connected"),
),
workspaceStatus().then((status) => {
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(withSession.id)
await removeWorkspace(withoutSession.id)
await removeWorkspace(first.id)
await removeWorkspace(second.id)
})
})