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,105 @@
|
||||
package mcp
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
||||
"github.com/Tencent/WeKnora/cli/internal/output"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
)
|
||||
|
||||
// TestToolErrorResult_TypedError_PopulatesStructuredContent verifies the
|
||||
// helper maps a typed cmdutil.Error to MCP StructuredContent as *output.ErrDetail.
|
||||
func TestToolErrorResult_TypedError_PopulatesStructuredContent(t *testing.T) {
|
||||
err := cmdutil.NewError(cmdutil.CodeAuthUnauthenticated, "no creds")
|
||||
res := toolErrorResult(err)
|
||||
if !res.IsError {
|
||||
t.Errorf("expected IsError true")
|
||||
}
|
||||
if res.StructuredContent == nil {
|
||||
t.Fatal("expected StructuredContent populated")
|
||||
}
|
||||
sc, ok := res.StructuredContent.(*output.ErrDetail)
|
||||
if !ok {
|
||||
t.Fatalf("StructuredContent has unexpected type %T", res.StructuredContent)
|
||||
}
|
||||
if sc.Type != "auth.unauthenticated" {
|
||||
t.Errorf("type: got %v want auth.unauthenticated", sc.Type)
|
||||
}
|
||||
// retry_argv should fall back to ["weknora","auth","login"] via cmdutil default
|
||||
if !reflect.DeepEqual(sc.RetryArgv, []string{"weknora", "auth", "login"}) {
|
||||
t.Errorf("retry_argv: got %v", sc.RetryArgv)
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolErrorResult_TextFallback verifies the human-readable Content[0]
|
||||
// contains code + message + (hint? + retry?) lines.
|
||||
func TestToolErrorResult_TextFallback(t *testing.T) {
|
||||
err := cmdutil.NewError(cmdutil.CodeKBIDRequired, "kb_id is required")
|
||||
res := toolErrorResult(err)
|
||||
if len(res.Content) == 0 {
|
||||
t.Fatal("expected Content[0]")
|
||||
}
|
||||
// Assertion is best-effort on the text shape; exact prose may vary
|
||||
// with hint/retry defaults. Lock the type code prefix.
|
||||
text := contentText(t, res.Content[0])
|
||||
if !strings.Contains(text, "local.kb_id_required: kb_id is required") {
|
||||
t.Errorf("text fallback missing code:message; got %q", text)
|
||||
}
|
||||
}
|
||||
|
||||
// contentText extracts the Text field from an mcpsdk.Content value.
|
||||
// Lives in the test file to avoid leaking helpers into production.
|
||||
func contentText(t *testing.T, c any) string {
|
||||
t.Helper()
|
||||
// Direct assertion to the concrete type used by toolErrorResult.
|
||||
if tc, ok := c.(*mcpsdk.TextContent); ok {
|
||||
return tc.Text
|
||||
}
|
||||
// Fallback: some go-sdk versions may expose a GetText() method.
|
||||
if tc, ok := c.(interface{ GetText() string }); ok {
|
||||
return tc.GetText()
|
||||
}
|
||||
t.Fatalf("cannot extract text from Content of type %T", c)
|
||||
return ""
|
||||
}
|
||||
|
||||
// TestToolErrorResult_IsErrorFlagSet verifies IsError is always true.
|
||||
func TestToolErrorResult_IsErrorFlagSet(t *testing.T) {
|
||||
res := toolErrorResult(cmdutil.NewError(cmdutil.CodeInputMissingFlag, "doc_id is required"))
|
||||
if !res.IsError {
|
||||
t.Error("expected IsError=true")
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolErrorResult_ContentPresent verifies Content slice is non-empty.
|
||||
func TestToolErrorResult_ContentPresent(t *testing.T) {
|
||||
res := toolErrorResult(cmdutil.NewError(cmdutil.CodeInputInvalidArgument, "page_size must be in 1..1000"))
|
||||
if len(res.Content) == 0 {
|
||||
t.Error("expected at least one Content item")
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolErrorResult_NetworkError verifies a network error code round-trips
|
||||
// through toolErrorResult with the correct type in StructuredContent.
|
||||
func TestToolErrorResult_NetworkError(t *testing.T) {
|
||||
err := cmdutil.NewError(cmdutil.CodeNetworkError, "dial failed")
|
||||
res := toolErrorResult(err)
|
||||
if !res.IsError {
|
||||
t.Error("expected IsError=true")
|
||||
}
|
||||
sc, ok := res.StructuredContent.(*output.ErrDetail)
|
||||
if !ok {
|
||||
t.Fatalf("StructuredContent has unexpected type %T", res.StructuredContent)
|
||||
}
|
||||
if sc.Type != "network.error" {
|
||||
t.Errorf("type: got %v want network.error", sc.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress unused-import warning if sdk isn't used in this file.
|
||||
var _ = sdk.KnowledgeBase{}
|
||||
Reference in New Issue
Block a user