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:
@@ -13,19 +13,9 @@ export const inject = ['slots', 'layout', 'sessions', 'workspaces']
|
||||
*/
|
||||
export function apply(ctx: ClientContext): void {
|
||||
const injectProps = (): SidebarRootInjected => ({
|
||||
// The shell's New Session button targets the most recently active
|
||||
// Workspace; an explicit Workspace still wins for scoped create actions.
|
||||
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) },
|
||||
)
|
||||
},
|
||||
// The shell's New Session button rides the runtime's shared action
|
||||
// (recent-Workspace targeting; explicit Workspace wins for scoped actions).
|
||||
startSession: (workspaceId) => { ctx.workspaces.startSession(workspaceId) },
|
||||
toggleSidebar: () => { ctx.layout.toggleSidebar() },
|
||||
})
|
||||
ctx.effect(
|
||||
|
||||
@@ -9,10 +9,7 @@ async function bench(declare = true) {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SlotsService).await()
|
||||
const layout = { toggleSidebar: vi.fn() }
|
||||
const workspaces = {
|
||||
connectWorkspace: vi.fn(async () => 'blank-1' as never),
|
||||
list: { getSnapshot: () => ({ recentWorkspaceId: undefined }) },
|
||||
}
|
||||
const workspaces = { startSession: vi.fn() }
|
||||
const sessions = { open: vi.fn(), clear: vi.fn() }
|
||||
ctx.provide('layout', layout)
|
||||
ctx.provide('sessions', sessions as never)
|
||||
@@ -39,13 +36,11 @@ describe('ui-sidebar apply', () => {
|
||||
expect(b.slots.spec('sidebar.workspaces')).toEqual({ kind: 'single', scope: 'root' })
|
||||
const injected = (b.slots.entries('sidebar')[0]!.inject as () => SidebarRootInjected)()
|
||||
expect(Object.keys(injected)).toEqual(['startSession', 'toggleSidebar'])
|
||||
// Workspace given: reuse-or-create the blank session, then navigate.
|
||||
// Both arms delegate to the runtime's shared New Session action.
|
||||
injected.startSession('workspace' as never)
|
||||
expect(b.workspaces.connectWorkspace).toHaveBeenCalledWith('workspace')
|
||||
await vi.waitFor(() => { expect(b.sessions.open).toHaveBeenCalledWith('blank-1') })
|
||||
// No workspace (the shell's New Session button): clear into the view state.
|
||||
expect(b.workspaces.startSession).toHaveBeenCalledWith('workspace')
|
||||
injected.startSession()
|
||||
expect(b.sessions.clear).toHaveBeenCalledOnce()
|
||||
expect(b.workspaces.startSession).toHaveBeenLastCalledWith(undefined)
|
||||
injected.toggleSidebar()
|
||||
expect(b.layout.toggleSidebar).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user