perf: optimize app startup and background lifecycles

This commit is contained in:
inman
2026-08-19 00:56:15 +08:00
parent 31332f6d76
commit 927e13349b
121 changed files with 4359 additions and 1400 deletions

View File

@@ -498,6 +498,33 @@ describe('Sidebar project initialization flow', () => {
expect(sidebar).not.toHaveClass('fixed', 'sidebar-peek-surface', 'pt-10');
});
it('shows Robot agents under the workbench and routes agent actions through the shared URL', async () => {
hostApiFetchMock.mockResolvedValue({
success: true,
data: {
status: 'active',
agents: [
{ id: 'robot-agent-1', name: '桌面助手', config_revision: 2 },
{ id: 'robot-agent-2', name: '书房助手', config_revision: 1 },
],
devices: [{ id: 'robot-device-1', agent_id: 'robot-agent-1', assignment_revision: 3 }],
},
});
render(<MemoryRouter initialEntries={['/ai-hardware']}><Sidebar /></MemoryRouter>);
expect(screen.getByRole('button', { name: '机器人工作台' })).toBeInTheDocument();
expect(await screen.findByTestId('sidebar-robot-agent-robot-agent-1')).toHaveTextContent('桌面助手');
expect(screen.getByTestId('sidebar-robot-agent-robot-agent-1')).toHaveTextContent('1 台设备');
expect(screen.getByTestId('sidebar-robot-agent-robot-agent-2')).toHaveTextContent('0 台设备');
navigateMock.mockClear();
fireEvent.click(screen.getByTestId('sidebar-robot-agent-robot-agent-2'));
expect(navigateMock).toHaveBeenLastCalledWith({ pathname: '/ai-hardware', search: '?agent=robot-agent-2' });
fireEvent.click(screen.getByTestId('sidebar-robot-create-agent'));
expect(navigateMock).toHaveBeenLastCalledWith({ pathname: '/ai-hardware', search: '?create=1' });
});
it('shows an available update beside the lower-left account control', async () => {
hostApiFetchMock.mockResolvedValue({ projects: [], activeProject: null });
render(<MemoryRouter><Sidebar /></MemoryRouter>);
@@ -604,7 +631,8 @@ describe('Sidebar project initialization flow', () => {
fireEvent.click(await screen.findByRole('button', { name: `进入项目 ${project.name}` }));
const projectConfigError = await screen.findByTestId('project-config-error');
expect(projectConfigError).toBeInTheDocument();
expect(screen.getByTestId('project-config-error-overlay')).toHaveClass('fixed', 'inset-0', 'backdrop-blur-md');
expect(screen.getByTestId('project-config-error-overlay')).toHaveClass('fixed', 'inset-0', 'bg-foreground/15');
expect(screen.getByTestId('project-config-error-overlay')).not.toHaveClass('backdrop-blur-md');
expect(projectConfigError.closest('[data-testid="sidebar"]')).toBeNull();
fireEvent.click(screen.getByRole('button', { name: '移除项目卡片' }));
const removeDialog = screen.getByRole('dialog', { name: `移除项目“${project.name}”?` });