Repository navigation
test(core): 复现远端 presign 孤儿清理的两条根因(真 WebDAV + 真 DB) - #243
Open
zy84338719 wants to merge 2 commits into
Open
zy84338719 wants to merge 2 commits into
zy84338719 wants to merge 2 commits into
Conversation
落点 core;配套设计稿 docs/specs/2026-11-29-remote-orphan-recursive-list-design.md (hub 仓)。本 PR **不含任何生产代码改动**——只落复现测试,把设计稿 §1.2 的 根因从「读码推断」升级为「可执行证据」。 三条判据在当前 main(v0.50.0 / c9f1d22)上**必红**: 1. TestRepro_ListRemoteObjects_MissesDeepKeys 真 WebDAV 写入 uploads/2026/11/29/repro-deep-object.bin(磁盘确认存在) ⇒ ListRemoteObjects("uploads/") 返回 **0 条** ⇒ 证实根因 A:7 个后端 List 全是单层非递归,三层深对象扫不到。 2. TestRepro_ListRemoteObjects_KeyIsFullRelativePath 返回 Key="shallow.bin"(期望 uploads/shallow.bin) ⇒ 证实根因 B:WebDAV/FTP/SFTP/OneDrive 返回裸目录项名。 3. TestRepro_Janitor_DeletesWrongObject(端到端:真 WebDAV + 真 sqlite DB) 引用集 = {uploads/shallow.bin},扫描产出孤儿 = {shallow.bin} ⇒ 活对象被判孤儿;删除用裸名 ⇒ 日志 "delete failed key=orphan.bin err=文件不存在",删掉的是**根目录同名文件**,真孤儿 uploads/orphan.bin 仍在。 ⇒ 实际后果是「**删错对象**」(数据丢失)+「孤儿永久泄漏」, **不是**设计稿初版推断的「删掉活对象」。 变异验证(三件事均成立):注入「WebDAV List 改 path.Join(key, fi.Name())」 的修复方向 ⇒ 编译通过 + e2e 转绿 + 还原复跑仍红 ⇒ 断言有牙齿。 既有基线未破:app/admin 既有 5 个孤儿测试全绿 ⇒ 假绿成因坐实 (桩口径统一所以绿,真后端口径不一致所以红)。 另:hasRemoteKey 这类「多口径都算命中」的辅助函数本轮不改(属后续修复面), 本 PR 只取证。
1 of 3 tasks
CI 的 Gofmt 步(gofmt -l .)判红:app/admin/orphan_janitor_e2e_repro_test.go 的块注释里列表型缩进不符合 gofmt 规范化(gofmt 把 "// · xxx" 折成 "// · xxx" 形态)。纯注释格式,零行为变化。 本地复扫 gofmt -l . 已干净;三条复现判据仍按预期红(钉住缺陷现状)。
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.
背景
矩阵稿 §5 登记的两条「已知产品缺口」,本 PR 只取证、不修:
ListRemoteObjects的 Key 口径跨后端不一致」配套设计稿(hub 仓):
2026-11-29-remote-orphan-recursive-list-design.md
两条此前只有读码推断,本 PR 把它们升级为真后端可执行证据。
生产代码零改动(
git diff c9f1d22 -- . ':!*_test.go'为空)。实测取证(真 WebDAV 服务 + 真 sqlite DB + 真 Janitor)
TestRepro_ListRemoteObjects_MissesDeepKeysuploads/2026/11/29/repro-deep-object.bin(磁盘确认存在)⇒ListRemoteObjects("uploads/")返回 0 条List全是单层非递归,三层深对象扫不到TestRepro_ListRemoteObjects_KeyIsFullRelativePathKey="shallow.bin"(期望uploads/shallow.bin)TestRepro_Janitor_DeletesWrongObjectdelete failed key="orphan.bin" err="文件不存在";根目录shallow.bin消失,真孤儿uploads/orphan.bin仍在根因(逐条实测确认)
根因 A —— 列举不递归。 真实对象 key 是
uploads/YYYY/MM/DD/<id><ext>(app/presign/presign.go:906),三层深;而storage/storage.go:419的ListRemoteObjects注释写着「递归」,实际是op.List(ctx, prefix)单次调用:List实现ListObjects{Recursive: false}listAll后取首段segclient.ReadDirconn.Listcli.ReadDir/childrenLISTSTATUSPathSuffix(单层相对)⇒ 扫
uploads/只见到首层目录项,被md.IsDir过滤 ⇒ 返回空集。根因 B —— Key 口径错位 ⇒ 删错对象。
引用集(
app/admin/janitor.go:385)用完整相对路径uploads/shallow.bin,比对(
:408)只做referenced[TrimSuffix(o.Key,"/")];WebDAV 的o.Key是裸名shallow.bin⇒ 两者永不相等 ⇒ 有 DB 引用的活对象被判成孤儿 ⇒ 拿裸名去
DeleteFile(:325)⇒ 删掉的是存储根下的同名文件,真身反而删不掉。
变异验证(三件事均成立)
List的Path改为path.Join(key, fi.Name())(= 修复方向);CI 实测(2026-11-29)
首轮 CI(
06055fc)的Test (race)失败点精确等于这三条复现用例,其余包全
ok(含repo/db/dao、transport/http/handler等)⇒ 无意外破坏。既有基线未破 + 假绿成因坐实
app/admin既有 5 个孤儿测试(含TestCleanRemotePresignOrphans_NeverDeletesReferencedObject)全绿,而真后端同场景必红
⇒ 假绿成因坐实:桩返回统一 Key 口径所以绿,真后端口径不一致所以红。
桩层假绿的成因已定位到两处:
app/admin/janitor_orphan_test.go:四用例全用remoteStorageStub(统一口径,与真实驱动分歧正好相反);storage/remote_integration_common_test.go:130hasRemoteKey:显式兼容三种口径(
o.Key == key || o.Key == base || HasSuffix(o.Key, "/"+base))⇒ 连真后端集成用例也判绿。这两处的修正在下一批(属「修实现」面),本 PR 只取证。
自测
go test -race ./...;frontend:npm run typecheck && npm test)make train-bump,未手改 —— 本 PR 不触及合并后
下一批按设计稿 §3 落递归器 + Key 归一器,让三条复现判据转绿(复现测试即验收标准)。