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,133 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTagScopesFromMentionedItems(t *testing.T) {
|
||||
scopes := tagScopesFromMentionedItems([]MentionedItemRequest{
|
||||
{Type: "tag", ID: "tag-1", KBID: "kb-1"},
|
||||
{Type: "tag", ID: "tag-2", KBID: "kb-1"},
|
||||
{Type: "tag", ID: "tag-3", KBID: "kb-2"},
|
||||
{Type: "tag", ID: "orphan", KBID: ""},
|
||||
})
|
||||
assert.Len(t, scopes, 2)
|
||||
byKB := make(map[string][]string)
|
||||
for _, scope := range scopes {
|
||||
byKB[scope.KnowledgeBaseID] = scope.TagIDs
|
||||
}
|
||||
assert.ElementsMatch(t, []string{"tag-1", "tag-2"}, byKB["kb-1"])
|
||||
assert.Equal(t, []string{"tag-3"}, byKB["kb-2"])
|
||||
}
|
||||
|
||||
func TestMergeTagScopesFromRequestIDs_SingleKB(t *testing.T) {
|
||||
scopes := mergeTagScopesFromRequestIDs(
|
||||
[]types.TagScope{{KnowledgeBaseID: "kb-1", TagIDs: []string{"tag-1"}}},
|
||||
[]string{"tag-2"},
|
||||
[]string{"kb-1"},
|
||||
)
|
||||
assert.Len(t, scopes, 1)
|
||||
assert.ElementsMatch(t, []string{"tag-1", "tag-2"}, scopes[0].TagIDs)
|
||||
}
|
||||
|
||||
func TestMergeTagScopesFromRequestIDs_OrphanWithSingleKB(t *testing.T) {
|
||||
scopes := mergeTagScopesFromRequestIDs(nil, []string{"tag-9"}, []string{"kb-1"})
|
||||
assert.Len(t, scopes, 1)
|
||||
assert.Equal(t, "kb-1", scopes[0].KnowledgeBaseID)
|
||||
assert.Equal(t, []string{"tag-9"}, scopes[0].TagIDs)
|
||||
}
|
||||
|
||||
func TestMergeTagScopesFromRequestIDs_AmbiguousKBIgnored(t *testing.T) {
|
||||
scopes := mergeTagScopesFromRequestIDs(nil, []string{"tag-9"}, []string{"kb-1", "kb-2"})
|
||||
assert.Empty(t, scopes)
|
||||
}
|
||||
|
||||
func TestValidateUnscopedTagIDs(t *testing.T) {
|
||||
assert.NoError(t, validateUnscopedTagIDs(nil, nil))
|
||||
assert.NoError(t, validateUnscopedTagIDs(nil, []string{"kb-1", "kb-2"}))
|
||||
assert.NoError(t, validateUnscopedTagIDs([]string{"tag-9"}, []string{"kb-1"}))
|
||||
assert.Error(t, validateUnscopedTagIDs([]string{"tag-9"}, []string{"kb-1", "kb-2"}))
|
||||
assert.Error(t, validateUnscopedTagIDs([]string{"tag-9"}, nil))
|
||||
}
|
||||
|
||||
// TestSearchResultFromMap_RoundTrip simulates the Redis round trip: a
|
||||
// *types.SearchResult is serialized to JSON, deserialized into a generic map,
|
||||
// and rebuilt via searchResultFromMap. All fields, including metadata, must
|
||||
// survive.
|
||||
func TestSearchResultFromMap_RoundTrip(t *testing.T) {
|
||||
original := &types.SearchResult{
|
||||
ID: "chunk-1",
|
||||
Content: "first part\nsecond part",
|
||||
KnowledgeID: "knowledge-1",
|
||||
ChunkIndex: 3,
|
||||
KnowledgeTitle: "title",
|
||||
StartAt: 10,
|
||||
EndAt: 20,
|
||||
Seq: 2,
|
||||
Score: 4.5,
|
||||
ChunkType: "text",
|
||||
ParentChunkID: "parent-1",
|
||||
ImageInfo: `[{"url":"cdn.example.com"}]`,
|
||||
KnowledgeFilename: "doc.txt",
|
||||
KnowledgeSource: "upload",
|
||||
KnowledgeDescription: "desc",
|
||||
KnowledgeBaseID: "kb-1",
|
||||
Metadata: map[string]string{"page": "3"},
|
||||
}
|
||||
|
||||
raw, err := json.Marshal(original)
|
||||
require.NoError(t, err)
|
||||
var refMap map[string]interface{}
|
||||
require.NoError(t, json.Unmarshal(raw, &refMap))
|
||||
|
||||
got := searchResultFromMap(refMap)
|
||||
|
||||
assert.Equal(t, original.ID, got.ID)
|
||||
assert.Equal(t, original.Content, got.Content)
|
||||
assert.Equal(t, original.KnowledgeID, got.KnowledgeID)
|
||||
assert.Equal(t, original.ChunkIndex, got.ChunkIndex)
|
||||
assert.Equal(t, original.KnowledgeTitle, got.KnowledgeTitle)
|
||||
assert.Equal(t, original.StartAt, got.StartAt)
|
||||
assert.Equal(t, original.EndAt, got.EndAt)
|
||||
assert.Equal(t, original.Seq, got.Seq)
|
||||
assert.Equal(t, original.Score, got.Score)
|
||||
assert.Equal(t, original.ChunkType, got.ChunkType)
|
||||
assert.Equal(t, original.ParentChunkID, got.ParentChunkID)
|
||||
assert.Equal(t, original.ImageInfo, got.ImageInfo)
|
||||
assert.Equal(t, original.KnowledgeFilename, got.KnowledgeFilename)
|
||||
assert.Equal(t, original.KnowledgeSource, got.KnowledgeSource)
|
||||
assert.Equal(t, original.KnowledgeDescription, got.KnowledgeDescription)
|
||||
assert.Equal(t, original.KnowledgeBaseID, got.KnowledgeBaseID)
|
||||
assert.Equal(t, original.Metadata, got.Metadata)
|
||||
}
|
||||
|
||||
func TestCreateAgentQueryEventIncludesPersistedTimestamps(t *testing.T) {
|
||||
userAt := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
|
||||
assistantAt := time.Date(2026, 1, 2, 3, 4, 6, 0, time.UTC)
|
||||
|
||||
evt := createAgentQueryEvent("sess-1", "asst-1", "user-1", userAt, assistantAt)
|
||||
|
||||
assert.Equal(t, types.ResponseTypeAgentQuery, evt.Type)
|
||||
assert.Equal(t, "sess-1", evt.Data["session_id"])
|
||||
assert.Equal(t, "asst-1", evt.Data["assistant_message_id"])
|
||||
assert.Equal(t, "user-1", evt.Data["user_message_id"])
|
||||
assert.Equal(t, userAt.Format(time.RFC3339Nano), evt.Data["user_created_at"])
|
||||
assert.Equal(t, assistantAt.Format(time.RFC3339Nano), evt.Data["assistant_created_at"])
|
||||
}
|
||||
|
||||
func TestCreateAgentQueryEventOmitsZeroTimestamps(t *testing.T) {
|
||||
evt := createAgentQueryEvent("sess-1", "asst-1", "", time.Time{}, time.Time{})
|
||||
|
||||
_, hasUserID := evt.Data["user_message_id"]
|
||||
_, hasUserAt := evt.Data["user_created_at"]
|
||||
_, hasAssistantAt := evt.Data["assistant_created_at"]
|
||||
assert.False(t, hasUserID)
|
||||
assert.False(t, hasUserAt)
|
||||
assert.False(t, hasAssistantAt)
|
||||
}
|
||||
Reference in New Issue
Block a user