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
81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
package memory
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestListDocumentsShowsHabitsNotOneOffs(t *testing.T) {
|
|
svc, _, tenantRepo := newMemoryHarness(t)
|
|
ctx := enabledCtx(t, tenantRepo, 1, "alice")
|
|
|
|
ref := []types.MemoryDocAffinity{{
|
|
KnowledgeID: "doc-1", KnowledgeBaseID: "kb-1", Title: "排班手册",
|
|
}}
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
docs, total, err := svc.ListDocuments(ctx, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Zero(t, total, "one citation is noise, not a habit")
|
|
require.Empty(t, docs)
|
|
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
docs, total, err = svc.ListDocuments(ctx, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Equal(t, int64(1), total)
|
|
require.Len(t, docs, 1)
|
|
require.Equal(t, "排班手册", docs[0].Title)
|
|
require.Equal(t, 2, docs[0].Hits)
|
|
require.Equal(t, []string{"doc-1"}, svc.FamiliarKnowledgeIDs(ctx))
|
|
}
|
|
|
|
func TestListDocumentsDoesNotLeakAcrossPeople(t *testing.T) {
|
|
svc, _, tenantRepo := newMemoryHarness(t)
|
|
alice := enabledCtx(t, tenantRepo, 1, "alice")
|
|
bob := enabledCtx(t, tenantRepo, 1, "bob")
|
|
ref := []types.MemoryDocAffinity{{KnowledgeID: "doc-1", Title: "排班手册"}}
|
|
svc.RecordAnswerSources(alice, ref)
|
|
svc.RecordAnswerSources(alice, ref)
|
|
|
|
docs, total, err := svc.ListDocuments(bob, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Zero(t, total)
|
|
require.Empty(t, docs)
|
|
require.Empty(t, svc.FamiliarKnowledgeIDs(bob))
|
|
}
|
|
|
|
func TestDeleteDocumentStopsPersonalizingRetrieval(t *testing.T) {
|
|
svc, _, tenantRepo := newMemoryHarness(t)
|
|
ctx := enabledCtx(t, tenantRepo, 1, "alice")
|
|
ref := []types.MemoryDocAffinity{{KnowledgeID: "doc-1", Title: "排班手册"}}
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
|
|
docs, _, err := svc.ListDocuments(ctx, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Len(t, docs, 1)
|
|
require.NoError(t, svc.DeleteDocument(ctx, docs[0].ID))
|
|
|
|
left, total, err := svc.ListDocuments(ctx, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Zero(t, total)
|
|
require.Empty(t, left)
|
|
require.Empty(t, svc.DocumentAffinity(ctx, []string{"doc-1"}))
|
|
}
|
|
|
|
func TestClearDropsDocumentAffinity(t *testing.T) {
|
|
svc, _, tenantRepo := newMemoryHarness(t)
|
|
ctx := enabledCtx(t, tenantRepo, 1, "alice")
|
|
ref := []types.MemoryDocAffinity{{KnowledgeID: "doc-1", Title: "排班手册"}}
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
svc.RecordAnswerSources(ctx, ref)
|
|
|
|
_, err := svc.Clear(ctx)
|
|
require.NoError(t, err)
|
|
docs, total, err := svc.ListDocuments(ctx, 10, 0)
|
|
require.NoError(t, err)
|
|
require.Zero(t, total)
|
|
require.Empty(t, docs)
|
|
}
|