Repository navigation
test(api): replace MyScale and Elasticsearch JA test mocks with recording fakes - #44913
ShousenZHANG wants to merge 8 commits into
Conversation
…ding fakes Both modules now import the real provider code, since clickhouse-connect and elasticsearch are provider dependencies, and replace only the network client: FakeClickHouseClient records each command and query with its parameters, and FakeElasticsearch tracks created indices. Collection creation, inserts and searches run their real code, the factory tests compare whole configs and use a real Flask app context, and every test parameter and return is annotated.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #44913 +/- ##
==========================================
+ Coverage 89.52% 89.54% +0.01%
==========================================
Files 6009 6012 +3
Lines 376843 377210 +367
Branches 76238 76278 +40
==========================================
+ Hits 337380 337758 +378
+ Misses 33465 33459 -6
+ Partials 5998 5993 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Part of #36288. Following #44775, #44853 and #44898, type the MyScale and Elasticsearch JA unit tests and replace their
MagicMockobjects with real values and small recording fakes.test_myscale_vector.pyimports the real provider module instead of reloading it under a stubclickhouse_connectmodule;clickhouse-connectis a dependency ofdify-vdb-myscale. Onlyget_clientis replaced:FakeClickHouseClientrecords the connection arguments and each command and query with its bound parameters.create,_create_collection,add_textsand_searchnow run their real code instead of being stubbed, so the tests check the generated SQL and parameters end to end.test_elasticsearch_ja_vector.pyimports the real modules and injectsFakeElasticsearchthrough the real constructor by replacing theElasticsearchclass, soping()and the version check run too. The fake index API records each creation,redis_clientis a small recording fake, and the factory test uses a real Flask app context instead of aSimpleNamespaceforcurrent_app.Every test parameter and return is annotated. This changes test code only. Importing the real
clickhouse_connectemits aDeprecationWarningfrom the library itself on Python 3.13 (the'u'array type code).Validation on Python 3.13:
main. The Elasticsearch JA tests also pass whentest_elasticsearch_vector.py, which reloads these modules, runs first.pyrefly checkwithimplicit-any-parameter,unannotated-returnandimplicit-any-empty-containerset to error: 50 diagnostics onmainunder the unit-test configuration, 0 after under both the production and unit-test configurations. CI does not enable these three rules, so they were checked locally.SET allow_experimental_object_type, a swapped connection user, a hard-codedLIMIT, a wrong sort order, a non-Japanese analyzer or a shorter cache TTL. The new tests fail for 16; the tests onmainfail for 11, all of which the new tests also catch. The remaining change only affects documents with empty metadata, which these tests do not cover.MagicMock,cast,SimpleNamespace,spec,Anyor type ignore.Tests ran through the local Windows pytest wrapper; the lint and type-check commands were run individually rather than through
make.Screenshots
MagicMock: 24Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint godsFrom Claude Code