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:
@@ -19,6 +19,8 @@ import {
|
||||
Button,
|
||||
Paper,
|
||||
InputBase,
|
||||
List,
|
||||
ListItemButton,
|
||||
} from '@mui/material';
|
||||
import { Send, Paperclip, Square, X, FileText, Image as ImageIcon } from 'lucide-react';
|
||||
import { nanoid } from 'nanoid';
|
||||
@@ -304,8 +306,11 @@ export function ChatInput(): React.JSX.Element {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed && attachments.length === 0) return;
|
||||
if (isStreaming) return;
|
||||
if (!configLoaded) return; // P1-6: 配置未加载完成时禁止发送
|
||||
if (!toolsReady) return; // v0.3.18: 工具未就绪时禁止发送
|
||||
// v0.7.4 P1-8: 闭包陈旧修复 —— configLoaded/toolsReady 不在依赖数组内
|
||||
// (草稿恢复后 input 不再变化,闭包永远捕获初始 false,按钮看似可用但点击被静默拦截)。
|
||||
// 改为从 store 读取最新值,彻底消除依赖遗漏类 bug。
|
||||
if (!useAgentStore.getState().configLoaded) return; // P1-6: 配置未加载完成时禁止发送
|
||||
if (!useAgentStore.getState().toolsReady) return; // v0.3.18: 工具未就绪时禁止发送
|
||||
|
||||
// 处理 / 命令
|
||||
if (trimmed.startsWith('/')) {
|
||||
@@ -324,7 +329,7 @@ export function ChatInput(): React.JSX.Element {
|
||||
import('@renderer/lib/export-markdown')
|
||||
.then(({ buildSessionMarkdown, downloadMarkdown }) => {
|
||||
const messages = useAgentStore.getState().messages;
|
||||
const md = buildSessionMarkdown('会话导出', messages);
|
||||
const md = buildSessionMarkdown(t('chat.export.title'), messages);
|
||||
downloadMarkdown(`session-${Date.now()}.md`, md);
|
||||
})
|
||||
.catch(() => {});
|
||||
@@ -423,13 +428,25 @@ export function ChatInput(): React.JSX.Element {
|
||||
return;
|
||||
}
|
||||
// Cmd/Ctrl+Enter — 发送消息(规范要求,优先于 Enter)
|
||||
// v0.7.4 P1-7: IME 合成期间组合键同样拦截(拼音选字时按 Cmd/Ctrl+Enter 不应发送)
|
||||
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
||||
if (e.nativeEvent.isComposing || e.keyCode === 229) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
return;
|
||||
}
|
||||
// Enter(不带修饰键)— 发送消息(保持聊天应用习惯)
|
||||
// v0.7.4 P1-7: 中文输入法(IME)合成事件保护 —— 拼音选字回车会触发
|
||||
// keydown Enter(keyCode 229 / isComposing=true),旧实现直接发送,
|
||||
// 中文用户高频误发送。合成中回车一律拦截,仅放行真实发送回车。
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
if (e.nativeEvent.isComposing || e.keyCode === 229) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
return;
|
||||
@@ -493,53 +510,54 @@ export function ChatInput(): React.JSX.Element {
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
{/* / 命令菜单 */}
|
||||
{/* / 命令菜单 — v0.7.4 P3-7: 手写 div 弹层改为 MUI Paper+List(遵循 MUI 铁律:
|
||||
禁止自写 UI 交互组件)。悬停/点击/键盘导航由 MUI 组件内建提供。 */}
|
||||
{showSlashMenu && filteredCommands.length > 0 && (
|
||||
<div
|
||||
style={{
|
||||
<Paper
|
||||
elevation={8}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
bottom: '100%',
|
||||
left: 0,
|
||||
right: 0,
|
||||
marginBottom: 4,
|
||||
padding: '4px 0',
|
||||
background: 'var(--bg-secondary, #1a1d27)',
|
||||
border: '1px solid var(--border-color, #2a2d3a)',
|
||||
borderRadius: 8,
|
||||
boxShadow: '0 -4px 12px rgba(0,0,0,0.2)',
|
||||
mb: 1,
|
||||
maxHeight: 240,
|
||||
overflow: 'auto',
|
||||
borderRadius: 2,
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
bgcolor: 'background.paper',
|
||||
zIndex: 10,
|
||||
}}
|
||||
>
|
||||
{filteredCommands.map((cmd) => (
|
||||
<div
|
||||
key={cmd.id}
|
||||
onClick={() => {
|
||||
setInput(cmd.label + ' ');
|
||||
setShowSlashMenu(false);
|
||||
textareaRef.current?.focus();
|
||||
}}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
padding: '6px 12px',
|
||||
fontSize: 12,
|
||||
cursor: 'pointer',
|
||||
color: 'var(--text-primary, #e1e4ed)',
|
||||
}}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,0.05)')}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.background = 'transparent')}
|
||||
>
|
||||
<span style={{ color: '#818cf8', fontSize: 14, fontWeight: 700, flexShrink: 0 }}>
|
||||
/
|
||||
</span>
|
||||
<span style={{ fontFamily: 'monospace', fontSize: 12 }}>{cmd.label}</span>
|
||||
<span style={{ color: 'var(--text-secondary, #64748b)', fontSize: 11 }}>
|
||||
{cmd.description()}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<List dense disablePadding>
|
||||
{filteredCommands.map((cmd) => (
|
||||
<ListItemButton
|
||||
key={cmd.id}
|
||||
onClick={() => {
|
||||
setInput(cmd.label + ' ');
|
||||
setShowSlashMenu(false);
|
||||
textareaRef.current?.focus();
|
||||
}}
|
||||
sx={{ gap: 1.5, py: 0.75 }}
|
||||
>
|
||||
<Typography
|
||||
sx={{ color: 'primary.main', fontSize: 14, fontWeight: 700, flexShrink: 0 }}
|
||||
>
|
||||
/
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{cmd.label}
|
||||
</Typography>
|
||||
<Typography
|
||||
sx={{ color: 'text.secondary', fontSize: 11, ml: 'auto', textAlign: 'right' }}
|
||||
>
|
||||
{cmd.description()}
|
||||
</Typography>
|
||||
</ListItemButton>
|
||||
))}
|
||||
</List>
|
||||
</Paper>
|
||||
)}
|
||||
|
||||
<input
|
||||
@@ -600,10 +618,10 @@ export function ChatInput(): React.JSX.Element {
|
||||
<Tooltip
|
||||
title={
|
||||
supportsImages
|
||||
? '附加文件(图片/文本/代码)'
|
||||
? t('input.attach.image')
|
||||
: multimodalEnabled
|
||||
? '附加文件(文本/代码)— 当前模型不支持图片'
|
||||
: '附加文件(文本/代码)— 多模态未开启(设置 → LLM 配置)'
|
||||
? t('input.attach.textOnly.model')
|
||||
: t('input.attach.textOnly.toggle')
|
||||
}
|
||||
>
|
||||
<IconButton size="small" sx={{ color: 'text.secondary' }} onClick={handleFileSelect}>
|
||||
|
||||
Reference in New Issue
Block a user