fix(chat): stop duplicating pasted-text attachments when editing a sent message#273
Merged
Merged
Conversation
…nt message Pasting a long block of text turns it into an uploaded "pasted text" file referenced inline by the message via a "[Pasted text N: path]" marker, rendered as a chip once the message is sent (PastedTextChip / splitUserAttachmentsForDisplay). Clicking "edit" on that sent user bubble reused the raw, unfiltered attachment list for the editor's attachment-card row instead of applying the same split the read-only bubble already uses, so the pasted text showed up twice: once as a floating attachment card, and once as the raw "[Pasted text N: path]" marker text inside the editable textarea. Reuse splitUserAttachmentsForDisplay inside EditableUserMessageBubble so the attachment-card row only shows files not already referenced by a marker in the (live) editable text. The full, unfiltered attachment list is still what gets submitted on resend, so nothing is dropped from the message. Mirror the same fix into the gateway WebUI (crates/agent-gateway/web). Add regression coverage in agent-gui verifying the duplicate card is hidden while the marker is present, still shown when there is no marker, and reappears if the marker is edited away.
The third case claimed to prove the card list reacts "live" as the marker is retyped, but it only rendered once with a marker-free initialText — so it asserted the same thing as the case above it and never drove a state transition. There is no DOM test environment here (renderToStaticMarkup only), so a genuine retype cannot be expressed; drop the misleading name rather than keep a test that overstates what it checks. Replace it with two cases that cover ground the suite was missing: - multiple markers in one message must each suppress their own card (fails against the pre-fix component, so it is a real guard) - a stale marker whose file is no longer attached must hide nothing, pinning the match to relativePath rather than label or position test:frontend 1251/1251, tsc --noEmit clean, biome unchanged at 365 warnings. No source changes.
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.
问题
复制一段长文本粘贴到输入框时,会被转成"粘贴文本"附件并在正文里插入
[Pasted text N: 相对路径]标记;发送后只读气泡会把该附件从卡片列表里隐藏,只用PastedTextChip把它渲染成内嵌的绿色 tag。点击该用户气泡上的"编辑"按钮后,编辑态直接复用了未经过滤的附件列表,同时文本框展示的是原始文本(仍带着
[Pasted text N: 路径]标记)。于是同一份粘贴内容被展示了两次:一次是附件卡片,一次是文本框里那段本该被渲染成 tag 的原始标记文字。agent-gui(桌面主实现)与agent-gateway/web(网关 WebUI 镜像)的EditableUserMessageBubble是各自独立实现,同样的疏漏两边都存在。修复
复用只读气泡已经在用的
splitUserAttachmentsForDisplay,让编辑态的附件卡片列表也按"文本里是否还带着该文件的标记"过滤;提交/重发时仍然使用完整、未过滤的附件列表,因此不会因为隐藏了卡片就把该附件从消息里丢掉。crates/agent-gui/src/pages/chat/transcript/EditableUserMessageBubble.tsxcrates/agent-gateway/web/src/components/GatewayTranscript.tsx(镜像同步)测试
crates/agent-gui/test/chat/editable-user-message-bubble.test.mjs(新增,4 个用例):renderToStaticMarkup(无 jsdom/testing-library),无法驱动 state 变更,因此不含「边打字边删标记」的实时用例;useMemo依赖为[draftAttachments, draftText]。agent-gui:test:frontend(1251 用例)、tsc --noEmit、biome lint全部通过;lint 警告数与 main 基线一致(365 条,均为历史遗留、与本次改动无关)。agent-gateway/web:tsc --noEmit、node --test(416 用例)全部通过;biome check src/306 条警告,与 main 基线逐条一致(全为历史遗留)。无用户可见的行为回归——粘贴附件在发送/重发链路上的内容不变(提交时仍使用完整、未过滤的附件列表),只是编辑视图不再重复展示。