feat: v0.7.4 时序语义修正 · 防线实效补漏 · 全量测试翻倍 — 2406 用例 + jsdom 组件测试全量回归
P1 修复面收口: - 超时三态区分(aborted→USER_INTERRUPT / ETIMEDOUT→TIMEOUT / 其余→ERROR), 根治"真实网络超时被误报为用户中断" - 流空闲超时统一(SSE/Ollama/Anthropic 读循环 60s 无数据抛 504 进重试通道) - 同会话并发 sendMessage 防重入(isRunning 守卫)+ 会话存在性预检 + 前置调用移入 try(ERROR+DONE 双事件保证,根治 isStreaming 假死) - 清空审计后 resetChainCache(根治 verifyChain 误报 TAMPERED) - DONE 不再提前清理 TRACE(TERMINATED 统一收尾,补全最终迭代录制) - IME 合成回车不发送(普通 Enter + Cmd/Ctrl+Enter 双分支)+ handleSend 闭包修复 P2 安全纵深: - preload 移除原始 electronAPI 暴露(渲染层零使用,关掉 XSS invoke 任意通道单点风险) - CORS 同源回显根治(仅当前浏览页面 Origin,did-navigate 同步) - MEMORY.md 命令保护正则扩展(括号/$/反引号/< 重定向边界 + 前导路径) - write_file append TOCTOU 统一(open 后 realpath 校验,新文件分支补漏) - 敏感键归一化(authKey 驼峰/连字符命中)+ MCP headers 鉴权值加密落库 - ReDoS 检测共享化(search_files/file_editor 统一拦截) - run_tests/lint_code 升风险 + 需确认 + npx --no-install(执行边界对齐 run_command) - MCP/SearXNG/llm.baseURL/updateFeedUrl 配置类 URL 高危目标校验(IPv6 去括号 + 十六进制映射解析 + 尾点剥离) P3 架构还债: - temperature/maxTokens 热生效(引擎/编排器/SubAgent 三处接线)+ setBatch 单事务落盘 - SessionRecorder flush 竞态根治(flushPromise 等待 + 超限内联落盘 + stopRecording async) - 内存收口(lastConsolidationBySession LRU / subTraces 清理 / 会话删除 disposeEngine) - i18n 全量收口(28 组件 + 353 key 双字典,状态标签改渲染时函数) - 死代码清理(updateTraceStep/HEADER_HEIGHT/void preA/失实注释) - 斜杠菜单 MUI 化 + 删除逻辑收敛 resetSessionState + Blob URL 统一释放 + 用户消息"仅保存"落库(saveMessage 透传前端 id 修复 id 错位) P4 能力演进: - 死循环检测拆分(驻留前置 + 乒乓后置带进度信号,合法交替不误报) - run-lock 30s 超时强制 abort(旧 run 卡死不无限排队) - RETRY 双通道 stream_reset(前端按 run 归属精确清空,根治重试文本重复) - FTS5 trigram 中文子串搜索(迁移 9 版本化 SCHEMA_VERSION=2,≤2 字符 LIKE 回退) - getContextWindow 兜底 1M→128K(未知模型防 413) 测试: - 855 → 2406 用例(+1551,2.8 倍):服务层 +325(含 MemoryManager 51 新用例)、 工具实体 +483、IPC/适配器 +390(含 OpenAI/Anthropic/Ollama 独立套件)、 纯函数表格化 +330;引入 jsdom + @testing-library(14 组件测试文件 249 用例) - 修复 R1(saveMessage id 透传)/ R2(stream_reset 精确归属)两个回归缺陷 - 遗留低危项清零:git-tools 顺序耦合 / web-fetch 真实时间退避 / slo 内存断言 / mcp-security 多余 skipIf / deepseek-balance 命名误导 / 组件 mock 注入脆弱性 版本: 0.7.4; README 同步(工具风险表/版本徽章); 依赖: 移除 @electron-toolkit/preload, 新增 jsdom/@testing-library(devDependencies 不打包) 回归: typecheck 双端 0 错误; ESLint 0/0; Electron ABI 全量 2406/2406 零跳过; 系统 Node 2110 通过 296 跳过(better-sqlite3 ABI)
This commit is contained in:
@@ -18,6 +18,9 @@ import {
|
||||
Box,
|
||||
Alert,
|
||||
} from '@mui/material';
|
||||
// v0.7.4 P3-1: 文案出层(字典含注册副作用,须在 t() 使用前 import)
|
||||
import { t } from '@renderer/lib/i18n';
|
||||
import '@renderer/lib/i18n-strings';
|
||||
|
||||
export function MCPSettings() {
|
||||
const [servers, setServers] = useState<
|
||||
@@ -74,16 +77,14 @@ export function MCPSettings() {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(newHeaders.trim());
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
throw new Error('需要 JSON 对象');
|
||||
throw new Error(t('settings.mcp.headersInvalid'));
|
||||
}
|
||||
headers = Object.fromEntries(
|
||||
Object.entries(parsed as Record<string, unknown>).map(([k, v]) => [k, String(v)]),
|
||||
);
|
||||
} catch {
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) =>
|
||||
mod.default.error('自定义请求头需为合法 JSON 对象,如 {"Authorization": "Bearer xxx"}'),
|
||||
)
|
||||
.then((mod) => mod.default.error(t('settings.mcp.headersInvalid')))
|
||||
.catch(() => {});
|
||||
return;
|
||||
}
|
||||
@@ -118,13 +119,15 @@ export function MCPSettings() {
|
||||
loadServers();
|
||||
} else {
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(r?.error ?? '添加 MCP 服务失败'))
|
||||
.then((mod) => mod.default.error(r?.error ?? t('settings.mcp.addFailed')))
|
||||
.catch(() => {});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[MCPSettings]', err);
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(`添加 MCP 服务失败:${(err as Error).message}`))
|
||||
.then((mod) =>
|
||||
mod.default.error(t('settings.mcp.addFailedMsg', { message: (err as Error).message })),
|
||||
)
|
||||
.catch(() => {});
|
||||
}
|
||||
};
|
||||
@@ -154,21 +157,21 @@ export function MCPSettings() {
|
||||
setConfirmRemove(null);
|
||||
loadServers();
|
||||
} else {
|
||||
setRemoveError(r?.error ?? '移除失败');
|
||||
setRemoveError(r?.error ?? t('settings.mcp.removeFailed'));
|
||||
}
|
||||
} catch (err) {
|
||||
setRemoveError((err as Error).message ?? '移除失败');
|
||||
setRemoveError((err as Error).message ?? t('settings.mcp.removeFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Stack spacing={2}>
|
||||
<Typography variant="subtitle2" sx={{ fontWeight: 600 }}>
|
||||
MCP 服务
|
||||
{t('settings.mcp.title')}
|
||||
</Typography>
|
||||
{servers.length === 0 ? (
|
||||
<Typography variant="caption" sx={{ textAlign: 'center', py: 4, color: 'text.secondary' }}>
|
||||
暂无 MCP 服务
|
||||
{t('settings.mcp.empty')}
|
||||
</Typography>
|
||||
) : (
|
||||
servers.map((s) => (
|
||||
@@ -196,7 +199,7 @@ export function MCPSettings() {
|
||||
</Typography>
|
||||
{s.toolCount > 0 && (
|
||||
<Typography variant="caption" sx={{ color: 'text.secondary' }}>
|
||||
{s.toolCount} 工具
|
||||
{t('settings.mcp.toolCount', { count: s.toolCount })}
|
||||
</Typography>
|
||||
)}
|
||||
</Stack>
|
||||
@@ -214,18 +217,26 @@ export function MCPSettings() {
|
||||
loadServers();
|
||||
} else {
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(r?.error ?? '操作失败'))
|
||||
.then((mod) =>
|
||||
mod.default.error(r?.error ?? t('settings.mcp.toggleFailed')),
|
||||
)
|
||||
.catch(() => {});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[MCPSettings]', err);
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(`操作失败:${(err as Error).message}`))
|
||||
.then((mod) =>
|
||||
mod.default.error(
|
||||
t('settings.mcp.toggleFailedMsg', { message: (err as Error).message }),
|
||||
),
|
||||
)
|
||||
.catch(() => {});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{s.status === 'connected' ? '断开' : '连接'}
|
||||
{s.status === 'connected'
|
||||
? t('settings.mcp.disconnect')
|
||||
: t('settings.mcp.connect')}
|
||||
</Button>
|
||||
{/* L-11 修复: 点击移除打开 MUI Dialog 二次确认,而非原生 confirm() */}
|
||||
<Button
|
||||
@@ -234,7 +245,7 @@ export function MCPSettings() {
|
||||
sx={{ fontSize: 10, minWidth: 40 }}
|
||||
onClick={() => setConfirmRemove(s.name)}
|
||||
>
|
||||
移除
|
||||
{t('settings.mcp.remove')}
|
||||
</Button>
|
||||
</Stack>
|
||||
</Stack>
|
||||
@@ -251,14 +262,14 @@ export function MCPSettings() {
|
||||
maxWidth="xs"
|
||||
fullWidth
|
||||
>
|
||||
<DialogTitle>确认移除</DialogTitle>
|
||||
<DialogTitle>{t('settings.mcp.removeConfirmTitle')}</DialogTitle>
|
||||
<DialogContent>
|
||||
<Typography variant="body2">
|
||||
确定移除 MCP 服务 "{confirmRemove}"?此操作不可撤销。
|
||||
{t('settings.mcp.removeConfirmBody', { name: confirmRemove ?? '' })}
|
||||
</Typography>
|
||||
{removeError && (
|
||||
<Alert severity="error" sx={{ mt: 1, fontSize: 12 }}>
|
||||
移除失败:{removeError}
|
||||
{t('settings.mcp.removeFailedMsg', { message: removeError })}
|
||||
</Alert>
|
||||
)}
|
||||
</DialogContent>
|
||||
@@ -270,10 +281,10 @@ export function MCPSettings() {
|
||||
}}
|
||||
color="inherit"
|
||||
>
|
||||
取消
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button onClick={handleConfirmRemove} color="error" variant="contained">
|
||||
移除
|
||||
{t('settings.mcp.remove')}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
@@ -292,7 +303,7 @@ export function MCPSettings() {
|
||||
size="small"
|
||||
value={newName}
|
||||
onChange={(e) => setNewName(e.target.value)}
|
||||
placeholder="服务名称"
|
||||
placeholder={t('settings.mcp.serverName')}
|
||||
/>
|
||||
{/* v0.4.1: 传输方式选择(stdio 本地命令 / streamable-http 远程) */}
|
||||
<Stack direction="row" spacing={1}>
|
||||
@@ -302,7 +313,7 @@ export function MCPSettings() {
|
||||
onClick={() => setNewTransport('stdio')}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
本地 (stdio)
|
||||
{t('settings.mcp.localStdio')}
|
||||
</Button>
|
||||
<Button
|
||||
variant={newTransport === 'streamable-http' ? 'contained' : 'outlined'}
|
||||
@@ -310,7 +321,7 @@ export function MCPSettings() {
|
||||
onClick={() => setNewTransport('streamable-http')}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
远程 (HTTP)
|
||||
{t('settings.mcp.remoteHttp')}
|
||||
</Button>
|
||||
</Stack>
|
||||
{newTransport === 'stdio' ? (
|
||||
@@ -319,13 +330,13 @@ export function MCPSettings() {
|
||||
size="small"
|
||||
value={newCommand}
|
||||
onChange={(e) => setNewCommand(e.target.value)}
|
||||
placeholder="命令路径(如 npx / node / python)"
|
||||
placeholder={t('settings.mcp.commandPlaceholder')}
|
||||
/>
|
||||
<TextField
|
||||
size="small"
|
||||
value={newArgs}
|
||||
onChange={(e) => setNewArgs(e.target.value)}
|
||||
placeholder="参数 (空格分隔)"
|
||||
placeholder={t('settings.mcp.argsPlaceholder')}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -334,14 +345,14 @@ export function MCPSettings() {
|
||||
size="small"
|
||||
value={newUrl}
|
||||
onChange={(e) => setNewUrl(e.target.value)}
|
||||
placeholder="Streamable HTTP URL(如 https://example.com/mcp)"
|
||||
placeholder={t('settings.mcp.urlPlaceholder')}
|
||||
/>
|
||||
{/* v0.7.2 P2-8: 远程传输自定义请求头(鉴权/网关路由)—— 留空匿名连接 */}
|
||||
<TextField
|
||||
size="small"
|
||||
value={newHeaders}
|
||||
onChange={(e) => setNewHeaders(e.target.value)}
|
||||
placeholder='自定义请求头 (JSON,可选),如 {"Authorization": "Bearer xxx"}'
|
||||
placeholder={t('settings.mcp.headersPlaceholder')}
|
||||
multiline
|
||||
minRows={2}
|
||||
slotProps={{ input: { sx: { fontFamily: 'monospace', fontSize: 11 } } }}
|
||||
@@ -358,7 +369,7 @@ export function MCPSettings() {
|
||||
}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
添加
|
||||
{t('settings.mcp.add')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
@@ -366,13 +377,13 @@ export function MCPSettings() {
|
||||
onClick={() => setShowAdd(false)}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
取消
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
</Stack>
|
||||
</Stack>
|
||||
) : (
|
||||
<Button variant="outlined" fullWidth size="small" onClick={() => setShowAdd(true)}>
|
||||
+ 添加 MCP 服务
|
||||
{t('settings.mcp.addServer')}
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user