test(web): cover workspace sidebar behavior

This commit is contained in:
_Kerman
2026-08-11 15:24:40 +08:00
parent 8005ab78bd
commit 6e303ac0b7
22 changed files with 420 additions and 48 deletions

View File

@@ -308,6 +308,48 @@ describe('workspace.create', () => {
})
})
describe('workspace.insertBefore', () => {
it('commits the complete order, streams one order frame, and maps unknown ids', async () => {
const { api, root } = await harness()
const first = expectOk(await api.workspace.create(request({ path: stageDir(root, 'first') }))).workspace
const second = expectOk(await api.workspace.create(request({ path: stageDir(root, 'second') }))).workspace
const third = expectOk(await api.workspace.create(request({ path: stageDir(root, 'third') }))).workspace
const abort = new AbortController()
const stream: AsyncIterator<RpcRequest<HostFrame>> =
api.events.host(request({}), abort.signal)[Symbol.asyncIterator]()
const changed = nextHostFrame(stream)
const reordered = expectOk(await api.workspace.insertBefore(request({
workspaceId: first.workspaceId,
beforeWorkspaceId: second.workspaceId,
})))
expect(reordered.workspaceIds).toEqual([third.workspaceId, first.workspaceId, second.workspaceId])
expect(await changed).toMatchObject({
payload: {
type: 'host/workspace-order-changed',
workspaceIds: [third.workspaceId, first.workspaceId, second.workspaceId],
},
})
expect(expectOk(await api.workspace.list(request({}))).items.map(item => item.workspaceId))
.toEqual(reordered.workspaceIds)
const missingSource = await api.workspace.insertBefore(request({
workspaceId: 'missing' as WorkspaceId,
}))
expect(missingSource.result).toMatchObject({
ok: false, error: { code: 'workspace-not-found', details: { workspaceId: 'missing' } },
})
const missingAnchor = await api.workspace.insertBefore(request({
workspaceId: first.workspaceId,
beforeWorkspaceId: 'missing-anchor' as WorkspaceId,
}))
expect(missingAnchor.result).toMatchObject({
ok: false, error: { code: 'workspace-not-found', details: { workspaceId: 'missing-anchor' } },
})
abort.abort()
})
})
describe('session creation and Workspace membership', () => {
it('attaches a preallocated idempotent session while cwd-only sessions stay ungrouped', async () => {
const { api, ctx, root } = await harness()

View File

@@ -84,6 +84,7 @@ function scriptedApi(overrides: {
create: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' }, created: true }),
rename: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' } }),
delete: r => ok(r, { deleted: true as const }),
insertBefore: r => ok(r, { workspaceIds: [r.payload.workspaceId] }),
insertSessionBefore: r => ok(r, { workspace: { workspaceId: 'w1' as never, path: '/t', title: 't', sessionIds: [], createdAt: '0', updatedAt: '0' } }),
archiveSession: r => ok(r, { archivedSessionIds: [r.payload.sessionId] }),
},

View File

@@ -174,6 +174,9 @@ function fakeApi(overrides: Partial<{ muxFrames: MuxFrame[]; hostFrames: HostFra
async delete(request) {
return { rpcId: request.rpcId, result: { ok: true, value: { deleted: true as const } } }
},
async insertBefore(request) {
return { rpcId: request.rpcId, result: { ok: true, value: { workspaceIds: [request.payload.workspaceId] } } }
},
async insertSessionBefore(request) {
return {
rpcId: request.rpcId,

View File

@@ -23,6 +23,7 @@ import {
workspaceArchiveSessionRequestSchema, workspaceArchiveSessionValueSchema,
workspaceCreateRequestSchema, workspaceCreateValueSchema, workspaceIdSchema,
workspaceDeleteRequestSchema, workspaceDeleteValueSchema,
workspaceInsertBeforeRequestSchema, workspaceInsertBeforeValueSchema,
workspaceInsertSessionBeforeRequestSchema, workspaceInsertSessionBeforeValueSchema,
workspaceListRequestSchema, workspaceListValueSchema,
workspaceRenameRequestSchema, workspaceRenameValueSchema, workspaceViewSchema,
@@ -351,6 +352,17 @@ describe('workspace domain schemas', () => {
expect(() => workspaceDeleteValueSchema.parse({ deleted: false })).toThrow()
})
it('insertBefore accepts an anchored or anchorless Workspace move and returns the complete order', () => {
expect(workspaceInsertBeforeRequestSchema.parse({
workspaceId: 'w1', beforeWorkspaceId: 'w2',
}).beforeWorkspaceId).toBe('w2')
expect(workspaceInsertBeforeRequestSchema.parse({ workspaceId: 'w1' }).beforeWorkspaceId)
.toBeUndefined()
expect(() => workspaceInsertBeforeRequestSchema.parse({ beforeWorkspaceId: 'w2' })).toThrow()
expect(workspaceInsertBeforeValueSchema.parse({ workspaceIds: ['w2', 'w1'] }).workspaceIds)
.toEqual(['w2', 'w1'])
})
it('insertSessionBefore accepts an anchored and an anchorless move', () => {
expect(workspaceInsertSessionBeforeRequestSchema.parse({ workspaceId: 'w1', sessionId: 's1', beforeSessionId: 's2' }).beforeSessionId).toBe('s2')
expect(workspaceInsertSessionBeforeRequestSchema.parse({ workspaceId: 'w1', sessionId: 's1' }).beforeSessionId).toBeUndefined()