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

This commit is contained in:
yawan
2026-09-22 16:19:06 +08:00
commit f7fc992f57
3929 changed files with 1006607 additions and 0 deletions
@@ -0,0 +1,95 @@
package service
import (
"context"
"testing"
"github.com/alicebob/miniredis/v2"
"github.com/redis/go-redis/v9"
)
func newGuardService(t *testing.T) *knowledgeService {
t.Helper()
mr, err := miniredis.Run()
if err != nil {
t.Fatalf("start miniredis: %v", err)
}
t.Cleanup(mr.Close)
rdb := redis.NewClient(&redis.Options{Addr: mr.Addr()})
t.Cleanup(func() { _ = rdb.Close() })
return &knowledgeService{redisClient: rdb}
}
func TestAcquireFAQCreateGuardRejectsConcurrentSameQuestion(t *testing.T) {
svc := newGuardService(t)
ctx := context.Background()
release, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-1", "哈哈哈")
if err != nil {
t.Fatalf("first acquire failed: %v", err)
}
if _, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-1", "哈哈哈"); err == nil {
t.Fatal("expected the retry to be rejected while the first create is in flight")
}
// Once the first create finishes the question is writable again, so a real
// retry after a genuine failure is not permanently blocked.
release()
release2, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-1", "哈哈哈")
if err != nil {
t.Fatalf("acquire after release failed: %v", err)
}
release2()
}
func TestAcquireFAQCreateGuardIsolatesUnrelatedCreates(t *testing.T) {
svc := newGuardService(t)
ctx := context.Background()
release, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-1", "哈哈哈")
if err != nil {
t.Fatalf("acquire failed: %v", err)
}
defer release()
for _, tc := range []struct {
name string
tenantID uint64
kbID string
question string
}{
{"different question", 1, "kb-1", "呵呵呵"},
{"different knowledge base", 1, "kb-2", "哈哈哈"},
{"different tenant", 2, "kb-1", "哈哈哈"},
} {
t.Run(tc.name, func(t *testing.T) {
release, err := svc.acquireFAQCreateGuard(ctx, tc.tenantID, tc.kbID, tc.question)
if err != nil {
t.Fatalf("acquire failed: %v", err)
}
release()
})
}
}
func TestAcquireFAQCreateGuardFallsBackWithoutRedis(t *testing.T) {
svc := &knowledgeService{}
ctx := context.Background()
release, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-lite", "哈哈哈")
if err != nil {
t.Fatalf("first acquire failed: %v", err)
}
if _, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-lite", "哈哈哈"); err == nil {
t.Fatal("expected in-process guard to reject the concurrent create")
}
release()
release2, err := svc.acquireFAQCreateGuard(ctx, 1, "kb-lite", "哈哈哈")
if err != nil {
t.Fatalf("acquire after release failed: %v", err)
}
release2()
}