package handler import "testing" // resolveToWorkspace 的判据。 // // 每一条都对着一个真实后果,不是凑覆盖率: // - Agent 间回信丢 path → 收信方落进一次性空目录(界面上每封多一条会话) // - 给人类填 path → 界面拼出 `gui-lab@/root/proj.别名` 这种错地址 // - 地址里明确写了 path → 必须照用(人的意图优先于兜底) func TestResolveToWorkspace(t *testing.T) { const ws = "/root/projects/demo" cases := []struct { name string addrPath string sessionWS string toIsHuman bool want string why string }{ { name: "地址里没写 path,收件方是 Agent → 继承会话 workspace", addrPath: "", sessionWS: ws, toIsHuman: false, want: ws, why: "这是 Agent 间回信与人点回复的常态;不继承就会落在一次性空目录里", }, { name: "地址里没写 path,收件方是人 → 保持空", addrPath: "", sessionWS: ws, toIsHuman: true, want: "", why: "给人类填 path 会拼出 gui-lab@/root/projects/demo.别名 这种错地址", }, { name: "地址里写了 path → 照用,不用会话 workspace", addrPath: "/other/place", sessionWS: ws, toIsHuman: false, want: "/other/place", why: "地址里的 path 是发件人的明确意图,兜底不该覆盖它", }, { name: "地址里写了 path,即使收件方是人 → 照用", addrPath: "/other/place", sessionWS: ws, toIsHuman: true, want: "/other/place", why: "人自己写了 path 就按他写的来(与上一条同一个原则)", }, { name: "会话确实没有 workspace,收件方是 Agent → 仍是空", addrPath: "", sessionWS: "", toIsHuman: false, want: "", why: "空串的语义是「不知道」,不能凭空编一个目录出来", }, { name: "会话没有 workspace,收件方是人 → 空", addrPath: "", sessionWS: "", toIsHuman: true, want: "", why: "两边都空,行为与改动前完全一致(无回归)", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got := resolveToWorkspace(c.addrPath, c.sessionWS, c.toIsHuman) if got != c.want { t.Errorf("resolveToWorkspace(%q, %q, human=%v) = %q,期望 %q —— %s", c.addrPath, c.sessionWS, c.toIsHuman, got, c.want, c.why) } }) } } // 反向对照:确认「收件方是否人类」这个维度**真的在起作用**。 // // 如果哪天有人把 toIsHuman 用错(比如传反了、或当成常量传),上面的表里 // 仍会有一半用例通过 —— 它们只在 want 恰好相同的情况下碰到。这里固定其他 // 输入、只翻转这一个维度,要求结果必须不同: // // 不翻转就通过,说明这个参数被忽略了(恒为默认、或被短路掉), // 那时「给人也填 path」的错地址会静默回归。 func TestResolveToWorkspace_HumanDimensionActuallyMatters(t *testing.T) { const ws = "/root/projects/demo" agent := resolveToWorkspace("", ws, false) human := resolveToWorkspace("", ws, true) if agent == human { t.Fatalf("收件方是人类与是 Agent 得到了同一个结果 %q —— "+ "要么 toIsHuman 没起作用,要么规则退化成了一律填/一律不填", agent) } if human != "" { t.Errorf("收件方是人类时 to_workspace 应为空,实得 %q", human) } if agent != ws { t.Errorf("收件方是 Agent 时应继承会话 workspace %q,实得 %q", ws, agent) } }