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

@@ -10,7 +10,11 @@ import type { DomainChanged } from '@deepseek-ai/dsh-storage-domain'
import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
import type { SessionHeader } from '@deepseek-ai/dsh-session'
import { MemoryMediaPool, MemoryStorageBackend } from '../../../storage/storage-domain/tests/helpers/memory-backend.ts'
import WorkspaceRegistry, { WorkspaceId, WorkspaceMoveInvalidError } from '../src/index.ts'
import WorkspaceRegistry, {
WorkspaceId,
WorkspaceMoveInvalidError,
WorkspaceOrderInvalidError,
} from '../src/index.ts'
import type { WorkspaceDomainState, WorkspaceRecord } from '../src/index.ts'
const DOMAIN_VERSION = 2
@@ -568,6 +572,49 @@ describe('WorkspaceRegistry create and lookup', () => {
})
})
describe('Workspace registry ordering', () => {
it('moves a workspace before an anchor or to the end and restores that order after restart', async () => {
const firstDir = await makeDir('order-first')
const secondDir = await makeDir('order-second')
const thirdDir = await makeDir('order-third')
const result = await harness()
const first = await result.registry.create(firstDir)
const second = await result.registry.create(secondDir)
const third = await result.registry.create(thirdDir)
expect(result.registry.list().map(item => item.id)).toEqual([third.id, second.id, first.id])
await expect(result.registry.insertBefore(first.id, second.id))
.resolves.toEqual([third.id, first.id, second.id])
await expect(result.registry.insertBefore(third.id))
.resolves.toEqual([first.id, second.id, third.id])
expect(storedState(result.pool).workspaceIds).toEqual([first.id, second.id, third.id])
const restarted = await harness({ pool: result.pool })
expect(restarted.registry.list().map(item => item.id)).toEqual([first.id, second.id, third.id])
})
it('keeps self-anchored and already-positioned moves write-free and rejects unknown ids', async () => {
const firstDir = await makeDir('order-noop-first')
const secondDir = await makeDir('order-noop-second')
const result = await harness()
const first = await result.registry.create(firstDir)
const second = await result.registry.create(secondDir)
const written = result.changes.length
await result.registry.insertBefore(second.id, second.id)
await result.registry.insertBefore(second.id, first.id)
await result.registry.insertBefore(first.id)
expect(result.changes).toHaveLength(written)
expect(result.registry.list().map(item => item.id)).toEqual([second.id, first.id])
await expect(result.registry.insertBefore(WorkspaceId('missing')))
.rejects.toBeInstanceOf(WorkspaceOrderInvalidError)
await expect(result.registry.insertBefore(second.id, WorkspaceId('missing-anchor')))
.rejects.toMatchObject({ workspaceId: 'missing-anchor' })
expect(result.changes).toHaveLength(written)
})
})
describe('Workspace session ordering', () => {
it('prepends new attaches and keeps repeat attach idempotent', async () => {
const dir = await makeDir('attach-order')