fix(snapshot): 拒绝旧式分块缺失索引的候选

This commit is contained in:
姚章浩
2026-10-28 01:17:58 +08:00
parent c4759bb61c
commit 74b9fedc57
3 changed files with 54 additions and 0 deletions
+7
View File
@@ -1,5 +1,12 @@
# Changelog
## 开发快照 snapshot/v0.1.102 - 2026-10-28
### Fixed
- 阻止旧式 status=0 普通分块缺失索引时被误判完整;仅明确的上下文父分块允许没有索引,显式标记已索引的分块仍须存在。
- 缺少可核验的无索引策略时返回覆盖未证实,不推断索引已禁用;Wiki-only 无索引库的完整支持仍待实现,不因此宣称整库验收通过。
## 开发快照 snapshot/v0.1.101 - 2026-10-28
### Fixed
@@ -271,7 +271,13 @@ func validateLibraryCandidate(identity PostgresIdentity, pg PostgresSnapshot, es
// v0.7.1 ChunkStatusIndexed is 2. One chunk can have several search
// records, so compare identities rather than counts. Stored-only parent
// chunks intentionally have no index and must not be rejected as missing.
// Text ingestion also leaves indexed chunks at the legacy default status
// zero. Without an archived no-index policy, absence is unverified, not
// proof that indexing was disabled. Parent chunks are context-only.
for id, chunk := range tables["chunks"] {
if chunk.ChunkStatus == 0 && chunk.ChunkType != "parent_text" && !indexedChunks[id] {
return errors.New("unverified legacy library chunk index coverage")
}
if chunk.ChunkStatus == 2 && !indexedChunks[id] {
return errors.New("missing indexed library chunk")
}
@@ -0,0 +1,41 @@
package v071
import (
"encoding/json"
"testing"
)
func TestLibraryCandidateLegacyChunkIndexCoverage(t *testing.T) {
for _, tc := range []struct {
name, kind string
status int
indexed, valid bool
}{
{"legacy text missing", "text", 0, false, false},
{"legacy text indexed", "text", 0, true, true},
{"legacy unknown type missing", "", 0, false, false},
{"context parent not indexed", "parent_text", 0, false, true},
{"stored parent not indexed", "parent_text", 1, false, true},
{"indexed parent missing", "parent_text", 2, false, false},
} {
t.Run(tc.name, func(t *testing.T) {
pg, es, _ := libraryCandidateFixture()
raw, err := json.Marshal(map[string]any{"id": "chunk-safe", "tenant_id": 10000, "knowledge_base_id": "kb-safe", "knowledge_id": "doc-safe", "content": "chunk", "status": tc.status, "chunk_type": tc.kind})
if err != nil {
t.Fatal(err)
}
pg.Tables[1] = newTableSnapshot("chunks", []json.RawMessage{raw})
if !tc.indexed {
es.Documents = nil
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
}
err = validateLibraryCandidate(PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, pg, es)
if tc.valid && err != nil {
t.Fatalf("valid chunk rejected: %v", err)
}
if !tc.valid && err == nil {
t.Fatal("missing legacy index escaped completeness validation")
}
})
}
}