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,106 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
// osClusterHandler simulates an OpenSearch cluster for the driver's
|
||||
// construction probe: GET / (version) + /_cat/plugins (k-NN on every node).
|
||||
func osClusterHandler(distribution, number string, knnInstalled bool) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.URL.Path == "/_cat/plugins" {
|
||||
if knnInstalled {
|
||||
_, _ = w.Write([]byte(`[{"name":"node-1","component":"opensearch-knn"}]`))
|
||||
} else {
|
||||
_, _ = w.Write([]byte(`[{"name":"node-1","component":"opensearch-sql"}]`))
|
||||
}
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"version":{"distribution":"` + distribution + `","number":"` + number + `"}}`))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOpenSearchEngine_WiresClientAndRepo(t *testing.T) {
|
||||
ts := httptest.NewServer(osClusterHandler("opensearch", "3.3.2", true))
|
||||
defer ts.Close()
|
||||
|
||||
store := types.VectorStore{
|
||||
ID: "", // env-style (no index prefix)
|
||||
EngineType: types.OpenSearchRetrieverEngineType,
|
||||
ConnectionConfig: types.ConnectionConfig{Addr: ts.URL},
|
||||
}
|
||||
svc, err := createOpenSearchEngine(context.Background(), store, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("createOpenSearchEngine: %v", err)
|
||||
}
|
||||
if svc == nil {
|
||||
t.Fatal("want non-nil engine service")
|
||||
}
|
||||
if svc.EngineType() != types.OpenSearchRetrieverEngineType {
|
||||
t.Errorf("engine type: want opensearch, got %s", svc.EngineType())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOpenSearchEngine_RejectsBadCluster(t *testing.T) {
|
||||
// Elasticsearch distribution must be rejected at construction.
|
||||
ts := httptest.NewServer(osClusterHandler("elasticsearch", "8.10.4", true))
|
||||
defer ts.Close()
|
||||
_, err := createOpenSearchEngine(context.Background(),
|
||||
types.VectorStore{EngineType: types.OpenSearchRetrieverEngineType,
|
||||
ConnectionConfig: types.ConnectionConfig{Addr: ts.URL}}, nil)
|
||||
if err == nil {
|
||||
t.Error("elasticsearch cluster should be rejected at engine creation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateEngineServiceFromStore_OpenSearchCaseReached(t *testing.T) {
|
||||
ts := httptest.NewServer(osClusterHandler("opensearch", "2.11.0", true))
|
||||
defer ts.Close()
|
||||
svc, err := createEngineServiceFromStore(context.Background(),
|
||||
types.VectorStore{EngineType: types.OpenSearchRetrieverEngineType,
|
||||
ConnectionConfig: types.ConnectionConfig{Addr: ts.URL}},
|
||||
nil, &config.Config{}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("createEngineServiceFromStore (opensearch case): %v", err)
|
||||
}
|
||||
if svc == nil || svc.EngineType() != types.OpenSearchRetrieverEngineType {
|
||||
t.Errorf("opensearch case not wired correctly: %v", svc)
|
||||
}
|
||||
}
|
||||
|
||||
// TestInitRetrieveEngineRegistry_OpenSearchEnvPath exercises the
|
||||
// RETRIEVE_DRIVER=opensearch env-path registration block end to end.
|
||||
func TestInitRetrieveEngineRegistry_OpenSearchEnvPath(t *testing.T) {
|
||||
ts := httptest.NewServer(osClusterHandler("opensearch", "3.3.2", true))
|
||||
defer ts.Close()
|
||||
|
||||
// In-memory DB: the vector_stores table is absent, so loadDBStores logs
|
||||
// and returns (non-fatal) — only the env-path block matters here.
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatalf("open in-mem db: %v", err)
|
||||
}
|
||||
|
||||
t.Setenv("RETRIEVE_DRIVER", "opensearch")
|
||||
t.Setenv("OPENSEARCH_ADDR", ts.URL)
|
||||
|
||||
// nil store repository and engine factory: this exercises the env-driver
|
||||
// path, which never rebuilds a database-backed store.
|
||||
registry, err := initRetrieveEngineRegistry(db, &config.Config{}, &fakeAuditSvc{}, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("initRetrieveEngineRegistry: %v", err)
|
||||
}
|
||||
if _, err := registry.GetRetrieveEngineService(types.OpenSearchRetrieverEngineType); err != nil {
|
||||
t.Errorf("opensearch engine not registered via env path: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user