Files
xinmi/internal/application/service/wiki_real_resolution_test.go
yawan f7fc992f57
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
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

94 lines
3.4 KiB
Go

package service
import (
"context"
"encoding/json"
"os"
"testing"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"github.com/stretchr/testify/require"
)
// checkpointsWikiPages serves the real pages of one knowledge base from a fixture.
type checkpointsWikiPages struct {
interfaces.WikiPageService
bySlug map[string]*types.WikiPageLite
}
func (f checkpointsWikiPages) ListBySlugs(ctx context.Context, kbID string, slugs []string) (map[string]*types.WikiPageLite, error) {
out := make(map[string]*types.WikiPageLite, len(slugs))
for _, slug := range slugs {
if page := f.bySlug[slug]; page != nil {
out[slug] = page
}
}
return out, nil
}
func (f checkpointsWikiPages) FindPagesByNormalizedTitles(ctx context.Context, kbID, pageType string, identities []string) ([]*types.WikiPageLite, error) {
wanted := make(map[string]bool, len(identities))
for _, identity := range identities {
wanted[identity] = true
}
var out []*types.WikiPageLite
for _, page := range f.bySlug {
if page.PageType == pageType && wanted[normalizeWikiIdentityTitle(page.Title)] {
out = append(out, page)
}
}
return out, nil
}
// Replays the fifteen real candidate payloads of one document through the complete
// reading-tail path (normalize, resolve, merge) against the pages that knowledge base
// really owns, so a conflict that aborted the document in production is reproduced
// and then fixed offline.
func TestWikiRealWindowsFullResolution(t *testing.T) {
windowsPath, pagesPath := os.Getenv("WIKI_REPLAY_FILE"), os.Getenv("WIKI_PAGES_FILE")
if windowsPath == "" || pagesPath == "" {
t.Skip("WIKI_REPLAY_FILE and WIKI_PAGES_FILE must be set")
}
rawWindows, err := os.ReadFile(windowsPath)
require.NoError(t, err)
var texts []string
require.NoError(t, json.Unmarshal(rawWindows, &texts))
rawPages, err := os.ReadFile(pagesPath)
require.NoError(t, err)
var pages []*types.WikiPageLite
require.NoError(t, json.Unmarshal(rawPages, &pages))
bySlug := make(map[string]*types.WikiPageLite, len(pages))
for _, page := range pages {
bySlug[page.Slug] = page
}
merged := combinedExtraction{}
for i, text := range texts {
var part combinedExtraction
require.NoError(t, json.Unmarshal([]byte(text), &part), "window %d", i)
merged.Entities = append(merged.Entities, part.Entities...)
merged.Concepts = append(merged.Concepts, part.Concepts...)
}
normalized, err := normalizeWikiFreshCandidates(merged)
require.NoError(t, err, "normalization rejected the real candidate set")
t.Logf("normalized: E=%d C=%d", len(normalized.Entities), len(normalized.Concepts))
service := &wikiIngestService{wikiService: checkpointsWikiPages{bySlug: bySlug}}
resolved, err := service.resolveWikiSourceIdentities(context.Background(), "kb-real", normalized, nil)
require.NoError(t, err, "identity resolution rejected the real candidate set")
t.Logf("resolved: E=%d C=%d pruning=%+v", len(resolved.Entities), len(resolved.Concepts), resolved.CandidatePruning)
require.Positive(t, len(resolved.Entities)+len(resolved.Concepts), "the document must still publish pages")
seen := map[string]string{}
for _, item := range append(append([]extractedItem{}, resolved.Entities...), resolved.Concepts...) {
if other, ok := seen[item.Slug]; ok && other != item.Name {
t.Fatalf("slug %q still shared by %q and %q", item.Slug, other, item.Name)
}
seen[item.Slug] = item.Name
}
t.Logf("final identity count: %d", len(seen))
}