refactor(host): reuse workspace stream baseline

This commit is contained in:
_Kerman
2026-08-11 18:58:59 +08:00
parent e991c63bdb
commit 230f3b8295
2 changed files with 6 additions and 3 deletions

View File

@@ -3379,10 +3379,11 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro
host(_request, signal) { host(_request, signal) {
const queue = new FrameQueue<RpcRequest<HostFrame>>() const queue = new FrameQueue<RpcRequest<HostFrame>>()
const committedWorkspaces = ctx.workspace.list()
const committedWorkspaceIds = new Set( const committedWorkspaceIds = new Set(
ctx.workspace.list().map(workspace => String(workspace.id)), committedWorkspaces.map(workspace => String(workspace.id)),
) )
let committedWorkspaceOrder = ctx.workspace.list().map(workspace => workspaceView(workspace).workspaceId) let committedWorkspaceOrder = committedWorkspaces.map(workspace => workspace.id)
// Frame-dedup baseline, same posture as committedWorkspaceIds: the // Frame-dedup baseline, same posture as committedWorkspaceIds: the
// stream opens against the current set; workspace.list re-baselines // stream opens against the current set; workspace.list re-baselines
// reconnecting clients, so only later changes need frames. // reconnecting clients, so only later changes need frames.

View File

@@ -310,14 +310,16 @@ describe('workspace.create', () => {
describe('workspace.insertBefore', () => { describe('workspace.insertBefore', () => {
it('commits the complete order, streams one order frame, and maps unknown ids', async () => { it('commits the complete order, streams one order frame, and maps unknown ids', async () => {
const { api, root } = await harness() const { api, ctx, root } = await harness()
const first = expectOk(await api.workspace.create(request({ path: stageDir(root, 'first') }))).workspace 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 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 third = expectOk(await api.workspace.create(request({ path: stageDir(root, 'third') }))).workspace
const abort = new AbortController() const abort = new AbortController()
const listWorkspaces = vi.spyOn(ctx.workspace, 'list')
const stream: AsyncIterator<RpcRequest<HostFrame>> = const stream: AsyncIterator<RpcRequest<HostFrame>> =
api.events.host(request({}), abort.signal)[Symbol.asyncIterator]() api.events.host(request({}), abort.signal)[Symbol.asyncIterator]()
expect(listWorkspaces).toHaveBeenCalledTimes(1)
const changed = nextHostFrame(stream) const changed = nextHostFrame(stream)
const reordered = expectOk(await api.workspace.insertBefore(request({ const reordered = expectOk(await api.workspace.insertBefore(request({
workspaceId: first.workspaceId, workspaceId: first.workspaceId,