Repository navigation
[6221] 附件预检策略上移宿主并修复不可读附件持续处理问题 - #4748
Merged
Merged
Conversation
PinkMagicFly
force-pushed
the
pigmagicfly/6221/unreadable-attachment-error
branch
from
October 19, 2026 09:19
bb376d7 to
bc8ab13
Compare
PinkMagicFly
force-pushed
the
pigmagicfly/6221/unreadable-attachment-error
branch
from
October 20, 2026 03:16
3617409 to
1cd0fb8
Compare
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.
变更概述
修复不可读文件添加为 Chat 附件后,附件按钮持续旋转、处理状态不退出且没有错误提示的问题。实施架构迁移:将附件预检策略从插件层上移至宿主层(
init-attachment.scm显式加载attachment-policy.scm),真假插件共享同一套预检策略契约与终态保证;假附件插件tm-attachment.scm瘦身,下发请求 JSON 瘦身为{taskId, path}。不可读等违规附件由宿主预检前置拦截,通过attachment-dispatch-error以exec-delayed异步派发qt-chat-attachment-error,复用现有 Qt 清理链移除处理中条目、停止按钮动画、解除发送栅栏并弹出中文 toast,同时保证权限恢复后可读附件流程完全正常。预检上移宿主后,附件链路首次由宿主直接执行编码敏感操作,暴露并修复了三处此前被插件层掩盖的缺陷:错误提示误报「附件插件不可用」、中文 toast 乱码、中文路径被误判为「文件不存在」。
详细改动
TeXmacs/plugins/attachment/progs/attachment-policy.scm(新增):attachment-max-count、attachment-max-total-bytes、attachment-allowed-extensions)与纯函数attachment-host-precheck;(and (path-file? p) (access fs-path 'R_OK))守卫下安全求值传入,避免对不可读文件求大小抛出permission-error。TeXmacs/plugins/attachment/progs/init-attachment.scm:$TEXMACS_PATH加载attachment-policy.scm;attachment-dispatch-error助手:统一exec-delayed错误派发,解决 C++attachTaskSession_在 glue 调用返回后才注册的时序问题;重复派发由attachTaskSession_的take幂等吸收,无需宿主防重表;attachment-ingest前置执行宿主预检:违规立即派发错误并返回#t触发面板清理,通过则向插件下发瘦身后的{taskId, path}请求 JSON;attachment-session-fallback-error)与 cancel 兜底路径。TeXmacs/plugins/attachment/goldfish/tm-attachment.scm(瘦身):fake-attachment-precheck;fake-attachment-ingest仅解析taskId与path;fake-attachment-ready-event单点计算filename与size并生成 ready 事件;catch #t异常兜底、假缓存 sweep 与非法 JSON 保护作为纵深防御。宿主预检暴露的三处缺陷修复(
init-attachment.scm):attachment-ingest形参命名为path会遮蔽(liii path)的 path 构造器,s7 中字符串可直接被调用(等价string-ref),(path path)按字符串应用抛type-error,经 C++call降级为假值后 toast「附件插件不可用」而非真实预检结论。形参改名为file-path;from_qstring传入 herk 实体形态路径,该形态仅在 wire 上由connection_write的tree_herk_to_utf8转回真实 UTF-8;宿主预检不经 wire,直接以实体串做文件系统调用会使中文路径path-file?恒假。attachment-ingest入口先经cork->utf8得fs-path专供文件系统调用,而文案文件名与 wire JSON 继续保持 herk 形态(各出口另有确定性解码);utf8->cork转实体形态(toast 侧cork_to_utf8只认实体)。该转换不可放在统一出口——utf8->cork会把已是实体的通道文本转坏(<→<less>),故契约注释记于attachment-dispatch-error。src/Plugins/Qt/qt_chat_controller.cpp&qt_chat_tab_widget.cpp:onAttachRequested注释:预检归属宿主,下发请求仅含taskId与path;onAttachmentError → takeAttachmentPanel → attachmentError → attachment_items_changed状态清理链,重算hasProcessingAttachments停止动画并更新发送栅栏;ChatConversationPanel::setup_ui保持无头环境兼容,attachButton()访问器供单测断言。自动化测试:
TeXmacs/plugins/llm/progs/llm/tests/chat-protocol-test.scm:加载attachment-policy.scm全量测试attachment-host-precheck边界与chmod 000不可读断言;新增test-attachment-host-precheck-nonascii-path断言 herk 形态路径须cork->utf8解码后方可查得文件;测试假插件瘦身后的 ready 事件生成、非法 JSON 及故障注入异常兜底;tests/Plugins/Qt/qt_chat_tab_widget_test.cpp:覆盖收到错误后条目删除、动画停止与栅栏解禁;tests/Plugins/Qt/qt_chat_controller_test.cpp:覆盖onAttachmentError完整路由与栅栏重算。验证说明
gf fmt --check全量通过(基于 goldfish v18.11.40)xmake r chat-protocol-test:61 checks passed(新增 3 条非 ASCII 路径断言)xmake r qt_chat_controller_test:0 failedxmake r qt_chat_tab_widget_test:0 failedattachment-ingest):中文可读路径正常通过预检并拉起插件(修复前误报「文件不存在」)、中文不可读路径、ASCII 不可读路径、不存在路径四条均返回预期终态chmod 000构造不可读附件):不可读文件 toast 正确显示「附件文件不可读取: noperm.pdf」且中文无乱码、附件按钮停止旋转、处理中条目移除且不生成 chip、发送栅栏解除;中文路径附件 ready/chip 与中文 toast 文案显示正常;恢复权限后重新添加同一文件流程完全正常devel/6221.stem(PR [no ci] Minor improvement for the win package script #190),已同步补记上述三处修复。