Repository navigation
fix(v2): mark nested Git symlinks and alternates incomplete in reclaim digest - #435
Conversation
zhangxinhao
left a comment
There was a problem hiding this comment.
LGTM(c50c648)
@wanglongan587 我看了这个 PR,理解它是要在嵌套 Git 元数据含符号链接、特殊文件或 alternates 等无法完整验证的内容时拒绝丢弃工作区,同时继续允许嵌套工作树里的普通符号链接。可以合并。已覆盖常见的嵌套 Git 目录布局,建议后续补齐工作树已移除、名称含斜杠的子模块。
- 🔧 1 处小改已写成建议(nit-1):见行内 suggestion,可以一键采纳,也可以不改或留到以后。
- 📌 建议另开 PR 处理:P2-1 多层子模块目录漏检共享 Git 状态(不影响这次合并)
- 测试:
go test -race -count=1 -timeout=4m ./internal/workspacefs -run 'TestInspectReclaim'通过;go test -v -race -count=1 -timeout=4m ./internal/workspacereclaim -run 'TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates|TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository'没跑(未设置TEST_DATABASE_URL,所有选中的集成用例均被跳过。);git diff --check bec67e2a2404402e060ef94e81d630ca034e1644 HEAD通过;没跑全量和 e2e。
涉及删除数据,建议 owner 再看一眼。
以上都是建议,怎么处理由你决定。
自动检视 · 基于 c50c648 · 第 1 轮(全量)
| if _, err := modules.Lstat(path.Join(name, "commondir")); err == nil || !errors.Is(err, fs.ErrNotExist) { | ||
| d.incomplete("commondir inside nested module", err) | ||
| } | ||
| d.gitTree(modules, name) |
There was a problem hiding this comment.
P2-1(建议) git submodule deinit 后,名为 group/lib 的子模块仍会在 .git/modules/group/lib 保留 Git 元数据,工作树里已经没有 .git 供后续解析。gitState 只枚举 modules 的直接子项,所以这里检查的是 group 根下的 commondir 和 objects/info/alternates,漏掉了真正的子模块目录。若它引用了 checkout 内被忽略的共享 Git 状态,该状态变动后 revision 仍可能保持不变,旧确认可以删掉未预览的数据。建议按实际的子模块 Git 目录执行检查,并补一条 deinit 后仍应拒绝丢弃的回归测试。
改动较大,建议另开 PR 处理,不影响这次合并。
| if status := git(t, wt, "status", "--short"); !strings.Contains(status, "lib.txt") { | ||
| t.Fatalf("unexpected git status through symlinked index: %q", status) | ||
| } |
There was a problem hiding this comment.
nit-1(可选) status --short 里出现 lib.txt 也可能只是报告未跟踪或删除,无法证明 Git 通过符号链接读到了暂存内容。直接读取 index 里的 blob,也能避免 status 刷新索引。
| if status := git(t, wt, "status", "--short"); !strings.Contains(status, "lib.txt") { | |
| t.Fatalf("unexpected git status through symlinked index: %q", status) | |
| } | |
| if got := git(t, wt, "show", ":lib.txt"); got != "staged" { | |
| t.Fatalf("staged content through symlinked index = %q, want %q", got, "staged") | |
| } |
可直接采纳,也可以不改。
Refs ora-space/circus#1387
Parent: ora-space/circus#1354
Summary
Fixes a fail-open gap in workspace reclaim preview (
gitIdentity): when a nested repository uses symlinks,objects/info/alternates, or.git/modules/<name>/commondirinside its nested Git metadata,treeonly hashed link paths/targets without failing closed. A symlinked or external shared Git target could therefore change commits, refs, objects, or index state outside the bound digest, lettingdiscardproceed against an unchangedrevisionand delete unpreviewed Git state.Following D2 of the reclaim design (digest without following symlinks and fail closed when exact content cannot be verified), symlinks and
objects/info/alternatesinside nested Git metadata are now marked incomplete (GitIdentityComplete = false), causingdiscardableto becomefalseanddiscardto return409 discard_unverifiable.Changes
v2-server/internal/workspacefs/reclaim_check.goobjects/info/alternatesinside nested Git directories viadigester.gitTree,digester.walkTree,digester.checkGitDir, anddigester.rejectAlternates.checkedGitDirsalongsidedigestedingitIdentityso nestedrepo/.gitdirectories already hashed duringtree(root, repo)still undergo strict nested-Git validation.commondirentries inside.git/modules/<name>and reject nestedGitDir/CommonDirresolving to the checkout root (rel == ".").GitIdentityComplete = true).v2-server/internal/workspacefs/reclaim_check_test.goTestInspectReclaimMarksSymlinksAndAlternatesInNestedGitIncompletecovering 8 fail-closed cases (symlinked nestedrefs/objects, symlink insidegitfiletarget, symlinked.git/modules/<name>,commondirinside.git/modules/<name>,objects/info/alternates, symlinked nestedindex, symlink insidecommondirtarget, symlink inside.git/modules/<name>) plus working-tree symlink regression check.v2-server/internal/workspacereclaim/reclaim_test.goTestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates(symlinked shared Git state, symlinked nestedindex,alternates, symlink swapped in after preview ->ErrDeletionPreviewStale/ErrDiscardUnverifiable) andTestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository.v2-server/internal/workspacefs/README.md&v2-server/README.mdobjects/info/alternatesinside nested Git directories make the digest incomplete (discardable = false).Specs / ADR Status
ora-space/specs:decisions/cloud/project-git/20261119-reclaim-deleted-conversation-workspace.md(currentlystatus: implemented).alternatesfail-closed clarification and updatetest-cases/cloud/project-git/workspace-reclaim.mdevidence with the merged commit SHA.Verification
Run in WSL as non-root
wanglongan(uid=1000) against PostgreSQL 18 (TEST_DATABASE_URL="postgres:///ora_1354_test?host=/var/run/postgresql"):gofmt -l ./internal/workspacefs ./internal/workspacereclaim-> empty (gofmt ok)go vet ./...-> passgo build -buildvcs=false ./...-> pass (VCS stamping disabled only for UID mismatch across WSL DrvFs mount)go test -race -count=1 ./internal/workspacefs ./internal/workspacereclaim ./internal/gitexclude ./internal/store ./internal/chat ./internal/boot ./internal/agentruntime ./internal/server-> all 8 packagesok(workspacefs6.400s,workspacereclaim19.786s,gitexclude1.101s,store59.550s,chat4.225s,boot1.011s,agentruntime5.997s,server80.238s)go test -v -race -count=1 ./internal/workspacefs -run "TestInspectReclaimMarksSymlinksAndAlternatesInNestedGitIncomplete"-> 9/9 subcasesPASS(0.53s)go test -v -race -count=1 ./internal/workspacereclaim -run "TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates|TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository|TestReclaimRetriesWhenHEADsObjectIsUnreadable"-> allPASS(TestReclaimRetriesWhenHEADsObjectIsUnreadable0.31s,TestDiscardIsRefusedWhenNestedGitUsesSymlinksOrAlternates4/4 subcases 1.61s,TestDiscardStillAllowsWorkingTreeSymlinksInNestedRepository0.30s)git diff --check-> pass