Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

merge: 同步 main 并保留群设置两组回归测试

shenjiacheng3ae583faba05
diff --cc apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
index 635e9f5f81,c4398970ea..335b940faa
--- a/apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
@@@ -1,7 -1,7 +1,7 @@@
- import { useCallback, useEffect, useRef, useState } from 'react';
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ChevronDown, ChevronUp, Crown, Shield } from 'lucide-react';
import { useTranslation } from 'react-i18next';
-import { useNavigate } from 'react-router-dom';
+import { useNavigate, useSearchParams } from 'react-router-dom';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Select } from '@/components/ui/select';
diff --cc apps/desktop/src/renderer/features/bots/__tests__/ChatGroupSettings.test.tsx
index 1ebda81a69,40ce96abd5..942c919b82
--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatGroupSettings.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatGroupSettings.test.tsx
@@@ -1,34 -1,16 +1,36 @@@
// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
-import { MemoryRouter } from 'react-router-dom';
+import type { ReactNode } from 'react';
+import { MemoryRouter, RouterProvider, createMemoryRouter, useLocation } from 'react-router-dom';
+import { transferableAbortController } from 'node:util';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import { ChatGroupSettings } from '../ChatGroupSettings';
+import { BotSettingsDrawer } from '../BotSettingsDrawer';
import type { BotGroupSummary } from '../../../../shared/botGroupChat';
const mocks = vi.hoisted(() => ({ manage: vi.fn(), ownedBots: vi.fn(), refresh: vi.fn(), confirm: vi.fn() }));
-vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+const profiles = vi.hoisted(() => ({
+ list: [{ id: 'bot', name: 'Partner', status: 'active', sessions: [] as Array<{ id: string }>, capabilities: {}, skills: [] as string[] }],
+}));
+const translate = (key: string, options?: { name?: string }) =>
+ typeof options?.name === 'string' ? `${key}:${options.name}` : key;
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: translate }) }));
+vi.mock('../botPronounContext', () => ({
+ useBotTranslation: () => ({ t: translate }),
+ BotPronounProvider: ({ children }: { children: ReactNode }) => children,
+}));
+vi.mock('../useRemoteBots', () => ({ useRemoteBots: () => [] }));
+vi.mock('../RemoteBotSettings', () => ({ RemoteBotSettings: () => null }));
+vi.mock('../companionCloudStore', () => ({ useCompanionCloud: () => ({ demotedBotIds: [] as string[] }) }));
+vi.mock('../BotsHomeView', () => ({
+ BotSettings: ({ bot, initialPage }: { bot: { id: string; name: string }; initialPage?: string }) => (
+ <div data-testid="bot-settings" data-bot-id={bot.id} data-initial-page={initialPage}>{bot.name}</div>
+ ),
+}));
vi.mock('@/components/ui/confirm-dialog-provider', () => ({ useConfirmDialog: () => ({ confirm: mocks.confirm }) }));
- vi.mock('@/components/settings/ProfileEditDialog', () => ({ ProfileEditDialog: () => null }));
+ vi.mock('@/components/settings/ProfileEditDialog', () => ({ ProfileEditDialog: ({ open, avatarEditor }: {
+ open: boolean; avatarEditor?: { hint: string; save(avatar: { type: 'reset' }): Promise<void> };
+ }) => open && avatarEditor ? <button onClick={() => void avatarEditor.save({ type: 'reset' })}>{avatarEditor.hint}</button> : null }));
-vi.mock('../botStore', () => ({ useBotProfiles: () => [{ id: 'bot' }] }));
+vi.mock('../botStore', () => ({ useBotProfiles: () => profiles.list }));
vi.mock('../BotAvatar', () => ({ BotAvatar: () => null }));
vi.mock('../botGroupStore', () => ({ refreshBotGroups: mocks.refresh }));
vi.mock('@/contexts/dataOwnerGeneration', () => ({ getDataOwnerGeneration: () => 1, isDataOwnerGenerationCurrent: () => true }));
@@@ -92,7 -55,21 +94,21 @@@ it('keeps a sole archived owner in the
action: { type: 'archive', archived: false, expectedRevision: 1 },
}));
});
-afterEach(cleanup);
+afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
+ // The actual dialog is covered by ProfileEditDialog.avatarCrop.test.tsx.
+ // Here the real group settings must supply a group destination, never account editing.
+ it('edits only this member avatar and hides editing on older servers', async () => {
+ const view = render(<MemoryRouter><ChatGroupSettings group={group()} /></MemoryRouter>);
+ expect(screen.queryByRole('button', { name: key('editProfile') })).toBeNull();
+ expect(screen.queryByRole('button', { name: key('groupAvatar') })).toBeNull();
+ view.rerender(<MemoryRouter><ChatGroupSettings group={{ ...group(), supportsMemberAvatar: true }} /></MemoryRouter>);
+ fireEvent.click(screen.getByRole('button', { name: key('groupAvatar') }));
+ fireEvent.click(screen.getByRole('button', { name: key('groupAvatarHint') }));
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledWith({
+ groupId: 'room', action: { type: 'avatar', actorId: 'me', avatar: { type: 'reset' } },
+ }));
+ expect(mocks.refresh).toHaveBeenCalledOnce();
+ });
it('lets a member change their own nickname while keeping another owner’s grant read-only', async () => {
render(<MemoryRouter><ChatGroupSettings group={group()} /></MemoryRouter>);
expect((screen.getByRole('textbox', { name: key('name') }) as HTMLInputElement).disabled).toBe(true);