Files
knowledge-governance/internal/releaseadapter/v071/library_chunk_sequence_test.go
T
姚章浩 ee9d078794
build / build (push) Successful in 1m26s
fix(release): 分配目标分块序列并保持原值恢复
2026-10-31 06:08:05 +08:00

36 lines
1.2 KiB
Go

package v071
import (
"encoding/json"
"testing"
)
func TestChunkSequenceProjectionKeepsContent(t *testing.T) {
for _, restore := range []bool{false, true} {
target := &ProductionLibraryTarget{scope: ProductionScope{TenantID: 10001, KnowledgeBaseID: "kb-target"}, snapshotTenant: 10002, snapshotKB: "kb-source", preserveChunkSequence: restore}
row := map[string]json.RawMessage{"id": json.RawMessage(`"chunk-src"`), "tenant_id": json.RawMessage(`10002`), "knowledge_base_id": json.RawMessage(`"kb-source"`), "seq_id": json.RawMessage(`7`), "content": json.RawMessage(`"exact content"`)}
if err := target.rowTransform("chunks")(row); err != nil {
t.Fatal(err)
}
_, present := row["seq_id"]
if present != restore {
t.Fatalf("restore=%v seq_id present=%v", restore, present)
}
if string(row["content"]) != `"exact content"` || string(row["id"]) != `"chunk-src"` {
t.Fatal("content identity was changed")
}
before, err := canonicalRowDigest(row)
if err != nil {
t.Fatal(err)
}
row["content"] = json.RawMessage(`"corrupted"`)
after, err := canonicalRowDigest(row)
if err != nil {
t.Fatal(err)
}
if before == after {
t.Fatal("content corruption was hidden")
}
}
}