Repository navigation
Conversation
Annotate the test functions and model the request payloads so `core/plugin/impl/test_datasource.py` can leave the strict-mode exclusion list. The three `fake_request` helpers are consumed as `mocker.patch.object(..., side_effect=fake_request)`, so their annotation describes what the patched callable returns rather than a tuple. Their `**kwargs` are declared with `Unpack[TypedDict]` because a plain `object` value would make `kwargs["transformer"]` uncallable, and the nested payload literals are typed with module-level `TypedDict`s because dict invariance otherwise rejects them. No test logic, assertion, or expected value is touched. Verification: - project-wide `pyrefly check` on `tests/unit_tests/pyrefly.toml`: 29 errors, all `missing-import` from packages absent in the local venv, zero warnings (`min-severity = "warn"`, so a warning alone fails `make type-check-core`). - target file reports zero diagnostics. - `pytest` on the file: 11 passed before and after. - `ruff check` and `ruff format --check` pass.
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #46353 +/- ##
==========================================
+ Coverage 90.30% 90.33% +0.02%
==========================================
Files 6493 6504 +11
Lines 408308 409465 +1157
Branches 81880 81949 +69
==========================================
+ Hits 368728 369881 +1153
- Misses 33176 33200 +24
+ Partials 6404 6384 -20
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:
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-25 11:39:57.955940251 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-25 11:39:47.663854368 +0000
@@ -1147,27 +1147,27 @@
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/e2e_tests/containers/services/tools/test_mcp_tools_manage_service.py:72:20
ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:752:20
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:765:20
ERROR Type `None` is not iterable [not-iterable]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:753:32
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:766:32
ERROR Type `None` is not iterable [not-iterable]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:754:32
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:767:32
ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:763:20
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:776:20
ERROR Type `None` is not iterable [not-iterable]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:764:34
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:777:34
ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:778:20
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:791:20
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:779:16
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:792:16
ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:787:20
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:800:20
ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:795:20
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:808:20
ERROR Type `None` is not iterable [not-iterable]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:804:33
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:817:33
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:805:16
+ --> tests/e2e_tests/containers/services/tools/test_tools_transform_service.py:818:16
ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
--> tests/e2e_tests/containers/services/tools/test_workflow_tools_manage_service.py:109:38
ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
|
The transformer closures are declared by BasePluginClient as Callable[[dict[str, Any]], dict[str, Any]], so narrowing them to a TypedDict violated contravariance and brought the payload type reports back onto the production file the PR was meant to clean up. Keep the transformer signature as dict[str, Any] and cast the payload inside, and widen the two fields the daemon really can send empty: the provider name may be missing, and the schema may be any resolved SchemaType.
`check_no_new_cast.py` rejected the three `cast(PluginDatasource*Payload, json_response)` calls this branch added to the product code, so the Style Check job went red. A `TypedDict` accepts a keyword-splat construction from an already-`dict[str, Any]` value, which gives the same narrowing without a `typing.cast` and keeps pyrefly at zero errors on the file.
There was a problem hiding this comment.
3 inline suggestions at cca150a59b, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
There was a problem hiding this comment.
2 inline suggestions at cca150a59b, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
There was a problem hiding this comment.
2 inline suggestions at 9d8e7713fd, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
The typed transformers added branches for payloads without a declaration, without an identity, and without an output schema. Exercise each fallback through the real request path so the patch coverage gate sees them.
asukaminato0721
left a comment
There was a problem hiding this comment.
CI is failing: API Tests, Run API Tests / API Unit Tests (3.13, shard 2/2). Please fix it. 2 inline suggestions at 7ae7ea1787, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 2 review threads are still unresolved.
dify-codereview
Replace the TypedDict labels around the plugin daemon datasource payloads with Pydantic v2 models so the response shape is parsed, not just annotated, at the boundary (parse-don't-validate). Declared fields (identity.name, identity.provider, output_schema) are type-checked on validation; undeclared keys are carried through with extra="allow" because the downstream entity models still own the rest of the daemon payload. The transformers return model_dump(exclude_unset=True) so the base client re-validates the envelope as before. The unit tests annotate the transformer payloads as plain dicts and need the same TID251 per-file ignore for typing.Any that test_plugin.py already has in tests/unit_tests/.ruff.toml.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 6b0a579cff, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 2 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 542b97b8f4, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 3 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
CI is failing: Style Check / Python Style. Please fix it. 1 inline suggestion at c1ea9c35b2, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 3 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at ccd58fc7ed, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 3 review threads are still unresolved.
dify-codereview
| return httpx.Response(200, json=daemon_response) | ||
|
|
||
| with httpx.Client(transport=httpx.MockTransport(handle)) as http_client: | ||
| mocker.patch.object(plugin_client_module, "_httpx_client", http_client) |
There was a problem hiding this comment.
This is an external boundary: define a small typing.Protocol for what the code needs, have the production code accept it as a parameter, and pass a fake that implements the Protocol in the test, instead of patching or mocking it.
dify-codereview · tests-real-dependencies (protocol-di) Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
This test swaps the module-level HTTP client for a real httpx.Client backed by MockTransport. It still runs the production request builder and response parser, and checks the actual GET to /management/datasource, the provider and plugin_id query parameters, and the normalized response. The injected DatasourceProviderListRequester serves /management/datasources (plural), and the neighboring tests exercise both list entry points with it. I kept the single-provider test at the HTTP transport boundary so it still catches regressions in the default request path without making a network call.
Inject a narrow requester Protocol for online-drive downloads so tests can use a typed fake instead of patching the private stream helper. Preserve the production transport fallback and lazy yield-from behavior.
asukaminato0721
left a comment
There was a problem hiding this comment.
Consider splitting this into smaller pull requests: it adds 261 lines of non-test code, past about 150. Split it by feature: each pull request carries one functional change together with its tests, so each feature stands on its own and can be reviewed, merged and reverted independently. A rule of thumb, not a requirement. Size counts added non-test lines; tests, lock files and snapshots do not count.
dify-codereview
test(api): bring the plugin datasource tests under strict pyrefly
Annotate the test functions and model the request payloads so
core/plugin/impl/test_datasource.pycan leave the strict-mode exclusion list.The three
fake_requesthelpers are consumed asmocker.patch.object(..., side_effect=fake_request), so their annotation describes what the patchedcallable returns rather than a tuple. Their
**kwargsare declared withUnpack[TypedDict]because a plainobjectvalue would makekwargs["transformer"]uncallable, and the nested payload literals are typedwith module-level
TypedDicts because dict invariance otherwise rejects them.No test logic, assertion, or expected value is touched.
Verification:
pyrefly checkontests/unit_tests/pyrefly.toml: 29 errors,all
missing-importfrom packages absent in the local venv, zero warnings(
min-severity = "warn", so a warning alone failsmake type-check-core).pyteston the file: 11 passed before and after.ruff checkandruff format --checkpass.