Repository navigation
fix(test): 隔离单元测试持久化目录 - #792
Merged
deepcoldy merged 1 commit intoAug 9, 2026
Merged
Conversation
LucasIcarus
marked this pull request as ready for review
August 8, 2026 13:51
LucasIcarus
force-pushed
the
fix/unit-test-session-isolation
branch
from
August 8, 2026 18:30
327a37e to
b91f841
Compare
LucasIcarus
force-pushed
the
fix/unit-test-session-isolation
branch
from
August 8, 2026 18:32
b91f841 to
6431659
Compare
Merged
|
🚀 Released in v3.11.0 |
xiaoxueSunn
added a commit
to xiaoxueSunn/botmux
that referenced
this pull request
Aug 10, 2026
三轮双审的两处测试修复(均只碰测试,非生产代码 bug): ① fresh 回归假绿:claude-code 分支每次调用现算(newerFile 直读盘),无 30s miss 负缓存,fresh 是 no-op——删掉生产代码 fresh 透传后 claude 用例照样过(假护栏)。 改用 codex 分支(cachedTranscriptPathLookup + retryMiss:q.fresh 真有负缓存): 种下 miss → 落盘 → 非 fresh 仍 null / fresh 当场解析成功。mutation 已坐实: 把 fresh:q.fresh 改成 false,该用例即失败。 ② 测试污染真实 ~/.claude:上一版 fixture 写进 join(homedir(),'.claude','projects', <projectKey>) 且 afterEach 只删 .jsonl、不删 projectKey 目录,历次留下空目录 (PR deepcoldy#792 同类:单测污染开发者真实数据目录)。改为 CODEX_HOME 定向到临时目录, beforeAll 设置 / afterAll 还原并整体清理,绝不触碰真实 ~/.claude 或 ~/.codex。 已清理本机历史残留的 -*-todo-cwd-* 空目录。 Claude 的 Task* 增量重放仍由纯 parseOpenTodos 单测覆盖;增量游标/fail-closed/文件 替换机制与方言无关,codex 落盘用例同样验证。todo-state 24 全绿,无 home 目录污染。 Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Botmux daemon/worker 会把真实的
SESSION_DATA_DIR注入 agent 会话。开发者若直接在该会话里运行 unit tests,Vitest 的 unit project 会继承这个路径。dashboard-ipc的 Message Listener Preview 用例虽然 mock 了 worker fork,仍会经过triggerSessionTurn→sessionStore.createSession的真实持久化路径。因此测试 fixture 曾被写入~/.botmux/data,在 Dashboard 中显示为[External] Message Listener Preview会话。测试结束后再清理真实数据并不能可靠解决这个问题:失败或强制终止可能跳过清理,测试运行期间也已经与 live daemon 共享文件;反向删除真实 session 文件还会引入并发误删风险。这里把隔离提前到测试模块 import 之前,使 unit tests 从一开始就看不到调用环境的生产数据目录。
修改
unitproject 增加专用 global setup:每轮测试创建一个系统临时根目录,并在 project teardown 统一兜底回收。<run-root>/file-*/data:SESSION_DATA_DIR;dirname(SESSION_DATA_DIR)派生的有效 Botmux home,避免 schedules、transcripts、per-bot state 等在并行文件间共享。beforeAll/beforeEach中显式选择临时目录的能力。afterAll清理文件根,project teardown 兜底 collect/import failure。teardown 不恢复调用环境的真实目录,避免 worker 退出前的异步窗口重新触碰 live data。sessionStore.createSession落盘、data dir 与有效 Botmux home 的路径 containment、跨 test override 修复,以及显式 test override 的兼容性。范围与兼容性
unitproject;不修改 daemon/worker 运行时代码,也不改变 e2e project。tmpdir、join、mkdtempSync、mkdirSync、rmSync,不覆盖HOME,兼容 macOS 与 Linux 的临时目录和路径规则。SIGKILL、掉电等无法执行进程内 teardown 的场景,最多留下系统临时目录,不会再污染生产 Botmux session 数据。验证
pnpm buildSESSION_DATA_DIR,运行后该目录 0 写入。TMPDIR=/tmp的 Linux-shaped 路径验证:4/4 tests passed;模拟生产目录 0 写入,botmux-unit-*临时根 0 残留。upstream/master原样复现;其余 6 个仅在全量负载下失败的 runner/timeout/临时目录竞态用例,在本分支与纯 upstream 分别单跑均通过。相关真实行为测试另为 4/4 passed。本项不标记为全绿。git diff --check upstream/master...HEAD