From fa471bc4c415afe8c3b2f0283b5b572e7a39db06 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 19 Dec 2025 20:10:16 +0800 Subject: [PATCH] Update tests to use context and correct URL references - Modified the `createTestContext` function to use `context.Background()` for improved context management in tests. - Updated the URL in the `TestAddURL` function to point to the correct Yao Agent Caller resource, ensuring accurate test assertions for added URLs. --- agent/search/handlers/web/agent_test.go | 3 ++- kb/api/addurl_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/agent/search/handlers/web/agent_test.go b/agent/search/handlers/web/agent_test.go index 8438c06f..d6fafbdf 100644 --- a/agent/search/handlers/web/agent_test.go +++ b/agent/search/handlers/web/agent_test.go @@ -1,6 +1,7 @@ package web_test import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -278,7 +279,7 @@ func createTestContext(t *testing.T) *agentContext.Context { UserID: "test-user", TenantID: "test-tenant", } - ctx := agentContext.New(nil, authorized, "test-chat-id") + ctx := agentContext.New(context.Background(), authorized, "test-chat-id") ctx.AssistantID = "tests.web-agent-caller" return ctx } diff --git a/kb/api/addurl_test.go b/kb/api/addurl_test.go index fc48827f..41d5db15 100644 --- a/kb/api/addurl_test.go +++ b/kb/api/addurl_test.go @@ -67,10 +67,10 @@ func TestAddURL(t *testing.T) { t.Run("AddURLSuccess", func(t *testing.T) { params := &api.AddURLParams{ CollectionID: collectionID, - URL: "https://example.com", + URL: "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go", Locale: "en", Metadata: map[string]interface{}{ - "title": "Example Website", + "title": "Yao Agent Caller", "description": "A test URL document", }, Chunking: &api.ProviderConfigParams{ @@ -96,7 +96,7 @@ func TestAddURL(t *testing.T) { if result != nil { assert.Equal(t, collectionID, result.CollectionID) assert.NotEmpty(t, result.DocID) - assert.Equal(t, "https://example.com", result.URL) + assert.Equal(t, "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go", result.URL) assert.Contains(t, result.Message, "successfully") t.Logf("Added URL document: %s", result.DocID) } @@ -107,7 +107,7 @@ func TestAddURL(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, doc) assert.Equal(t, "url", doc["type"]) - assert.Equal(t, "https://example.com", doc["url"]) + assert.Equal(t, "https://raw.githubusercontent.com/trheyi/yao/refs/heads/main/agent/caller/caller.go", doc["url"]) t.Logf("✅ URL Document verified: type=%v, url=%v, status=%v", doc["type"], doc["url"], doc["status"]) } })