feat(sessions): 添加多后端回放一致性测试框架#114
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #114 +/- ##
==========================================
Coverage ? 87.90681%
==========================================
Files ? 479
Lines ? 44984
Branches ? 0
==========================================
Hits ? 39544
Misses ? 5440
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
实现 ReplayHarness 和 DiffEngine,覆盖 event/state/memory/summary 四维度跨后端一致性验证。包含 10 条 replay case (7 正常 + 3 注入) 和 29 个测试用例,支持 InMemory ↔ SQLite 轻量对比。 Fixes trpc-group#89 RELEASE NOTES: 新增 Session/Memory 多后端回放一致性测试框架
422fff7 to
5b900a7
Compare
|
I have read the CLA Document and I hereby sign the CLA |
|
这里是否可以在不修改框架源码的前提下,编写一个真正运行的例子,包含tool调用,采用真实模型跑一下,采用mock的方式或者其他的方式构造一下异常情况,看看是否通过你的这个test检查出来,该issue最终的目的是可以检查真实场景下的异常,避免代码修改过程中引入比较难发现的bug,记忆细微的出错,可能导致整个语义产生偏差 |
AI Code Review我现在已经完全理解了。第 2 层(Layer 2)的断言检查“cherry blossom”是否出现在
等等——第 32 行是压缩后的 但是聚合报告显示 InMemory 的事件[1..4] 是旧文本(Osaka, Shinkansen)——这意味着压缩将旧事件保留在索引 1..10 的位置,而新事件(cherry blossom)在索引 11..14。所以“cherry blossom”确实存在(在索引 11+)。第 2 层的 那么,真正的测试有效性问题在于:测试声称要验证“压缩后追加的新事件已保留”和“摘要+保留的事件+新事件共同覆盖上下文”,但 Layer-2 实际上只检查了 第 1061 行:“报告应反映预期的分歧”,然后 我现在已经掌握了所需的一切。让我再检查一下 让我检查一下 测试文件执行了 现在让我完成审查。再检查一次: 让我验证一下 我已经掌握得足够多了。让我撰写审查报告。## 发现的问题 🚨 Critical
|
| result: RawResult, | ||
| ) -> None: | ||
| kw = step.kwargs | ||
| session_id = kw.get("session_id") or (result.session.id if result.session else None) |
There was a problem hiding this comment.
get_session 回退使用陈旧的 result.session.id
_handle_get_session 在 session_id 为空时回退到 result.session.id,而 result.session 是上次返回的深拷贝,压缩后未刷新会读到压缩前事件快照。建议每次 get_session 后强制以新返回值为准,并统一使用 self._sessions[label].id 作为回退。
| assert "cherry blossom" in all_text.lower(), (f"{label}: new events after summary are missing. " | ||
| f"Events text: {all_text[:200]}") | ||
|
|
||
| # Report should reflect expected divergences |
There was a problem hiding this comment.
test_replay_summary_truncation 未断言 report.passed
该用例计算 report.passed 后从未对其断言,而聚合报告显示 case_07 实际 passed=false 且存在事件不一致,使测试形同虚设。建议显式 assert report.passed 或对 inconsistencies 为空做断言。
045a7fd to
5b900a7
Compare
AI Code Review我已经了解了所有背景信息。让我来撰写最终的审查意见。 发现的问题🚨 Critical
|
| f"Events text: {all_text[:200]}") | ||
|
|
||
| # Report should reflect expected divergences | ||
| report.passed = len(report.inconsistencies) == 0 |
There was a problem hiding this comment.
test_replay_summary_truncation 未断言 report.passed
该用例声称做跨后端严格一致性校验,但只断言了 summary 元数据与 state,未对 report.passed/report.inconsistencies 做任何断言,case_07 的事件顺序分歧会被静默放过。应补充 assert report.passed 或对允许的 event 不一致做显式分类断言。
AI Code Review已全部确认。正在撰写审查报告。 发现的问题🚨 Critical
|
| output_path.write_text(json.dumps(output, indent=2, ensure_ascii=False), encoding="utf-8") | ||
|
|
||
| # ── Assertions ── | ||
| assert output["total_cases"] == len(_ALL_CASES), ( |
There was a problem hiding this comment.
引用未定义的 _ALL_CASES
test_generate_aggregated_diff_report 断言使用了从未定义的 _ALL_CASES,运行即抛 NameError,聚合报告测试必然失败。改用 len(list_replay_cases()) 或显式定义 _ALL_CASES。
AI Code Review确认 — 现在我已经掌握了所有信息。让我来撰写最终的审查意见。 发现的问题
|
@raychen911 感谢老师建议!在未修改框架底层源码的前提下,补充了可直接运行的端到端示例、基于 DeepSeek 的 Tool Call 链路,同时新增 4 类 Mock 异常注入用例,覆盖超时、网络截断、半写入失败、记忆语义细微篡改场景,均可通过回放差异检测捕获问题,详情如下: 端到端运行示例文件: # 基本模式(无需 API Key)
python replay_consistency_demo.py
# 真实模型模式(采用 DEEPSEEK_API_KEY)
export DEEPSEEK_API_KEY="sk-xxx"
python replay_consistency_demo.py --real-model场景 1~4:模拟数据 + 异常检测(无需 API Key)
场景 5:真实模型 + Tool Calling(需 DeepSeek API Key)基于 DeepSeek v4 Flash,使用 OpenAI SDK 直接对接(遵循官方 关键设计决策:
Mock 注入用例文件: 通过 case_11:LLM 超时模拟case_12:网络故障模拟case_13:部分写入失败模拟case_14:记忆语义偏差模拟(核心场景) |
实现 ReplayHarness 和 DiffEngine,覆盖 event/state/memory/summary 四维度跨后端一致性验证。包含 10 条 replay case (7 正常 + 3 注入)
和 29 个测试用例,支持 InMemory ↔ SQLite 轻量对比。
Fixes #89
RELEASE NOTES: 新增 Session/Memory 多后端回放一致性测试框架