Repository navigation
test(serve): share clamp fixture and pin socket pruning - #17841
Conversation
- Share the pairing-listener clamp drive and harmonize its assertions. - Pin pruning of normally closed sockets through the existing shutdown and disable sweeps.
|
✅ Qwen Triage finished — CI landed green on ✅ Qwen Triage 已完成 —— |
|
Thanks for the PR! Template looks good ✓ — all sections present, including the Chinese translation and an honest "Tested on" matrix. Problem: observed, not theoretical. This is the test-coverage gap recorded in #17781 (items 1–2), filed by a maintainer from the #17737 review: the two clamp drives had drifted (67 of 87 lines identical), and neither socket tracker's delete-on-close half had a pin — removing it would leak one retained entry per connection with every test still green. The PR's mutation controls demonstrate exactly that failure mode. Direction: aligned — this is deferred review debt being paid down, requested by the issue itself. No CHANGELOG signal needed for a test-only change. Scope is honest: item 3 ( Size: test-only — 0 production lines, 252 test lines (+139/−113) across 3 files, no generated/schema changes. No core paths touched, no maintainer escalation needed. Approach: the scope feels right. One listener-kind-parameterized fixture replaces the two drifted copies (net −67 lines in Risk: no elevated risk signals — all changed files are tests, and the production consumers are byte-for-byte unchanged. Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ —— 各节齐全,含中文翻译与如实标注的测试平台矩阵。 问题:已观测,非理论性。这是 #17781(第 1–2 项)记录的测试覆盖缺口,由维护者从 #17737 评审中立 issue:两份钳制驱动已漂移(87 行中 67 行相同),且两个 socket 跟踪器的 close 剪枝半都没有钉——删掉它会每连接泄漏一项而所有测试仍绿。PR 的变异对照正好演示了这一失败模式。 方向:对齐——这是按 issue 要求偿还的评审延后项。仅测试变更无需 CHANGELOG 信号。范围诚实:第 3 项( 规模:仅测试——0 行生产代码,3 个文件共 252 行测试(+139/−113),无生成/schema 改动。未触及核心路径,无需维护者升级。 方案:范围合理。一个按 listener kind 参数化的夹具取代两份漂移副本( 风险:无升级风险信号——改动文件均为测试,生产消费者逐字节不变。 进入代码审查 🔍 — Qwen Code · qwen4-max Reviewed at |
|
Code review — no blockers. I checked the new pins against the production code they observe, and the oracles hold:
Not verified: the mutation controls are the author's claim, not independently re-run — triage never executes PR code. Static review above confirms the oracles discriminate, but a green suite alone proves the pins pass, not that they fail when the production delete is removed. Also not verified: Windows/Linux behavior — the author ran macOS only, and CI's Windows/macOS unit matrices are skipped for this PR, so the new real-socket pins get Linux CI coverage. Sandboxed verification would settle this: CI evidence (fetched once at review time; the finalize workflow updates the table below when CI settles): 40 check runs on the reviewed commit — 8 success, 22 skipped, 9 in progress, 1 waiting, zero failures. The checks that matter most here (Lint & Static, the Linux unit-test tree, Serve A/B) are still running, so the suites that actually execute these tests have not reported yet. The Windows/macOS matrices and integration lanes are skipped, not failed. Final CI results for
One row per check name (latest run); skipped checks omitted; failures sort first. / 每个检查名一行(取最新一次运行),省略 skipped,失败项排在最前。 Real-scenario testing: N/A — test-only change, no CLI/TUI/Web UI/wire surface touched; the production consumers are unchanged. 中文说明代码审查——无阻断项。我把新钉与其观察的生产代码逐一核对,oracle 成立:
未验证:变异对照是作者自述,未独立重跑——triage 从不执行 PR 代码。上述静态审查确认 oracle 有判别力,但绿套件只证明钉通过,不证明移除生产删除语句后钉会失败。另未验证:Windows/Linux 行为——作者仅在 macOS 运行,且本 PR 的 CI Windows/macOS 单元矩阵被跳过,新真实 socket 钉只有 Linux CI 覆盖。 沙箱验证可以补齐: CI 证据(审查时一次性拉取,CI 落定后由 finalize 工作流更新下表):审查提交上共 40 个 check——8 成功、22 跳过、9 进行中、1 等待,零失败。最关键的检查(Lint & Static、Linux 单元测试树、Serve A/B)仍在运行,真正执行这些测试的套件尚未出结果。Windows/macOS 矩阵与集成通道为 CI 跳过,并非失败。 真实场景测试:N/A——仅测试变更,未触及 CLI/TUI/Web UI/线路表面,生产消费者不变。 — Qwen Code · qwen4-max Reviewed at |
|
Confidence: 4/5 — clean test-only change that does exactly what the maintainer-filed issue asked; the two open items are procedural (CI still landing) and the author-reported mutation evidence, not doubts about the code. Stepping back: my independent proposal before reading the diff was "one kind-parameterized clamp helper plus two close-then-sweep pins that spy on the closed socket's destroy" — the PR is precisely that, and it goes slightly further by strengthening the remote-access variant's assertions to match the pairing copy. The pins observe pruning through the real consumers rather than exposing tracker internals, which is the harder but more durable choice the issue explicitly preferred. Net −67 lines in the clamp section, honest scope (item 3 deferred, issue referenced not closed), and teardown that is explicit and bounded. In six months this is the fixture I would want to extend, not curse. Non-blocking notes, for the record: the mutation-discrimination claim rests on the author's controls plus my static confirmation of the oracles — Verdict: approve. Five PR CI workflow runs are still in flight on 中文说明置信度:4/5——干净的仅测试变更,完全按维护者所立 issue 的要求执行;两个未决项是程序性的(CI 尚未落定)与作者自述的变异证据,而非对代码的疑虑。 回顾:读 diff 前我的独立方案是"一个按 kind 参数化的钳制 helper,加两个先关闭再扫描、对已关闭 socket 的 destroy 做 spy 的钉"——PR 正是如此,且更进一步把 remote-access 变体的断言强化到与配对副本一致。新钉通过真实消费者观察剪枝而非暴露跟踪器内部,这是 issue 明确倾向的更难但更耐久的选择。钳制段净 −67 行,范围诚实(第 3 项延后,issue 只引用不关闭),清理显式且有界。半年后这是我会愿意扩展而非抱怨的夹具。 非阻断记录:变异判别力的结论依赖作者的对照实验加我对 oracle 的静态确认——如需独立验证可用 结论:批准。该提交上仍有 5 个 PR CI 工作流在运行,批准延后至 CI 在该提交上全绿——finalize 工作流会自动提交绑定该提交的批准;若有检查变红或 head 移动则不予批准。 — Qwen Code · qwen4-max Reviewed at |
🩺 serve daemon A/BBuilt the PR base vs this PR head
|
| field | PR base (before) | this PR (after) |
|---|---|---|
activeWorkStaleMs |
80 |
78 |
— Qwen Code · serve A/B
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship — CI landed green after the review. ✅
chiga0
left a comment
There was a problem hiding this comment.
Code review — approved
Scope: the three test files at ddb92f1 (base 933497a). Production consumers are untouched — the diff is 0 production lines.
Checked (both oracles against the production code they observe)
serve-app-lifecycle.ts:77-79adds on'connection'and prunes viasocket.once('close', …);forceCloseConnections()destroys every tracked survivor first thing in the sweep (closeAllConnections()+ unconditionaldestroy()), so a retained-but-closed socket is observable only as an extradestroy()call. Same shape inlocal-control/service.ts:274-276/close()at 553-561. The production prune listener registers at connection time, i.e. before the test's close-resolve listener, so "closed" and "pruned" cannot race.- Shared fixture is equivalent for both kinds: both helpers return
handle/lanBase/lanAuth/restore,handle.server.address()is the same port the remote fixture used to return asprimaryPort, andawait pair.restore()covers the async pairing restore and the sync remote one. The unified drive is stricter forremote-access: full per-listener occupancy map, limits map and plain/healthwere previously asserted only in the pairing copy. byListeneris aRecord<ListenerKind, number>initialised with all three keys (sse-occupancy.ts:52-57), andmaxSseConnectionsPerListenercomes fromsseListenerCapsForStatus(opts), which is kind-independent — so the exact-equality assertions are safe in both modes.
Ran (Node 22, standalone replication of the tracker + force-close sweep, since no repo checkout exists here — the vitest suites themselves were not executed): with prune-on-close, 0 extra destroy() calls on the already-closed socket; with the delete line withheld, 1. The probe discriminates, which is the property the two new pins rely on.
No blocking findings. Approval blockers: none.
Not covered: the author's vitest runs and mutation controls were not re-executed here; Windows/Linux local runs remain untested (macOS only per the PR). One non-blocking nit at most — in the new service.test.ts case service.enable()/first connect sit just outside the try, so a connect failure would leave the listener enabled for the rest of the file; low impact and consistent with the file's other failure-only paths, so I am not asking for a change.
Cross-check: the prior qwen-code-review-bot review reaches the same conclusions; nothing in it that I missed. Its one open caveat — that mutation discrimination is the author's claim — is narrowed here to the mechanism level by the probe above. Its note that Windows/macOS matrices were skipped stands.
Reviewed with AI assistance.
|
|
What this PR does
This test-only change removes the duplicated Local Control / remote-access clamp drive and adds the missing delete-on-close coverage requested by items 1–2 of #17781.
There are no production-code, wire-protocol, CLI, TUI, or Web UI changes.
Why it's needed
The two clamp tests had drifted in both assertions and teardown, making future listener fixes easy to apply inconsistently. Both socket trackers already destroyed surviving connections at shutdown, but neither test suite proved that a normally closed connection left its tracker; removing the
close-handler deletion therefore leaked one retained entry per connection without failing any pin.Reviewer Test Plan
How to verify
Run from
packages/cliunless noted otherwise:npx vitest run src/serve/serve-app-lifecycle.test.ts src/serve/local-control/service.test.ts --coverage.enabled=false— 41 tests passed.npx vitest run src/serve/server.test.ts --coverage.enabled=false -t 'Unified SSE admission/occupancy'— 13 tests passed, including both migrated clamp cases.npx prettier --check packages/cli/src/serve/server.test.ts packages/cli/src/serve/serve-app-lifecycle.test.ts packages/cli/src/serve/local-control/service.test.tsandnpx eslint packages/cli/src/serve/server.test.ts packages/cli/src/serve/serve-app-lifecycle.test.ts packages/cli/src/serve/local-control/service.test.ts --max-warnings 0— both passed.NODE_OPTIONS='--max-old-space-size=6144' npm run build --workspace @qwen-code/qwen-codeandNODE_OPTIONS='--max-old-space-size=6144' npm run typecheck --workspace @qwen-code/qwen-code— both passed.this.openSockets.delete(socket)andsockets.delete(socket)from their respective socketclosehandlers made each new pruning test fail with one unexpecteddestroycall on the already-closed socket; restoring the production files restored the green focused tests.The full
server.test.tsfile was also run twice. The final run passed 1,514 of 1,518 tests but retained four unrelated failures: two idempotency-ring cases, one session-organization error case, and one#17502cleanup-hook timeout. The#17502case passed when rerun in the smaller isolated selection; the other three hit their explicit long-suite timeouts when grouped in that selection. Neither clamp case failed in this final full run, and the complete 13-test unified section passes independently.Pre-push self-review: separate read-only correctness/test-integrity and simplicity passes both returned no findings. Local CI review-gate: UNVERIFIED. The full
qwen review runattempt returnedcompleted: falseafter 773,695 ms with no composed report; a bounded diagnostic timed out without a verdict, the wrapper rejected the direct--auth-typealignment flag, and a final configured-provider attempt was stopped before producing a verdict. These attempts do not provide a CI-engine approval and are not presented as one.Evidence (Before & After)
N/A — this is a test-only refactor and coverage change. UI verification: N/A because there is no changed reachable user surface to exercise: the inspected
runQwenServe/LocalControlServiceconsumers remain byte-for-byte unchanged in the candidate, and the new checks observe those existing paths through Vitest rather than changing CLI, TUI, Web UI, API, or wire behavior.Mutation evidence is discriminating rather than coverage-only: each new pin fails only after its corresponding production delete-on-close statement is removed.
Tested on
Environment (optional)
Node.js v22.23.4 on macOS, using repository workspace dependencies and built workspace prerequisites. Runtime/TUI verification N/A for the test-only reason above.
Risk & Scope
waitForClosingListener()upgraded-socket item and the thread's drain-dispose discussion are unchanged, so this PR references rather than auto-closes the issue.Linked Issues
Refs #17781. Follows #17737.
中文说明
这个 PR 做了什么
这个仅测试变更按 #17781 第 1–2 项要求,移除 Local Control / remote-access 钳制驱动的重复实现,并补上缺失的 close 删除覆盖。
没有生产代码、线路协议、CLI、TUI 或 Web UI 变更。
为什么需要
两份钳制测试的断言与清理逻辑已经漂移,后续 listener 修复很容易只应用到一份。两个 socket tracker 都会在 shutdown 时销毁幸存连接,但此前没有任何测试证明正常关闭的连接会离开 tracker;因此删除
close处理器中的删除语句会让每个连接永久多保留一项,而现有测试仍会通过。评审测试计划
如何验证
除非另有说明,均在
packages/cli下运行:npx vitest run src/serve/serve-app-lifecycle.test.ts src/serve/local-control/service.test.ts --coverage.enabled=false——41 项测试通过。npx vitest run src/serve/server.test.ts --coverage.enabled=false -t 'Unified SSE admission/occupancy'——13 项测试通过,包括迁移后的两个钳制用例。npx prettier --check packages/cli/src/serve/server.test.ts packages/cli/src/serve/serve-app-lifecycle.test.ts packages/cli/src/serve/local-control/service.test.ts与npx eslint packages/cli/src/serve/server.test.ts packages/cli/src/serve/serve-app-lifecycle.test.ts packages/cli/src/serve/local-control/service.test.ts --max-warnings 0——均通过。NODE_OPTIONS='--max-old-space-size=6144' npm run build --workspace @qwen-code/qwen-code与NODE_OPTIONS='--max-old-space-size=6144' npm run typecheck --workspace @qwen-code/qwen-code——均通过。close处理器中临时删除this.openSockets.delete(socket)与sockets.delete(socket),两个新剪枝用例均按预期失败,并各自观察到对已关闭 socket 的一次意外destroy调用;恢复生产文件后,聚焦测试恢复通过。完整
server.test.ts文件也运行了两次。最后一轮 1,518 项测试中 1,514 项通过,仍有四个无关失败:两个幂等环用例、一个会话组织错误用例,以及一个#17502清理 hook 超时。#17502用例在更小的隔离选择中重跑通过;另外三个在该选择中一起运行时达到了各自显式的长套件超时。最后一轮完整运行中两个钳制用例均未失败,完整的 13 项 unified section 独立运行通过。推送前自审:独立的只读正确性/测试完整性检查与简洁性检查均未发现问题。本地 CI review-gate:UNVERIFIED(未验证)。 完整的
qwen review run尝试在 773,695 ms 后返回completed: false,没有 composed 报告;有界诊断运行超时且没有 verdict;wrapper 拒绝了直接对齐的--auth-type参数;最后一轮使用已配置 provider 的尝试在产生 verdict 前停止。这些尝试不构成 CI 引擎批准,本文也不将其表述为批准。证据(前后对比)
N/A——这是仅测试的重构与覆盖变更。UI 验证:N/A,因为没有已改变的可达用户表面可供验证:候选中的
runQwenServe/LocalControlService消费者保持逐字节不变,新检查通过 Vitest 观察这些现有路径,未改变 CLI、TUI、Web UI、API 或线路行为。变异证据具有判别力,而非只提供行覆盖:每个新用例仅在对应生产 close 删除语句被移除后失败。
测试平台
环境(可选)
macOS 上的 Node.js v22.23.4,使用仓库 workspace 依赖与已构建的 workspace 前置产物。运行时/TUI 验证因上述仅测试原因 N/A。
风险与范围
waitForClosingListener()已升级 socket 项与讨论串中的 drain-dispose 讨论均未改变,因此本 PR 只引用 issue,不自动关闭它。关联 Issue
Refs #17781。承接 #17737。