refactor: dedupe the jscpd clones; drop the baseline loading gate
- Extract the shared New Session action into WorkspacesService.startSession (sidebar button and workspace browser both delegate; recent-Workspace targeting and the no-workspace clear live in one place). - Fold the chip-insertion transaction shared by insert-ref and paste-upgrade into one InputMachine helper. - Share the fixture's session-not-found guard across the sessionId-addressed catalog routes. - Drop the AppFrame baselines-ready loading gate (user ruling: the bare status line reads worse than the shell's own pending rendering); both column occupants mount from first paint.
This commit is contained in:
@@ -34,19 +34,9 @@ export const inject = ['slots', 'sessions', 'workspaces']
|
||||
*/
|
||||
export function apply(ctx: ClientContext): void {
|
||||
const browserInjected = (): WorkspaceBrowserInjected => ({
|
||||
// Explicit group actions keep their target; an unscoped New Session
|
||||
// action resolves through the runtime's recent-Workspace projection.
|
||||
startSession: (workspaceId) => {
|
||||
const target = workspaceId ?? ctx.workspaces.list.getSnapshot().recentWorkspaceId
|
||||
if (target === undefined) {
|
||||
ctx.sessions.clear()
|
||||
return
|
||||
}
|
||||
void ctx.workspaces.connectWorkspace(target).then(
|
||||
(sessionId) => { ctx.sessions.open(sessionId) },
|
||||
(reason: unknown) => { console.warn('new session failed:', reason) },
|
||||
)
|
||||
},
|
||||
// Explicit group actions keep their target; unscoped New Session rides
|
||||
// the runtime's shared action (recent-Workspace projection inside).
|
||||
startSession: (workspaceId) => { ctx.workspaces.startSession(workspaceId) },
|
||||
open: (sessionId) => { ctx.sessions.open(sessionId) },
|
||||
renameWorkspace: async (workspaceId, title) => { await ctx.workspaces.rename(workspaceId, title) },
|
||||
insertSessionBefore: async (workspaceId, sessionId, beforeSessionId) => {
|
||||
|
||||
@@ -14,17 +14,16 @@ async function bench() {
|
||||
path: 'name' in input ? `/projects/${input.name}` : input.path,
|
||||
title: 'new', sessionIds: [], createdAt: '0', updatedAt: '0',
|
||||
}))
|
||||
const connectWorkspace = vi.fn(async () => 'blank-1' as never)
|
||||
const startSession = vi.fn()
|
||||
const rename = vi.fn(async () => ({}))
|
||||
const insertSessionBefore = vi.fn(async () => ({}))
|
||||
const open = vi.fn()
|
||||
const clear = vi.fn()
|
||||
ctx.provide('workspaces', {
|
||||
create, connectWorkspace, rename, insertSessionBefore,
|
||||
list: { getSnapshot: () => ({ recentWorkspaceId: undefined }) },
|
||||
create, startSession, rename, insertSessionBefore,
|
||||
} as never)
|
||||
ctx.provide('sessions', { open, clear } as never)
|
||||
return { ctx, slots: ctx.get('slots') as SlotsService, create, connectWorkspace, rename, insertSessionBefore, open, clear }
|
||||
return { ctx, slots: ctx.get('slots') as SlotsService, create, startSession, rename, insertSessionBefore, open, clear }
|
||||
}
|
||||
|
||||
type HoleName = 'sidebar.workspaces' | 'conversation.hero.workspace' | 'conversation.empty.workspace'
|
||||
@@ -60,13 +59,11 @@ describe('ui-workspace apply', () => {
|
||||
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
||||
|
||||
const browser = (b.slots.entries('sidebar.workspaces')[0]!.inject as () => WorkspaceBrowserInjected)()
|
||||
// Workspace given: reuse-or-create the blank session, then navigate.
|
||||
// Both arms delegate to the runtime's shared New Session action.
|
||||
browser.startSession('ws' as never)
|
||||
expect(b.connectWorkspace).toHaveBeenCalledWith('ws')
|
||||
await vi.waitFor(() => { expect(b.open).toHaveBeenCalledWith('blank-1') })
|
||||
// No workspace: clear the selection into the New Session pure view state.
|
||||
expect(b.startSession).toHaveBeenCalledWith('ws')
|
||||
browser.startSession()
|
||||
expect(b.clear).toHaveBeenCalledOnce()
|
||||
expect(b.startSession).toHaveBeenLastCalledWith(undefined)
|
||||
browser.open('session' as never)
|
||||
expect(b.open).toHaveBeenCalledWith('session')
|
||||
await browser.renameWorkspace('ws' as never, 'renamed')
|
||||
|
||||
Reference in New Issue
Block a user