空 mode 计划不映射;索引 source_id 按语义映射;relation 按字段表解析。 隔离回归按持久映射 ID 断言,DS02 故障注入真实命中。
This commit is contained in:
@@ -23,10 +23,10 @@ func r12ESDoc(t *testing.T, fx *writeSetFixture, id string) map[string]any {
|
||||
return recoveryIndexReadback(t, fx)[id]
|
||||
}
|
||||
|
||||
func r12PutDoc(t *testing.T, fx *writeSetFixture, id string, tenant uint64, kb, knowledge, content string, embedding []float64) {
|
||||
func r12PutDoc(t *testing.T, fx *writeSetFixture, id, chunkID string, tenant uint64, kb, knowledge, content string, embedding []float64) {
|
||||
t.Helper()
|
||||
body, err := json.Marshal(map[string]any{"tenant_id": tenant, "knowledge_base_id": kb,
|
||||
"knowledge_id": knowledge, "chunk_id": id, "source_id": id, "content": content, "embedding": embedding})
|
||||
"knowledge_id": knowledge, "chunk_id": chunkID, "source_id": chunkID, "content": content, "embedding": embedding})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -158,7 +158,9 @@ func TestR12IndexOracleDetectsContentVectorAndMetadataChangesIsolated(t *testing
|
||||
if err := target.Verify(fx.ctx, expect); err != nil {
|
||||
t.Fatalf("baseline oracle must pass: %v", err)
|
||||
}
|
||||
published := r12ESDoc(t, fx, "chunk-src")
|
||||
docID := expectedIndexID("chunk-src")
|
||||
chunkID := expectedTargetID(wsTargetTenant, wsTargetKB, "chunks", "chunk-src")
|
||||
published := r12ESDoc(t, fx, docID)
|
||||
if published == nil {
|
||||
t.Fatal("published document missing")
|
||||
}
|
||||
@@ -168,29 +170,29 @@ func TestR12IndexOracleDetectsContentVectorAndMetadataChangesIsolated(t *testing
|
||||
originalKnowledge, _ := source["knowledge_id"].(string)
|
||||
|
||||
// 1) 正文被改。
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, originalKnowledge, "被篡改的正文", []float64{0.1, 0.2})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, originalKnowledge, "被篡改的正文", []float64{0.1, 0.2})
|
||||
if err := target.Verify(fx.ctx, expect); err == nil {
|
||||
t.Fatal("正文篡改没有让独立 oracle 变红")
|
||||
}
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
if err := target.Verify(fx.ctx, expect); err != nil {
|
||||
t.Fatalf("恢复正文后 oracle 必须通过:%v", err)
|
||||
}
|
||||
// 2) 向量被改(同维不同值)。
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.9, 0.8})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.9, 0.8})
|
||||
if err := target.Verify(fx.ctx, expect); err == nil {
|
||||
t.Fatal("向量篡改没有让独立 oracle 变红")
|
||||
}
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
if err := target.Verify(fx.ctx, expect); err != nil {
|
||||
t.Fatalf("恢复向量后 oracle 必须通过:%v", err)
|
||||
}
|
||||
// 3) metadata(knowledge_id)被改。
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, "doc-target", originalContent, []float64{0.1, 0.2})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, "doc-target", originalContent, []float64{0.1, 0.2})
|
||||
if err := target.Verify(fx.ctx, expect); err == nil {
|
||||
t.Fatal("metadata 篡改没有让独立 oracle 变红")
|
||||
}
|
||||
r12PutDoc(t, fx, "chunk-src", wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
r12PutDoc(t, fx, docID, chunkID, wsTargetTenant, wsTargetKB, originalKnowledge, originalContent, []float64{0.1, 0.2})
|
||||
if err := target.Verify(fx.ctx, expect); err != nil {
|
||||
t.Fatalf("恢复 metadata 后 oracle 必须通过:%v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user