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
5 changes: 2 additions & 3 deletions apps/desktop/renderer-architecture.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,6 @@
"useStableActions": 6,
"useState": 17,
"useSystemUiLocale": 1,
"useTaskEntryController": 1,
"useTaskSubmissionReadiness": 1,
"useToast": 1,
"useTurnActionRegistry": 1,
Expand Down Expand Up @@ -979,8 +978,8 @@
"@maka/ui/icons": 1,
"react": 1
},
"importSpecifiers": 184,
"nonTriviaTokens": 15687
"importSpecifiers": 183,
"nonTriviaTokens": 15680
},
"src/renderer/use-app-shell-composer-quotes.ts": {
"importDeclarations": 3,
Expand Down
48 changes: 46 additions & 2 deletions apps/desktop/src/main/__tests__/task-entry-boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,39 @@ describe('Task Entry feature boundary', () => {
const productionEntry = readFileSync(join(featureRoot, 'index.ts'), 'utf8');
assert.equal(productionEntry.includes('createFakeTaskEntryServices'), false);
assert.equal(productionEntry.includes("from './testing"), false);
assert.equal(productionEntry.includes('useTaskEntryController'), false);
assert.equal(productionEntry.includes('TaskEntryProvider,'), false);
assert.equal(productionEntry.includes('useTaskEntryOwnership'), false);
});

it('keeps the controller owned by TaskEntryProvider and out of renderer roots', () => {
const controllerOwner = join(featureRoot, 'ui', 'task-entry-provider.tsx');
const consumers: string[] = [];
for (const path of sourceFiles(join(desktopRoot, 'src', 'renderer'))) {
if (!/\.tsx?$/.test(path) || path.endsWith('use-task-entry-controller.ts')) continue;
const source = readFileSync(path, 'utf8');
if (/\buseTaskEntryController\s*\(/.test(source)) {
consumers.push(relative(desktopRoot, path));
}
}
assert.deepEqual(consumers, [relative(desktopRoot, controllerOwner)]);
});

it('keeps the controller module behind TaskEntryProvider and the testing entry', () => {
const importers: string[] = [];
for (const path of sourceFiles(featureRoot)) {
if (!/\.tsx?$/.test(path)) continue;
const source = readFileSync(path, 'utf8');
for (const match of source.matchAll(/from\s+['"]([^'"]+)['"]/g)) {
if (match[1]?.includes('controller/use-task-entry-controller')) {
importers.push(relative(desktopRoot, path));
}
}
}
assert.deepEqual(importers.sort(), [
'src/renderer/features/task-entry/testing.ts',
'src/renderer/features/task-entry/ui/task-entry-provider.tsx',
]);
});

it('keeps Task Entry catalog, picker, and directory handoff ownership out of AppShell', () => {
Expand All @@ -96,10 +129,21 @@ describe('Task Entry feature boundary', () => {
'newTaskDraftKey(',
'RemoteProjectDirectoryDialog',
'const workspacePicker: WorkspacePickerModel',
'useTaskEntryController',
'useTaskEntryShellProjection',
'taskEntry.host',
'taskEntry.owner',
'<TaskEntryHost model=',
'<TaskEntry.TaskEntryHost model=',
]) {
assert.equal(appShell.includes(forbidden), false, forbidden);
}
assert.equal(appShell.includes('const taskEntry = useTaskEntryController({'), true);
assert.equal(appShell.includes('<TaskEntryHost model={taskEntry.host} />'), true);
for (const required of [
'<TaskEntry.TaskEntryRoot>',
'<TaskEntry.TaskEntryWorkspacePickerConsumer manageProjects=',
'<TaskEntry.TaskEntryHost />',
]) {
assert.equal(appShell.includes(required), true, required);
}
});
});
189 changes: 189 additions & 0 deletions apps/desktop/src/main/__tests__/task-entry-provider-scope.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* 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 { LocaleProvider, ToastProvider } from '@maka/ui';
import { cleanupFakeDom, installReactRenderer } from './fake-dom.js';
import {
createFakeTaskEntryServices,
TaskEntryRoot,
TaskEntryServicesProvider,
TaskEntryWorkspacePickerConsumer,
useTaskEntryHostModel,
type TaskEntryCatalog,
type TaskEntryHost,
type TaskEntryShellProjection,
type TaskEntryServices,
} from '../../renderer/features/task-entry/testing.js';

