WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
)
|
||||
|
||||
type summaryStaleKnowledgeRepo struct {
|
||||
interfaces.KnowledgeRepository
|
||||
knowledge *types.Knowledge
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *summaryStaleKnowledgeRepo) GetKnowledgeByID(
|
||||
_ context.Context, _ uint64, _ string,
|
||||
) (*types.Knowledge, error) {
|
||||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
clone := *r.knowledge
|
||||
return &clone, nil
|
||||
}
|
||||
|
||||
type summaryStaleChunkRepo struct {
|
||||
interfaces.ChunkRepository
|
||||
chunks map[string]*types.Chunk
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *summaryStaleChunkRepo) GetChunkByID(
|
||||
_ context.Context, _ uint64, chunkID string,
|
||||
) (*types.Chunk, error) {
|
||||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
chunk, ok := r.chunks[chunkID]
|
||||
if !ok {
|
||||
return nil, errors.New("chunk not found")
|
||||
}
|
||||
clone := *chunk
|
||||
return &clone, nil
|
||||
}
|
||||
|
||||
func TestSummarySourceChangedDetectsMetadataDrift(t *testing.T) {
|
||||
t.Parallel()
|
||||
stale, err := summarySourceChanged(
|
||||
context.Background(),
|
||||
&summaryStaleKnowledgeRepo{knowledge: &types.Knowledge{CustomMetadata: types.JSON(`{"region":"Shanghai"}`)}},
|
||||
&summaryStaleChunkRepo{},
|
||||
1, "knowledge-1", `{"region":"Beijing"}`, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !stale {
|
||||
t.Fatal("expected metadata drift to be stale")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarySourceChangedDetectsChunkRevisionDrift(t *testing.T) {
|
||||
t.Parallel()
|
||||
stale, err := summarySourceChanged(
|
||||
context.Background(),
|
||||
&summaryStaleKnowledgeRepo{knowledge: &types.Knowledge{CustomMetadata: types.JSON(`{}`)}},
|
||||
&summaryStaleChunkRepo{chunks: map[string]*types.Chunk{
|
||||
"chunk-1": {ID: "chunk-1", ContentRevision: 2, IsEnabled: true},
|
||||
}},
|
||||
1, "knowledge-1", `{}`, []*types.Chunk{{ID: "chunk-1", ContentRevision: 1, IsEnabled: true}},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !stale {
|
||||
t.Fatal("expected chunk revision drift to be stale")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarySourceChangedReturnsLookupErrors(t *testing.T) {
|
||||
t.Parallel()
|
||||
lookupErr := errors.New("database unavailable")
|
||||
_, err := summarySourceChanged(
|
||||
context.Background(),
|
||||
&summaryStaleKnowledgeRepo{err: lookupErr},
|
||||
&summaryStaleChunkRepo{},
|
||||
1, "knowledge-1", `{}`, nil,
|
||||
)
|
||||
if !errors.Is(err, lookupErr) {
|
||||
t.Fatalf("expected lookup error, got %v", err)
|
||||
}
|
||||
|
||||
_, err = summarySourceChanged(
|
||||
context.Background(),
|
||||
&summaryStaleKnowledgeRepo{knowledge: &types.Knowledge{CustomMetadata: types.JSON(`{}`)}},
|
||||
&summaryStaleChunkRepo{err: lookupErr},
|
||||
1, "knowledge-1", `{}`, []*types.Chunk{{ID: "chunk-1"}},
|
||||
)
|
||||
if !errors.Is(err, lookupErr) {
|
||||
t.Fatalf("expected chunk lookup error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarySourceChangedAcceptsCurrentSnapshot(t *testing.T) {
|
||||
t.Parallel()
|
||||
stale, err := summarySourceChanged(
|
||||
context.Background(),
|
||||
&summaryStaleKnowledgeRepo{knowledge: &types.Knowledge{CustomMetadata: types.JSON(`{"region":"Shanghai"}`)}},
|
||||
&summaryStaleChunkRepo{chunks: map[string]*types.Chunk{
|
||||
"chunk-1": {ID: "chunk-1", ContentRevision: 3, IsEnabled: true},
|
||||
}},
|
||||
1, "knowledge-1", `{"region":"Shanghai"}`,
|
||||
[]*types.Chunk{{ID: "chunk-1", ContentRevision: 3, IsEnabled: true}},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if stale {
|
||||
t.Fatal("expected current snapshot to be accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user