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。

fix(desktop): 修正 Forge OIDC 确认窗交互

fmfsaisaiaa9ee0fe6b78
diff --git a/apps/desktop/src/renderer/cindy-brain/ForgeOidcInstallConfirmHost.tsx b/apps/desktop/src/renderer/cindy-brain/ForgeOidcInstallConfirmHost.tsx
index 9106957b62..e9648c4dee 100644
--- a/apps/desktop/src/renderer/cindy-brain/ForgeOidcInstallConfirmHost.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/ForgeOidcInstallConfirmHost.tsx
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
-import { useTranslation } from 'react-i18next';
+import { Trans, useTranslation } from 'react-i18next';
import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
@@ -61,9 +61,15 @@ export function ForgeOidcInstallConfirmHost() {
describeContent: true,
requireTypedConfirmation: {
expected: payload.ghostId,
- label: t('settings.ghosts.forgeOidcInstallConfirm.typedIdLabel', {
- id: payload.ghostId,
- }),
+ label: (
+ <Trans
+ i18nKey="settings.ghosts.forgeOidcInstallConfirm.typedIdLabel"
+ values={{ id: payload.ghostId }}
+ components={{
+ strong: <strong className="font-semibold text-[var(--confirm-title)]" />,
+ }}
+ />
+ ),
},
confirmText: t('settings.ghosts.forgeOidcInstallConfirm.confirm'),
cancelText: t('settings.ghosts.forgeOidcInstallConfirm.cancel'),
diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/ForgeOidcInstallConfirmHost.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/ForgeOidcInstallConfirmHost.test.tsx
index 0a21976197..d7b93d0527 100644
--- a/apps/desktop/src/renderer/cindy-brain/__tests__/ForgeOidcInstallConfirmHost.test.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/ForgeOidcInstallConfirmHost.test.tsx
@@ -1,9 +1,14 @@
// @vitest-environment jsdom
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import type { ReactNode } from 'react';
+import type { ReactElement, ReactNode } from 'react';
import { ForgeOidcInstallConfirmHost } from '../ForgeOidcInstallConfirmHost';
+import enCommon from '../../i18n/locales/en/common.json';
+import jaCommon from '../../i18n/locales/ja/common.json';
+import koCommon from '../../i18n/locales/ko/common.json';
+import zhCNCommon from '../../i18n/locales/zh-CN/common.json';
+import zhTWCommon from '../../i18n/locales/zh-TW/common.json';
const mocks = vi.hoisted(() => ({ confirm: vi.fn() }));
@@ -12,6 +17,7 @@ vi.mock('@/components/ui/confirm-dialog-provider', () => ({
}));
vi.mock('react-i18next', () => ({
+ Trans: () => null,
useTranslation: () => ({
t: (key: string, options?: { id?: string }) => (options?.id ? `${key}:${options.id}` : key),
}),
@@ -62,13 +68,19 @@ describe('ForgeOidcInstallConfirmHost', () => {
const options = mocks.confirm.mock.calls[0][0] as {
content: ReactNode;
contentSelectable: boolean;
- requireTypedConfirmation: { expected: string; label: string };
+ requireTypedConfirmation: { expected: string; label: ReactNode };
};
expect(options.contentSelectable).toBe(true);
- expect(options.requireTypedConfirmation).toEqual({
- expected: 'acme-tool',
- label: 'settings.ghosts.forgeOidcInstallConfirm.typedIdLabel:acme-tool',
- });
+ expect(options.requireTypedConfirmation.expected).toBe('acme-tool');
+ const label = options.requireTypedConfirmation.label as ReactElement<{
+ i18nKey: string;
+ values: { id: string };
+ components: { strong: ReactElement<{ className?: string }> };
+ }>;
+ expect(label.props.i18nKey).toBe('settings.ghosts.forgeOidcInstallConfirm.typedIdLabel');
+ expect(label.props.values).toEqual({ id: 'acme-tool' });
+ expect(label.props.components.strong.type).toBe('strong');
+ expect(label.props.components.strong.props.className).toContain('font-semibold');
render(<>{options.content}</>);
expect(screen.getByText('Acme Tool')).toBeTruthy();
@@ -78,4 +90,17 @@ describe('ForgeOidcInstallConfirmHost', () => {
expect(screen.queryByRole('button')).toBeNull();
expect(resolveConfirm).toHaveBeenCalledWith('request-1', true);
});
+
+ it.each([
+ ['zh-CN', zhCNCommon],
+ ['zh-TW', zhTWCommon],
+ ['en', enCommon],
+ ['ja', jaCommon],
+ ['ko', koCommon],
+ ])('%s 的手输提示用加粗 id 且不再用引号包裹', (_locale, common) => {
+ const label = common.settings.ghosts.forgeOidcInstallConfirm.typedIdLabel;
+ // 直接读每个 locale,排除缺 key 后被英文 fallback 掩盖。
+ expect(label).toContain(' <strong>{{id}}</strong> ');
+ expect(label).not.toMatch(/[“”「」]/);
+ });
});
diff --git a/apps/desktop/src/renderer/components/ui/__tests__/confirmDialogScroll.test.tsx b/apps/desktop/src/renderer/components/ui/__tests__/confirmDialogScroll.test.tsx
index e86c3aabec..00bc9a82b1 100644
--- a/apps/desktop/src/renderer/components/ui/__tests__/confirmDialogScroll.test.tsx
+++ b/apps/desktop/src/renderer/components/ui/__tests__/confirmDialogScroll.test.tsx
@@ -156,6 +156,9 @@ describe('ConfirmDialog 长内容布局', () => {
render(<ConfirmDialog open onOpenChange={() => {}} title="确定退出?" confirmText="退出" />);
const dialog = screen.getByRole('alertdialog');
expect(dialog.querySelectorAll('.overflow-y-auto').length).toBe(0);
+ // 对照项:没有显式开放框选的普通确认框仍保持防误选行为。
+ expect(dialog.className).toContain('select-none');
+ expect(dialog.className).not.toContain('select-text');
expect(flashScrollbar).not.toHaveBeenCalled();
});
@@ -176,9 +179,11 @@ describe('ConfirmDialog 长内容布局', () => {
);
const input = screen.getByLabelText('输入插件 id');
const confirmButton = screen.getByRole('button', { name: '安装' });
- expect(screen.getByRole('alertdialog').querySelector('.overflow-y-auto')?.className).toContain(
- 'select-text',
- );
+ const dialog = screen.getByRole('alertdialog');
+ // 根节点必须撤掉 select-none;只在子滚动区加 select-text 无法保证展示 id 可框选。
+ expect(dialog.className).toContain('select-text');
+ expect(dialog.className).not.toContain('select-none');
+ expect(dialog.querySelector('.overflow-y-auto')?.className).toContain('select-text');
fireEvent.change(input, { target: { value: ' acme-tool ' } });
expect((confirmButton as HTMLButtonElement).disabled).toBe(true);
diff --git a/apps/desktop/src/renderer/components/ui/confirm-dialog-provider.tsx b/apps/desktop/src/renderer/components/ui/confirm-dialog-provider.tsx
index 1e7fecdd3d..83b33dbfc2 100644
--- a/apps/desktop/src/renderer/components/ui/confirm-dialog-provider.tsx
+++ b/apps/desktop/src/renderer/components/ui/confirm-dialog-provider.tsx
@@ -38,7 +38,7 @@ export interface ConfirmOptions {
/** 逐字输入 expected 才可确认;由 ConfirmDialog 持有本轮输入状态。 */
requireTypedConfirmation?: {
expected: string;
- label: string;
+ label: ReactNode;
placeholder?: string;
};
/** 允许确认正文与富内容被框选复制。 */
diff --git a/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx b/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
index 5eba5db1df..1917a61772 100644
--- a/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
+++ b/apps/desktop/src/renderer/components/ui/confirm-dialog.tsx
@@ -52,7 +52,7 @@ export interface ConfirmDialogProps {
/** 要求逐字输入 expected 才能确认;匹配不做 trim 或大小写折叠。 */
requireTypedConfirmation?: {
expected: string;
- label: string;
+ label: ReactNode;
placeholder?: string;
};
/** 允许正文和富内容被框选复制;缺省保持普通确认框的防误选行为。 */
@@ -183,7 +183,8 @@ export function ConfirmDialog({
// inset-0 + m-auto + h-fit:布局矩形即视觉矩形,挖洞与弹窗严格重合。
'fixed inset-0 z-[10000] m-auto h-fit',
'flex max-h-[85vh] flex-col',
- 'w-full select-none rounded-xl p-4',
+ 'w-full rounded-xl p-4',
+ contentSelectable ? 'select-text' : 'select-none',
'bg-[var(--confirm-bg)] shadow-[var(--confirm-shadow)]',
// 布局居中弹窗用无 translate 的 layout keyframes;共享
// confirm-content-in/out 的每一帧都烘 translate(-50%, -50%),
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index bd9a8de2cb..a1e86116f9 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -4343,7 +4343,7 @@
"pluginNameLabel": "Plugin",
"pluginIdLabel": "Plugin id",
"hostsLabel": "Organization identity injection hosts",
- "typedIdLabel": "Enter the plugin id “{{id}}” to confirm",
+ "typedIdLabel": "Enter the plugin id <strong>{{id}}</strong> to confirm",
"confirm": "Install and allow testing",
"cancel": "Cancel"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 9622d91c26..e2ef0775df 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -4342,7 +4342,7 @@
"pluginNameLabel": "プラグイン",
"pluginIdLabel": "プラグイン id",
"hostsLabel": "組織 ID の注入先ホスト",
- "typedIdLabel": "確認するにはプラグイン id「{{id}}」を入力",
+ "typedIdLabel": "確認するにはプラグイン id <strong>{{id}}</strong> を入力",
"confirm": "インストールしてテストを許可",
"cancel": "キャンセル"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index c3c2a4164e..9cdd80b26e 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -4342,7 +4342,7 @@
"pluginNameLabel": "플러그인",
"pluginIdLabel": "플러그인 id",
"hostsLabel": "조직 ID 삽입 호스트",
- "typedIdLabel": "확인하려면 플러그인 id “{{id}}” 입력",
+ "typedIdLabel": "확인하려면 플러그인 id <strong>{{id}}</strong> 입력",
"confirm": "설치 및 테스트 허용",
"cancel": "취소"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index dc06b8e312..078d0d14db 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -4334,7 +4334,7 @@
"pluginNameLabel": "插件",
"pluginIdLabel": "插件 id",
"hostsLabel": "企业身份注入域名",
- "typedIdLabel": "输入插件 id“{{id}}”以确认",
+ "typedIdLabel": "输入插件 id <strong>{{id}}</strong> 以确认",
"confirm": "安装并允许自测",
"cancel": "取消"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 22749cbeae..3d7a556cc3 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -4334,7 +4334,7 @@
"pluginNameLabel": "插件",
"pluginIdLabel": "插件 id",
"hostsLabel": "企業身份注入網域",
- "typedIdLabel": "輸入插件 id「{{id}}」以確認",
+ "typedIdLabel": "輸入插件 id <strong>{{id}}</strong> 以確認",
"confirm": "安裝並允許自測",
"cancel": "取消"
},