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:
@@ -16,7 +16,7 @@ vi.mock('electron-log', () => ({
|
||||
}));
|
||||
|
||||
import { DeepSeekAdapter } from '../deepseek.adapter';
|
||||
import type { MetonaRequest } from '../../types';
|
||||
import type { MetonaRequest, MetonaImageContent } from '../../types';
|
||||
|
||||
const mockFetch = vi.fn();
|
||||
vi.stubGlobal('fetch', mockFetch);
|
||||
@@ -37,7 +37,7 @@ function makeAdapter(model: string): DeepSeekAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
function makeRequest(images?: Array<{ url: string }>): MetonaRequest {
|
||||
function makeRequest(images?: MetonaImageContent[]): MetonaRequest {
|
||||
return {
|
||||
meta: {
|
||||
sessionId: 's',
|
||||
@@ -60,7 +60,12 @@ function okResponse(): Response {
|
||||
} as unknown as Response;
|
||||
}
|
||||
|
||||
function requestBody(): { model: string; messages: Array<Record<string, unknown>> } {
|
||||
// toNativeRequest 返回 Record<string, unknown>;这里收敛为「已知字段 + 任意扩展字段」
|
||||
// 的交叉类型,测试可直接断言 max_tokens/thinking/temperature/stop/stream 等协议字段。
|
||||
function requestBody(): { model: string; messages: Array<Record<string, unknown>> } & Record<
|
||||
string,
|
||||
unknown
|
||||
> {
|
||||
const [, init] = mockFetch.mock.calls[0] as [string, RequestInit];
|
||||
return JSON.parse(init.body as string);
|
||||
}
|
||||
@@ -122,4 +127,275 @@ describe('DeepSeek vision 模型多模态请求格式(v0.5.4)', () => {
|
||||
const userMsg = body.messages[1];
|
||||
expect(userMsg.content).toBe('这张图片里有什么?');
|
||||
});
|
||||
|
||||
it('vision 模型:多张图片全部转为 image_url parts(保持顺序)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send(
|
||||
makeRequest([
|
||||
{ url: 'data:image/png;base64,AAA' },
|
||||
{ url: 'data:image/png;base64,BBB' },
|
||||
{ url: 'data:image/jpeg;base64,CCC' },
|
||||
]),
|
||||
);
|
||||
|
||||
const body = requestBody();
|
||||
const parts = body.messages[1].content as Array<Record<string, unknown>>;
|
||||
expect(parts).toHaveLength(4); // 1 text + 3 image
|
||||
expect(parts[1]).toMatchObject({
|
||||
type: 'image_url',
|
||||
image_url: { url: 'data:image/png;base64,AAA' },
|
||||
});
|
||||
expect(parts[2]).toMatchObject({
|
||||
type: 'image_url',
|
||||
image_url: { url: 'data:image/png;base64,BBB' },
|
||||
});
|
||||
expect(parts[3]).toMatchObject({
|
||||
type: 'image_url',
|
||||
image_url: { url: 'data:image/jpeg;base64,CCC' },
|
||||
});
|
||||
});
|
||||
|
||||
it('vision 模型:无文本消息时仍生成 image parts(不丢弃图片)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest([{ url: 'data:image/png;base64,AAA' }]),
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: null,
|
||||
images: [{ url: 'data:image/png;base64,AAA' }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
const parts = body.messages[1].content as Array<Record<string, unknown>>;
|
||||
// 无文本 → 只有 image_url part(text part 不生成)
|
||||
expect(parts).toHaveLength(1);
|
||||
expect(parts[0].type).toBe('image_url');
|
||||
});
|
||||
|
||||
it('非 vision 模型:即使 content 为 null 也不转换图片(纯 null content)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-pro');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest([{ url: 'data:image/png;base64,AAA' }]),
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: null,
|
||||
images: [{ url: 'data:image/png;base64,AAA' }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
const userMsg = body.messages[1];
|
||||
expect(userMsg.content).toBeNull();
|
||||
});
|
||||
|
||||
it('vision 模型 detail 字段被丢弃(image_url 仅保留 url)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send(makeRequest([{ url: 'data:image/png;base64,AAA', detail: 'high' }]));
|
||||
|
||||
const body = requestBody();
|
||||
const parts = body.messages[1].content as Array<Record<string, unknown>>;
|
||||
expect(parts[1]).toEqual({
|
||||
type: 'image_url',
|
||||
image_url: { url: 'data:image/png;base64,AAA' },
|
||||
});
|
||||
});
|
||||
|
||||
it('vision 模型 max_tokens 未配置 → 默认 8192(MODEL_INFO 上限)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest(),
|
||||
params: { temperature: 0, stream: false },
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
expect(body.max_tokens).toBe(8_192);
|
||||
});
|
||||
|
||||
it('vision 模型 thinking 参数显式映射(thinkingEnabled 兼容)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest([{ url: 'data:image/png;base64,AAA' }]),
|
||||
params: { maxTokens: 4096, temperature: 0, stream: false, thinkingEnabled: true },
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
// vision 模型 supportsThinking=false,但参数仍透传 thinking enabled(引擎决定)
|
||||
expect(body.thinking).toEqual({ type: 'enabled' });
|
||||
});
|
||||
|
||||
it('vision 模型 messages 数组首位始终为 system 消息', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send(makeRequest([{ url: 'data:image/png;base64,AAA' }]));
|
||||
const body = requestBody();
|
||||
expect(body.messages[0].role).toBe('system');
|
||||
expect(body.messages[0].content as string).toContain('sys');
|
||||
});
|
||||
|
||||
it('tool 结果消息不被 images 转换影响(role=tool 保留 tool_call_id)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest([{ url: 'data:image/png;base64,AAA' }]),
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: '请读图',
|
||||
images: [{ url: 'data:image/png;base64,AAA' }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: null,
|
||||
toolCalls: [
|
||||
{
|
||||
id: 'tc1',
|
||||
name: 'view_image',
|
||||
args: { path: 'a.png' },
|
||||
iteration: 1,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
{
|
||||
role: 'tool',
|
||||
content: null,
|
||||
toolResult: {
|
||||
toolCallId: 'tc1',
|
||||
toolName: 'view_image',
|
||||
result: { path: 'a.png' },
|
||||
success: true,
|
||||
durationMs: 1,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
const toolMsg = body.messages[3];
|
||||
expect(toolMsg.role).toBe('tool');
|
||||
expect(toolMsg.tool_call_id).toBe('tc1');
|
||||
expect(toolMsg.content).toBe('{"path":"a.png"}');
|
||||
});
|
||||
|
||||
it('孤立 tool 消息被过滤(无前置 tool_calls)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest(),
|
||||
messages: [
|
||||
{ role: 'user', content: 'hi', timestamp: Date.now() },
|
||||
{
|
||||
role: 'tool',
|
||||
content: null,
|
||||
toolResult: {
|
||||
toolCallId: 'tc_orphan',
|
||||
toolName: 'x',
|
||||
result: 'r',
|
||||
success: true,
|
||||
durationMs: 1,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
],
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
// system + user,孤立 tool 被剔除
|
||||
expect(body.messages).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('temperature 与 stop 序列透传', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest(),
|
||||
params: { maxTokens: 4096, temperature: 0.4, stream: false, stopSequences: ['<END>'] },
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
expect(body.temperature).toBe(0.4);
|
||||
expect(body.stop).toEqual(['<END>']);
|
||||
});
|
||||
|
||||
it('send(非流式路径)强制 stream=false 且不附加 stream_options', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest([{ url: 'data:image/png;base64,AAA' }]),
|
||||
params: { maxTokens: 4096, temperature: 0, stream: true },
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
// send() 契约:无论请求参数如何,非流式路径强制 stream=false,stream_options 仅流式路径注入
|
||||
expect(body.stream).toBe(false);
|
||||
expect(body.stream_options).toBeUndefined();
|
||||
});
|
||||
|
||||
it('非 vision 模型带图片不产生 image_url(content 保持字符串)', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash');
|
||||
|
||||
await adapter.send(makeRequest([{ url: 'data:image/png;base64,AAA' }]));
|
||||
const body = requestBody();
|
||||
const userMsg = body.messages[1];
|
||||
expect(typeof userMsg.content).toBe('string');
|
||||
expect(userMsg.content).not.toContain('image_url');
|
||||
});
|
||||
|
||||
it('vision 模型 base64 data URI 原样保留在 image_url 中', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
const dataUri = 'data:image/png;base64,' + 'Z'.repeat(50);
|
||||
await adapter.send(makeRequest([{ url: dataUri }]));
|
||||
const body = requestBody();
|
||||
const parts = body.messages[1].content as Array<Record<string, unknown>>;
|
||||
expect(parts[1]).toMatchObject({ image_url: { url: dataUri } });
|
||||
});
|
||||
|
||||
it('vision 模型 reasoning_content 在 assistant 历史中保留', async () => {
|
||||
mockFetch.mockResolvedValue(okResponse());
|
||||
const adapter = makeAdapter('deepseek-v4-flash-vision-exp');
|
||||
|
||||
await adapter.send({
|
||||
...makeRequest(),
|
||||
messages: [
|
||||
{ role: 'user', content: 'hi', timestamp: Date.now() },
|
||||
{ role: 'assistant', content: 'answer', reasoningContent: 'trace', timestamp: Date.now() },
|
||||
],
|
||||
} as MetonaRequest);
|
||||
|
||||
const body = requestBody();
|
||||
const assistantMsg = body.messages[2] as Record<string, unknown>;
|
||||
expect(assistantMsg.reasoning_content).toBe('trace');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user