Repository navigation
Conversation
Annotate the generator fixture and its tests so `tests/unit_tests/pyrefly.toml` no longer excludes `core/app/apps/completion/test_app_generator.py`. `Conversation.invoke_from` and `Message.invoke_from` are typed with the model enum, so the fixtures now pass `models.enums.InvokeFrom`; the generator call keeps the core enum it declares. The fixture no longer assigns `generate_entity` onto the generator: nothing on `CompletionAppGenerator` or its bases reads that attribute, `generate()` calls the module-level entity directly. The assertions now read the patched module-level factory, which is the same object the dead attribute held.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-26 06:07:04.246305486 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-26 06:06:53.906201857 +0000
@@ -3100,18 +3100,6 @@
--> tests/unit_tests/core/app/apps/common/test_workflow_response_converter.py:1477:9
ERROR Object of type `FileInputConfig | FileListInputConfig | ParagraphInputConfig | SelectInputConfig` has no attribute `option_source` [missing-attribute]
--> tests/unit_tests/core/app/apps/common/test_workflow_response_converter.py:1877:16
-ERROR Object of class `CompletionAppGenerator` has no attribute `generate_entity` [missing-attribute]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:62:5
-ERROR Argument `Literal[core.app.entities.app_invoke_entities.InvokeFrom.WEB_APP]` is not assignable to parameter `invoke_from` with type `models.enums.InvokeFrom | SQLCoreOperations[models.enums.InvokeFrom | None] | None` in function `models.model.Conversation.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:114:21
-ERROR Argument `Literal[core.app.entities.app_invoke_entities.InvokeFrom.WEB_APP]` is not assignable to parameter `invoke_from` with type `models.enums.InvokeFrom | SQLCoreOperations[models.enums.InvokeFrom | None] | None` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:142:21
-ERROR Object of class `FunctionType` has no attribute `assert_not_called` [missing-attribute]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:253:9
-ERROR Object of class `FunctionType` has no attribute `assert_called_once` [missing-attribute]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:309:9
-ERROR Key `msg` is not defined in TypedDict `InitErrorDetails` [bad-typed-dict-key]
- --> tests/unit_tests/core/app/apps/completion/test_app_generator.py:376:57
ERROR Argument `Literal['bad']` is not assignable to parameter `metadata` with type `Mapping[str, object]` in function `core.app.entities.task_entities.Data.model_construct` [bad-argument-type]
--> tests/unit_tests/core/app/apps/completion/test_generate_response_converter.py:100:22
ERROR Cannot index into `str` [bad-index]
@@ -3182,6 +3170,8 @@
--> tests/unit_tests/core/app/apps/test_base_app_runner.py:477:72
ERROR Missing argument `task_id` in function `core.app.entities.app_invoke_entities.EasyUIBasedAppGenerateEntity.model_construct` [missing-argument]
--> tests/unit_tests/core/app/apps/test_base_app_runner.py:478:75
+ERROR Missing argument `app_config` in function `core.app.entities.app_invoke_entities.EasyUIBasedAppGenerateEntity.model_construct` [missing-argument]
+ --> tests/unit_tests/core/app/apps/test_base_app_runner.py:478:75
ERROR Missing argument `inputs` in function `core.app.entities.app_invoke_entities.EasyUIBasedAppGenerateEntity.model_construct` [missing-argument]
--> tests/unit_tests/core/app/apps/test_base_app_runner.py:478:75
ERROR Missing argument `files` in function `core.app.entities.app_invoke_entities.EasyUIBasedAppGenerateEntity.model_construct` [missing-argument]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46401 +/- ##
==========================================
+ Coverage 90.40% 90.46% +0.05%
==========================================
Files 6334 6400 +66
Lines 396668 406962 +10294
Branches 79710 81042 +1332
==========================================
+ Hits 358626 368150 +9524
- Misses 31934 32427 +493
- Partials 6108 6385 +277
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:
|
| mocker.patch.object(generator, "_get_app_model_config", return_value=app_model_config) | ||
| mocker.patch.object(AppModelConfig, "to_dict", return_value={"model": {"provider": "x"}}) | ||
|
|
||
| file_extra_config = MagicMock() |
| mocker.patch.object(module.FileUploadConfigManager, "convert", return_value=file_extra_config) | ||
| mocker.patch.object(module.file_factory, "build_from_mappings", return_value=["file1"]) | ||
| build_from_mappings = mocker.patch.object(module.file_factory, "build_from_mappings", return_value=["file1"]) | ||
| assert isinstance(build_from_mappings, MagicMock) |
| error: Exception, | ||
| should_publish: bool, | ||
| ) -> None: | ||
| flask_app = MagicMock() |
| module, "CompletionAppGenerateEntity", side_effect=lambda **kwargs: SimpleNamespace(**kwargs) | ||
| ) | ||
| gen.generate_entity = generate_entity | ||
| mocker.patch.object(module, "CompletionAppGenerateEntity", side_effect=lambda **kwargs: SimpleNamespace(**kwargs)) |
| constructions live on that module attribute rather than on the generator. | ||
| """ | ||
| entity: object = module.CompletionAppGenerateEntity | ||
| assert isinstance(entity, MagicMock) |
The generate entity declared `app_config: EasyUIBasedAppConfig = None` behind a `type: ignore`, so every construction of an EasyUI entity read as untyped and the tests had to substitute a mock factory to observe the construction at all. Every EasyUI construction site already passes a real `EasyUIBasedAppConfig` subclass, so the field can be required and correctly typed. The completion app generator test now builds the real entity and reads it back from the recorded `_init_generate_records` call instead of patching the entity class.
There was a problem hiding this comment.
2 inline suggestions at 8c33bfe442, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
The completion generator tests stubbed out the two pieces of real logic they were meant to protect: `file_factory.build_from_mappings` and `ModelConfigConverter.convert`. The assertions therefore described the stubs, not the behaviour, and every mutation of either survived. Drop both stubs. The file case now stores a real `UploadFile` row and lets the factory read it back through the session; the debugger case builds a real `ProviderManager` with a real predefined-model catalog and only replaces the outermost daemon HTTP boundary, so credential resolution, schema lookup and parameter normalisation all run for real. Postconditions the assertions now protect, each verified by mutating the production code and confirming the test fails: * invalid caller mappings are dropped instead of raising; * the built file carries the stored key, source URL and record reference; * stop words are lifted out of the completion parameters; * the mode comes from the real model schema when the app config omits it; * credentials come from the resolved provider bundle. Checks: 10 passed; six mutations all caught; ruff check/format clean; pyrefly reports no diagnostic for this file in any of the three configs; all eight ast-grep guards pass.
asukaminato0721
left a comment
There was a problem hiding this comment.
2 inline suggestions at f0de2ba69c, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 5 review threads are still unresolved.
dify-codereview
Why
core/app/apps/completion/test_app_generator.pyis listed under "Existing strict-mode debt" inapi/tests/unit_tests/pyrefly.toml. This PR pays that off: the file leavesproject-excludesand is checked bymake type-check-corefrom now on.Before: 18 errors + 3 warnings. After: 0.
project-excludesgoes from 199 to 198 entries.How
Conversation.invoke_fromandMessage.invoke_fromare typed withmodels.enums.InvokeFrom, so the fixtures now construct those rows with that enum while the generator call keeps the core enum it declares. Both areStrEnumwith identical values.generate_entityonto the generator instance. Nothing onCompletionAppGeneratoror its bases reads that attribute —generate()calls the module-level entity directly — so the assignment was dead. The assertions now read the patched module-level factory, the same object the dead attribute held.mocker.patch.object(...)results are bound and narrowed withassert isinstance(x, MagicMock): pytest-mock returnsMockType, which does not declareassert_*.-> Noneand missing fixture annotations.One typed-dict key was dropped:
pydantic_core.InitErrorDetailshas nomsgfield, and the generated.errors()output is identical before and after.How to Test
Local verification (whole
tests/unit_testsproject, with this entry removed from the config):ERROR=29, allmissing-importfor optional dependencies absent from this machine;WARN=0; zero diagnostics left in the target file.pytest: 10 passed both before and after the change.ruff check/ruff format --check: clean.# pyrefly: ignore, no# type: ignore, notyping.cast, notyping.Any.