fix(drive): --latest 扫描不完整时拒绝产出 Top-N 并杜绝 sortTime 泄露 - #899
Open
haofeng0705 wants to merge 2 commits into
Open
Conversation
12 tasks
haofeng0705
force-pushed
the
fix/drive-latest-incomplete-scan
branch
from
August 6, 2026 13:42
c908b21 to
4cc7583
Compare
drive list --latest 承诺「全局最新 N 个」,但两处缺陷让不完整结果冒充全局最新。 P1-a sortTime 泄露:runDriveListDepth 采集端无条件把内部排序字段 sortTime 写进 每个 item,emit 仅在单层 latest(reqDepth==1)路径经 stripDriveDepthDecorations 删除。--depth 2(无 latest)与 depth>1 --latest 两条路径都把 sortTime 泄露进输出 契约。修法:在 emitDriveDepthResult 尾部无条件 delete sortTime,覆盖正常 emit、 SIGINT 取消、unrecoverable partial 三条路径;采集端保持不动(内部字段,排序时才读)。 P1-b 不完整扫描仍产出 Top-N:尾部拒绝 guard 只拦全局截断(truncated),不拦递归 途中目录读取失败——后者把可恢复失败记进 errs[] 后照常 emit,Top-N 落在漏扫子树的 不完整集合上却以退出码 0 返回。修法:guard 扩为 latest>0 && (truncated || len(errs)>0),走新增 driveLatestIncompleteError(TRUNCATED / INCOMPLETE 双 token, 后者带首个失败的 folder/depth/reason);unrecoverable 分支在 latest>0 时不吐 partial 直接回根因错误。同步 --latest flag help 反映新行为。 第三条疑似缺陷(别名互斥漏 --page-size/--page-token)经核对为 main 上的伪缺陷: drive list 从未注册这两个 flag,传入会被 cobra 直接 unknown flag 拒绝,不存在静默 失效,故不搬。 新增 drive_latest_incomplete_test.go 独立锁定两个 P1:sortTime 不泄露(两条路径)、 目录失败拒绝产出、构造器双分支、Suggestion 每子句自洽。改代码前已验证对旧代码为红。
haofeng0705
force-pushed
the
fix/drive-latest-incomplete-scan
branch
from
August 7, 2026 01:56
4cc7583 to
54ffef2
Compare
haofeng0705
marked this pull request as ready for review
August 7, 2026 02:22
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.
背景
本 PR 取代 #885。#885 原本要把内部 wukong 上游的
drive list --latest整分支同步下来,但核对后发现 main 已有一份独立实现(玉澜 via #868,commit58dfbc5b,同上游不同港)—— 核心runDriveListLatest/applyDriveListLatest字节级一致。整分支移植会覆盖同事已合入的骨架,得不偿失。因此关闭 #885,改在本 PR 中只搬两个 main 上真实成立的行为修复,不动已有实现骨架。
修复
P1-a
sortTime泄露进输出契约 ——runDriveListDepth采集端无条件写内部排序字段sortTime,而 emit 仅在单层 latest(reqDepth==1)路径经stripDriveDepthDecorations删除。--depth 2(无 latest)与depth>1 --latest两条路径都把sortTime泄露进输出。修法:在emitDriveDepthResult尾部无条件delete,一处覆盖正常 emit / SIGINT 取消 / unrecoverable partial 三条路径。采集端保持不动(内部字段,排序时才读)。P1-b 不完整扫描仍以退出码 0 产出「Top-N」 —— 尾部拒绝 guard 只拦全局截断(
truncated),不拦递归途中目录读取失败;后者把可恢复失败记进errs[]后照常 emit,Top-N 落在漏扫子树的不完整集合上却冒充全局最新。修法:guard 扩为latest>0 && (truncated || len(errs)>0),走新增driveLatestIncompleteError(LATEST_SCAN_TRUNCATED/LATEST_SCAN_INCOMPLETE双 token,后者带首个失败的 folder/depth/reason);unrecoverable 分支在latest>0时不吐 partial,直接回根因错误。同步--latestflag help 反映新行为。明确不搬
第三条疑似缺陷(别名互斥漏
--page-size/--page-token)经逐行核对为 main 上的伪缺陷:drive list从未注册这两个 flag,传入会被 cobra 直接unknown flag拒绝,不存在静默失效。搬过去需凭空引入crossProductAliasPeers架构 + 注册隐藏别名,违反最小影响原则。同样不动:main 已有的
runDriveListLatest/applyDriveListLatest/drive_latest.go骨架(字节级同源)。测试
新增
internal/helpers/drive_latest_incomplete_test.go独立锁定两个 P1(避开 main 的pr868_*_test.go/drive_depth_test.go,杜绝命名撞车):sortTime不泄露(depth>1 --latest与--depth 2无 latest 两条路径)LATEST_SCAN_INCOMPLETE且 stdout 无 items)driveLatestIncompleteError截断/目录失败双分支 + folder 回落--latest)改代码前已在纯
origin/main上验证这些断言对旧代码为红(sortTime 泄露、INCOMPLETE 拒绝均失败),修后转绿 —— 证明测试确实盖得住缺陷。Reviewer 须知