8000
Skip to content

fix(repl): 多槽位 auto-save 绕过 SESSIONS_DIR monkeypatch,chaos/resume 等 12 个测试失败 #73

Description

@xianyu-sheng

Bug 描述

xenon/repl/session.py 中的多槽位自动保存改造(未提交的 WIP)破坏了测试对 SESSIONS_DIR 的 monkeypatch 约定:SessionSlotManager 模块(xenon/repl/session_slot_manager.py:19)定义了自己的模块级 SESSIONS_DIR = Path.home() / ".xenon" / "sessions"auto_save() 里通过 get_slot_manager() 惰性创建的全局单例以该路径为默认值。测试长期以来通过改写 xenon.repl.session.SESSIONS_DIR 来隔离会话目录(如 chaos 测试在子进程中 session_module.SESSIONS_DIR = Path(os.environ["XENON_CHAOS_SESSIONS"])),改造后 auto_save() 不再读取 session.pySESSIONS_DIR,导致 auto-save 写到真实 ~/.xenon/sessions/ 而恢复路径去测试目录找 _auto.json → FileNotFoundError。

注意:本 issue 针对的是工作区未提交改动引入的回归,供修复时参考;若该改动已演进请忽略。

复现步骤

cd ~/Xenon
python3 -m pytest tests/chaos/test_execution_recovery_chaos.py::test_sigkill_recovers_all_parallel_tools_without_replaying -q

实际行为

FileNotFoundError: 会话 '_auto' 不存在: /tmp/pytest-*/sessions/_auto.json
xenon/repl/session.py:197

工作区 WIP 下全量测试 12 failed / 2339 passed;git stash 回退 WIP 后同批测试通过(35/37,剩余 2 个失败与 HEAD 的 permissions 提示格式有关,疑似同样来自工作区其他未完成改动)。

12 个失败用例:

  • tests/chaos/test_execution_recovery_chaos.py::test_sigkill_recovers_all_parallel_tools_without_replaying
  • tests/repl/test_permissions_execution_policy.py(2 个 format_confirm_message 用例)
  • tests/test_context_continuity.py::test_runtime_checkpoint_preserves_tool_roles_and_memory
  • tests/test_permission_integration.py(4 个)
  • tests/test_realtime_query_followups.py::test_mcp_confirmation_never_displays_unknown_server_marker
  • tests/test_resume.py::TestCleanupExpired::test_cleanup_removes_expired
  • tests/test_terminal_activity.py::test_repl_permission_prompt_freezes_and_resumes_activity
  • tests/test_tool_execution_lifecycle.py::test_lifecycle_callback_persists_each_transition_to_session

期望行为

测试对 session.SESSIONS_DIR 的重写应对 auto-save 全链路生效——槽位管理器不应绕过它。

根因与修复方向(建议,不改代码)

根因:全局单例 get_slot_manager() 在首次调用时捕获模块级默认路径,且 SessionSlotManager.SESSIONS_DIRsession.SESSIONS_DIR 是两份拷贝,测试只能改到后者。

修复方向(三选一):

  1. get_slot_manager() 惰性构造时传入 session.SESSIONS_DIR当前值(读模块属性而非 slot_manager 模块自己的常量),即 SessionSlotManager(sessions_dir=SESSIONS_DIR)
  2. 或删除 session_slot_manager.py:19 的重复常量,__init__ 默认值改为 None 并在内部延迟解析 session.SESSIONS_DIR
  3. 同时建议把 _global_slot_manager 单例改为可按 sessions_dir 缓存/重置,避免测试间串扰(tests/repl/test_session_slot_manager.py 已用 tmp_path 显式构造,问题主要出在经过 get_slot_manager() 的路径)。

环境

  • Xenon 工作区(v0.8.5 + 未提交多槽位 WIP)
  • Python 3.12, Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0