ACP / MCP 完善

This commit is contained in:
2026-06-11 12:43:18 +08:00
parent 1415d3b43b
commit 0561e126cd
22 changed files with 786 additions and 219 deletions
@@ -45,3 +45,28 @@ func TestFsWrite_OutsideWorktree(t *testing.T) {
require.NotNil(t, res.Err)
assert.Equal(t, -32001, res.Err.Code)
}
// 父目录是 worktree 内指向外部的 symlink、目标文件不存在 → 必须被拒,
// 且外部目录不能出现新建文件(防 symlink 逃逸写出 worktree)。
func TestFsWrite_SymlinkDirEscape(t *testing.T) {
t.Parallel()
tmp := t.TempDir()
outside := t.TempDir()
link := filepath.Join(tmp, "link-dir")
if err := os.Symlink(outside, link); err != nil {
t.Skipf("symlink not supported on this platform: %v", err)
}
h := handlers.NewFsWriteHandler()
sess := handlers.SessionContext{CwdPath: tmp}
params := mustJSON(t, map[string]any{
"sessionId": "x", "path": filepath.Join(link, "escape.txt"), "content": "evil",
})
res := h.Handle(context.Background(), sess, params)
require.NotNil(t, res.Err)
assert.Equal(t, -32001, res.Err.Code)
_, statErr := os.Stat(filepath.Join(outside, "escape.txt"))
assert.True(t, os.IsNotExist(statErr), "外部目录不应被写入")
}