背景:not_useful_count 被两种语义混写——用户人工点「没用」(feedback.go MarkNotUseful) 与 dedup/合并流程自动降权(core.go Dedup demote) 都写同一字段。 实测 35010 行里 509 条非零但 human useful 仅 21 ⇒ 字段被混写。P2 自适应阈值 要靠它当标签,统计即垃圾。 改法(AC1-5,禁部署): - LanceDB(arrow_schema) + sqlite(create/alter) 两侧同步新增 human_not_useful_count / dedup_downweight_count(additive,不删旧列) - 两个写入点各写各的:feedback.go→IncrementHumanNotUseful; core.go dedup→IncrementDedupDownweight - not_useful_count 保留 deprecated,新代码不再读(读侧仅 Scan/迁移保留) - 存量迁移工具 cmd/split_notuseful(--dry-run 默认,apply 需终审); 实测存量无可按来源判定行(M=0)→ 全部归 unknown(K=109 存活行),apply=no-op - 单测 TestSplitNotUsefulFieldIsolation:两写入点写不同字段,相对增量断言 go build/vet/test + rust build 全绿;rust open() schema 演进在副本上 实测补列 human_not_useful_count/dedup_downweight_count 成功。
63 lines
2.4 KiB
Go
63 lines
2.4 KiB
Go
package storage
|
||
|
||
import "testing"
|
||
|
||
// TestSplitNotUsefulFieldIsolation — GA-P0-1 (t_718d8707) AC5
|
||
//
|
||
// 覆盖「两个写入点写不同字段」:
|
||
//
|
||
// 写入点1(feedback.go MarkNotUseful 人工「没用」)→ IncrementHumanNotUseful
|
||
// 写入点2(core.go Dedup 自动降权) → IncrementDedupDownweight
|
||
//
|
||
// 断言用**相对增量**(绝对值会被其它路径的计数干扰,见 AC5):
|
||
//
|
||
// 每次调用只 +1 到各自字段,其它两个字段必须原样不变。
|
||
func TestSplitNotUsefulFieldIsolation(t *testing.T) {
|
||
mlc := NewMemLanceClient(nil)
|
||
mlc.mu.Lock()
|
||
mlc.memories["mem_split_1"] = &memEntry{ID: "mem_split_1", NotUsefulCount: 3}
|
||
mlc.mu.Unlock()
|
||
|
||
e := mlc.memories["mem_split_1"]
|
||
|
||
// 写入点1:人工「没用」→ 只加 human_not_useful_count,不动其它两字段
|
||
if err := mlc.IncrementHumanNotUseful("mem_split_1"); err != nil {
|
||
t.Fatalf("IncrementHumanNotUseful err: %v", err)
|
||
}
|
||
if e.HumanNotUsefulCount != 1 {
|
||
t.Fatalf("human_not_useful_count: 相对增量 +1,want 1 got %d", e.HumanNotUsefulCount)
|
||
}
|
||
if e.NotUsefulCount != 3 {
|
||
t.Fatalf("human 路径不得污染 not_useful_count,want 3 got %d", e.NotUsefulCount)
|
||
}
|
||
if e.DedupDownweightCount != 0 {
|
||
t.Fatalf("human 路径不得污染 dedup_downweight_count,want 0 got %d", e.DedupDownweightCount)
|
||
}
|
||
|
||
// 写入点2:dedup 降权 → 只加 dedup_downweight_count,不动其它两字段
|
||
if err := mlc.IncrementDedupDownweight("mem_split_1"); err != nil {
|
||
t.Fatalf("IncrementDedupDownweight err: %v", err)
|
||
}
|
||
if e.DedupDownweightCount != 1 {
|
||
t.Fatalf("dedup_downweight_count: 相对增量 +1,want 1 got %d", e.DedupDownweightCount)
|
||
}
|
||
if e.HumanNotUsefulCount != 1 {
|
||
t.Fatalf("dedup 路径不得污染 human_not_useful_count,want 1 got %d", e.HumanNotUsefulCount)
|
||
}
|
||
if e.NotUsefulCount != 3 {
|
||
t.Fatalf("dedup 路径不得污染 not_useful_count,want 3 got %d", e.NotUsefulCount)
|
||
}
|
||
|
||
// AC3:IncrementNotUseful 是 deprecated 历史混写列,仍只动 not_useful_count(向后兼容)
|
||
if err := mlc.IncrementNotUseful("mem_split_1"); err != nil {
|
||
t.Fatalf("IncrementNotUseful err: %v", err)
|
||
}
|
||
if e.NotUsefulCount != 4 {
|
||
t.Fatalf("not_useful_count(历史列) 相对增量 +1,want 4 got %d", e.NotUsefulCount)
|
||
}
|
||
if e.HumanNotUsefulCount != 1 || e.DedupDownweightCount != 1 {
|
||
t.Fatalf("历史列写入不得污染拆分字段,want human=1 dedup=1 got human=%d dedup=%d",
|
||
e.HumanNotUsefulCount, e.DedupDownweightCount)
|
||
}
|
||
}
|