RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
ci(tests): run migrated Go API tests (#21077)
Sbaaoui Idriss987457c07f98
diff --git a/.github/workflows/sep-tests.yml b/.github/workflows/sep-tests.ymlindex d16b66e42b..d1643f8160 100644--- a/.github/workflows/sep-tests.yml+++ b/.github/workflows/sep-tests.yml@@ -687,8 +687,9 @@ jobs:sudo docker ps -a --filter "label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}" -q | xargs -r sudo docker rm -fsudo docker compose -f "${COMPOSE_FILE}" -p ${COMPOSE_PROJECT_NAME} up -d- - name: Run New RESTFUL api tests against Infinity+ - name: Run search API tests against Infinityrun: |+ set -euo pipefailexport http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""svc_ready=0for i in $(seq 1 60); do@@ -704,7 +705,20 @@ jobs:sudo docker logs ${RAGFLOW_CONTAINER}exit 1fi- source .venv/bin/activate && set -o pipefail; DOC_ENGINE=infinity pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} --durations=100 test/testcases/restful_api 2>&1 | tee infinity_restful_api_test.log+ source .venv/bin/activate+ pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} --durations=100 test/testcases/restful_api/test_searches.py 2>&1 | tee infinity_search_api_test.log++ - name: Run Go API tests against Infinity+ # Search fixtures above configure the default models used by the Go suite.+ # Go API tests have no priority filtering; run the full suite every time.+ run: |+ set -euo pipefail+ export http_proxy="" https_proxy="" no_proxy="" HTTP_PROXY="" HTTPS_PROXY="" NO_PROXY=""+ if [ -n "${RUNNER_WORKSPACE_PREFIX:-}" ]; then+ export GOMODCACHE="${RUNNER_WORKSPACE_PREFIX}/gomodcache"+ export GOCACHE="${RUNNER_WORKSPACE_PREFIX}/gobuild"+ fi+ ./build.sh --test-integration-go -timeout 60m ./test/api 2>&1 | tee infinity_go_api_test.log- name: Upload coverage reports to Codecovuses: codecov/codecov-action@v5@@ -1251,8 +1265,9 @@ jobs:sudo docker ps -a --filter "label=com.docker.compose.project=${COMPOSE_PROJECT_NAME}" -q | xargs -r sudo docker rm -fsudo docker compose -f "${COMPOSE_FILE}" -p ${COMPOSE_PROJECT_NAME} up -d- - name: Run New RESTFUL api tests against Elasticsearch+ - name: Run search API tests against Elasticsearchrun: |+ set -euo pipefailexport http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY=""svc_ready=0for i in $(seq 1 60); do@@ -1268,7 +1283,20 @@ jobs:sudo docker logs ${RAGFLOW_CONTAINER}exit 1fi- source .venv/bin/activate && set -o pipefail; pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} --durations=100 test/testcases/restful_api 2>&1 | tee es_restful_api_test.log+ source .venv/bin/activate+ pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} --durations=100 test/testcases/restful_api/test_searches.py 2>&1 | tee es_search_api_test.log++ - name: Run Go API tests against Elasticsearch+ # Search fixtures above configure the default models used by the Go suite.+ # Go API tests have no priority filtering; run the full suite every time.+ run: |+ set -euo pipefail+ export http_proxy="" https_proxy="" no_proxy="" HTTP_PROXY="" HTTPS_PROXY="" NO_PROXY=""+ if [ -n "${RUNNER_WORKSPACE_PREFIX:-}" ]; then+ export GOMODCACHE="${RUNNER_WORKSPACE_PREFIX}/gomodcache"+ export GOCACHE="${RUNNER_WORKSPACE_PREFIX}/gobuild"+ fi+ ./build.sh --test-integration-go -timeout 60m ./test/api 2>&1 | tee es_go_api_test.log- name: Collect ragflow log Elasticsearchif: ${{ !cancelled() }}@@ -1325,7 +1353,7 @@ jobs:ragflow_native_backend:name: ragflow_native_backend# Runs AFTER both per-engine go jobs (which contain the doc-engine-specific- # server build + Python RESTFUL correctness runs). The DeepDoc native+ # server build + Go API and Python search correctness runs). The DeepDoc native# backend is doc-engine-independent, so running it ONCE here — instead of# duplicated (and memory-competing) inside each go job — removes the# redundant second -race pass and the concurrent -race OOM risk. Running itdiff --git a/internal/service/document/document_dataset_update.go b/internal/service/document/document_dataset_update.goindex e313c7f8df..9108159423 100644--- a/internal/service/document/document_dataset_update.go+++ b/internal/service/document/document_dataset_update.go@@ -179,11 +179,6 @@ func (s *DocumentService) UpdateDatasetDocument(ctx context.Context, userID, dat}if present["parser_config"] && req.ParserConfig != nil {- // Normalize "pages" ranges before persistence. Invalid ranges are- // rejected (fail-fast) — the request is aborted with a clear error.- if err = pipelinepkg.NormalizeParserConfigPages(req.ParserConfig); err != nil {- return nil, common.CodeDataError, err- }var dslJSON []bytedslJSON, err = service.LoadPipelineDSL(ctx, isPipeline, effParserID, effPipelineID)if err != nil {@@ -379,6 +374,12 @@ func (s *DocumentService) validateDatasetDocumentUpdate(ctx context.Context, datreturn common.CodeDataError, err}}+ if present["parser_config"] && req.ParserConfig != nil {+ // Reject invalid page ranges before any names or metadata are persisted.+ if err := pipelinepkg.NormalizeParserConfigPages(req.ParserConfig); err != nil {+ return common.CodeDataError, err+ }+ }return common.CodeSuccess, nil}diff --git a/internal/service/document/document_test.go b/internal/service/document/document_test.goindex 80b8a7b618..9c53001f87 100644--- a/internal/service/document/document_test.go+++ b/internal/service/document/document_test.go@@ -2471,6 +2471,44 @@ func TestUpdateDatasetDocumentRejectsUnsupportedParserIDForVisualDoc(t *testing.}}+func TestUpdateDatasetDocumentRejectedParserConfigPreservesNames(t *testing.T) {+ db := setupServiceTestDB(t)+ pushServiceDB(t, db)+ insertTestKB(t, "kb-1", "tenant-1", 1, 0, 0)+ insertNamedTestDoc(t, "doc-1", "kb-1", "old.pdf", 0, 0)+ insertTestFile(t, "file-1", "folder-1", "old.pdf", new("old.pdf"))+ insertTestFile2Document(t, "f2d-1", "file-1", "doc-1")++ _, code, err := testDocumentService(t).UpdateDatasetDocument(t.Context(), "user-1", "kb-1", "doc-1", &UpdateDatasetDocumentRequest{+ Name: new("must_not_persist.pdf"),+ ParserConfig: map[string]any{+ "Parser:HipSignsRhyme": map[string]any{+ "pdf": map[string]any{"pages": []any{[]any{3, 1}}},+ },+ },+ }, map[string]bool{"name": true, "parser_config": true})+ if code != common.CodeDataError || err == nil || !strings.Contains(err.Error(), "from must be <= to") {+ t.Fatalf("expected invalid page range rejection, got code=%v err=%v", code, err)+ }++ doc, err := dao.NewDocumentDAO().GetByID(t.Context(), db, "doc-1")+ if err != nil {+ t.Fatal(err)+ }+ if doc.Name == nil {+ t.Error("rejected parser config removed document name")+ } else if *doc.Name != "old.pdf" {+ t.Errorf("rejected parser config changed document name: %q", *doc.Name)+ }+ file, err := dao.NewFileDAO().GetByID(t.Context(), db, "file-1")+ if err != nil {+ t.Fatal(err)+ }+ if file.Name != "old.pdf" {+ t.Errorf("rejected parser config changed file name: %q", file.Name)+ }+}+func TestUpdateDatasetDocumentRenameUpdatesDocumentAndFile(t *testing.T) {db := setupServiceTestDB(t)pushServiceDB(t, db)diff --git a/internal/service/metadata.go b/internal/service/metadata.goindex 29972971ed..05e2222f7e 100644--- a/internal/service/metadata.go+++ b/internal/service/metadata.go@@ -102,10 +102,12 @@ func (s *MetadataService) SearchMetadata(ctx context.Context, kbID, tenantID strOffset: 0,Limit: size,Filter: map[string]interface{}{- "id": docIDs,"kb_id": kbID,},}+ if len(docIDs) > 0 {+ searchReq.Filter["id"] = docIDs+ }searchResult, err := s.docEngine.SearchMetadata(ctx, searchReq)if err != nil {diff --git a/test/api/session_api_test.go b/test/api/session_api_test.goindex d6ab65dcaf..7139492760 100644--- a/test/api/session_api_test.go+++ b/test/api/session_api_test.go@@ -62,8 +62,8 @@ func TestRESTSessionLifecyclePersistsAndDeletes(t *testing.T) {t.Fatalf("updated name was not persisted: %v", persisted)}- deleted := object(t, restOK(t, restCall(t, TestConfig, http.MethodDelete, "/chats/"+chatID+"/sessions", apiObject{"ids": []string{sessionID}}, nil))["data"])- if deleted["success_count"] != float64(1) {+ deleted := restOK(t, restCall(t, TestConfig, http.MethodDelete, "/chats/"+chatID+"/sessions", apiObject{"ids": []string{sessionID}}, nil))["data"]+ if deleted != true {t.Fatalf("delete result=%v", deleted)}remaining := restOK(t, restCall(t, TestConfig, http.MethodGet, "/chats/"+chatID+"/sessions", nil, apiObject{"page_size": 20}))@@ -108,7 +108,10 @@ func TestRESTSessionValidationAndIsolation(t *testing.T) {other := createRESTChat(t, nil)otherID := other["id"].(string)cross := restCall(t, TestConfig, http.MethodGet, "/chats/"+otherID+"/sessions/"+session["id"].(string), nil, nil)- restCode(t, cross, http.StatusOK, 404)+ restCode(t, cross, http.StatusOK, 102)+ if cross.JSON["message"] != "session does not belong to this chat" {+ t.Fatalf("cross-chat session error=%v", cross.JSON)+ }invalidChat := restCall(t, TestConfig, http.MethodPost, "/chats/"+uniqueName("missing")+"/sessions", apiObject{"name": "x"}, nil)restCode(t, invalidChat, http.StatusOK, 404)}@@ -146,10 +149,13 @@ func TestRESTSessionAuthorizationAndFiltering(t *testing.T) {if len(filtered) != 1 || object(t, filtered[0])["name"] != "filter_2" {t.Fatalf("name filter returned %v", filtered)}- page := object(t, restOK(t, restCall(t, TestConfig, http.MethodGet, "/chats/"+chatID+"/sessions", nil, apiObject{"page": 2, "page_size": 2}))["data"])- if len(array(t, page)) != 2 {+ page := array(t, restOK(t, restCall(t, TestConfig, http.MethodGet, "/chats/"+chatID+"/sessions", nil, apiObject{"page": 2, "page_size": 2, "orderby": "name", "desc": false}))["data"])+ if len(page) != 2 {t.Fatalf("page size was not applied: %v", page)}+ if object(t, page[0])["name"] != "filter_2" || object(t, page[1])["name"] != "filter_3" {+ t.Fatalf("page offset or ordering was not applied: %v", page)+ }}func TestRESTSessionConcurrentCreationAndListing(t *testing.T) {@@ -212,21 +218,42 @@ func TestRESTChatCompletionValidationAndStreamContract(t *testing.T) {if err != nil || len(events) < 2 {t.Fatalf("invalid completion SSE: events=%d err=%v", len(events), err)}- var sawData, sawTerminal bool- for _, event := range events {- if event.Data == "[DONE]" {- sawTerminal = true- continue- }+ var sawData, sawFinal, sawTerminal bool+ var streamSessionID string+ for i, event := range events {var payload apiObjectif err := json.Unmarshal([]byte(event.Data), &payload); err != nil {t.Fatalf("SSE event is not JSON: %q", event.Data)}- if payload["data"] != nil {- sawData = true+ if payload["code"] != float64(0) {+ t.Fatalf("SSE event returned an error: %v", payload)+ }+ if payload["data"] == true {+ if i != len(events)-1 {+ t.Fatal("SSE terminal event was followed by more events")+ }+ sawTerminal = true+ continue+ }+ data := object(t, payload["data"])+ sessionID, ok := data["session_id"].(string)+ if !ok || sessionID == "" || data["chat_id"] != chatID {+ t.Fatalf("SSE event lost chat/session identity: %v", data)+ }+ if streamSessionID == "" {+ streamSessionID = sessionID+ } else if sessionID != streamSessionID {+ t.Fatalf("SSE session identity changed: got=%s want=%s", sessionID, streamSessionID)+ }+ if _, ok := data["answer"].(string); !ok {+ t.Fatalf("SSE event omitted answer: %v", data)+ }+ sawData = true+ if data["final"] == true {+ sawFinal = true}}- if !sawData || !sawTerminal {- t.Fatalf("SSE lacked data and terminal events: %v", events)+ if !sawData || !sawFinal || !sawTerminal {+ t.Fatalf("SSE lacked answer, final, or terminal events: %v", events)}}