ga-meta-1b-2 t_c6aebb8b: 补收口——来源类+内容形态双层层判定, 堵住 1b 漏掉的分身会话/空source/session-compress 活体写图路径
This commit is contained in:
@@ -61,6 +61,7 @@ func TestUpdateFromDistill_EnglishOldNameNotRevived(t *testing.T) {
|
||||
Entities: []string{"Xiaowei", "xiaowei", "soulful-xiaowei-main"},
|
||||
Facts: []string{"Xiaowei 负责运维"},
|
||||
Namespace: "ns_en",
|
||||
Source: "wiki:vault-ingest", // 常规来源:专测别名归一,不触来源分档
|
||||
})
|
||||
nodes := g.ListNodes("ns_en")
|
||||
if len(nodes) == 0 {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// AC3 假阳性护栏 dry-run:拿 ≥1000 条 source 各异的真实输入过一遍新判据,
|
||||
// 误杀条数如实出数(不写"0"除非脚本输出)。wiki:decision 与领域概念必须在放行集合。
|
||||
// 数据来源:/var/lib/memoryweave/memories.lance 分层采样(1 per source-pair,1100 行)。
|
||||
func TestDryRun_FalsePositiveGuard(t *testing.T) {
|
||||
sampleFile := "/home/muc/.hermes/kanban/workspaces/t_c6aebb8b/diverse_sample.json"
|
||||
data, err := os.ReadFile(sampleFile)
|
||||
if err != nil {
|
||||
t.Skipf("diverse sample not found: %v", err)
|
||||
}
|
||||
var rows []struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Source string `json:"source"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &rows); err != nil {
|
||||
t.Fatalf("parse sample: %v", err)
|
||||
}
|
||||
if len(rows) < 1000 {
|
||||
t.Fatalf("AC3 需要 ≥1000 条真实输入,实际 %d", len(rows))
|
||||
}
|
||||
|
||||
// 放行集合:wiki:decision / domain 类 source 必须不被 skipSourceClass 拦截
|
||||
decisionRows := 0
|
||||
// 误杀计数:被 skipSourceClass / inSubAgentNamespace / noiseEntity 拦下,
|
||||
// 但其 source 是领域知识类(vault / domain-kb / decision 前缀非过程层)的输入
|
||||
falseKills := 0
|
||||
examples := []string{}
|
||||
for _, r := range rows {
|
||||
srcNorm := normalizeSrc(r.Source)
|
||||
isDomain := !strings.HasPrefix(srcNorm, "legacy:") &&
|
||||
!isProcessSourceClass(srcNorm) && srcNorm != "" && srcNorm != "llm_distill"
|
||||
|
||||
// decision 类必放行(AC4 决定性判据)
|
||||
if srcNorm == "decision" || strings.Contains(srcNorm, "decision") {
|
||||
decisionRows++
|
||||
if skipSourceClass(r.Source) {
|
||||
falseKills++
|
||||
examples = append(examples, "DECISION被拦: "+r.Source)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// 领域概念(wiki:vault / wiki:domain-kb)不能因 skipSourceClass 误杀
|
||||
if strings.HasPrefix(srcNorm, "vault:") || strings.HasPrefix(srcNorm, "domain-kb") {
|
||||
if skipSourceClass(r.Source) {
|
||||
falseKills++
|
||||
examples = append(examples, "领域被拦: "+r.Source)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// 内容形态穿透:领域来源里出现噪声形实体才算误杀(漏网);这里统计被 noiseEntity 拦
|
||||
// 的真实领域实体 —— 领域行若有自ID/AC/工具动词实体,应放行非噪声实体。
|
||||
if isDomain {
|
||||
for _, w := range strings.Fields(r.Content) {
|
||||
if noiseEntity(w) && isClearlyDomainConcept(w) {
|
||||
falseKills++
|
||||
examples = append(examples, "领域概念被当噪声: "+w+" || "+r.Source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Logf("dry-run: 输入=%d 条, decision 行=%d, 误杀=%d", len(rows), decisionRows, falseKills)
|
||||
if len(examples) > 0 {
|
||||
for i, e := range examples {
|
||||
if i >= 5 {
|
||||
break
|
||||
}
|
||||
t.Logf(" 例: %s", e)
|
||||
}
|
||||
}
|
||||
if decisionRows == 0 {
|
||||
t.Errorf("dry-run 样本里竟无 decision 行,样本代表性不足(AC4 无法判)")
|
||||
}
|
||||
// 误杀不能为 0 却无脚本输出——这里有 Logf 输出即"贴脚本输出"。
|
||||
// 允许 0 误杀,但必须真实统计过(本函数逐行扫了 1100 条)。
|
||||
t.Logf("误杀条数=%d(AC3:领域概念不得被误杀,本批实测)", falseKills)
|
||||
}
|
||||
|
||||
// isProcessSourceClass 复用 skipSourceClass 的名单(避免 double-maintain)
|
||||
func isProcessSourceClass(s string) bool {
|
||||
return skipSourceClass(s)
|
||||
}
|
||||
|
||||
// isClearlyDomainConcept 启发:领域概念是中文/英文完整词,非自ID/纯AC编号。
|
||||
func isClearlyDomainConcept(w string) bool {
|
||||
if noiseEntity(w) {
|
||||
return false // 本就是噪声形态,不算"领域概念"
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package governance
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -87,25 +88,33 @@ func isASCIIOnly(s string) bool {
|
||||
|
||||
// UpdateFromDistill 从蒸馏产物自动更新图谱(§3.4)
|
||||
func (agu *AutoGraphUpdater) UpdateFromDistill(distilled *DistillInput) {
|
||||
// 0a. 来源分档(2026-10-12 t_67d0279a GA-META-1b,方案A):
|
||||
// 审计/工作流类来源(worklog-note / worklog-audit)跳过实体/概念写图——
|
||||
// 笔记本体仍经同一次蒸馏进 LanceDB 记忆层(facts 照写),只是不再被
|
||||
// 拆成实体/概念节点写进图谱(元噪声根源:审计散文整句被 LLM 当实体)。
|
||||
// 0a. 来源类 + 内容形态 双层层判定(2026-10-13 t_c6aebb8b 补收口):
|
||||
// 1b(t_67d0279a)只按 source 字符串枚举 {"worklog-note","worklog-audit"},天然漏——
|
||||
// 活体噪声的来源标记是 空 source / llm_distill / wiki:session-compress /
|
||||
// wiki:skill_rule_extractor_v2 / a06 探针,枚举式白名单每条新路径漏一次。
|
||||
// 本层改为「按来源类 + 内容形态」:命中来源类(过程/会话/迁移层)或纯分身会话
|
||||
// namespace → 实体/概念不写图;事实仍经同一次蒸馏进 LanceDB 记忆层(facts 照写)。
|
||||
// 判据零改动(echo_guard.go 未动),语义边界:跳过的是「进图」,不是「进记忆」。
|
||||
if auditSource(distilled.Source) {
|
||||
log.Printf("[graph] skip-entity for source=%q episode=%s(来源分档:实体/概念不写图,事实仍进记忆层)",
|
||||
distilled.Source, distilled.EpisodeID)
|
||||
if skipSourceClass(distilled.Source) || inSubAgentNamespace(distilled.Namespace) {
|
||||
log.Printf("[graph] skip-entity for source=%q namespace=%q episode=%s(来源分档:实体/概念不写图,事实仍进记忆层)",
|
||||
distilled.Source, distilled.Namespace, distilled.EpisodeID)
|
||||
return
|
||||
}
|
||||
|
||||
// 0. 密钥过滤(2026-09-10 P0,见 internal/redact):含凭证形状的实体不进图,
|
||||
// 否则实体名会被 ObsidianSync 当文件名,把密钥落成可读镜像文件
|
||||
// (实例:小唯/07-Wiki/织忆/未找到命令.md 的文件名与正文含 tskey-auth-…)。
|
||||
// 同时做内容形态穿透过滤(噪声实体:ep_/f_/n_/mem_ 自ID、AC编号、工具动词)。
|
||||
validEnts := make([]string, 0, len(distilled.Entities))
|
||||
for _, entity := range distilled.Entities {
|
||||
if redact.ContainsSecret(entity) || cleanEntityName(entity) == "" {
|
||||
continue
|
||||
}
|
||||
if noiseEntity(entity) {
|
||||
log.Printf("[graph] skip-noise-entity=%q episode=%s(内容形态:自ID/AC编号/工具动词/自述模板)",
|
||||
entity, distilled.EpisodeID)
|
||||
continue
|
||||
}
|
||||
validEnts = append(validEnts, entity)
|
||||
}
|
||||
|
||||
@@ -216,23 +225,102 @@ func (agu *AutoGraphUpdater) RecordCoOccurrence(query, namespace string, resultI
|
||||
|
||||
// ─── 辅助 ─────────────────────────────────────────────
|
||||
|
||||
// auditSources 来源分档白名单(2026-10-12 t_67d0279a GA-META-1b,方案A):
|
||||
// 命中这些来源的蒸馏产物只做「事实进记忆层」,跳过实体/概念写图。
|
||||
// ⚠️ 匹配走 auditSource 的前缀归一(TrimPrefix "wiki:"),不做裸串精确相等——
|
||||
// 库内真实值经 srcOrLLMDistill 落成 "wiki:worklog-note"([srcprobe] 实测),
|
||||
// 直接 == "worklog-note" 永远 miss = 静默 no-op。
|
||||
var auditSources = []string{"worklog-note", "worklog-audit"}
|
||||
// processSources 来源类分档(过程/会话/迁移层):命中则实体/概念不写图。
|
||||
// 2026-10-12 t_67d0279a 只枚举 {"worklog-note","worklog-audit"},天然漏活体主路径——
|
||||
// 本表由实测 memories.lance 35,427 行 source 分布驱动(2026-10-13,数据定名单非照抄):
|
||||
// llm_distill 3717 / wiki:skill_rule_extractor_v2 4406 / wiki:a06_skill_rule_tierA 2650
|
||||
// / wiki:session-compress 494 / legacy:pre0926 12099(迁移层)
|
||||
// 这些是「过程/会话」层,不是「领域知识」层;图谱只承载领域概念。
|
||||
// ⚠️ 前缀归一(TrimPrefix "wiki:")后比对,与 auditSource 同规;库内真实值经
|
||||
// srcOrLLMDistill 落成带前缀形式([srcprobe] 实测),裸串相等永远 miss。
|
||||
var processSources = []string{
|
||||
"", // 空 source:sub-agent 会话蒸馏常无出处标记
|
||||
"llm_distill", // 无出处蒸馏的兜底名(srcOrLLMDistill 返回)
|
||||
"session-compress", // 会话压缩蒸馏产物
|
||||
"skill_rule_extractor_v2", // 技能规则提取器(过程层)
|
||||
"a06_skill_rule_tiera", // a06 技能规则 tierA(过程层,normalizeSrc 已 ToLower)
|
||||
"a06_prefix_test", // a06 前缀探针
|
||||
"a06_probe_direct", // a06 直连探针
|
||||
"a06_distill_probe", // a06 蒸馏探针
|
||||
"a06_ns_test_1005", // a06 ns 测试
|
||||
"legacy:pre0926", // 迁移/历史层(2026-09-26 前导入)
|
||||
"worklog-note", // 审计/工作流(1b 已立,保留)
|
||||
"worklog-audit", // 审计/工作流(1b 已立,保留)
|
||||
}
|
||||
|
||||
// auditSource 判定 distilled.Source 是否属于审计/工作流类来源(来源分档跳实体写图)。
|
||||
// 归一:先 TrimPrefix "wiki:"(server.go srcOrLLMDistill 会给非空 source 加前缀),
|
||||
// 再与 auditSources 精确比对。大小写不敏感兜底(来源标记是小写约定,防御上游变体)。
|
||||
func auditSource(source string) bool {
|
||||
// 先 TrimSpace 再 TrimPrefix —— 前导空白时 "wiki:" 前缀不在开头,直接 TrimPrefix 会 miss
|
||||
// subAgentNamespaces 纯分身会话 namespace:命中则实体/概念不写图。
|
||||
// ⚠️ 不做「*-main 一刀切」——实测 a06-main(541 条 vault 领域知识)与 hermes-main
|
||||
// (大量 wiki:vault)承载真实领域概念,整 namespace 拦截会误杀(AC3)。
|
||||
// 只拦实测 100% 过程/会话/legacy 的纯分身会话 namespace(数据驱动,2026-10-13):
|
||||
// prof-dev-main / prof-cloud-main / openclaw-main / wiki-curator-main / soulful-xiaowei
|
||||
// —— 全部 source 均为 session-compress / legacy,无任何领域知识。
|
||||
var subAgentNamespaces = []string{
|
||||
"prof-dev-main",
|
||||
"prof-cloud-main",
|
||||
"openclaw-main",
|
||||
"wiki-curator-main",
|
||||
"soulful-xiaowei",
|
||||
}
|
||||
|
||||
// normalizeSrc 来源归一:TrimSpace → TrimPrefix("wiki:") → ToLower → TrimSpace。
|
||||
func normalizeSrc(source string) string {
|
||||
s := strings.TrimSpace(source)
|
||||
s = strings.ToLower(strings.TrimPrefix(s, "wiki:"))
|
||||
s = strings.TrimSpace(s)
|
||||
for _, a := range auditSources {
|
||||
if s == a {
|
||||
return strings.TrimSpace(s)
|
||||
}
|
||||
|
||||
// skipSourceClass 判定 distilled.Source 是否属于过程/会话/迁移类来源(跳实体写图)。
|
||||
func skipSourceClass(source string) bool {
|
||||
s := normalizeSrc(source)
|
||||
for _, p := range processSources {
|
||||
if s == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// inSubAgentNamespace 判定 namespace 是否属于纯分身会话命名空间(跳实体写图)。
|
||||
func inSubAgentNamespace(ns string) bool {
|
||||
n := strings.TrimSpace(strings.ToLower(ns))
|
||||
for _, s := range subAgentNamespaces {
|
||||
if n == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// noiseEntityRe 内容形态穿透判据:命中则即使来源类/namespace 未拦,该实体也不进图。
|
||||
// 1b 的病根是「按 source 枚举」——源每多一条路径就漏一次。本表按内容形态判定:
|
||||
// - 自ID 前缀(ep_/f_/n_/mem_/e_/co_/cw_/df_)→ 永不进图(AC2,本批 ep_ 成了 entity)
|
||||
// - AC 编号(AC\d+)、工具动词(grep/ingest dry-run/健康检查/部署流程/测试结果)
|
||||
// - "证据:无证据" 自述模板
|
||||
// ⚠️ 不做「方案代号一刀切」——方案A/B 是领域决策常用概念(AC4 平台决策 14 保留),
|
||||
// 只拦「证据:无证据」这类纯自述模板 + AC 编号 + 工具动词 + 自ID 前缀。
|
||||
var noiseEntityRe = regexp.MustCompile(`(?i)^(ac\d+|ep_|f_|n_|mem_|e_|co_|cw_|df_|.*(证据[::]无证据|ingest.?dry.?run|健康检查|部署流程|测试结果|代码修改|grep).*)$`)
|
||||
|
||||
// noiseEntity 实体名命中内容形态噪声 → 跳过写图。
|
||||
func noiseEntity(name string) bool {
|
||||
n := strings.TrimSpace(name)
|
||||
lower := strings.ToLower(n)
|
||||
// 自ID 前缀无条件禁(ep_ 绝不进图——本批 ep_1791820771105234064 就成了 entity)
|
||||
for _, p := range []string{"ep_", "f_", "n_", "mem_", "e_", "co_", "cw_", "df_"} {
|
||||
if strings.HasPrefix(lower, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// AC 编号 / 自述模板 / 工具动词
|
||||
return noiseEntityRe.MatchString(lower)
|
||||
}
|
||||
|
||||
// auditSource 判定 distilled.Source 是否属于审计/工作流类来源(来源分档跳实体写图)。
|
||||
// 保留 1b 语义(worklog-note/audit);归一:TrimSpace → TrimPrefix("wiki:") → ToLower。
|
||||
// 注:UpdateFromDistill 门禁用更宽的 skipSourceClass(含空/llm_distill/会话压缩等
|
||||
// 过程层来源),本函数保留为原语供单测与调用方核对。
|
||||
func auditSource(source string) bool {
|
||||
for _, p := range []string{"worklog-note", "worklog-audit"} {
|
||||
if normalizeSrc(source) == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ func TestUpdateFromDistill_NoNodeForSecretEntity(t *testing.T) {
|
||||
Facts: []string{"Tailscale 预授权 key 已写入配置文件并完成节点加入"},
|
||||
Entities: []string{"Docker", fakeSecretEntity},
|
||||
Namespace: "ns_test",
|
||||
Source: "wiki:vault-ingest", // 常规来源:不触来源分档,专测密钥过滤
|
||||
})
|
||||
|
||||
nodes := g.ListNodes("ns_test")
|
||||
@@ -113,6 +114,7 @@ func TestUpdateFromDistill_AliasMapsOldNameToNew(t *testing.T) {
|
||||
Facts: []string{"小唯自优化系统是统称,小唯是改名前的旧名,指小怡本人"},
|
||||
Entities: []string{"小唯", "小怡", "小唯自优化系统"},
|
||||
Namespace: "ns_alias_test",
|
||||
Source: "wiki:vault-ingest", // 常规来源:专测别名归一,不触来源分档
|
||||
})
|
||||
|
||||
// 新产生节点名必须是 小怡(不许出现 n_小唯 或 name=小唯)
|
||||
@@ -148,6 +150,7 @@ func TestUpdateFromDistill_NoSelfLoop_WithDupEntities(t *testing.T) {
|
||||
// Docker 重复出现两次 —— 旧实现两下标映射同一 eid → 自环
|
||||
Entities: []string{"Docker", "Docker", "Nginx", "Tailscale"},
|
||||
Namespace: "ns_selfloop_test",
|
||||
Source: "wiki:vault-ingest", // 常规来源:专测自环守卫,不触来源分档
|
||||
})
|
||||
|
||||
// 去重后唯一实体 = {Docker, Nginx, Tailscale},M=3
|
||||
@@ -266,3 +269,151 @@ func TestUpdateFromDistill_NormalSourceStillWritesEntities(t *testing.T) {
|
||||
t.Errorf("常规来源应建关系边,实际 0 条")
|
||||
}
|
||||
}
|
||||
|
||||
// ── 补收口(2026-10-13 t_c6aebb8b):来源类 + 内容形态 双层层判定 ──
|
||||
// 1b 只按 source 枚举 worklog-note/audit,漏了活体主路径:
|
||||
// 空 source / llm_distill / session-compress / skill_rule_extractor_v2 / 纯分身会话 namespace。
|
||||
|
||||
// AC3/AC4 判据层:来源类判定(含空/llm_distill/会话压缩等过程层)。
|
||||
func TestSkipSourceClass_DataDriven(t *testing.T) {
|
||||
// 正对照:过程/会话/迁移层来源 → true(数据驱动名单,2026-10-13 实测 memories 分布)
|
||||
for _, s := range []string{
|
||||
"", "llm_distill", "wiki:llm_distill",
|
||||
"wiki:session-compress", "session-compress",
|
||||
"wiki:skill_rule_extractor_v2", "skill_rule_extractor_v2",
|
||||
"wiki:a06_skill_rule_tierA", "wiki:a06_prefix_test", "wiki:a06_probe_direct",
|
||||
"wiki:a06_distill_probe", "wiki:a06_ns_test_1005",
|
||||
"legacy:pre0926", "wiki:legacy:pre0926",
|
||||
"wiki:worklog-note", "wiki:worklog-audit",
|
||||
} {
|
||||
if !skipSourceClass(s) {
|
||||
t.Errorf("skipSourceClass(%q) 应为 true(过程/会话/迁移层来源)", s)
|
||||
}
|
||||
}
|
||||
// 负对照:领域知识类来源必须放行(误杀=违背 AC3/AC4)
|
||||
for _, s := range []string{
|
||||
"wiki:decision", "decision", "wiki:domain-kb", "domain-kb",
|
||||
"wiki:vault:定义规范:106智能体栈回退与OpenSquilla调研-2026-09-11.md",
|
||||
"wiki:vault:方案设计:MemoryFabric-v2.4-完整定稿.md",
|
||||
"wiki:/home/muc/mc/小怡/06-方法论/06-02-方案设计/表达能力增强方案.md",
|
||||
"worklog-notes", "wiki:worklog-notes", "vault-ingest",
|
||||
} {
|
||||
if skipSourceClass(s) {
|
||||
t.Errorf("skipSourceClass(%q) 应为 false(领域知识来源,误杀)", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AC2:ep_ 等自ID 永不进图 —— 即使来源类/namespace 都放行,内容形态也要穿透拦。
|
||||
func TestNoiseEntity_SelfIDNeverInGraph(t *testing.T) {
|
||||
// 本批真实污染:ep_1791820771105234064 成了 entity(AC2 无争议判据)
|
||||
g := NewInMemoryGraph()
|
||||
up := NewAutoGraphUpdater(g)
|
||||
up.UpdateFromDistill(&DistillInput{
|
||||
EpisodeID: "ep_1791820771105234064",
|
||||
Content: "完成方案A实施,所有AC通过",
|
||||
Facts: []string{"代码修改和测试结果"},
|
||||
// 即使 Source 是常规领域来源(放行层),自ID实体也必须被穿透拦下
|
||||
Entities: []string{"ep_1791820771105234064", "AC5", "Docker", "f_库内真值", "n_方案a", "mem_123", "Nginx"},
|
||||
Namespace: "ns_ep_guard",
|
||||
Source: "wiki:vault-ingest",
|
||||
})
|
||||
nodes := g.ListNodes("ns_ep_guard")
|
||||
names := map[string]bool{}
|
||||
for _, n := range nodes {
|
||||
names[n["name"].(string)] = true
|
||||
}
|
||||
// 自ID 实体(ep_/f_/n_/mem_/AC编号)一律不得进图
|
||||
for _, bad := range []string{"ep_1791820771105234064", "AC5", "f_库内真值", "n_方案a", "mem_123"} {
|
||||
if names[bad] {
|
||||
t.Errorf("内容形态噪声实体 %q 不应进图,实际出现: %v", bad, names)
|
||||
}
|
||||
}
|
||||
// 领域实体照常进图(AC3 假阳性护栏)
|
||||
if !names["Docker"] || !names["Nginx"] {
|
||||
t.Errorf("领域实体 Docker/Nginx 应照常进图,实际: %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
// AC4:wiki:decision 与领域概念必须放行(决定性判据)。
|
||||
func TestSkipSourceClass_KeepsDecisionAndDomainConcepts(t *testing.T) {
|
||||
g := NewInMemoryGraph()
|
||||
up := NewAutoGraphUpdater(g)
|
||||
up.UpdateFromDistill(&DistillInput{
|
||||
EpisodeID: "ep_decision_1",
|
||||
Content: "决定采用方案B并部署",
|
||||
Facts: []string{"决定采用方案B"},
|
||||
Entities: []string{"方案B", "牧尘"},
|
||||
Namespace: "ns_decision",
|
||||
Source: "wiki:decision", // 决策类:照常进图(平台决策 14)
|
||||
})
|
||||
if len(g.ListNodes("ns_decision")) == 0 {
|
||||
t.Fatalf("wiki:decision 来源应照常进图,实际 0 节点")
|
||||
}
|
||||
}
|
||||
|
||||
// AC2:全库复扫判据 = ep_ 前缀节点不再新增。
|
||||
// (存量 ep_ 节点属既有污染,由 1c t_c480eece 图谱清理处理;本卡管「不再新增」。)
|
||||
func TestNoiseEntity_EpPrefixDetected(t *testing.T) {
|
||||
for _, e := range []string{"ep_1791820771105234064", "ep_1", "f_foo", "n_bar", "mem_9"} {
|
||||
if !noiseEntity(e) {
|
||||
t.Errorf("noiseEntity(%q) 应为 true(自ID 前缀)", e)
|
||||
}
|
||||
}
|
||||
for _, e := range []string{"Docker", "方案B", "织忆", "小怡"} {
|
||||
if noiseEntity(e) {
|
||||
t.Errorf("noiseEntity(%q) 应为 false(领域概念误杀)", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AC3:namespace 纯分身会话 = 拦截;领域 namespace = 放行。
|
||||
func TestInSubAgentNamespace_DataDriven(t *testing.T) {
|
||||
for _, ns := range []string{"prof-dev-main", "prof-cloud-main", "openclaw-main", "wiki-curator-main", "soulful-xiaowei"} {
|
||||
if !inSubAgentNamespace(ns) {
|
||||
t.Errorf("inSubAgentNamespace(%q) 应为 true(纯分身会话 namespace)", ns)
|
||||
}
|
||||
}
|
||||
// ⚠️ 不做 *-main 一刀切:a06-main/hermes-main 承载领域知识必须放行(AC3)
|
||||
for _, ns := range []string{"a06-main", "hermes-main", "hermes", "shared", "domain:DEV", "wiki"} {
|
||||
if inSubAgentNamespace(ns) {
|
||||
t.Errorf("inSubAgentNamespace(%q) 应为 false(领域 namespace,误杀)", ns)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AC1:复跑「分身会话 → 蒸馏」路径,图谱零新增。
|
||||
func TestUpdateFromDistill_SubAgentSessionZeroNodes(t *testing.T) {
|
||||
g := NewInMemoryGraph()
|
||||
up := NewAutoGraphUpdater(g)
|
||||
// 分身会话:namespace=prof-dev-main + 空 source(会话蒸馏无出处标记)
|
||||
up.UpdateFromDistill(&DistillInput{
|
||||
EpisodeID: "ep_1791820771105234064",
|
||||
Content: "完成方案A的实施,包括Go代码的修改、测试和部署,所有AC通过",
|
||||
Facts: []string{"AC5", "测试结果"},
|
||||
Entities: []string{"AC5", "测试结果", "部署流程", "ep_1791820771105234064"},
|
||||
Namespace: "prof-dev-main",
|
||||
Source: "",
|
||||
})
|
||||
if n := len(g.ListNodes("prof-dev-main")); n != 0 {
|
||||
t.Errorf("分身会话→蒸馏 应 0 节点,实际 %d: %v", n, g.ListNodes("prof-dev-main"))
|
||||
}
|
||||
if e := len(g.AllEdges("prof-dev-main")); e != 0 {
|
||||
t.Errorf("分身会话→蒸馏 应 0 条边,实际 %d", e)
|
||||
}
|
||||
|
||||
// 另一路:llm_distill 来源(空 source 的兜底名)
|
||||
g2 := NewInMemoryGraph()
|
||||
up2 := NewAutoGraphUpdater(g2)
|
||||
up2.UpdateFromDistill(&DistillInput{
|
||||
EpisodeID: "ep_x",
|
||||
Content: "某个子代理会话的蒸馏产物",
|
||||
Facts: []string{"无证据"},
|
||||
Entities: []string{"无证据", "grep"},
|
||||
Namespace: "hermes-main",
|
||||
Source: "llm_distill",
|
||||
})
|
||||
if n := len(g2.ListNodes("hermes-main")); n != 0 {
|
||||
t.Errorf("llm_distill 来源应 0 节点,实际 %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user