[1106] 调研:标签页切换时未保存标志误显的排查方法演示#3789
Draft
da-liii wants to merge 10 commits into
Draft
Conversation
- 7.1 详述 m_isDirty 的初始化与变动(唯一写入点 applyDisplayTitle) - 7.2 记录已验证结论:Scheme window-set-view 不能复现 bug,真实鼠标 点击走的副作用链才是触发路径;已搭好 MOGAN_TEST_GUI=1 + delayed chain 的 GUI 自动化骨架作为下一步 QTest 的工作基础 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- TeXmacs/tests/1106.scm + tmu/1106_{a,b}.tmu:用 exec-delayed-at
串异步链在 GUI 进程里 open 两个文档并来回切 tab,链尾自退出
- xmake/tests.lua:集成测试新增 MOGAN_TEST_GUI=1 环境变量开关,
开启后以真实 GUI 进程(不带 -headless)启动且不在 -x 外层自动
quit,默认行为不变
- buffer_modified / applyDisplayTitle / replaceTabPages 加 LIII_DEBUG
临时日志,方便定位 tab 切换时 buffer / 标题的实际状态
当前结论:Scheme window-set-view 不能复现 bug,需要真正的鼠标事件
路径(QTMTabPage::mousePressEvent 副作用)才会触发。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
关键认知更新:之前两轮失败不是 Scheme 切换路径太干净,而是因为 夹具在 $TEXMACS_PATH/tests/tmu/ 下走的是 load-buffer 的 clean 分支。 改用 /tmp 下的副本立即复现,load-buffer 完成的瞬间 buffer 就被标记 为 modified,切换过程持续 true。下一步在 7.3 定位 load-buffer-main 链路里哪一步误置 modified。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 1106.scm:每次启动把 $TEXMACS_PATH 夹具复制到 /tmp 再 load-buffer, 避免检入夹具被污染;改用 /tmp 路径后 buffer_modified 在 load 完成 瞬间就返回 true,applyDisplayTitle 收到 rawTitle 带 " *",bug 复现 - 1106_a.tmu / 1106_b.tmu:恢复成干净最小内容(前一轮 GUI 跑污染过) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
根因:auto-backup-ensure-buffer-doc-id! 给不在 $TEXMACS_PATH 下的 新加载 buffer 注入 stem-doc-id 环境变量,init_env 写入动作被 editor 当成普通修改推入 undo 栈并触发 require_save,导致刚加载的 buffer 立 刻被判为未保存。 修复:在 init_env 之后立刻 (buffer-pretend-saved name) 重置 saved 标志,doc-id 仍然写入,auto-backup 功能不受影响。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- tm-files.scm: auto-backup-ensure-buffer-doc-id! 在 init_env 写入 doc-id 后调用 (buffer-pretend-saved name),抵消 init_env 推入 undo 栈的修改,避免 load-buffer 后 buffer 被错误标记为未保存 - archiver.cpp: 临时在 require_save 加 [1106-arch] 调试日志 (LIII_DEBUG),后续验证稳定后清理 验证:MOGAN_TEST_GUI=1 xmake r 1106 跑 5 轮切换,buffer_modified 全部 false,applyDisplayTitle 收到的 rawTitle 不再带 " *"。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This reverts commit 2f18733.
- 1106.scm:切换调用从 (window-set-view win v #t) 改为 (switch-to-view-index N),与 std 2/std 3 (ctrl+2/ctrl+3) 完全 相同的代码路径。但实测仍不能复现手动按键时的 dirty 误报,说明 bug 触发于按键链路的附属副作用(焦点/光标/装饰通知),不在 switch-to-view-index 本身。 - tm-files.scm:在 auto-backup-ensure-buffer-doc-id! 加 [1106-ab] 调试日志,用于确认 init-env 分支执行时机。已验证:夹具带 doc-id 时走 keep-old 分支,buffer 保持 clean;夹具不带 doc-id 时走 inject-new 分支,init-env 触发 require_save,buffer 被误判为 modified。 下一步:需要真实按键事件路径来复现 switch-to-view-index 之外的 副作用。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
这个 PR 是什么
不是修复,是调研成果展示——给同事演示一套"GUI 交互类 bug 如何系统性排查"的方法论。
bug 现象:打开两个已保存的文档,仅切 tab(不编辑)也会让标签页标题错误出现
*(未保存标志)。所有相关代码路径和推理过程都在devel/1106.md的 7.1/7.2/7.3。已定位的根因(部分)
load 时
init-env注入 doc-id 触发 dirty:夹具没有
stem-doc-id时,auto-backup-ensure-buffer-doc-id!(tm-files.scm:817)会调用(init-env "stem-doc-id" doc-id)注入 UUID。init-env写 buffer 的环境变量会推 modification 到 undo 栈,触发archiver_rep::require_save(archiver.cpp:643),把last_save置成 -1,于是刚加载的 buffer 立刻被判为未保存。夹具带
stem-doc-id时(TeXmacs/tests/tmu/1106_{a,b}.tmu已加),函数走 keep-old 分支,bug 不复现。未定位的路径
真实按键切换 tab 仍能复现 bug,但集成测试里用
(switch-to-view-index N)(和std 2/std 3即 ctrl+2/ctrl+3 完全相同的代码路径)来回切换 5 轮,bug 不复现。这提示真正的触发点是按键链路的附属副作用(焦点切换、光标保存/恢复、装饰通知等),不在
switch-to-view-index本身。需要真实键盘事件才能复现,当前集成测试基础设施覆盖不到。为什么是 draft
集成测试无法复现真实按键路径下的 bug,所以无法在当前架构下写出一个稳定的回归测试。计划重构 tab 切换相关代码后再修复,让按键链路的副作用可控可测。
演示的排查方法
基础设施
xmake/tests.lua新增MOGAN_TEST_GUI=1环境变量开关:集成测试以真实 GUI 进程(非 headless)启动,-x外层不自动 quit,允许exec-delayed-at串异步链TeXmacs/tests/1106.scm:delayed-chain GUI 自动化脚本,open → 切换 N 轮 → 自己退出TeXmacs/tests/tmu/1106_{a,b}.tmu:最小夹具运行方式
临时调试日志(保留用于演示)
src/Texmacs/Data/new_buffer.cppbuffer_modified[1106]src/Plugins/Qt/QTMTabPage.cppapplyDisplayTitle[1106-qt]src/Plugins/Qt/QTMTabPage.cppreplaceTabPages[1106-qt]src/Data/History/archiver.cpprequire_save/notify_save/conform_save[1106-arch]TeXmacs/progs/texmacs/texmacs/tm-files.scmauto-backup-ensure-buffer-doc-id![1106-ab]所有日志都用
LIII_DEBUG宏包裹,release 构建会被编译器剔除,零运行时开销。排查推理链(详见 devel/1106.md 7.1/7.2/7.3)
m_isDirty成员变量的初始化与变动(唯一写入点applyDisplayTitle,只在构造时调用)$TEXMACS_PATH下不行、为什么/tmp下才行(auto-backup-buffer-eligible?排除$TEXMACS_PATH)init-env注入 doc-id 触发require_save;修复思路是在注入后(buffer-pretend-saved name)抵消 dirty 副作用给同事的建议
🤖 Generated with Claude Code