Repository navigation
test(feishu): cover inbound file attachment lifecycle - #13278
Conversation
|
I addressed R1-1 through R1-7 in
I independently reproduced R1-8 with the real 300-character filename write: no dispatch, and an orphan UUID directory still present after 60 seconds. I recorded it separately in #13334. The failing regression should land with its production fix, not as a permanently red test in this coverage-only PR; moving ownership alone would not restore the text fallback. That behavior remains unfixed here and is not silently dismissed. Verification on Windows/Node 22.21.1 with pinned pnpm: full Feishu suite 305/305, independent shuffled full suite 305/305, root build/typecheck, targeted ESLint/Prettier and diff check pass; two clean independent diff audits. Filesystem checks are real, while network and dispatch boundaries are mocked. The previous upstream Feishu suite also passed; its general CI failure was the unchanged core recall-scan latency assertion. Fresh CI on this head is required—I am not declaring that failure a proven flake or weakening its threshold. 中文说明在 真实 300 字符文件名探针独立复现了 R1-8:无分发,60 秒后仍有孤立目录。该生产缺陷另记于 #13334;失败回归应与生产修复一起提交,不将本仅测试 PR 永久置红,也不声称已修复。仅提前记录目录所有权不能恢复文本回退。 Windows/Node 22.21.1/锁定 pnpm:完整飞书套件与独立随机顺序套件均 305/305,根目录 build/typecheck、ESLint/Prettier、diff 检查通过,独立审查两遍无新发现。文件系统是真实操作,网络和分发边界为模拟。此前上游飞书套件通过,通用 CI 失败在未修改的 core recall-scan 延迟断言;需要新 head 的 CI,不把该失败当作已证明的抖动,也不放宽阈值。 Current-head CI update: the e517f1b unit job passes all 305 Feishu tests. General CI remains red at the unchanged core cold-scan latency case: 315.0 / 299.6 / 276.3 ms versus 275 ms. Feishu runs after that failed core suite in this job. This is not a claim of proven flakiness or approval-on-green; a controlled upstream baseline/rerun disposition is still needed. R1-8 now has the separate main-based fix/regression in #13337, following @doudouOUC's confirmation in #13334; production remains unchanged in this coverage-only PR. 中文:新版 e517f1b 上游单测中飞书 305 项全通过,通用 CI 仍在未修改 core 冷扫描延迟用例失败:315.0 / 299.6 / 276.3 ms 对 275 ms 门槛,飞书套件在其后执行。不声称已证明抖动或满足绿色审批,仍需受控基线/重跑处置。R1-8 在 #13334 得到独立确认后,现有 main-based 独立修复及回归 #13337;本仅测试 PR 不改生产行为。 October 4 follow-up: I requested a rerun of the exact failed Ubuntu job above, but GitHub rejected the request with HTTP 403: repository admin rights are required. Could a maintainer rerun or provide a baseline disposition for that cold-scan failure? The 305 passing Feishu tests and the unchanged production scope are still the current evidence; I have not weakened the timing threshold or marked general CI green. |
|
I investigated the remaining Ubuntu failure at In three alternating base/head pairs on local Linux Docker, both versions failed the same cold limit; warm-cache and all five lane controls passed. This used an isolated benchmark dependency install, not the full hosted runner. The green upstream baseline job used an ECS runner with a 1,250 ms ceiling, so it does not establish a passing hosted baseline. I have left the benchmark unchanged and am not treating this as a proven flake. @wenshao Could you triage or rerun the Ubuntu job and review this head? My rerun attempt was denied because it requires repository admin rights. |
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
Partially reviewed — gaps disclosed. Suggestions are inline.
Not reviewed: reverse audit — stopped before round 3 by the review time budget.
中文说明
仅完成部分审查,审查缺口已披露。 建议见行内评论。
未审查:反向审计——评审时间预算不足,未能开始第 3 轮。
— qwen3.8-max via Qwen Code /review (v0.25.0)
|
I merged main’s #13525 fix and re-ran the two failing CLI cases: both pass. Build, lint, typecheck and all 308 Feishu tests also pass on |
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline.
中文说明
已审查。 建议见行内评论。
— qwen3.8-max via Qwen Code /review (v0.25.0)
|
Completed the controlled Linux comparison; raw logs, hashes and JUnit reports are attached to that run. All seven test invocations exited 0.
Main/head/head/main isolated runs and sequential main/head full-core runs used the same GitHub-hosted Linux runner, Node 22.23.3 and frozen pnpm 11.24.0 dependencies. The original hosted 275 ms ceiling, default workers, PR coverage setting and existing two retries were unchanged. The timing suite passed within both full-core runs too. Although the console log is silent, JUnit retained the full-core 1,000-topic cold distributions (best/median/worst): main 145.9/174.3/240.0 ms, head 108.5/129.2/161.5 ms. This one fixed-order pair is not evidence that the PR makes identical core code faster. Relative to integrated main, the only PR change is the Feishu adapter test; core, production code, configuration and dependencies are identical. In the failed upstream log, core failed at 14:13:22 UTC, while Feishu started at 14:25:41 and passed all 308 tests. The new Feishu timers/files were not running at the earlier failure. Green upstream main runs used the different ECS lane and are not a hosted-275-ms control. I found no evidence of a regression introduced by this PR and have left its code unchanged. The historical slowdown was not reproduced here, but its cause remains unresolved: this is a different hosted VM, not a replay of the entire original workspace workload/CLI-before-core state or HOME isolation. Current main is a contextual third arm, not the matched baseline. I am not calling the old failure proven flakiness or replacing upstream CI with the fork result. Could a maintainer rerun the failed upstream Linux job on the unchanged head and review the coverage-only change? |
yiliang114
left a comment
There was a problem hiding this comment.
LGTM. This adds real coverage over a path that had none, and I checked the expectations against production rather than trusting the table.
The six sanitization cases are exactly right. I ran each input through the production pipeline at FeishuAdapter.ts:2758-2765 — basename(name).replace(/\0/g, '') then .replace(/[^\w.-]/g, '_').replace(/^\.+/, '_') || \feishu_file_${Date.now()}``:
| input | expected | why |
|---|---|---|
.hidden |
_hidden |
^\.+ collapse, dot is in the allowed class so it survives the first replace |
../report\0.txt |
report.txt |
basename strips the traversal, then the NUL replace |
... |
_ |
the whole leading dot run collapses to a single _ |
\0 |
feishu_file_1790985600000 |
empties out, so the ` |
my report (final).pdf |
my_report__final_.pdf |
space + each paren → _ |
a\nb.txt |
a_b.txt |
\n isn't in [\w.-] |
The fallback case is the one worth calling out: feishu_file_1790985600000 is Date.now() under the faked clock (vi.setSystemTime('2026-10-03T00:00:00Z')), and that value checks out exactly. So the test pins the timestamped-filename branch instead of hand-waving it with expect.any(String).
The lifecycle cases are similarly grounded — the 59_999 / +1 pair pins the real setTimeout(..., 60_000) in the finally at :2829, and starts the 60-second cleanup countdown only after the mocked dispatch settles correctly proves the timer is scheduled after the await rather than at download time (file survives 70 s while dispatch is pending, then dies exactly 60 s after settlement). The stoppedMessages case matches the immediate-removal branch at :2803.
On the two things I'd normally push on:
- The
mediaStatus: 401→403row. @qwen-code-review-bot's R2-1 is correct that this was the package's only resource-download 401 case, and @jabrailkhalil reproduced the gap and filed #13845. The bot raised it as a Suggestion, and the deferral is tracked rather than dropped, so I'm not treating it as a blocker here — but it does mean resource-401 is currently unpinned in this package, and #13845 is where that gets closed. vi.mock('node:os')is file-wide in a 256 KB test file. It's safe as written — the factory keepsactual.tmpdiras the default andafterEachrestores it — but every other test in the file now sits behind that mock. Worth knowing; not worth changing.
One non-blocking note: 12 check runs exist on this head but the Test lanes are all skipped, so there's no CI evidence behind these assertions. The author's own Linux comparison run is linked in the thread, but a lane run on this head before merge would be the clean signal.
中文
LGTM。这给一条原本没有覆盖的路径补上了真实覆盖,而且我是拿生产代码核过这些期望值的,没有直接采信表格。
六个净化用例完全正确。 我把每个输入都过了一遍 FeishuAdapter.ts:2758-2765 的生产管线——basename(name).replace(/\0/g, '') 再 .replace(/[^\w.-]/g, '_').replace(/^\.+/, '_') || \feishu_file_${Date.now()}``:
| 输入 | 期望 | 原因 |
|---|---|---|
.hidden |
_hidden |
^\.+ 折叠;点在允许字符类里,所以第一次 replace 不会动它 |
../report\0.txt |
report.txt |
basename 先剥掉目录穿越,再走 NUL replace |
... |
_ |
整段前导点折叠成单个 _ |
\0 |
feishu_file_1790985600000 |
清空后触发 ` |
my report (final).pdf |
my_report__final_.pdf |
空格与两个括号各变 _ |
a\nb.txt |
a_b.txt |
\n 不在 [\w.-] 里 |
兜底那条值得单独说:feishu_file_1790985600000 就是假时钟(vi.setSystemTime('2026-10-03T00:00:00Z'))下的 Date.now(),而且这个值精确对得上。所以测试是真的钉住了带时间戳的文件名分支,而不是用 expect.any(String) 糊过去。
生命周期用例同样有据——59_999 / +1 这一对钉住的是 :2829 处 finally 里真实的 setTimeout(..., 60_000);而 starts the 60-second cleanup countdown only after the mocked dispatch settles 正确证明了计时器是在 await 之后才排上的,不是下载时就排(dispatch 挂起期间文件挺过 70 秒,settlement 之后整 60 秒才消失)。stoppedMessages 那条对应 :2803 的立即删除分支。
关于我通常会追问的两点:
mediaStatus: 401→403这一行。 @qwen-code-review-bot 的 R2-1 说得对,这原本是该包里唯一的 resource-download 401 用例,@jabrailkhalil 也复现了这个缺口并立了 #13845。bot 是以 Suggestion 提出的,而且延期是被追踪的而不是被丢掉的,所以我不把它当本 PR 的阻塞项——但确实意味着 resource-401 目前在该包里没有 pin,#13845 是补它的地方。vi.mock('node:os')是文件级的,而这个测试文件有 256 KB。写法本身是安全的——factory 保留了actual.tmpdir作为默认值,afterEach也会复原——但文件里其他所有测试现在都处在这个 mock 之下。知道这一点即可,不值得改。
一点非阻塞:该 head 上有 12 个 check run,但 Test lane 全是 skipped,所以这些断言背后没有 CI 证据。作者自己的 Linux 对照运行在线程里有链接,但合并前在本 head 上跑一次 lane 会是更干净的信号。
…shu-inbound-file-coverage
|
Thanks for checking this. I merged main’s current lint gate in |
|
I ran the current head on Linux: 326 passed, no skips; pinned main has 311 passed. Both POSIX permission cases execute. Comparison. This is fork CI; upstream CI/review is still pending. |
|
I checked |
|
Thanks for the detailed re-review and for syncing Update, October 20: Qwen Code CI for There has since been another maintainer main-merge, to current head |
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
Partially reviewed — gaps disclosed. Suggestions are inline.
Not reviewed: build-and-test — Test (macos-latest, Node 22.x) and Test (windows-latest, Node 22.x) were skipped in CI and the package suite ran locally on Linux only.
Not reviewed: reverse audit — stopped before round 1 by the review time budget.
中文说明
仅完成部分审查,审查缺口已披露。 建议见行内评论。
未审查(原文为英文):build-and-test — Test (macos-latest, Node 22.x) and Test (windows-latest, Node 22.x) were skipped in CI and the package suite ran locally on Linux only.
未审查:反向审计——评审时间预算不足,未能开始第 1 轮。
— qwen3.8-max via Qwen Code /review (v0.25.3)
| describe('inbound file dispatch', () => { | ||
| const systemTmpDir = tmpdir(); | ||
| const bytes = new Uint8Array([0, 1, 255]); |
There was a problem hiding this comment.
[Suggestion] R7-1: [probe] This new block rebuilds, nearly line for line, the inbound-file fixture that the sibling inbound-file-store.test.ts already owns, and re-pins two of the storage invariants that suite already pins — so the inbound-file store now has two test owners with two independently maintained fixture copies.
The cost is measurable rather than stylistic. Changing the store's directory layout ('channel-files' to 'channel-files-x' at FeishuAdapter.ts:2755) turns both files red — 4 tests here and 13 there; changing the attachment type: 'file' to 'document' (:2772) turns both red as well. A single production change to the layout or the attachment shape now needs lockstep edits in two suites that share no harness. The two copies have already diverged on what they assert: the store suite pins text: '(file: report.pdf)' together with syntheticText: true (:139-142), while the happy path here asserts syntheticText (:993) but not text — so a change to the placeholder string fails one file and passes the other, with nothing flagging the disagreement.
This is not the round-3 finding R3-1 re-derived. R3-1 named the duplicate filename-sanitizer table and the 59,999/60,000 ms cleanup boundary; both were removed, and neither a sanitizer it.each nor any 59_999 remains in this block. What is left is a different slice: the roughly 30-line harness plus the layout and attachment-shape assertions.
Witness:
three one-line production mutations, full package suite per arm
(baseline proven first: 6 files / 323 tests passed)
layout 'channel-files' -> 'channel-files-x' FeishuAdapter.ts:2755
-> Test Files 2 failed | 4 passed (6) / Tests 17 failed | 306 passed (323)
red in BOTH adapter.test.ts > inbound file dispatch > persists a file message...
AND inbound-file-store.test.ts > keeps successful files until the existing cleanup grace period
shape type: 'file' -> 'document' FeishuAdapter.ts:2772
-> Test Files 2 failed | 4 passed (6) / Tests 3 failed | 320 passed (323)
window 60_000 -> 30_000 FeishuAdapter.ts:2829
-> Test Files 1 failed | 5 passed (6) / Tests 3 failed | 320 passed (323)
all three in inbound-file-store.test.ts, NONE in the new block
grep "'media'" inbound-file-store.test.ts -> zero hits
Keep the adapter-level cases this block is the only place to prove — sender-policy gate ordering, the auth 401/500/network fallbacks, missing file_name, file versus media routing, dispatch-rejection cleanup, stop-during-download, and timer-starts-after-dispatch — and drop from them the store-owned assertions: the attachment-shape toEqual, the readFileSync byte comparison, and the channel-files/<uuid> layout walk. Assert only what the adapter decides (attachment present or absent, text, syntheticText, and that no directory is created on a failure path). Where a store invariant is genuinely new — two same-named messages landing in distinct directories — move that case into inbound-file-store.test.ts and reuse its fixture instead of re-declaring systemTmpDir, bytes and receive().
Two facts any trim must not violate. First, a media-message case has to survive somewhere: inbound-file-store.test.ts:113 hardcodes message_type: 'file' in its receive() helper and nothing there overrides it to 'media' (its only override is message_type: 'text' at :373), and the pre-existing adapter.test.ts:633-641 tests the pure parser extractContent('media', ...) in isolation without ever reaching the file store — so the it.each(['file', 'media']) at :978 is the sole coverage that extractContent('media')'s fileKey/fileName (FeishuAdapter.ts:2971-2977) reach the store path. Second, if cases are relocated rather than deleted, note that inbound-file-store.test.ts:21-29 installs file-wide node:fs spies and its beforeEach fetch mock at :81-88 hard-asserts the exact resource URL, so the token-failure and missing-file_name cases (which never reach that URL) need that guard relaxed or made per-case rather than dropped.
中文说明
这个新 describe 块几乎逐行重建了同目录 inbound-file-store.test.ts 已经拥有的入站文件测试夹具,并重复钉住了该套件已经钉住的两条存储不变量——于是入站文件存储现在有两个测试归属方,各自维护一份夹具副本。
这个代价是可测量的,而不是风格问题。修改存储目录布局(FeishuAdapter.ts:2755 处 'channel-files' 改成 'channel-files-x')会让两个文件同时变红——本文件 4 个用例、存储套件 13 个;把附件 type: 'file' 改成 'document'(:2772)同样让两边都变红。也就是说,布局或附件形状的任何一次生产代码改动,现在都要在两个完全不共享夹具的套件里同步修改。两份副本在断言内容上其实已经出现分歧:存储套件同时钉住了 text: '(file: report.pdf)' 和 syntheticText: true(:139-142),而这里的正常路径只断言了 syntheticText(:993)却没有断言 text——所以占位文本一旦改动,一个文件失败、另一个通过,而且没有任何东西会提示这种不一致。
这不是第 3 轮的 R3-1 被重新推导出来。R3-1 指的是重复的文件名净化表和 59,999/60,000 ms 清理边界,这两处都已被移除,本块里既没有净化 it.each 也没有任何 59_999。剩下的是另一个切片:约 30 行夹具,加上布局和附件形状的断言。
建议保留只有本块才能证明的适配层级用例——发送者策略门的顺序、认证 401/500/网络失败回退、缺少 file_name、file 与 media 路由、分发拒绝后的清理、下载期间停止、以及计时器在分发结束后才启动——并从中删掉归属存储套件的断言:附件形状的 toEqual、readFileSync 字节比对、以及 channel-files/<uuid> 布局遍历。只断言适配器自己决定的东西(附件有无、text、syntheticText,以及失败路径上不创建目录)。真正属于新增的存储不变量——两条同名消息落在不同目录——建议移入 inbound-file-store.test.ts 并复用它的夹具,而不是重新声明 systemTmpDir、bytes 和 receive()。
有两点在精简时不能违反。第一,media 消息用例必须在某处保留:inbound-file-store.test.ts:113 在它的 receive() 辅助函数里硬编码了 message_type: 'file',该文件没有任何地方覆盖成 'media'(唯一的覆盖是 :373 的 message_type: 'text'),而既有的 adapter.test.ts:633-641 只孤立测试纯解析函数 extractContent('media', ...),根本不会走到文件存储——所以 :978 的 it.each(['file', 'media']) 是 extractContent('media') 的 fileKey/fileName(FeishuAdapter.ts:2971-2977)能到达存储路径的唯一覆盖。第二,如果是搬迁而非删除用例,注意 inbound-file-store.test.ts:21-29 安装了文件级的 node:fs spy,其 beforeEach 的 fetch mock 在 :81-88 硬断言了精确的资源 URL,所以认证失败和缺少 file_name 这两个用例(它们永远不会请求该 URL)需要放宽该守卫或改成按用例设置,而不是直接删掉。
— qwen3.8-max via Qwen Code /review (v0.25.3)
There was a problem hiding this comment.
[Suggestion] R7-1: [probe] Still stands — re-checked at head d0d79c86: the code at this anchor is byte-identical to what round 7 reviewed, and five of this round's agents (reuse, altitude, performance, and two adversarial personas) independently re-derived the same duplication. This block rebuilds, nearly line for line, the inbound-file fixture that the sibling inbound-file-store.test.ts already owns — the node:os tmpdir mock, the systemTmpDir/bytes constants, the tokenCache seed, the handleInbound spy, the resource-URL fetch mock, the afterEach and the receive() helper — and re-pins the storage invariants that suite already pins, so one contract now has two independently maintained harnesses.
The two copies have also diverged in what they assert: the store suite pins text: '(file: report.pdf)' together with syntheticText: true (:139-142), while the happy path here asserts syntheticText (:994) but not text — a change to the placeholder string fails one file and passes the other with nothing flagging the disagreement. And a single production change to the directory layout ('channel-files', FeishuAdapter.ts:2755), the attachment shape (type: 'file', :2772) or the 60 s timer (:2829) now requires lockstep edits in both suites.
Witness (round-7 probe — three one-line production mutations, full package suite per arm, baseline proven green first; anchor code unchanged since):
layout 'channel-files' -> 'channel-files-x' FeishuAdapter.ts:2755
-> Tests 17 failed | 306 passed (323)
red in BOTH adapter.test.ts AND inbound-file-store.test.ts
shape type: 'file' -> 'document' FeishuAdapter.ts:2772
-> Tests 3 failed | 320 passed (323) red in both files
window 60_000 -> 30_000 FeishuAdapter.ts:2829
-> Tests 3 failed | 320 passed (323)
all three in inbound-file-store.test.ts, NONE in the new block
The fix guidance in the root comment of this thread stands unchanged: keep the adapter-level cases this block is the only place to prove (sender-policy gate ordering, the auth 401/500/network fallbacks, missing file_name, file-vs-media routing, dispatch-rejection cleanup, stop-during-download, timer-starts-after-dispatch), drop from them the store-owned assertions (the attachment-shape toEqual, the readFileSync byte comparison, the channel-files/<uuid> layout walk), and relocate the genuinely new store invariant — two same-named messages landing in distinct directories — into inbound-file-store.test.ts, reusing its fixture instead of re-declaring systemTmpDir, bytes and receive(). Two facts any trim must not violate: the it.each(['file', 'media']) at :978 is the sole coverage that extractContent('media')'s fileKey/fileName (FeishuAdapter.ts:2971-2977) reach the store path, because the store file's receive() hardcodes message_type: 'file' (inbound-file-store.test.ts:113); and relocated cases run under that file's module-scope node:fs spies (:21-29) whose beforeEach fetch mock (:81-88) hard-asserts the exact resource URL, so the token-failure and missing-file_name cases need that guard relaxed or made per-case rather than dropped.
中文说明
R7-1 仍然成立 —— 已在 head d0d79c86 重新核查:锚点处代码与第 7 轮审查时逐字节一致,本轮 5 个独立 agent(复用、抽象层级、性能及两个对抗视角)再次推导出同一重复。该块几乎逐行重建了同目录 inbound-file-store.test.ts 已经拥有的入站文件夹具 —— node:os tmpdir mock、systemTmpDir/bytes 常量、tokenCache 注入、handleInbound spy、资源 URL fetch mock、afterEach 以及 receive() 辅助函数 —— 并重复钉住该套件已钉住的存储不变量:同一契约现在有两套独立维护的夹具。
两份副本的断言内容已经出现分歧:存储套件同时钉住 text: '(file: report.pdf)' 与 syntheticText: true(:139-142),而这里的正常路径只断言 syntheticText(:994)未断言 text —— 占位文本一旦改动,一个文件失败、另一个通过,且没有任何东西提示这种不一致。目录布局('channel-files',FeishuAdapter.ts:2755)、附件形状(type: 'file',:2772)或 60 秒计时器(:2829)的任何一次生产改动,现在都要在两个套件里同步修改。
证据(第 7 轮探针 —— 三个单行生产变异,每个变异跑完整包套件,基线先证全绿;锚点代码自那以后未变):布局变异 → 17 failed | 306 passed(两个文件同时变红);附件类型变异 → 3 failed | 320 passed(两边都红);60_000→30_000 → 3 failed | 320 passed(全部在存储套件,新块无一变红)。
修复建议与本线程主评论一致:保留只有本块才能证明的适配层用例(发送者策略门顺序、认证 401/500/网络失败回退、缺少 file_name、file 与 media 路由、分发拒绝后清理、下载期间停止、计时器在分发结束后才启动),从中删掉归属存储套件的断言(附件形状 toEqual、readFileSync 字节比对、channel-files/ 布局遍历),并把真正新增的存储不变量 —— 两条同名消息落在不同目录 —— 移入 inbound-file-store.test.ts 复用其夹具,而不是重新声明 systemTmpDir、bytes 和 receive()。精简时不能违反两点::978 的 it.each(['file', 'media']) 是 extractContent('media') 的 fileKey/fileName(FeishuAdapter.ts:2971-2977)能到达存储路径的唯一覆盖,因为存储文件的 receive() 在 :113 硬编码了 message_type: 'file';搬迁后的用例会运行在该文件的模块级 node:fs spy(:21-29)之下,其 beforeEach fetch mock(:81-88)硬断言精确资源 URL —— 认证失败与缺少 file_name 的用例需要放宽该守卫或改成按用例设置,而不是直接删掉。
— qwen3.8-max via Qwen Code /review (v0.26.0)
| expect( | ||
| getPrivateMethod<Map<string, number>>(channel, 'seenMessages').has( | ||
| 'inbound-file', | ||
| ), | ||
| ).toBe(false); |
There was a problem hiding this comment.
[Suggestion] R7-2: [probe] cleans up after dispatch rejects is the only test guarding the per-message dedup rollback at FeishuAdapter.ts:2842 (processMessage().catch(...) to this.seenMessages.delete(msgId), commented "Allow Feishu retries by removing the dedup entry on failure"), and it asserts only that seenMessages.has('inbound-file') is false. Inspecting one key is not enough to tell the scoped delete(msgId) apart from a whole-map clear().
Replace delete(msgId) with clear() — a plausible simplification — and the entire package suite stays green, measured at 323/323 and byte-identical to baseline. Meanwhile the dedup gate at FeishuAdapter.ts:2604 (if (this.seenMessages.has(msgId)) return;) has started forgetting every other in-flight message. Two messages can be in flight at once — this same diff's keeps two messages with the same filename in separate directories drives exactly that — so when one dispatch rejects, a Feishu webhook retry or duplicate delivery of the other message is no longer deduped and is processed a second time: a duplicate card session and a duplicate bridge.prompt agent run for a message the user sent once. The existing TTL-sweep test does not catch it either, because it seeds msg_old without any dispatch rejection, so clear() never fires there.
Witness:
four arms in an isolated probe tree
(baseline proven first: adapter.test.ts 185/185, package 6 files / 323 passed)
MUTANT this.seenMessages.clear() at FeishuAdapter.ts:2842
-> Test Files 6 passed (6) / Tests 323 passed (323)
SURVIVED — byte-identical to baseline; grep -n confirms one site changed
CONTROL rollback removed (void 0)
-> x FeishuChannel > inbound file dispatch > cleans up after dispatch rejects
Tests 1 failed | 184 passed (185)
FIX second concurrent message added as suggested, pristine source
-> 1 passed
FIX+MUTANT
-> AssertionError: expected false to be true // Object.is equality
The control arm is what makes the survival meaningful rather than vacuous: no-oping the rollback turns that exact test red, so the catch handler really is exercised and the test really does guard the rollback. The mutant survives precisely because the assertion inspects one key — the map holds only 'inbound-file' when the catch fires, so delete(msgId) and clear() leave identical observable state.
Extend this case (or add a sibling) with a second concurrent message whose dispatch succeeds, then assert the rollback is scoped rather than total: keep expect(seenMessages.has('inbound-file')).toBe(false) and add expect(seenMessages.has('inbound-file-2')).toBe(true). Drive it the way keeps two messages with the same filename in separate directories at :1107 already does — receive('report.txt', 'inbound-file-2') plus the widened two-URL fetchSpy guard accepting resourceUrl.replace('/inbound-file/', '/inbound-file-2/') — and select which dispatch rejects via the envelope's own message id rather than mockResolvedValueOnce ordering, since the two processMessage chains settle independently.
The rollback must stay per-message and must not disturb the TTL sweep: FeishuAdapter.ts:336-338 (for (const [id, ts] of this.seenMessages) { ... this.seenMessages.delete(id); }) is a separate deletion site, and its test at adapter.test.ts:3014-3024 seeds msg_old and asserts only msg_old is swept. With the second-message assertion in place, mutating this.seenMessages.delete(msgId) to this.seenMessages.clear() at FeishuAdapter.ts:2842 must turn cleans up after dispatch rejects red — that mutation was executed during review and produced AssertionError: expected false to be true.
中文说明
cleans up after dispatch rejects 是唯一守护 FeishuAdapter.ts:2842 处按消息粒度去重回滚的用例(processMessage().catch(...) 调用 this.seenMessages.delete(msgId),注释为 "Allow Feishu retries by removing the dedup entry on failure"),而它只断言了 seenMessages.has('inbound-file') 为 false。只检查一个键,不足以区分按范围的 delete(msgId) 和清空整个 map 的 clear()。
把 delete(msgId) 换成 clear()——这是一个看起来很合理的简化——整个包测试套件依然全绿,实测 323/323,与基线逐字节一致。与此同时,FeishuAdapter.ts:2604 的去重门(if (this.seenMessages.has(msgId)) return;)开始遗忘所有其他在途消息。两条消息可以同时处于在途状态——本次改动里的 keeps two messages with the same filename in separate directories 正是这种场景——所以当其中一条分发被拒绝时,另一条消息的飞书 webhook 重试或重复投递不再被去重,会被第二次处理:为用户只发送过一次的消息产生重复的卡片会话和重复的 bridge.prompt 智能体运行。既有的 TTL 清扫测试也抓不到它,因为该测试只是塞入 msg_old,并没有任何分发拒绝,所以 clear() 在那里根本不会触发。
上面的四组对照是在隔离探针树中执行的:MUTANT 组(改成 clear())323/323 全绿存活;CONTROL 组(移除回滚)让该用例准确变红(1 failed | 184 passed),这正说明存活是有意义的而非空洞的——catch 处理确实被执行,该用例确实在守护这次回滚;FIX 组(按建议加入第二条并发消息)在原始代码下通过;FIX+MUTANT 组失败于 AssertionError: expected false to be true。变异之所以能存活,恰恰是因为断言只检查一个键——catch 触发时 map 里只有 'inbound-file',所以 delete(msgId) 和 clear() 留下的可观察状态完全相同。
建议扩展该用例(或新增一个兄弟用例),加入第二条并发消息且其分发成功,然后断言回滚是按范围而非全量的:保留 expect(seenMessages.has('inbound-file')).toBe(false),并增加 expect(seenMessages.has('inbound-file-2')).toBe(true)。驱动方式可以照 :1107 的 keeps two messages with the same filename in separate directories 来做——receive('report.txt', 'inbound-file-2') 加上放宽为两个 URL 的 fetchSpy 守卫(接受 resourceUrl.replace('/inbound-file/', '/inbound-file-2/'))——并且通过信封自身的 message id 来决定哪一次分发被拒绝,而不是依赖 mockResolvedValueOnce 的顺序,因为两条 processMessage 链是各自独立结束的。
回滚必须保持按消息粒度,且不能干扰 TTL 清扫:FeishuAdapter.ts:336-338(for (const [id, ts] of this.seenMessages) { ... this.seenMessages.delete(id); })是另一个独立的删除点,其测试位于 adapter.test.ts:3014-3024,塞入 msg_old 并断言只有 msg_old 被清扫。加入第二条消息的断言后,把 FeishuAdapter.ts:2842 的 this.seenMessages.delete(msgId) 变异为 this.seenMessages.clear() 必须让 cleans up after dispatch rejects 变红——评审过程中已实际执行该变异,结果为 AssertionError: expected false to be true。
— qwen3.8-max via Qwen Code /review (v0.25.3)
There was a problem hiding this comment.
[Suggestion] R7-2: [probe] Still stands — re-checked at head d0d79c86: the code at this anchor is byte-identical to what round 7 reviewed, and this round's test-coverage and persona agents re-confirmed that the single-key assertion is unchanged and still the rollback's only guard. cleans up after dispatch rejects is the only test guarding the per-message dedup rollback at FeishuAdapter.ts:2842 (processMessage().catch(...) → this.seenMessages.delete(msgId), "Allow Feishu retries by removing the dedup entry on failure"), and it asserts only that seenMessages.has('inbound-file') is false — inspecting one key cannot tell the scoped delete(msgId) apart from a whole-map clear().
Replacing delete(msgId) with clear() — a plausible simplification — keeps the entire package suite green (measured 323/323, byte-identical to baseline) while the dedup gate at FeishuAdapter.ts:2604 starts forgetting every other in-flight message. Two messages can be in flight at once — this same diff drives exactly that at :1106 — so when one dispatch rejects, a Feishu webhook retry or duplicate delivery of the other message is no longer deduped and is processed a second time: a duplicate card session and a duplicate bridge.prompt agent run for a message the user sent once. The TTL-sweep test does not catch it either: it seeds msg_old with no dispatch rejection, so clear() never fires there.
Witness (round-7 probe — four arms in an isolated tree, baseline proven green first; anchor code unchanged since):
MUTANT this.seenMessages.clear() at FeishuAdapter.ts:2842
-> Test Files 6 passed (6) / Tests 323 passed (323)
SURVIVED — byte-identical to baseline
CONTROL rollback removed (void 0)
-> 1 failed | 184 passed (185) — 'cleans up after dispatch rejects' red
FIX second concurrent message added as suggested, pristine source
-> 1 passed
FIX+MUTANT -> AssertionError: expected false to be true
The fix in the root comment stands: extend this case (or add a sibling) with a second concurrent message whose dispatch succeeds, keep expect(seenMessages.has('inbound-file')).toBe(false) and add expect(seenMessages.has('inbound-file-2')).toBe(true), driven the way the two-message test at :1106 already does — receive('report.txt', 'inbound-file-2') plus the widened two-URL fetchSpy guard — selecting which dispatch rejects via the envelope's own message id rather than mockResolvedValueOnce ordering, since the two processMessage chains settle independently. The rollback must stay per-message and must not disturb the TTL sweep: FeishuAdapter.ts:336-338 (for (const [id, ts] of this.seenMessages) { ... this.seenMessages.delete(id); }) is a separate deletion site, and its existing test seeds msg_old and asserts only msg_old is swept. As the acceptance criterion, with the second-message assertion in place, mutating this.seenMessages.delete(msgId) to this.seenMessages.clear() at FeishuAdapter.ts:2842 must turn cleans up after dispatch rejects red — executed during round 7: AssertionError: expected false to be true.
中文说明
R7-2 仍然成立 —— 已在 head d0d79c86 重新核查:锚点处代码与第 7 轮审查时逐字节一致,本轮测试覆盖与对抗视角 agent 再次确认单键断言未变、且仍是该回滚的唯一守护。cleans up after dispatch rejects 是唯一守护 FeishuAdapter.ts:2842 处按消息粒度去重回滚的用例(processMessage().catch(...) 调用 this.seenMessages.delete(msgId),注释为 "Allow Feishu retries by removing the dedup entry on failure"),而它只断言 seenMessages.has('inbound-file') 为 false —— 只检查一个键,不足以区分按范围的 delete(msgId) 和清空整个 map 的 clear()。
把 delete(msgId) 换成 clear()(一个看起来很合理的简化)会让整个包套件保持全绿(实测 323/323,与基线逐字节一致),而 FeishuAdapter.ts:2604 的去重门开始遗忘所有其他在途消息。两条消息可以同时处于在途状态 —— 本次改动在 :1106 正是这种场景 —— 所以当其中一条分发被拒绝时,另一条消息的飞书 webhook 重试或重复投递不再被去重,会被第二次处理:为用户只发送过一次的消息产生重复的卡片会话和重复的 bridge.prompt 智能体运行。TTL 清扫测试也抓不到它:该测试只是塞入 msg_old,没有任何分发拒绝,clear() 在那里根本不会触发。
证据(第 7 轮探针 —— 隔离树中四组对照,基线先证全绿;锚点代码自那以后未变):MUTANT 组(改成 clear())323/323 全绿存活,与基线逐字节一致;CONTROL 组(移除回滚)让该用例准确变红(1 failed | 184 passed);FIX 组(按建议加入第二条并发消息)在原始代码下通过;FIX+MUTANT 组失败于 AssertionError: expected false to be true。
修复建议与主评论一致:扩展该用例(或新增兄弟用例),加入第二条并发消息且其分发成功;保留 expect(seenMessages.has('inbound-file')).toBe(false),并增加 expect(seenMessages.has('inbound-file-2')).toBe(true);驱动方式照 :1106 的两条消息用例来做 —— receive('report.txt', 'inbound-file-2') 加放宽为两个 URL 的 fetchSpy 守卫 —— 并通过信封自身的 message id 决定哪一次分发被拒绝,而不是依赖 mockResolvedValueOnce 顺序,因为两条 processMessage 链各自独立结束。回滚必须保持按消息粒度,且不能干扰 TTL 清扫:FeishuAdapter.ts:336-338 是另一个独立的删除点,其现有测试塞入 msg_old 并断言只有 msg_old 被清扫。验收标准:加入第二条消息断言后,把 FeishuAdapter.ts:2842 的 delete(msgId) 变异为 clear() 必须让 cleans up after dispatch rejects 变红 —— 第 7 轮已实际执行该变异,结果为 AssertionError: expected false to be true。
— qwen3.8-max via Qwen Code /review (v0.26.0)
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
Partially reviewed — gaps disclosed.
3 Suggestion-level finding(s) this review confirmed are already reported on this PR and are not repeated:
- download-failure placeholder asymmetry pinned by the new fallback tests — already recorded in the round-5 deferral list (review 5563001857) and ruled non-blocking as the P3 observation of @yiliang114's approval review (review 5574640650)
- resource-401 coverage lost in the mediaStatus 401→403 relabel — already reported as R2-1 (comment 4209707769), reproduced by the author and tracked in #13845
- collect-mode retention/drain gap behind the dispatch-settlement lifetime test — already ruled fixed as R1-2 (comment 4201108295); collect-mode deletion tracked in #11554
Not reviewed: build-and-test — Test (macos-latest, Node 22.x) and Test (windows-latest, Node 22.x) were skipped in CI at this head; the package suite ran green on Linux only (Agent 7's scoped local run, 323 passed).
Not explored to full depth (tool budget reached): "agent 1d": none — no check was cut short..
Not reviewed: reverse audit — stopped before round 1 by the review time budget.
Deferred under the convergence posture (round 8, not a blocker) — recorded, not requested in this round:
packages/channels/feishu/src/adapter.test.ts:1054 — [review] D8-1: sender-denial test has no positive witness that the sender gate dropped the event
中文说明
仅完成部分审查,审查缺口已披露。
本轮确认的 3 条建议级发现已在 PR 上报告过,不再重复发布(列表见上方英文部分)。
未审查(原文为英文):build-and-test — Test (macos-latest, Node 22.x) and Test (windows-latest, Node 22.x) were skipped in CI at this head; the package suite ran green on Linux only (Agent 7's scoped local run, 323 passed).
未探索到全部深度(达到工具调用预算):"agent 1d":none — no check was cut short.。
未审查:反向审计——评审时间预算不足,未能开始第 1 轮。
收敛姿态下延后(第 8 轮,非阻断)——已记录,本轮不要求修改:共 1 条(原文未翻译,列表见上方英文部分)。
— qwen3.8-max via Qwen Code /review (v0.26.0)
|
I have tracked the remaining R7-1/R7-2 suggestions in #15271: fixture ownership and a two-message dedup rollback regression. After eight review rounds, I am deferring these non-blocking test improvements in line with the repository guidance and keeping this PR coverage-only. The current rollback remains scoped to the failed message; no production behavior is being changed here. |
Local verification — macOS arm64 (test-only PR)Verdict: no blocking issues found in local verification. This PR changes one test file and no production code. On macOS the Feishu package is green on both arms, the +12 delta is exactly the new tests, and all 13 production mutations I injected were killed by the intended assertion — the new tests are load-bearing rather than merely passing. Verified at head Scope and A/B
CI runs only Mutation matrix — 13/13 killedFor every behavior the new tests name, I broke the production path and ran only the 12 new tests. Each mutant run collected exactly 12 tests, the unmutated control is 12/12 green, and every red landed on the intended assertion.
The non-obvious pins are M5 (timer starts at the wrong boundary), M7 (dedup rollback), M9 (auth failure must stay non-fatal) and M13 (no side effects for a rejected sender). Those are the behaviors most likely to regress silently, and each is now tied to a failure. Stability and static gates
Non-blocking notes
ReproduceTwo detached worktrees, each bootstrapped with 中文摘要(点击展开)结论:本地验证未发现阻塞问题。 本 PR 只改一个测试文件,生产代码零改动。macOS arm64 实测 base 311 项、head 323 项,全部通过,差值正好是新增的 12 个用例。 证据
非阻塞
复现:两个 worktree 各自 |
|
Thanks for the thorough macOS checks and mutation tests, and for merging this! |
|
Released in v0.26.1. |




What this PR does
I added inbound-file dispatch coverage for file and media envelopes, stored bytes and MIME types, text fallbacks, same-name isolation, cleanup after dispatch settlement, stop during download, and rejected dispatch. Production behavior is unchanged.
Auth HTTP 401, HTTP 500 and network failure must deliver one text fallback without calling media download. The separate resource-403 case now requires the exact resource GET, a media-download call with the cached token, and the HTTP403 diagnostic. A missing token can no longer make that test pass without downloading. A disallowed sender must cause no download, dispatch or storage.
Why it's needed
This is the coverage-only follow-up agreed in #13220 after #13170. Local-write cleanup was fixed independently in merged #13337. I removed the duplicate filename-sanitizer table and cleanup-boundary assertions now owned by that fix's storage tests, while keeping dispatch-lifetime coverage here.
Reviewer Test Plan
How to verify
Check that file and media messages dispatch the expected envelope and real stored bytes in owned temporary directories. Failed authentication and resource downloads should produce their respective text fallbacks without attachments. Rejecting a sender must have no file side effects. A downloaded file must survive until mocked dispatch settles; stop and rejected dispatch must preserve cleanup ownership. These checks do not establish real collect-mode retention.
Evidence
October19,
47875528aa9e0a70ae77c2b2b21f3726f750d4f7: frozen pnpm installation, full repository build, lint, typecheck and CLI bundle passed locally. The complete Feishu package passed 321 tests across six files, with two existing POSIX-permission tests skipped on Windows and no failures. Formatting and two full-diff audit passes passed, followed by independent review.The regression check removed the cached-token seed: the old resource-failure assertions still passed while only authentication ran, but the strengthened test fails because the required media download never occurs. The intact case passes. Production source was not changed for this probe. Fresh upstream CI and renewed maintainer review are still required.
Tested on
Network and dispatch are mocked; filesystem reads/writes are real and confined to owned temporary directories. Timers are controlled. No live Feishu or model calls were made.
Risk & Scope
No production behavior, dependency, interface or migration changes. Live Feishu, downstream prompt construction, real collect-mode retention (#11554), resource-401 renewal policy (#13845), size caps and permission hardening remain separate work. The duplicate-coverage and missing-download-witness review comments are addressed in this revision.
Linked Issues
Closes #13220. Follows #13170. Separate defects: #11554 and #13845; write-failure cleanup landed in #13337.
中文说明
我补充了 file/media 入站消息的分发封装、文件字节与 MIME、文本回退、同名隔离、分发结束后清理、下载期间停止及分发拒绝测试。生产行为不变。这是 #13170 后在 #13220 中约定的仅测试工作;写入失败清理已在 #13337 独立合并。
认证 401、500 和网络失败须保留文本回退且不调用媒体下载。资源 403 用例现要求准确的资源 GET、带缓存 token 的下载调用及 HTTP403 诊断,缺少 token 不再能产生假阳性。拒绝的发送者不应触发下载、分发或存储。文件名表与 59,999/60,000 ms 边界由已有存储测试负责,不在此重复;这里保留分发结束前文件仍存在、停止及拒绝后清理的独立行为。
评审时请检查真实字节与封装、各失败分支不带附件、拒绝发送者没有副作用,以及模拟分发结束前保留文件。此处不证明真实 collect 模式的文件保留。
10月19日
47875528aa9e0a70ae77c2b2b21f3726f750d4f7:Windows 本地冻结安装、全仓 build/lint/typecheck/bundle 通过;六个文件 321 项通过、两个既有 POSIX 权限用例跳过、零失败。格式、两次完整 diff 自查及独立审查完成。去掉缓存 token 后,旧断言仍通过且只触发认证;强化后的测试因未调用媒体下载而失败,完整代码则通过。探针未修改生产代码。此前 Linux 上游版本的 326 项无跳过结果是历史记录,当前版本仍待新 CI 和维护者复审;macOS 未本地测试。网络和分发使用 mock,文件系统读写真实且限制在自有临时目录,计时器受控。未调用真实飞书或模型。没有生产行为、依赖、接口或迁移修改。真实 collect 保留(#11554)、资源 401 续期(#13845)、大小上限及权限加固仍独立处理。