Compare commits

...

3 Commits

Author SHA1 Message Date
姚章浩 55fba5fc0e fix(snapshot): 按表解析状态并保留完整Wiki内容
build / build (push) Successful in 1m11s
2026-10-28 00:57:43 +08:00
姚章浩 ce2f90c1c5 fix(snapshot): 阻止已索引分块缺失时封存整库
build / build (push) Successful in 1m12s
2026-10-28 00:43:31 +08:00
姚章浩 2c5ecdf0f3 fix(version): 补齐整库基础版本的独立快照说明
build / build (push) Successful in 1m11s
2026-10-28 00:34:20 +08:00
6 changed files with 216 additions and 2 deletions
+34
View File
@@ -1,5 +1,39 @@
# Changelog
## 开发快照 snapshot/v0.1.99 - 2026-10-28
### Fixed
- 修复整库归档将 Wiki 页面与问题记录的字符串状态误按分块整数状态解析的问题;分块状态仅在分块表中解析,Wiki 状态和正文原样保留。
- 候选捕获回归改用非空 Wiki 页面与问题记录,防止空表夹具漏检。本次仍不代表完整同步恢复业务已交付。
## 开发快照 snapshot/v0.1.98 - 2026-10-28
### Fixed
- 修复整库候选封存只单向校验搜索索引的问题:数据库标记为已索引的分块必须在导出索引中存在,否则拒绝封存;按分块身份而非总数量核对,避免重复索引掩盖缺失。仅存储的父分块仍允许不建索引。
- 本修复增强候选完整性,不代表整库业务入口、生产同步恢复或语义验收已经完成。
## 开发快照 snapshot/v0.1.97 - 2026-10-28
### Fixed
- 补齐已部署 0.1.96 的独立开发说明与精确提交绑定,恢复版本记录核验所需的开发快照证据;不变更正式版本号,不声称整库同步已经交付。
- 更正整库验收文档中仍写“未提交、未部署”的历史状态,保留未接线、未验收与生产执行边界。
## 开发快照 snapshot/v0.1.96 - 2026-10-27
目标提交:9105f8316cc870a62b5ddacd1496f0cb0f798d87
### Added
- 增加整库 PostgreSQL 只读快照、Elasticsearch PIT 导出及独立资源归档,包含完整 Wiki 表、资源关联和摘要校验。
- 增加测试写入服务暂停、持久恢复日志、异常与进程中断恢复原语,并实现候选捕获协调函数。
### Changed
- 本版本仅交付基础模块:尚无整库业务调用入口、版本验收绑定、生产预备份与同步恢复工作流、新发布页面及完整存储治理。隔离测试通过不等于完整业务验收通过;不包含生产执行或实际清理授权。
## [Unreleased]
### Added
+1 -1
View File
@@ -83,7 +83,7 @@
2. 数据库 MVCC 与 ES PIT 是各自独立的快照,不能把两者拼接视为一致整版。用户已确认方案 A:封存期间自动暂停测试服务;全部写入者隔离、异常恢复及实际停用时长尚待实现与验证,不修改 WeKnora 源码,不暂停生产。
3. 已检查本地 v0.7.1 源码:`EnqueueWikiRetract` 在持久化 pending op 失败时记录警告后返回;因此 pending/dead-letter 都为空仍不证明撤销语义已处理。必须补充删除后共享 Wiki 内容的实测与验收绑定。
4. 生产预备份、独立恢复演练、持久化协调作业、授权 API、真实进度、发布页面与完整存储治理仍未交付;以上验收项目保持待验证。
5. 当前新增代码未提交、未推送、未部署;未执行生产同步、恢复或真实业务清理。
5. 基础模块已随 `0.1.96 / 9105f8316cc870a62b5ddacd1496f0cb0f798d87` 提交、推送并部署到本地测试治理平台;运行 API/worker 的二进制摘要已读回校验。该部署不等于业务功能接线或完整验收通过;未执行生产同步、恢复或真实业务清理。完整验收仍受本节及下述缺失接线阻塞。
## 方案 A:暂停与恢复原语的实测证据
@@ -116,6 +116,7 @@ type libraryRow struct {
OwnerType string `json:"owner_type"`
OwnerID string `json:"owner_id"`
Content string `json:"content"`
ChunkStatus int `json:"-"`
}
func validateLibraryCandidate(identity PostgresIdentity, pg PostgresSnapshot, es SearchSnapshot) error {
@@ -151,6 +152,17 @@ func validateLibraryCandidate(identity PostgresIdentity, pg PostgresSnapshot, es
if json.Unmarshal(raw, &row) != nil {
return errors.New("invalid library content row")
}
// Status is table-specific: chunks use integers, Wiki pages/issues
// use strings. Decode chunk metadata only for its owning table.
if table.Name == "chunks" {
var metadata struct {
Status int `json:"status"`
}
if json.Unmarshal(raw, &metadata) != nil {
return errors.New("invalid library chunk status")
}
row.ChunkStatus = metadata.Status
}
if table.Name == "knowledge_tag_relations" {
if !validSearchIdentifier(row.KnowledgeID) || !validSearchIdentifier(row.TagID) {
return errors.New("invalid library tag relation")
@@ -220,6 +232,7 @@ func validateLibraryCandidate(identity PostgresIdentity, pg PostgresSnapshot, es
return errors.New("invalid library index digest")
}
seen := map[string]bool{}
indexedChunks := map[string]bool{}
for _, document := range es.Documents {
var row libraryRow
if json.Unmarshal(document.Source, &row) != nil || !validSearchIdentifier(document.ID) || seen[document.ID] {
@@ -233,6 +246,15 @@ func validateLibraryCandidate(identity PostgresIdentity, pg PostgresSnapshot, es
if !searchHitMatches(document.Source, SearchIdentity{TenantID: identity.TenantID, KnowledgeBaseID: identity.KnowledgeBaseID, KnowledgeID: row.KnowledgeID}) {
return errors.New("cross-scope library index")
}
indexedChunks[row.ChunkID] = true
}
// 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.
for id, chunk := range tables["chunks"] {
if chunk.ChunkStatus == 2 && !indexedChunks[id] {
return errors.New("missing indexed library chunk")
}
}
return nil
}
@@ -88,7 +88,14 @@ func libraryCandidateFixture() (PostgresSnapshot, SearchSnapshot, *libraryCandid
newTableSnapshot("resources", []json.RawMessage{json.RawMessage(`{"id":"res-safe","tenant_id":10000,"handle":"ABCDEFGHIJKLMNOPQRSTUV","provider":"oss","physical_path":"oss://fixture/source.txt","size":4}`)}),
}
for _, name := range []string{"resource_bindings", "knowledge_tags", "knowledge_tag_relations", "wiki_folders", "wiki_pages", "wiki_page_issues", "wiki_log_entries"} {
tables = append(tables, newTableSnapshot(name, nil))
var rows []json.RawMessage
switch name {
case "wiki_pages":
rows = []json.RawMessage{json.RawMessage(`{"id":"wiki-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","status":"published","content":"complete wiki body"}`)}
case "wiki_page_issues":
rows = []json.RawMessage{json.RawMessage(`{"id":"issue-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","status":"open"}`)}
}
tables = append(tables, newTableSnapshot(name, rows))
}
es := SearchSnapshot{MappingSHA256: shaBytes([]byte("mapping")), Documents: []SearchDocument{{ID: "es-safe", Source: json.RawMessage(`{"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","chunk_id":"chunk-safe","content":"chunk"}`)}}}
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
@@ -0,0 +1,71 @@
package v071
import (
"context"
"encoding/json"
"os"
"strings"
"testing"
"time"
"knowledge-governance/internal/librarysnapshot"
)
func TestLibraryCandidateIndexCompletenessUsesChunkIdentity(t *testing.T) {
for _, mode := range []string{"stored-parent", "multiple-records-one-chunk", "same-count-missing-chunk"} {
t.Run(mode, func(t *testing.T) {
pg, es, _ := libraryCandidateFixture()
rows := []json.RawMessage{json.RawMessage(`{"id":"chunk-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","content":"chunk","status":2,"chunk_type":"text"}`)}
if mode == "stored-parent" {
rows = append(rows, json.RawMessage(`{"id":"parent-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","content":"context","status":1,"chunk_type":"parent_text"}`))
} else {
es.Documents = append(es.Documents, SearchDocument{ID: "es-second", Source: append(json.RawMessage(nil), es.Documents[0].Source...)})
if mode == "same-count-missing-chunk" {
rows = append(rows, json.RawMessage(`{"id":"chunk-second","tenant_id":10000,"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","content":"second","status":2,"chunk_type":"text"}`))
}
}
pg.Tables[1] = newTableSnapshot("chunks", rows)
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
err := validateLibraryCandidate(PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, pg, es)
if mode == "same-count-missing-chunk" {
if err == nil || !strings.Contains(err.Error(), "missing indexed library chunk") {
t.Fatalf("same counts masked a missing chunk: %v", err)
}
} else if err != nil {
t.Fatalf("valid index shape rejected: %v", err)
}
})
}
}
func TestLibraryCandidateRejectsMissingIndexedChunk(t *testing.T) {
pg, es, objects := libraryCandidateFixture()
pg.Tables[1] = newTableSnapshot("chunks", []json.RawMessage{json.RawMessage(`{"id":"chunk-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","knowledge_id":"doc-safe","content":"chunk","status":2,"chunk_type":"text"}`)})
identity := PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}
if err := validateLibraryCandidate(identity, pg, es); err != nil {
t.Fatalf("complete indexed chunk rejected: %v", err)
}
es.Documents = nil
es.DocumentsSHA256, _ = searchDocumentsDigest(es.Documents)
root := t.TempDir()
if err := os.Chmod(root, 0700); err != nil {
t.Fatal(err)
}
archive, err := librarysnapshot.Open(root, 1024*1024)
if err != nil {
t.Fatal(err)
}
defer archive.Close()
contract := librarysnapshot.Compatibility{WeKnoraVersion: "v0.7.1", SchemaVersion: 74, RetrieverEngine: "elasticsearch_v8", EmbeddingModel: "fixture-model", EmbeddingDimension: 1024, IndexMappingSHA256: es.MappingSHA256}
id, err := ArchiveLibraryCandidate(context.Background(), archive, "internal", identity, contract, pg, es, objects, time.Now().UTC())
if err == nil || id != "" {
t.Fatal("sealed a supposedly complete library with an indexed PostgreSQL chunk missing from Elasticsearch")
}
if !strings.Contains(err.Error(), "missing indexed library chunk") {
t.Fatalf("unexpected refusal: %v", err)
}
versions, err := os.ReadDir(root + "/versions")
if err != nil || len(versions) != 0 {
t.Fatalf("incomplete candidate became visible: versions=%d err=%v", len(versions), err)
}
}
@@ -0,0 +1,80 @@
package v071
import (
"context"
"encoding/json"
"io"
"os"
"testing"
"time"
"knowledge-governance/internal/librarysnapshot"
)
func TestLibraryCandidateArchivesWikiStringStatuses(t *testing.T) {
for _, tc := range []struct{ table, status string }{
{"wiki_pages", "draft"}, {"wiki_pages", "published"}, {"wiki_pages", "archived"},
{"wiki_page_issues", "open"}, {"wiki_page_issues", "resolved"},
} {
t.Run(tc.table+"/"+tc.status, func(t *testing.T) {
pg, es, objects := libraryCandidateFixture()
raw := json.RawMessage(`{"id":"wiki-safe","tenant_id":10000,"knowledge_base_id":"kb-safe","content":"complete wiki body","status":"` + tc.status + `"}`)
for i := range pg.Tables {
if pg.Tables[i].Name == tc.table {
pg.Tables[i] = newTableSnapshot(tc.table, []json.RawMessage{raw})
}
}
root := t.TempDir()
if err := os.Chmod(root, 0700); err != nil {
t.Fatal(err)
}
archive, err := librarysnapshot.Open(root, 1024*1024)
if err != nil {
t.Fatal(err)
}
defer archive.Close()
contract := librarysnapshot.Compatibility{WeKnoraVersion: "v0.7.1", SchemaVersion: 74, RetrieverEngine: "elasticsearch_v8", EmbeddingModel: "fixture-model", EmbeddingDimension: 1024, IndexMappingSHA256: es.MappingSHA256}
id, err := ArchiveLibraryCandidate(context.Background(), archive, "internal", PostgresIdentity{TenantID: 10000, KnowledgeBaseID: "kb-safe"}, contract, pg, es, objects, time.Now().UTC())
if err != nil {
t.Fatalf("valid Wiki string status rejected: %v", err)
}
saved, err := archive.Load(id)
if err != nil {
t.Fatal(err)
}
found := false
for _, part := range saved.Parts {
if part.Name != tc.table {
continue
}
found = true
r, e := archive.OpenPart(part)
if e != nil {
t.Fatal(e)
}
data, e := io.ReadAll(r)
r.Close()
if e != nil {
t.Fatal(e)
}
var rows []json.RawMessage
if e = json.Unmarshal(data, &rows); e != nil {
t.Fatal(e)
}
if len(rows) != 1 {
t.Fatalf("wiki rows=%d", len(rows))
}
var row map[string]any
if e = json.Unmarshal(rows[0], &row); e != nil {
t.Fatal(e)
}
if row["status"] != tc.status || row["content"] != "complete wiki body" {
t.Fatal("Wiki status/body changed in archive")
}
}
if !found {
t.Fatal("Wiki part missing")
}
})
}
}