chore(test): 删掉为已撤回的过滤写的判据(判据不该给错误实现护航)
This commit is contained in:
@ -1,87 +0,0 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
/*
|
||||
SuggestPaths 的候选过滤(2026-09-15 用户报的「莫名其妙的 pi@/home 会话」)。
|
||||
|
||||
背景是一整条**自增强环**:建议列表是从历史数据学的(mails.to_workspace + 平台心跳 +
|
||||
注册自报),而历史里混进了「进程恰好所在的目录」——`/root`、`/home`、`/home/program`、
|
||||
`/root/.pi/mail-sessions/<uuid>`。用户点了第一条建议 → 发信给 `zcode@/home` →
|
||||
那条会话的 workspace 成了 `/home` → 之后这条线索里所有参与方都显示 `xxx@/home`,
|
||||
pi 桥还会**真把 worker 起在 /home**(实测日志 `新建 pi 会话 …(cwd=/home)`),
|
||||
而沙箱 rw 只有 /home/program/agentmail ⇒ 那个 worker 连文件都写不了。
|
||||
|
||||
判据两侧都写:
|
||||
- 坏值必须被剔掉(否则环继续跑);
|
||||
- 好值必须保留,包括**还没创建的目录**(注册时自报的 /tmp/remotebot-ws 那种)
|
||||
—— 如果实现顺手加上存在性检查,这一条会红。
|
||||
*/
|
||||
func TestFilterWorkspaces(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in []string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "剔掉进程家目录、家目录本身、父目录、隐藏段(实测到的污染形状)",
|
||||
in: []string{
|
||||
"/root", // 进程家目录
|
||||
"/home", // 一切的家目录
|
||||
"/home/program", // 只是容器
|
||||
"/root/.pi/mail-sessions/8f056b73", // pi 的会话存储(隐藏段)
|
||||
"/home/program/agentmail", // ← 唯一像工作目录的
|
||||
},
|
||||
want: []string{"/home/program/agentmail"},
|
||||
},
|
||||
{
|
||||
name: "两个互不为祖先的项目目录都要保留",
|
||||
in: []string{"/home/program/agentmail", "/home/program/llmsproxy"},
|
||||
want: []string{"/home/program/agentmail", "/home/program/llmsproxy"},
|
||||
},
|
||||
{
|
||||
name: "还没创建的目录不因为'不存在'被剔(存在性检查是过度过滤)",
|
||||
in: []string{"/tmp/remotebot-ws", "/home/program/agentmail"},
|
||||
want: []string{"/tmp/remotebot-ws", "/home/program/agentmail"},
|
||||
},
|
||||
{
|
||||
name: "相对路径不是工作目录地址",
|
||||
in: []string{"rel/path", "/home/program/agentmail"},
|
||||
want: []string{"/home/program/agentmail"},
|
||||
},
|
||||
{
|
||||
name: "尾斜杠 / 中间 . 段都做 Clean(不是当成新候选)",
|
||||
in: []string{"/home/program/agentmail/"},
|
||||
want: []string{"/home/program/agentmail"},
|
||||
},
|
||||
{
|
||||
// 取舍:rule 4 让**更具体**的目录胜出。父子都是工作目录时父目录会被剔掉 ——
|
||||
// 这是为治本(`/home`、`/home/program` 那种容器)付出的代价:宁可少给
|
||||
// 一条候选(用户仍可手写),也不能把容器当工作目录(那会让 worker 起在
|
||||
// 一个连文件都写不了的目录里)。这条判据把代价钉住,避免以后有人
|
||||
// "顺手放宽"却没人知道为什么。
|
||||
name: "父子都是候选时只留更具体的那个(已知取舍)",
|
||||
in: []string{"/home/program/agentmail/./", "/home/program/agentmail/x"},
|
||||
want: []string{"/home/program/agentmail/x"},
|
||||
},
|
||||
{
|
||||
name: "空输入原样返回(不放大 nil/空切片差异)",
|
||||
in: nil,
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got := filterWorkspaces(c.in)
|
||||
if len(got) == 0 && len(c.want) == 0 {
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("filterWorkspaces(%v)\n got %v\nwant %v", c.in, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user