feat: v0.7.0 四阶段全量迭代 — 修复面收口 · 安全纵深 · 架构还债 · 能力演进
P1 修复面收口: v0.6.3 截断自愈推全量(Anthropic/Ollama/非流式/引擎兜底); SSE 上游错误帧检测进重试通道; clearMessages 摘要游标根治; truncateResult 内联图片白名单统一; 前端四 bug(确认弹窗锁死/MemoryViewer/ Virtuoso Footer/abort 尾部过滤) + reasoning 缓冲跨迭代污染; 托盘通知过滤与新建会话死链接线 P2 安全纵深: MCP 审批闭环(ConfirmationHook×PolicyEngine 联动+重名拒注册); SSRF 收敛 ssrf-guard 共享模块 (web_fetch 双通道校验+重定向终态复检); Electron 加固(preload CJS 化→sandbox:true/CSP/权限白名单/will-navigate); run_command cmd.exe 白名单通道元字符守门; diff_viewer 10MB 预检; Anthropic thinking 预算下限; Agnes 思考显式关闭 P3 架构还债: OpenAICompatibleAdapter 中间基类收敛四家样板; 错误分类单轨化(删 mapError/getFetchSignal, 超时显式 ETIMEDOUT); PRAGMA user_version 迁移版本化; 死代码清理专项(cn.ts/SHORTCUTS/ContextMenu 分支/ getWindowState/modifiedArgs/sandbox 空壳); i18next 引入; a11y 第一轮; SearXNG 页批量草稿模型统一 P4 能力演进: Ollama pull 可取消/capabilities 探测/num_ctx 实测缓存; UpdateService feed 比对式自动更新 (app:updateCheck IPC + StatusBar 入口); MiMo providerOptions(web_search 服务端工具/strict JSON); web_fetch extract_mode=markdown(turndown); network.proxyUrl 全局代理(Chromium sessions+undici dispatcher) 测试: 264 → 507 用例(Electron ABI 全绿零跳过), 覆盖引擎压缩管线/重试竞速/MEMORY.md 闸门/file_editor 五操作/ filesystem 七工具实体夹具/git 真实仓库/SSE 错误帧/全线截断自愈/Provider 请求形态矩阵/SSRF 表测/钩子分级矩阵/ OutputValidator 全量/SLO 指标/MCP 安全纯函数/task_manager 链路/渲染层纯域/i18n 桥契约
This commit is contained in:
@@ -256,6 +256,115 @@ describe.skipIf(!dbAvailable)('SessionSummary 分层上下文 × 截断交互',
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* B-2 回归:clearMessages 必须同步删除滚动摘要
|
||||
*
|
||||
* 缺陷根因(v0.6.4 审计):messages 使用隐式 rowid,非 AUTOINCREMENT 表全表
|
||||
* DELETE 后新消息的 rowid 从 1 重新分配。若清空消息时保留 session_summaries
|
||||
* 的 summarized_until_rowid 游标(如 =500),则:
|
||||
* (1) buildHistoryMessages 的 `rowid > 500` 过滤令所有新消息落空 →
|
||||
* 新对话永远不进入 LLM 历史(直到重新攒满 500 条);
|
||||
* (2) maybeSummarize 的 `rowid > lastSummarized` 增量判定长期误报"无增量"。
|
||||
*/
|
||||
describe.skipIf(!dbAvailable)('clearMessages × 摘要游标交互(B-2)', () => {
|
||||
let db: any;
|
||||
let sessionService: any;
|
||||
let summaryService: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { SessionService } = await import('../session.service');
|
||||
const { SessionSummaryService } = await import('../session-summary.service');
|
||||
db = new Database(':memory:');
|
||||
db.exec(`
|
||||
CREATE TABLE sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT DEFAULT '新会话',
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
message_count INTEGER DEFAULT 0,
|
||||
pinned INTEGER DEFAULT 0,
|
||||
archived INTEGER DEFAULT 0,
|
||||
metadata TEXT DEFAULT '{}'
|
||||
);
|
||||
CREATE TABLE messages (
|
||||
id TEXT PRIMARY KEY,
|
||||
session_id TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
content TEXT,
|
||||
reasoning_content TEXT,
|
||||
tool_calls TEXT,
|
||||
tool_result TEXT,
|
||||
attachments TEXT,
|
||||
iteration INTEGER,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE TABLE session_summaries (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
summary TEXT NOT NULL,
|
||||
summarized_until_rowid INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000)
|
||||
);
|
||||
`);
|
||||
db.prepare(
|
||||
'INSERT INTO sessions (id, created_at, updated_at, message_count) VALUES (?, ?, ?, ?)',
|
||||
).run('s_clear', Date.now(), Date.now(), 0);
|
||||
|
||||
sessionService = new SessionService(() => db);
|
||||
summaryService = new SessionSummaryService(
|
||||
() => db,
|
||||
sessionService,
|
||||
() => null as unknown as Parameters<typeof Object>[0],
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
try {
|
||||
db?.close();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
});
|
||||
|
||||
it('清空消息后摘要与游标一并清除;rowid 重分配后新对话正常进入历史', () => {
|
||||
const ins = (id: string, content: string): void => {
|
||||
db.prepare(
|
||||
`INSERT INTO messages (id, session_id, role, content, created_at) VALUES (?, ?, 'user', ?, ?)`,
|
||||
).run(id, 's_clear', content, Date.now());
|
||||
};
|
||||
|
||||
// 阶段一:5 条历史 + 摘要游标远超当前 rowid(模拟旧会话曾积累大量已摘要消息:
|
||||
// 用户在长会话里攒到 summarized_until_rowid=500 后执行"清空消息")
|
||||
for (let i = 1; i <= 5; i++) ins(`old_m${i}`, `旧消息 ${i}`);
|
||||
const maxRowIdBefore = (
|
||||
db.prepare(`SELECT MAX(rowid) AS r FROM messages WHERE session_id='s_clear'`).get() as { r: number }
|
||||
).r;
|
||||
expect(maxRowIdBefore).toBe(5);
|
||||
summaryService.saveSummary('s_clear', '覆盖全部旧消息的摘要', 500);
|
||||
|
||||
// 复现缺陷前提(且暴露缺陷真实严重度):rowid=6 < 游标 500,
|
||||
// 新消息全部被 `rowid > 500` 过滤落空;而摘要注入又要求"存在 tail"才生效
|
||||
// (buildHistoryMessages: existing && messages.length > 0)—— 结果历史恒为空:
|
||||
// 该会话从此刻起 LLM 完全失忆,直到新消息 rowid 涨过 500。
|
||||
ins('transition_m', '过渡期新消息');
|
||||
expect(summaryService.buildHistoryMessages('s_clear').length).toBe(0);
|
||||
|
||||
// 阶段二:用户点击"清空消息"
|
||||
expect(sessionService.clearMessages('s_clear')).toBe(true);
|
||||
expect(sessionService.getMessages('s_clear')).toHaveLength(0);
|
||||
|
||||
// 核心契约 1:摘要记录被同步删除(原实现此处残留 cursor=5)
|
||||
expect(summaryService.getSummary('s_clear')).toBeNull();
|
||||
|
||||
// 核心契约 2:全表 DELETE 后 rowid 从 1 重排(SQLite 非 AUTOINCREMENT 行为),
|
||||
// 若摘要未删,这些 rowid=1..n 的新消息将永远过不了 `rowid > 500` 过滤。
|
||||
for (let i = 1; i <= 2; i++) ins(`new_m${i}`, `新对话 ${i}`);
|
||||
const historyAfterClear = summaryService.buildHistoryMessages('s_clear');
|
||||
expect(historyAfterClear).toHaveLength(2);
|
||||
expect(historyAfterClear[0].content).toBe('新对话 1');
|
||||
expect(historyAfterClear[1].content).toBe('新对话 2');
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* F-3 回归:session_summaries 级联删除
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user