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。

test(ui): retain composer and market navigation regressions

MagicLizi1a59e4040ee6
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
index f6efb8fb32..23bc871d55 100644
--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
@@ -18,22 +18,24 @@ import type { AtMentionPanel } from '../AtMentionPanel';
import type { scanAtResources } from '@/lib/atResourceService';
import type { ExtraDirsButton } from '../ExtraDirsButton';
import type { PermissionSelector } from '../PermissionSelector';
+import type { ModelSelector } from '../ModelSelector';
import type { UseVoiceInputResult } from '@/voice-input/useVoiceInput';
import { useAttachments } from '@/hooks/useAttachments';
const h = vi.hoisted(() => ({ t: (key: string) => key, confirm: vi.fn(), editor: null as Editor | null, listening: false, stop: vi.fn().mockResolvedValue(undefined),
- setModel: vi.fn(), selectModel: undefined as undefined | ((id: string) => Promise<void | boolean>), remoteProviders: [] as ProviderView[],
+ setModel: vi.fn(), selectModel: undefined as ComponentProps<typeof ModelSelector>['onModelChange'] | undefined, remoteProviders: [] as ProviderView[],
remoteStatus: 'ready' as 'ready' | 'loading' | 'error',
scan: vi.fn<typeof scanAtResources>(),
atPanel: null as ComponentProps<typeof AtMentionPanel> | null,
documentChanged: vi.fn(),
voiceState: null as UseVoiceInputResult['state'] | null,
cancel: vi.fn().mockResolvedValue(undefined),
+ realModelSelector: false,
}));
vi.mock('react-i18next', async (original) => ({ ...await original<typeof import('react-i18next')>(), useTranslation: () => ({ t: h.t }) }));
vi.mock('react-router-dom', () => ({ useNavigate: () => vi.fn() }));
-vi.mock('@/components/ui/confirm-dialog-provider', () => ({ useConfirmDialog: () => ({ confirm: h.confirm }) }));
+vi.mock('@/components/ui/confirm-dialog-provider', async (original) => ({ ...await original<typeof import('@/components/ui/confirm-dialog-provider')>(), useConfirmDialog: () => ({ confirm: h.confirm }) }));
vi.mock('@/components/sidebar/SortableList', () => ({
SortableList: ({
items,
@@ -55,10 +57,13 @@ vi.mock('@/components/sidebar/SortableList', () => ({
</div>
),
}));
-vi.mock('../ModelSelector', async (original) => ({ ...await original<typeof import('../ModelSelector')>(), ModelSelector: ({ modelId, onModelChange }: { modelId: string; onModelChange: typeof h.selectModel }) => {
- h.selectModel = onModelChange;
- return <span data-testid="model-selector">{modelId}</span>;
-} }));
+vi.mock('../ModelSelector', async (original) => {
+ const real = await original<typeof import('../ModelSelector')>();
+ return { ...real, ModelSelector: (props: ComponentProps<typeof ModelSelector>) => {
+ h.selectModel = props.onModelChange;
+ return h.realModelSelector ? <real.ModelSelector {...props} /> : <span data-testid="model-selector">{props.modelId}</span>;
+ } };
+});
vi.mock('@/hooks/useSshCodexProviders', () => ({ useSshCodexProviders: () => ({ providers: h.remoteProviders, status: h.remoteStatus, refresh: () => {} }) }));
vi.mock('../ExtraDirsButton', () => ({ ExtraDirsButton: ({ open, onOpenChange, panel, disabled }: ComponentProps<typeof ExtraDirsButton>) => <><button aria-label="test-suggestions" disabled={disabled} onClick={() => onOpenChange?.(!open)} />{open && panel}</> }));
vi.mock('../PermissionSelector', () => ({ PermissionSelector: ({ disabled }: ComponentProps<typeof PermissionSelector>) => <button data-testid="permission-selector" disabled={disabled} /> }));
@@ -77,7 +82,7 @@ vi.mock('@/voice-input/useVoiceInput', () => ({ useVoiceInput: (editor: Editor |
const state = h.voiceState ?? (h.listening ? 'listening' : 'idle');
return { state, isListening: state === 'listening', isBusy: state === 'listening' || state === 'submitting' || state === 'refining', draftText: '', start: vi.fn(), stop: h.stop, cancel: h.cancel };
} }));
-vi.mock('@/hooks/useProviders', () => ({ useProviders: () => ({ providers: [], loading: false }) }));
+vi.mock('@/hooks/useProviders', () => ({ useProviders: () => ({ providers: [], providerOrder: [], loading: false }) }));
vi.mock('@/hooks/useDeviceProviders', () => ({ useDeviceProviders: () => ({ providers: [], loading: false, unsupported: false }) }));
vi.mock('@/hooks/useConnectedSource', () => ({ useConnectedSource: () => ({ hasConnectedSource: true, loading: false }) }));
vi.mock('@/hooks/useAvailableAgents', () => ({ useAvailableAgents: () => ({ agents: [], loading: false }) }));
@@ -91,6 +96,7 @@ const api: any = new Proxy({}, { get: (_obj, key) => {
if (key === 'getDataSnapshot') return () => { throw new Error('test bridge unavailable'); };
if (key === 'setGlobalShortcut') return () => Promise.resolve({ ok: true });
if (key === 'platform') return 'darwin';
+ if (key === 'modelAccess') return undefined;
if (key === 'then') return undefined;
if (String(key).startsWith('on')) return () => noOp;
return new Proxy(() => Promise.resolve(undefined), { get: (_fn, nested) => api[nested] });
@@ -114,6 +120,8 @@ beforeEach(() => {
h.documentChanged.mockClear();
h.listening = false;
h.voiceState = null;
+ h.stop.mockClear();
+ h.realModelSelector = false;
h.cancel.mockReset().mockResolvedValue(undefined);
h.atPanel = null;
h.scan.mockReset().mockResolvedValue({ success: true, items: [], truncated: false });
@@ -171,7 +179,8 @@ it('does not rehydrate an empty stored document when voice busy state changes',
// Replaces voiceInputEditorEditability's source guard (PR #6196, section 3.2).
// The voice hook is an external boundary; the editor and ChatInput lock effects
// are real. Existing hydration tests never observe editability, attachment
-// controls, permission availability or Escape ownership. Minimal unit inputs:
+// controls, permission availability or Escape ownership; #1663 also requires
+// the real stop button to stay usable under the recording's own lock. Minimal unit inputs:
// one idle -> listening -> submitting -> refining -> idle run and Escape on
// two top-level surfaces followed by the same editor. Reuse this jsdom harness.
it('locks editor and attachments for the whole voice run, but keeps permissions available', async () => {
@@ -184,9 +193,40 @@ it('locks editor and attachments for the whole voice run, but keeps permissions
expect(h.editor!.isEditable, state).toBe(!busy);
expect((screen.getByRole('button', { name: 'test-suggestions' }) as HTMLButtonElement).disabled, state).toBe(busy);
expect((screen.getByTestId('permission-selector') as HTMLButtonElement).disabled, state).toBe(false);
+ if (state === 'listening') {
+ // #1663: the recording's own lock must still leave its stop control usable.
+ const stop = screen.getByRole('button', { name: 'newChat.chatInput.voiceInput.stop' }) as HTMLButtonElement;
+ expect(stop.disabled).toBe(false);
+ await act(async () => { fireEvent.click(stop); });
+ expect(h.stop).toHaveBeenCalledExactlyOnceWith({ waitForRefinement: true, onReadyForEndCue: expect.any(Function) });
+ }
}
});
+// 9bc20cf894 / composerMorphScope: choosing a model used to drop focus to body.
+// Generic MorphPopover tests supply their own target and miss ChatInput's wiring.
+// Minimal unit input: one real selector choice, then focus returns to the live editor.
+it('returns focus to the editor after choosing a model from the real selector', async () => {
+ h.realModelSelector = true;
+ h.remoteProviders = [sshNativeCodexProvider([sshModel('remote-old'), sshModel('remote-new')])];
+ const onModelDidChange = vi.fn();
+ vi.stubGlobal('matchMedia', () => ({ matches: true, addListener: noOp, removeListener: noOp, addEventListener: noOp, removeEventListener: noOp }));
+ renderComposer({ hideRuntimeControls: false, sessionId: 'model-focus', remoteHostId: 'builder',
+ runtimeAgentKind: 'codex', vendorKey: 'codex', initialModel: 'remote-old',
+ initialProviderId: 'openai', initialEffort: 'low', onModelDidChange });
+ await waitFor(() => expect(h.editor).not.toBeNull());
+ fireEvent.click(screen.getByRole('button', { name: 'newChat.modelSelector.trigger.ariaWithEffort' }));
+ const nextModel = await screen.findByRole('option', { name: /remote-new/ });
+ await act(async () => {
+ fireEvent.pointerDown(nextModel);
+ nextModel.focus();
+ fireEvent.click(nextModel);
+ });
+ await waitFor(() => expect(screen.queryByRole('listbox', { name: 'newChat.modelSelector.modelListAria' })).toBeNull());
+ await waitFor(() => expect(onModelDidChange).toHaveBeenCalledExactlyOnceWith('remote-new'));
+ await waitFor(() => expect(document.activeElement).toBe(h.editor!.view.dom));
+});
+
it('defers Escape on top-level surfaces and cancels voice once from the editor', async () => {
h.listening = true;
renderComposer();
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx
index 1874b455d7..e93736941e 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx
@@ -158,6 +158,65 @@ async function openFromCatalog() {
}
describe('plugin page return navigation', () => {
+ // Regression #2871 (98929118d6): the real market-detail install flow must refresh
+ // the current page after an update/replacement. The card helper only checks the
+ // navigation decision; it cannot catch clearing marketDetail in the parent.
+ // Minimal unit input: one installed plugin and either market update state.
+ // Only IPC is faked; page/detail components and the install flow stay real.
+ // File alone: 20 tests, Vitest 5.29s / wall 6.12s on 2026-10-16.
+ it.each(['update-available', 'conflict'] as const)(
+ 'keeps the market detail visible and refreshed after %s succeeds',
+ async (installState) => {
+ const installed: InstalledGhost = {
+ manifest: { ...detail.manifest, name: 'Installed Plugin', version: '0.9.0' },
+ dir: path.join('plugins', detail.ghostId),
+ enabled: true,
+ approval: { state: 'approved', revision: 'market-navigation-revision' },
+ };
+ const marketDetail = { ...detail, installState };
+ const refreshedDetail: PluginMarketDetail = {
+ ...detail,
+ installState: 'installed',
+ enabled: true,
+ description: 'Refreshed market details after installation',
+ };
+ window.electronAPI.ghosts.listSync = () => ({ ghosts: [installed] });
+ let installationComplete = false;
+ loadDetail.mockImplementation(async () =>
+ installationComplete ? refreshedDetail : marketDetail,
+ );
+ const install = vi.fn(async () => {
+ installationComplete = true;
+ return {
+ ghost: { ...installed, manifest: { ...installed.manifest, version: detail.version } },
+ };
+ });
+ Object.assign(window.electronAPI.pluginMarket, { install });
+ render(page(`/plugins?market=${detail.pluginId}`));
+ await screen.findByRole('heading', { level: 1, name: detail.name });
+ const marketPage = screen.getByRole('main');
+
+ fireEvent.click(screen.getByRole('button', {
+ name: installState === 'conflict'
+ ? 'settings.ghosts.market.replace'
+ : 'settings.ghosts.market.update',
+ }));
+
+ await screen.findByText(refreshedDetail.description!);
+ expect(install).toHaveBeenCalledWith(detail.pluginId, expect.objectContaining({
+ expectedReleaseId: detail.releaseId,
+ expectedManifest: detail.manifest,
+ expectedInstalledApproval: 'approved:market-navigation-revision',
+ allowSourceReplacement: installState === 'conflict',
+ }));
+ expect(screen.getByRole('main')).toBe(marketPage);
+ expect(screen.getByRole('heading', { level: 1, name: detail.name })).toBeTruthy();
+ expect((screen.getByRole('button', {
+ name: 'settings.ghosts.market.installed',
+ }) as HTMLButtonElement).disabled).toBe(true);
+ },
+ );
+
it.each(['xd-ordinary', 'filo-ordinary'])(
'updates an ordinary root %s from a local file and offers export in packaged builds',
async (ghostId) => {
diff --git a/docs/dev-rules/desktop-unit-test-performance.md b/docs/dev-rules/desktop-unit-test-performance.md
index dfe5024c26..a87124dd3c 100644
--- a/docs/dev-rules/desktop-unit-test-performance.md
+++ b/docs/dev-rules/desktop-unit-test-performance.md
@@ -48,6 +48,11 @@ Windows 四片为 715/680/932/1,057 秒,关键路径 17 分 37 秒,较
Linux 四片为 754/535/693/699 秒,runner/DB 为 416 秒。后续卫生门与侧栏回归
补丁仍须由其自身 head 的完整 CI 核验。
+head `1a7fe95729` 的 client-ci run `38901684967` 全部 13 个 job 通过:Windows
+四片为 826/673/971/863 秒,关键路径 16 分 11 秒,较原基线减少约 53%;Linux
+四片为 733/679/670/719 秒,runner/DB 为 355 秒。这是完整 CI 的实测样本,
+不含排队,也不代表每轮固定收益;后续补丁仍须通过自身 head 的全部检查。
+
Vitest 每片切 `ceil(文件数 / 分片数)` 个文件,分片多于 2 个时,文件少的包末尾分片可能为空(6 个文件
分 4 片是 2、2、2、0)。runner 原来只在「文件数少于分片数」时补 `--passWithNoTests`,本机 4/4 分片因此
有 6 个包报 `NO_TESTS_REQUIRED`;现已按 Vitest 的切分方式判断空分片。
@@ -99,11 +104,19 @@ CI 仍须重新通过。
计时器模式也沿真实 Vitest 绑定追踪属性、解构、namespace 和静态赋值别名,并在
实际调用或 hook 执行处生效;恢复真实时钟后,后续测试的长等待不会沿用假时钟豁免。
未调用的别名、局部同名对象及 fixture 字符串不改变模式,基线未放宽。
+真实回调定时器也跟踪静态 `const` 别名与解构,并按函数被捕获时的时钟判定:提前
+保存的原生函数不会因之后启用假时钟而豁免,假时钟下保存的函数也不会因恢复真实
+时钟而误报。`node:timers` 的 named/namespace/default 绑定保留原生身份;
+当前 Vitest 3.2.7 的真实函数身份验证与 scanner 正反例均通过,基线保持 374 个文件。
导入设置恢复真实组件挂载回归,验证首次自动扫描与重入时先显示缓存、再更新结果,
2 项单文件命令约 2.2 秒。slash 空结果、目录队列插入与语音输入保护并入既有 ChatInput
文件,经过真实编辑器/hook 验证键盘消费、目录 chip、语音全生命周期只读与顶层弹层
-优先消费 Esc;整文件 11 项通过,完整命令 12.29 秒(收集 9.28 秒、执行 1.10 秒)。
+优先消费 Esc;同时保留录音中真实停止按钮可用,以及真实 ModelSelector 选完模型后
+回到编辑器焦点的历史回归。整文件 12 项通过,完整命令 9.02 秒(执行 1.01 秒)。
该文件已有重型编辑器依赖,继续复用同一 harness,未新增重复环境或放宽超时。
+市场更新/替换后保留并刷新原详情页的回归也并入现有 navigation harness,整文件
+20 项通过(完整命令 6.12 秒);只修改测试,清除详情或断开焦点/停止接线的内存
+坏变体均准确失败。
文件正文引用恢复为真实 CodeMirror 表格源码选区→引用按钮→草稿的 1 项回归(3.72 秒);
附件托盘恢复图片/文本点击与移除不冒泡的 3 项回归(2.04 秒)。模型加载错误提示、
子菜单 Portal、项目头拖动与付费模型计费页跳转都并入已有组件文件,完整文件分别