Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/desktop/renderer-architecture.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"react": 1
},
"importSpecifiers": 8,
"nonTriviaTokens": 672
"nonTriviaTokens": 671
},
"src/renderer/app-shell-effects.ts": {
"importDeclarations": 23,
Expand Down Expand Up @@ -871,8 +871,7 @@
"useTaskEntryController": 1,
"useTaskSubmissionReadiness": 1,
"useToast": 1,
"useTurnActionRegistry": 1,
"useWorkbarController": 1
"useTurnActionRegistry": 1
},
"lifecycleMethods": {},
"unresolvedDependencies": 0,
Expand Down Expand Up @@ -979,8 +978,8 @@
"@maka/ui/icons": 1,
"react": 1
},
"importSpecifiers": 184,
"nonTriviaTokens": 15687
"importSpecifiers": 182,
"nonTriviaTokens": 15659
},
"src/renderer/use-app-shell-composer-quotes.ts": {
"importDeclarations": 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const project: ProjectRecord = {
};

const hiddenSessionIds = new Set(['hidden']);
const hiddenSessionIdsStore = {
getState: () => hiddenSessionIds,
subscribe: () => () => undefined,
};

const fakeServices = createFakeSessionNavigationServices();

Expand Down Expand Up @@ -217,7 +221,7 @@ describe('useSessionNavigationReads', () => {
sessions: linkedCatalog,
activeSessionId: 'child',
activeSession: linkedCatalog[1],
hiddenSessionIds,
hiddenSessionIdsStore,
}),
}),
),
Expand Down
47 changes: 41 additions & 6 deletions apps/desktop/src/main/__tests__/workbar-boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,59 @@ describe('Workbar feature boundary', () => {
assert.equal(productionEntry.includes("from './testing"), false);
});

