mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 22:00:34 +08:00
Merge remote-tracking branch 'origin/main' into fix/auto-review-unavailable-user-confirm
Keep the Auto-review confirm-card fix current with main before classifying IM session disposal as a system denial. Signed-off-by: MagicLizi <jiali@magiclizi.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { cleanup, createEvent, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
@@ -175,8 +175,10 @@ describe('CustomProviderDialog preset locale ownership', () => {
|
||||
const option = await screen.findByRole('option', { name: expectedName });
|
||||
fireEvent.click(option);
|
||||
|
||||
expect(trigger.textContent).toContain(expectedName);
|
||||
expect(screen.getByDisplayValue(expectedName)).not.toBeNull();
|
||||
await waitFor(() => {
|
||||
expect(trigger.textContent).toContain(expectedName);
|
||||
expect(screen.getByDisplayValue(expectedName)).not.toBeNull();
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'settings.providers.custom.save' }));
|
||||
await waitFor(() => expect(createCustomProvider).toHaveBeenCalledTimes(1));
|
||||
@@ -241,6 +243,40 @@ describe('CustomProviderDialog preset locale ownership', () => {
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not consume runtime tab or input pointerdowns while a child layer is open', async () => {
|
||||
i18nState.language = 'zh-TW';
|
||||
const { onClose } = renderDialog();
|
||||
|
||||
const trigger = await screen.findByRole('button', {
|
||||
name: 'settings.providers.custom.presets.label',
|
||||
});
|
||||
const openPresetMenu = async () => {
|
||||
fireEvent.click(trigger);
|
||||
expect(await screen.findByRole('option', { name: '繁體供應商' })).not.toBeNull();
|
||||
};
|
||||
|
||||
await openPresetMenu();
|
||||
const piTab = screen.getByRole('tab', {
|
||||
name: 'settings.providers.custom.protocol.pi',
|
||||
});
|
||||
const tabPointerDown = createEvent.pointerDown(piTab, { button: 0 });
|
||||
fireEvent(piTab, tabPointerDown);
|
||||
expect(tabPointerDown.defaultPrevented).toBe(false);
|
||||
fireEvent.click(piTab);
|
||||
expect(piTab.getAttribute('aria-selected')).toBe('true');
|
||||
|
||||
await openPresetMenu();
|
||||
const baseUrl = screen.getByPlaceholderText(
|
||||
'settings.providers.custom.fields.baseUrlPlaceholder',
|
||||
);
|
||||
const inputPointerDown = createEvent.pointerDown(baseUrl, { button: 0 });
|
||||
fireEvent(baseUrl, inputPointerDown);
|
||||
expect(inputPointerDown.defaultPrevented).toBe(false);
|
||||
fireEvent.change(baseUrl, { target: { value: 'https://runtime.example.test/v1' } });
|
||||
expect((baseUrl as HTMLInputElement).value).toBe('https://runtime.example.test/v1');
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps Cancel as a direct form dismissal without a duplicate top-right button', async () => {
|
||||
i18nState.language = 'zh-TW';
|
||||
const { onClose } = renderDialog();
|
||||
|
||||
@@ -639,6 +639,25 @@ describe('校准结果要带上供应商', () => {
|
||||
});
|
||||
|
||||
describe('resolveDraftSessionProviderId', () => {
|
||||
it('唯一已连接来源是用户 Provider 时仍显式保留,避免 Claude 回退 Cindy gateway', () => {
|
||||
const codingPlan = {
|
||||
...provider('coding-plan', true, {
|
||||
'claude-code': [model('ark-code-latest')],
|
||||
}),
|
||||
source: 'user',
|
||||
} as ProviderView;
|
||||
|
||||
expect(
|
||||
resolveDraftSessionProviderId({
|
||||
providers: [codingPlan],
|
||||
agent: 'claude-code',
|
||||
model: 'ark-code-latest',
|
||||
explicitProviderId: null,
|
||||
effectiveProviderId: 'coding-plan',
|
||||
}),
|
||||
).toBe('coding-plan');
|
||||
});
|
||||
|
||||
it('XD 已连接但不提供当前模型时,不能省略校准选中的 Anthropic 来源(issue #1196)', () => {
|
||||
const gateway = provider('xd', true, {
|
||||
'claude-code': [model('claude-sonnet-5')],
|
||||
|
||||
@@ -431,6 +431,7 @@ export function CustomProviderDialog({
|
||||
const runtimeFillTriggerRef = useRef<HTMLButtonElement>(null);
|
||||
const modelPickerTriggerRef = useRef<HTMLButtonElement>(null);
|
||||
const modelFetchInFlightRef = useRef(false);
|
||||
const scrimRef = useRef<HTMLDivElement>(null);
|
||||
const dialogPanelRef = useRef<HTMLDivElement>(null);
|
||||
// 原生 window listener 的生命周期不跟着每次 render 重绑;layout effect 只把
|
||||
// 已提交的层状态写入 ref,既避开 passive effect 延迟,也不暴露被放弃的并发 render。
|
||||
@@ -479,6 +480,24 @@ export function CustomProviderDialog({
|
||||
return () => window.removeEventListener('keydown', onKeyDown, true);
|
||||
}, [dismissTopmostLayer]);
|
||||
|
||||
useEffect(() => {
|
||||
const onPointerDown = (event: PointerEvent) => {
|
||||
if (event.button !== 0) return;
|
||||
if (event.target !== scrimRef.current) return;
|
||||
if (!childLayerRef.current && !runtimeFillRef.current) return;
|
||||
|
||||
// This must run before Radix's document-capture outside-dismiss. The
|
||||
// scrim gesture belongs to the dialog's current child layer; consuming
|
||||
// it here prevents Radix from committing a closed popover before the
|
||||
// form can settle that layer exactly once.
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
dismissTopmostLayer();
|
||||
};
|
||||
window.addEventListener('pointerdown', onPointerDown, { capture: true });
|
||||
return () => window.removeEventListener('pointerdown', onPointerDown, true);
|
||||
}, [dismissTopmostLayer]);
|
||||
|
||||
useEffect(() => {
|
||||
const returnFocusElement =
|
||||
document.activeElement instanceof HTMLElement && document.activeElement !== document.body
|
||||
@@ -1587,6 +1606,8 @@ export function CustomProviderDialog({
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={scrimRef}
|
||||
data-custom-provider-dialog-scrim="true"
|
||||
className="fixed inset-0 z-[10000] flex items-center justify-center bg-[var(--overlay-modal)]"
|
||||
onPointerDown={(event) => {
|
||||
// pointerdown 时先按当前层级结算,避免 Popover 的 outside-dismiss 在随后
|
||||
|
||||
@@ -267,6 +267,13 @@ export function resolveDraftSessionProviderId({
|
||||
return explicitProviderId;
|
||||
}
|
||||
if (!effectiveProviderId) return null;
|
||||
// 预设通过「添加供应商」落地后同样属于 user provider。即使它是当前模型唯一的
|
||||
// 已连接来源,也不能省略 providerId:main / maker-core 的 null 语义是沿用各 harness
|
||||
// 的原生认证 fallback(Claude → Cindy gateway / Claude OAuth),不会反查目录里唯一的
|
||||
// BYOM 来源。省略后 UI 虽显示该来源,首轮 auth gate 却会去读 gateway key,最终报
|
||||
// `not authenticated: no_key`。用户来源必须始终显式钉住,保证其代理路由与密钥生效。
|
||||
const effectiveProvider = providers.find((provider) => provider.id === effectiveProviderId);
|
||||
if (effectiveProvider?.source === 'user') return effectiveProviderId;
|
||||
const modelDefaultProviderId = effectiveSourceIdForModel([...providers], null, model, agent);
|
||||
// main 收到 providerId=null 后按 agent 的原生来源选择启动链路,而不是只在“提供当前
|
||||
// 模型”的来源里重算。典型分叉:XD 与 Anthropic 都已连接,只有 Anthropic 目录含
|
||||
|
||||
Reference in New Issue
Block a user