From 40f217c2283068e96b8e30c2f55fdf1c855a4f5d Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 29 Jun 2026 17:43:38 +0800 Subject: [PATCH] test: fix stale Doris SQL-shape and flaky OSS bucket assertions Two pre-existing test failures on main, unrelated to any feature change: - Doris VectorRetrieve/KeywordsRetrieve inline LIMIT as a literal (Doris does not support placeholders for LIMIT/OFFSET), but the SQL-shape tests still expected `LIMIT ?` with TopK as a bound arg. Match the literal LIMIT and drop the extra argument. - TestOssEnsureBucket_CreateFails used the bucket name "test-bucket", which already exists globally on OSS, so IsBucketExist short-circuited and the create path never ran. Use a non-existent bucket name so the create-with-invalid-credentials path is actually exercised. --- .../repository/retriever/doris/repository_test.go | 14 +++++++++----- internal/application/service/file/oss_test.go | 7 +++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/application/repository/retriever/doris/repository_test.go b/internal/application/repository/retriever/doris/repository_test.go index 34f1b1c6..f6dd70b2 100644 --- a/internal/application/repository/retriever/doris/repository_test.go +++ b/internal/application/repository/retriever/doris/repository_test.go @@ -265,8 +265,10 @@ func TestVectorRetrieve_SQLShape(t *testing.T) { WithArgs("weknora", "weknora_embeddings_3"). WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(1)) - mock.ExpectQuery(`SELECT id, content, .*inner_product_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \?`). - WithArgs(true, 0.5, 5). + // Doris does not support placeholders for LIMIT, so TopK is inlined as a + // literal and is not a bound argument. + mock.ExpectQuery(`SELECT id, content, .*inner_product_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \d+`). + WithArgs(true, 0.5). WillReturnRows( sqlmock.NewRows([]string{ "id", "content", "source_id", "source_type", @@ -298,8 +300,8 @@ func TestVectorRetrieve_SQLShape_LegacyMode(t *testing.T) { WithArgs("weknora", "weknora_embeddings_3"). WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(1)) - mock.ExpectQuery(`SELECT id, content, .*cosine_distance_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \?`). - WithArgs(true, 0.5, 5). + mock.ExpectQuery(`SELECT id, content, .*cosine_distance_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \d+`). + WithArgs(true, 0.5). WillReturnRows( sqlmock.NewRows([]string{ "id", "content", "source_id", "source_type", @@ -345,8 +347,10 @@ func TestKeywordsRetrieve_SQLShape(t *testing.T) { WillReturnRows(sqlmock.NewRows([]string{"TABLE_NAME"}). AddRow("weknora_embeddings_768")) + // LIMIT is inlined (see VectorRetrieve), so only is_enabled and the + // MATCH_ANY query string are bound arguments. mock.ExpectQuery(`MATCH_ANY \?`). - WithArgs(true, "你好", 3). + WithArgs(true, "你好"). WillReturnRows( sqlmock.NewRows([]string{ "id", "content", "source_id", "source_type", diff --git a/internal/application/service/file/oss_test.go b/internal/application/service/file/oss_test.go index a6f71167..4144f29e 100644 --- a/internal/application/service/file/oss_test.go +++ b/internal/application/service/file/oss_test.go @@ -192,8 +192,11 @@ func TestOssEnsureBucket_CreateFails(t *testing.T) { t.Fatalf("newOSSClient() error: %v", err) } - // Should fail with invalid credentials - err = ossEnsureBucket(client, "test-bucket") + // Use a bucket that does not exist so IsBucketExist returns false and the + // create path is exercised; with invalid credentials PutBucket then fails. + // A common name like "test-bucket" already exists globally on OSS, which + // would short-circuit at IsBucketExist and make this assertion flaky. + err = ossEnsureBucket(client, "weknora-nonexistent-bucket-create-fails-12345") if err == nil { t.Error("ossEnsureBucket with invalid credentials should return an error") }