From 230f3b829506ca73f4657ca35018f6f43cbbdd82 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 11 Aug 2026 18:58:59 +0800 Subject: [PATCH] refactor(host): reuse workspace stream baseline --- packages/host/apiproxy/src/api-proxy.ts | 5 +++-- packages/host/apiproxy/tests/api-proxy-workspace.spec.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/host/apiproxy/src/api-proxy.ts b/packages/host/apiproxy/src/api-proxy.ts index 0a9a4e1fbd..8a139a9685 100644 --- a/packages/host/apiproxy/src/api-proxy.ts +++ b/packages/host/apiproxy/src/api-proxy.ts @@ -3379,10 +3379,11 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro host(_request, signal) { const queue = new FrameQueue>() + const committedWorkspaces = ctx.workspace.list() 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 // stream opens against the current set; workspace.list re-baselines // reconnecting clients, so only later changes need frames. diff --git a/packages/host/apiproxy/tests/api-proxy-workspace.spec.ts b/packages/host/apiproxy/tests/api-proxy-workspace.spec.ts index 1b98fedac5..d9b874f9f6 100644 --- a/packages/host/apiproxy/tests/api-proxy-workspace.spec.ts +++ b/packages/host/apiproxy/tests/api-proxy-workspace.spec.ts @@ -310,14 +310,16 @@ 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 { api, ctx, 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 listWorkspaces = vi.spyOn(ctx.workspace, 'list') const stream: AsyncIterator> = api.events.host(request({}), abort.signal)[Symbol.asyncIterator]() + expect(listWorkspaces).toHaveBeenCalledTimes(1) const changed = nextHostFrame(stream) const reordered = expectOk(await api.workspace.insertBefore(request({ workspaceId: first.workspaceId,