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,97 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/application/service/retriever"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// ctxRecordingRegistry captures the context handed to the store lookup and
|
||||
// then fails, so the caller stops before building retrieval params.
|
||||
type ctxRecordingRegistry struct {
|
||||
interfaces.RetrieveEngineRegistry
|
||||
seen context.Context
|
||||
}
|
||||
|
||||
func (r *ctxRecordingRegistry) GetByStoreID(string) (interfaces.RetrieveEngineService, error) {
|
||||
return nil, stderrors.New("store not in registry")
|
||||
}
|
||||
|
||||
func (r *ctxRecordingRegistry) GetOrLoadByStoreID(
|
||||
ctx context.Context, _ uint64, _ string,
|
||||
) (interfaces.RetrieveEngineService, error) {
|
||||
r.seen = ctx
|
||||
return nil, stderrors.New("build refused")
|
||||
}
|
||||
|
||||
// TestResolveStoreGroups_BoundsEngineResolution pins the ceiling on engine
|
||||
// resolution.
|
||||
//
|
||||
// Groups are resolved one at a time and each may rebuild a missing engine by
|
||||
// dialing its backend. This server configures no HTTP read or write timeout,
|
||||
// so without a budget here a search over several cold stores would run for as
|
||||
// long as the sum of those builds with nothing to stop it.
|
||||
func TestResolveStoreGroups_BoundsEngineResolution(t *testing.T) {
|
||||
storeID := "00000000-0000-0000-0000-0000000000bb"
|
||||
registry := &ctxRecordingRegistry{}
|
||||
svc := &knowledgeBaseService{
|
||||
retrieveEngine: registry,
|
||||
ownership: &fakeOwnership{owned: map[string]uint64{storeID: 1}},
|
||||
}
|
||||
kb := &types.KnowledgeBase{ID: "kb-1", TenantID: 1, VectorStoreID: &storeID}
|
||||
|
||||
_, err := svc.resolveStoreGroups(
|
||||
context.Background(), kb, []*types.KnowledgeBase{kb}, types.SearchParams{}, 5)
|
||||
|
||||
require.Error(t, err, "the refused build must surface as an error")
|
||||
require.NotNil(t, registry.seen, "the lookup must have been reached")
|
||||
|
||||
deadline, ok := registry.seen.Deadline()
|
||||
require.True(t, ok, "engine resolution must run under a deadline")
|
||||
// Compared against a literal rather than the constant itself: checking the
|
||||
// constant against its own value passes no matter what it is changed to.
|
||||
assert.InDelta(t, 12.0, time.Until(deadline).Seconds(), 0.5,
|
||||
"the deadline must come from the resolve budget")
|
||||
}
|
||||
|
||||
// TestStoreResolveBudgetExceedsOneBuild pins the relationship the budget
|
||||
// depends on. Resolution can rebuild an engine, so a budget at or below a
|
||||
// single build timeout would cut off the first rebuild it is meant to allow
|
||||
// and turn every cold store into an error.
|
||||
func TestStoreResolveBudgetExceedsOneBuild(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Greater(t, storeResolveBudget, retriever.EngineBuildTimeout,
|
||||
"the search budget must leave room for at least one engine build")
|
||||
}
|
||||
|
||||
// TestResolveStoreGroups_BudgetDoesNotOutliveTheCaller checks that the budget
|
||||
// only ever shortens the caller's context, never extends it.
|
||||
func TestResolveStoreGroups_BudgetDoesNotOutliveTheCaller(t *testing.T) {
|
||||
storeID := "00000000-0000-0000-0000-0000000000cc"
|
||||
registry := &ctxRecordingRegistry{}
|
||||
svc := &knowledgeBaseService{
|
||||
retrieveEngine: registry,
|
||||
ownership: &fakeOwnership{owned: map[string]uint64{storeID: 1}},
|
||||
}
|
||||
kb := &types.KnowledgeBase{ID: "kb-1", TenantID: 1, VectorStoreID: &storeID}
|
||||
|
||||
callerDeadline := time.Now().Add(2 * time.Second)
|
||||
ctx, cancel := context.WithDeadline(context.Background(), callerDeadline)
|
||||
defer cancel()
|
||||
|
||||
_, err := svc.resolveStoreGroups(ctx, kb, []*types.KnowledgeBase{kb}, types.SearchParams{}, 5)
|
||||
require.Error(t, err)
|
||||
|
||||
deadline, ok := registry.seen.Deadline()
|
||||
require.True(t, ok)
|
||||
assert.False(t, deadline.After(callerDeadline),
|
||||
"a caller that allows less time than the budget must still win")
|
||||
}
|
||||
Reference in New Issue
Block a user