fix(serve): validate readText line limits#5639
Conversation
|
@qwen-code /triage |
Verification report — real-execution A/BI checked out this branch and exercised the real TL;DR: verified correct, consistent with the existing Method
Results1. A/B on a real 5-line file (
Base degrades into 4 different behaviors (all / empty / truncated / newline-dropping) depending on the bad value — the PR makes all of them a consistent 2. The test is load-bearing. Reverting the 9-line check makes the PR's own new test fail ( 3. Reachability — the check is correctly scoped as service-boundary defense-in-depth. All external entry points already validate
The new guard protects direct/internal service callers (the scenario the PR body calls out), which is exactly what the new unit test exercises. 4. No regression for the one internal 5. Consistency. The new block mirrors the existing VerdictApprove. Correct, minimal, well-tested, no regression, no external behavior change, and consistent with the established pattern. The only nit (optional): the new 中文版(点击展开)验证报告 — 真实执行 A/B我检出本分支,针对真实临时文件驱动了真实的 结论:校验正确、与现有 方法
结果1. 真实 5 行文件(
Base 会根据非法值退化成 4 种不同行为(全部 / 空 / 截断 / 丢换行);PR 把它们统一为 2. 测试是有效的(load-bearing)。 移除那 9 行校验后,PR 自己的新测试会失败( 3. 可达性——该校验作为「服务边界纵深防御」定位准确。 所有外部入口在调用
新校验保护的是直接/内部服务调用方(正是 PR 描述里点名的场景),也正是新单测覆盖的路径。 4. 对唯一一个内部 5. 一致性。 新代码块与现有 结论建议合并(Approve)。 正确、最小、测试充分、无回归、无外部行为变化,且与既有模式一致。唯一可选的小点:新 |
|
Thanks for the PR! Template looks good ✓ — all required sections present and filled in. On direction: this is a clean defensive-boundary fix. Issue #5623 identifies a real inconsistency — On approach: the scope is minimal — 9 lines of validation mirroring the existing Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ — 所有必填部分均已填写。 方向:这是一个干净的服务边界防御修复。Issue #5623 指出了一个真实的不一致 — 方案:范围最小化 — 9 行校验代码逐字镜像现有 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
Code ReviewIndependent proposal: Given the issue — Comparison with diff: the PR does exactly this. The guard is a verbatim mirror of the Correctness: sound. Reuse check: the Test quality: good. The test iterates all 7 bad values from the issue and asserts both No blockers found. Test ResultsUnit tests (run from worktree on PR branch): Typecheck: CI status: all green — Test (windows, macos, ubuntu Node 22.x), Lint, CodeQL, Integration Tests (No-AK Smoke), Classify PR all pass. Real-Scenario TestingN/A — this is a non-user-visible service-boundary validation. The change is internal API contract enforcement; there is no CLI behavior to exercise via tmux. The unit tests drive the real 中文说明代码审查独立方案: 针对该问题 — 与 diff 对比: PR 正是这么做的。守卫逐字镜像 正确性: 可靠。 复用检查: 上方的 测试质量: 良好。测试遍历了 issue 中所有 7 个非法值,并断言了 无阻塞问题。 测试结果单元测试(在 worktree 的 PR 分支上运行):76/76 通过。 类型检查: CI 状态: 全绿。 真实场景测试N/A — 这是非用户可见的服务边界校验。变更是内部 API 契约执行,没有可通过 tmux 测试的 CLI 行为。单元测试已经驱动了真实的 — Qwen Code · qwen3.7-max |
Final DecisionThis PR is exactly what it claims to be: a 9-line service-boundary guard that makes Going back to my independent proposal from Stage 2 — the PR matches it exactly. I can't find a simpler path. The implementation mirrors the existing pattern verbatim, lives in the right place (same The only question worth asking is whether to extract a shared 76/76 tests pass, typecheck clean, CI all green across Windows, macOS, and Linux. The collaborator verification report (A/B testing on real files) independently confirmed the same findings. Approving. ✅ 中文说明最终决定这个 PR 正是它所声称的:一个 9 行的服务边界守卫,使 回到我在第二阶段的独立方案 — PR 与之完全一致。我找不到更简单的路径。实现逐字镜像了现有模式,放在正确的位置(同一个 唯一值得讨论的是是否提取一个共享的 76/76 测试通过,类型检查干净,CI 在 Windows、macOS 和 Linux 上全绿。协作者的验证报告(真实文件 A/B 测试)也独立确认了相同的发现。 通过。 ✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
What this PR does
Rejects invalid
readTextlimitvalues at theWorkspaceFileSystemboundary, matching the existing validation forline. Whenlimitis provided, it must now be a positive safe integer;0, negatives, fractions,NaN, infinities, and unsafe integers returnparse_error.Why it's needed
readTextalready documents and enforceslineas a positive integer, butlimitcould still reach the lower-level slicing logic unchecked when called directly from the filesystem service. That made the shared boundary less predictable for internal callers and left edge cases such asInfinity,NaN, floats, and unsafe integers to degrade into implementation-specific truncation behavior.Reviewer Test Plan
How to verify
Confirm that
WorkspaceFileSystem.readTextrejects invalidopts.limitvalues withparse_error, while the existingopts.linebehavior remains covered by the same test file.Commands run locally:
Evidence (Before & After)
Before:
readText(r, { limit: bad })accepted invalidlimitvalues at the service boundary and passed them to the lower-level read/slice path. After: invalidlimitvalues return anFsErrorwithkind === 'parse_error'. This is covered by the new unit test forInfinity,-Infinity,Number.MAX_SAFE_INTEGER + 1,0,-1,1.5, andNaN.Tested on
Environment (optional)
Local macOS arm64, Node.js v26.3.0.
Risk & Scope
limitinputs at the shared filesystem service boundary and mirrors existinglinevalidation.limitvalues now receiveparse_errorinstead of undefined slicing behavior.Linked Issues
Fixes #5623
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.
中文说明
What this PR does
这个 PR 在
WorkspaceFileSystem边界拒绝非法的readTextlimit值,和现有的line校验保持一致。现在只要传入limit,它就必须是正的安全整数;0、负数、小数、NaN、正负无穷以及不安全整数都会返回parse_error。Why it's needed
readText已经把line记录并校验为正整数,但直接从文件系统服务调用时,limit仍然可以绕过校验进入更底层的切片逻辑。这会让共享边界对内部调用方不够可预测,也会让Infinity、NaN、小数和不安全整数这类边界值退化成依赖实现细节的截断行为。Reviewer Test Plan
How to verify
确认
WorkspaceFileSystem.readText会对非法的opts.limit返回parse_error,同时现有的opts.line行为仍由同一个测试文件覆盖。本地运行过的命令:
Evidence (Before & After)
修复前:
readText(r, { limit: bad })会在服务边界接受非法的limit值,并继续传给更底层的读取和切片路径。修复后:非法的limit值会返回kind === 'parse_error'的FsError。新增单元测试覆盖了Infinity、-Infinity、Number.MAX_SAFE_INTEGER + 1、0、-1、1.5和NaN。Tested on
Environment (optional)
本地环境为 macOS arm64,Node.js v26.3.0。
Risk & Scope
limit输入,并与现有line校验保持一致。limit的内部调用方现在会收到parse_error,而不是进入未定义的切片行为。Linked Issues
Fixes #5623
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.