let shellRenders = 0;
let frameRenders = 0;
let workspaceRenders = 0;
let hostRenders = 0;
let latestTaskEntry: TaskEntryShellProjection | undefined;
let latestDirectoryHostId: string | undefined;
let latestWorkspaceGroupCount = 0;

function project(id: string) {
return {
id,
name: id,
locations: [{ path: `/tmp/${id}`, isWorktree: false }],
available: true,
preferredPath: `/tmp/${id}`,
};
}

function remoteHost(): Extract<TaskEntryHost, { state: 'available' }> {
return {
profile: { id: 'remote', name: 'Remote', kind: 'remote' },
hostId: 'host-remote',
readiness: 'ready',
state: 'available',
projects: [project('project-a')],
capabilities: {
chooseClientDirectory: false,
chooseHostDirectory: true,
selectNoProject: false,
},
selectedProjectId: 'project-a',
chatDefaults: { permissionMode: 'ask', thinkingLevel: 'high' },
};
}

function catalog(): TaskEntryCatalog {
return { defaultProfileId: 'remote', hosts: [remoteHost()] };
}

function WorkspaceProbe() {
return createElement(TaskEntryWorkspacePickerConsumer, {
manageProjects() {},
children: (workspacePicker) => {
workspaceRenders += 1;
latestWorkspaceGroupCount = workspacePicker.groups.length;
return null;
},
});
}

function HostProbe() {
const host = useTaskEntryHostModel();
hostRenders += 1;
latestDirectoryHostId = host.directoryHost?.hostId;
return null;
}

function FrameProbe() {
frameRenders += 1;
return createElement(Fragment, null, createElement(WorkspaceProbe), createElement(HostProbe));
}

function ShellProbe() {
return createElement(TaskEntryRoot, {
children: (taskEntry) => {
shellRenders += 1;
latestTaskEntry = taskEntry;
return createElement(FrameProbe);
},
});
}

function renderProvider(
root: ReturnType<typeof installReactRenderer>['root'],
services: TaskEntryServices,
) {
root.render(
createElement(LocaleProvider, {
locale: 'en',
children: createElement(
ToastProvider,
null,
createElement(
TaskEntryServicesProvider,
{ services },
createElement(ShellProbe),
),
),
}),
);
}

afterEach(() => {
shellRenders = 0;
frameRenders = 0;
workspaceRenders = 0;
hostRenders = 0;
latestTaskEntry = undefined;
latestDirectoryHostId = undefined;
latestWorkspaceGroupCount = 0;
cleanupFakeDom();
});

describe('TaskEntryProvider render scope', () => {
it('keeps a controller-only directory handoff below the shell frame', async () => {
const { root } = installReactRenderer();
const services = createFakeTaskEntryServices({
catalog: {
...createFakeTaskEntryServices().catalog,
getCatalog: async () => catalog(),
},
});

await act(async () => renderProvider(root, services));
assert.equal(latestTaskEntry?.selectors.target?.hostId, 'host-remote');
assert.equal(latestWorkspaceGroupCount, 1);

const shellBefore = shellRenders;
const frameBefore = frameRenders;
const workspaceBefore = workspaceRenders;
const hostBefore = hostRenders;
await act(async () => latestTaskEntry?.commands.addProject());

assert.equal(latestDirectoryHostId, 'host-remote');
assert.equal(shellRenders, shellBefore);
assert.equal(frameRenders, frameBefore);
assert.equal(workspaceRenders, workspaceBefore);
assert.equal(hostRenders, hostBefore + 1);

await act(async () => root.unmount());
});

it('retains the shell projection across an equivalent catalog refresh', async () => {
const { root } = installReactRenderer();
const services = createFakeTaskEntryServices({
catalog: {
...createFakeTaskEntryServices().catalog,
getCatalog: async () => catalog(),
},
});

await act(async () => renderProvider(root, services));
const shellBefore = shellRenders;
const frameBefore = frameRenders;
await act(async () => latestTaskEntry?.commands.refresh());

assert.equal(shellRenders, shellBefore);
assert.equal(frameRenders, frameBefore);
assert.equal(latestTaskEntry?.selectors.target?.projectId, 'project-a');

await act(async () => root.unmount());
});
});
Loading