Repository navigation
Conversation
Annotate the fixtures, the `_factory` helper, and the twelve test functions so `core/app/app_config/easy_ui_based_app/model_config/test_converter.py` can leave the strict-mode exclusion list. Fixtures are annotated with what they actually return (`SimpleNamespace`, `MagicMock`) instead of `None`, and the parametrised expectations use the real `ModelStatus` enum and `type[Exception]`. 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: 13 passed before and after. - `ruff check` and `ruff format --check` pass.
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46357 +/- ##
==========================================
- Coverage 90.62% 90.62% -0.01%
==========================================
Files 6665 6665
Lines 415303 415317 +14
Branches 83292 83293 +1
==========================================
+ Hits 376363 376369 +6
- Misses 32556 32563 +7
- Partials 6384 6385 +1
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:
|
|
|
||
| def _factory(**kwargs): | ||
| def _factory(**kwargs: object) -> SimpleNamespace: | ||
| return SimpleNamespace(**kwargs) |
| @@ -63,14 +63,14 @@ def mock_provider_bundle(self): | |||
| # model type instance | |||
| model_type_instance = MagicMock() | |||
| model_schema = MagicMock() | |||
| status: ModelStatus, | ||
| expected_exception: type[Exception], | ||
| ) -> None: | ||
| mock_provider = MagicMock() |
``ModelConfigConverter.convert`` resolved the tenant's provider graph itself, so any caller that already held the resolved bundle had to re-resolve it, and the conversion could not be exercised against real entities without patching ``create_plugin_provider_manager``. Accept an optional ``provider_model_bundle`` and only fall back to resolving it from the tenant when it is omitted; production callers are unchanged. The bundle's model type instance is typed by ``AIModel``, which already declares ``get_model_schema``, so the ``cast`` to ``LargeLanguageModel`` is dropped as well. With the bundle injectable, the unit tests build the real ``EasyUIBasedAppConfig``, ``ProviderConfiguration``, ``LargeLanguageModel`` and ``ModelConfigWithCredentialsEntity`` instead of ``MagicMock``/``SimpleNamespace`` stand-ins, which also surfaced that the reported provider is the full provider id rather than the bare provider name.
There was a problem hiding this comment.
2 inline suggestions at 639ff8024a, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
2 inline suggestions at 5bed6560ab, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
| provider_model_bundle=bundle, | ||
| ) | ||
|
|
||
| expected_stop: list[str] = parameters.get("stop", []) |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
Addressed in the production-owned shape: api/core/app/app_config/easy_ui_based_app/model_config/converter.py:22-32 defines CompletionParameters as a TypedDict (including provider-specific extra_items=object), and the test imports it at test_converter.py:19-23 and annotates the parameterized input at line 365. This is not an ad hoc dict[str, object] declaration in the test. I have also requested re-review of the updated head.
Move the ProviderCredentials and CompletionParameters TypedDicts from the test module into core/app/app_config/easy_ui_based_app/model_config/converter.py so tests import the production-owned payload shapes (parse-don't-validate). CompletionParameters uses extra_items=object so provider-specific parameters pass through unchanged. Also replace the ad hoc dict[str, object]() registry stand-in with the real registry type dict[str, list[ConfigurateMethod]]().
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at b11aa47ac4, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 4 review threads are still unresolved.
dify-codereview
|
I addressed the independent review finding in |
asukaminato0721
left a comment
There was a problem hiding this comment.
3 inline suggestions at 84a1d11e71, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 4 review threads are still unresolved.
dify-codereview
|
Follow-up to the conflict review: merged current |
Summary
Validation
a0542b34.ProviderConfigurationJSON schema is byte-for-byte unchanged.