it('keeps Workbar topology and resource lifecycle out of AppShell', () => {
it('owns the Workbar controller below AppShell', () => {
const appShell = readFileSync(
join(desktopRoot, 'src', 'renderer', 'app-shell.tsx'),
'utf8',
);
const productionEntry = readFileSync(join(featureRoot, 'index.ts'), 'utf8');
const provider = readFileSync(
join(featureRoot, 'ui', 'workbar-provider.tsx'),
'utf8',
);
const host = readFileSync(
join(featureRoot, 'ui', 'workbar-host.tsx'),
'utf8',
);
for (const forbidden of [
'useWorkbarLayoutState',
'terminalSessionWorkbarTabId',
'pendingSideChatClose',
'sideConversations',
'window.maka.shellRuns.start',
'useWorkbarController',
'workbar.selectors',
'workbar.commands',
'<WorkbarHost model=',
'Workbar.createWorkbarShellBridge',
]) {
assert.equal(appShell.includes(forbidden), false, forbidden);
}
assert.equal(
appShell.includes('<WorkbarHost model={workbar.host} />'),
true,
assert.equal(appShell.includes('<Workbar.WorkbarHost />'), true);
assert.equal(provider.includes('useWorkbarController({'), true);
assert.equal(provider.includes('function WorkbarShellBridgeOwner'), true);
assert.equal(provider.includes('createWorkbarShellBridge()'), true);
assert.equal(host.includes('useWorkbarHostModel()'), true);
assert.equal(productionEntry.includes('useWorkbarController'), false);
});

it('publishes the rail visibility as an equality-selected reader projection', () => {
const reads = readFileSync(
join(
desktopRoot,
'src',
'renderer',
'features',
'session-navigation',
'controller',
'use-session-navigation-reads.ts',
),
'utf8',
);

assert.equal(reads.includes('hiddenSessionIdsStore'), true);
assert.equal(reads.includes('useExternalStoreSelector('), true);
assert.equal(reads.includes('readonlyStringSetEqual'), true);
});

it('projects Work Board project identity through the controller-owned host model', () => {
Expand All @@ -131,9 +166,9 @@ describe('Workbar feature boundary', () => {
'utf8',
);

assert.equal(appShell.includes('projectId: currentProjectId'), true);
assert.equal(appShell.includes('projectId={currentProjectId}'), true);
assert.equal(
appShell.includes('projectAliases: currentProject?.aliases ?? []'),
appShell.includes('projectAliases={currentProject?.aliases ?? []}'),
true,
);
assert.equal(controller.includes('projectId: input.projectId'), true);
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/main/__tests__/workbar-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ function input(
authoritativeSessionIds: new Set(activeSession ? [activeSession.id] : []),
shellObscured: false,
modelChoices: [],
reportError: (title, description) => errors.push(`${title}: ${description}`),
reportError: (_sessionId, title, description) =>
errors.push(`${title}: ${description}`),
};
}

Expand Down
174 changes: 174 additions & 0 deletions apps/desktop/src/main/__tests__/workbar-provider-scope.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { strict as assert } from 'node:assert';
import { afterEach, describe, it } from 'node:test';
import { act, createElement, Fragment } from 'react';
import type { SessionSummary } from '@maka/core/session';
import { LocaleProvider } from '@maka/ui';
import { cleanupFakeDom, installReactRenderer } from './fake-dom.js';
import {
createFakeWorkbarServices,
createWorkbarShellBridge,
useWorkbarHostModel,
useWorkbarTitlebarModel,
WorkbarProvider,
WorkbarServicesProvider,
type UseWorkbarControllerInput,
type WorkbarHostModel,
type WorkbarServices,
type WorkbarShellBridge,
type WorkbarTitlebarModel,
} from '../../renderer/features/workbar/testing.js';

let shellRenders = 0;
let hostRenders = 0;
let titlebarRenders = 0;
let latestHost: WorkbarHostModel | undefined;
let latestTitlebar: WorkbarTitlebarModel | undefined;

function HostProbe() {
latestHost = useWorkbarHostModel();
hostRenders += 1;
return null;
}

function TitlebarProbe() {
latestTitlebar = useWorkbarTitlebarModel();
titlebarRenders += 1;
return null;
}

function ShellProbe() {
shellRenders += 1;
return createElement(
Fragment,
null,
createElement(HostProbe),
createElement(TitlebarProbe),
);
}

function session(id: string): SessionSummary {
return {
id,
name: id,
isFlagged: false,
isArchived: false,
labels: [],
hasUnread: false,
status: 'active',
backend: 'ai-sdk',
llmConnectionSlug: 'test',
connectionLocked: false,
model: 'test-model',
permissionMode: 'ask',
};
}

function input(activeSession: SessionSummary): UseWorkbarControllerInput {
return {
available: true,
activeSession,
projectId: activeSession.projectId,
projectAliases: [],
authoritativeSessionIds: new Set([activeSession.id, 'fork']),
shellObscured: false,
modelChoices: [],
reportError: () => undefined,
};
}

function renderProvider(
root: ReturnType<typeof installReactRenderer>['root'],
services: WorkbarServices,
bridge: WorkbarShellBridge,
) {
root.render(
createElement(LocaleProvider, {
locale: 'en',
children: createElement(
WorkbarServicesProvider,
{ services },
createElement(
WorkbarProvider,
{ ...input(session('a')), bridge },
createElement(ShellProbe),
),
),
}),
);
}

afterEach(() => {
shellRenders = 0;
hostRenders = 0;
titlebarRenders = 0;
latestHost = undefined;
latestTitlebar = undefined;
cleanupFakeDom();
delete (globalThis as { window?: unknown }).window;
});

describe('WorkbarProvider render scope', () => {
it('keeps controller updates below the shell and publishes its narrow bridge', async () => {
const { root } = installReactRenderer();
const bridge = createWorkbarShellBridge();
let visibilityNotifications = 0;
const unsubscribe = bridge.hiddenSessionIds.subscribe(() => {
visibilityNotifications += 1;
});

await act(async () =>
renderProvider(root, createFakeWorkbarServices(), bridge),
);
assert.equal(shellRenders, 1);
assert.equal(latestTitlebar?.available, true);

const initiallyCollapsed = bridge.getRightCollapsed();
const hostBeforeToggle = hostRenders;
const titlebarBeforeToggle = titlebarRenders;
await act(async () => latestTitlebar?.onToggle());
assert.equal(bridge.getRightCollapsed(), !initiallyCollapsed);
assert.equal(shellRenders, 1);
assert.equal(hostRenders, hostBeforeToggle + 1);
assert.equal(titlebarRenders, titlebarBeforeToggle + 1);

await act(async () => bridge.commands.openTool('review'));
assert.equal(
latestHost?.panelsState.right.tabs.some((tab) => tab.kind === 'review'),
true,
);
assert.equal(shellRenders, 1);

await act(async () =>
latestHost?.onForkVisibilityChange?.({
type: 'fork-created',
sessionId: 'fork',
}),
);
assert.equal(bridge.hiddenSessionIds.getState().has('fork'), true);
assert.equal(visibilityNotifications, 1);
assert.equal(shellRenders, 1);

unsubscribe();
await act(async () => root.unmount());
assert.equal(bridge.hiddenSessionIds.getState().size, 0);
});
});
7 changes: 2 additions & 5 deletions apps/desktop/src/renderer/app-shell-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function createAppShellE2eFixtureActions(options: {
setSearchModalOpen: Dispatch<SetStateAction<boolean>>;
setSessionListCollapsed(collapsed: boolean): void;
workbar: {
rightCollapsed: boolean;
getRightCollapsed(): boolean;
toggleRight(): void;
openTool(
kind: SessionWorkbarTabKind,
Expand Down Expand Up @@ -123,10 +123,7 @@ export function createAppShellE2eFixtureActions(options: {
if (state.sidebarCollapsed !== undefined) {
setSessionListCollapsed(state.sidebarCollapsed);
}
if (
state.workbarCollapsed !== undefined &&
state.workbarCollapsed !== workbar.rightCollapsed
) {
if (state.workbarCollapsed === !workbar.getRightCollapsed()) {
workbar.toggleRight();
}
if (
Expand Down
Loading