Repository navigation
Conversation
Graduate `node_spec`, `mock_nodes`, `test_file_service` and `test_base_app_generator` out of `project-excludes`. `mock_nodes` needed the most work: the twelve mock node classes now declare `@override` on `version` and `_run`, the result-style ones return a real `NodeRunResult`, and the mixin declares `_node_id` instead of relying on an attribute it only assigns at runtime. `test_advanced_prompt_transform` keeps its exclude entry. Its one remaining diagnostic comes from a case that passes a list of non-`ChatModelMessage` values to exercise the fall-through branch of `get_prompt`, but every value in the declared domain -- including an empty list -- matches one of the two `case` branches, so that branch cannot be reached from a value the type system allows. The other 28 diagnostics in that file are fixed here; only the fabricated case stays behind.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-17 07:23:18.466817302 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-17 07:23:02.070679348 +0000
@@ -1902,86 +1902,6 @@
--> tests/helpers/workflow/mock_factory.py:102:9
ERROR Cannot set item in `dict[str, type[MockAgentNode] | type[MockCodeNode] | type[MockDocumentExtractorNode] | type[MockHttpRequestNode] | type[MockIterationNode] | type[MockKnowledgeRetrievalNode] | type[MockLLMNode] | type[MockLoopNode] | type[MockParameterExtractorNode] | type[MockQuestionClassifierNode] | type[MockTemplateTransformNode] | type[MockToolNode]]` [unsupported-operation]
--> tests/helpers/workflow/mock_factory.py:185:44
-ERROR Unexpected keyword argument `node_id` in function `object.__init__` [unexpected-keyword]
- --> tests/helpers/workflow/mock_nodes.py:111:13
-ERROR Unexpected keyword argument `data` in function `object.__init__` [unexpected-keyword]
- --> tests/helpers/workflow/mock_nodes.py:112:13
-ERROR Unexpected keyword argument `init_params` in function `object.__init__` [unexpected-keyword]
- --> tests/helpers/workflow/mock_nodes.py:113:13
-ERROR Unexpected keyword argument `runtime_state` in function `object.__init__` [unexpected-keyword]
- --> tests/helpers/workflow/mock_nodes.py:114:13
-ERROR Object of class `MockNodeMixin` has no attribute `_node_id` [missing-attribute]
- --> tests/helpers/workflow/mock_nodes.py:125:56
-ERROR Object of class `MockNodeMixin` has no attribute `_node_id` [missing-attribute]
- --> tests/helpers/workflow/mock_nodes.py:140:56
-ERROR Object of class `MockNodeMixin` has no attribute `_node_id` [missing-attribute]
- --> tests/helpers/workflow/mock_nodes.py:151:56
-ERROR Class member `MockLLMNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:160:9
-ERROR Class member `MockLLMNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:164:9
-ERROR Class member `MockAgentNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:254:9
-ERROR Class member `MockAgentNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:258:9
-ERROR Class member `MockToolNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:306:9
-ERROR Class member `MockToolNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:310:9
-ERROR Class member `MockKnowledgeRetrievalNode.version` overrides parent class `KnowledgeRetrievalNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:359:9
-ERROR Class member `MockKnowledgeRetrievalNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:359:9
-ERROR Class member `MockKnowledgeRetrievalNode._run` overrides parent class `KnowledgeRetrievalNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:363:9
-ERROR Class member `MockKnowledgeRetrievalNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:363:9
-ERROR Class member `MockHttpRequestNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:416:9
-ERROR Class member `MockHttpRequestNode._run` overrides parent class `HttpRequestNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:420:9
-ERROR Class member `MockHttpRequestNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:420:9
-ERROR Class member `MockQuestionClassifierNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:469:9
-ERROR Class member `MockQuestionClassifierNode._run` overrides parent class `QuestionClassifierNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:473:9
-ERROR Class member `MockQuestionClassifierNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:473:9
-ERROR Class member `MockParameterExtractorNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:517:9
-ERROR Class member `MockParameterExtractorNode._run` overrides parent class `ParameterExtractorNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:521:9
-ERROR Class member `MockParameterExtractorNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:521:9
-ERROR Class member `MockDocumentExtractorNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:567:9
-ERROR Class member `MockDocumentExtractorNode._run` overrides parent class `DocumentExtractorNode` in an inconsistent manner [bad-override]
- --> tests/helpers/workflow/mock_nodes.py:571:9
-ERROR Class member `MockDocumentExtractorNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:571:9
-ERROR Class member `MockIterationNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:618:9
-ERROR Class member `MockLoopNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:627:9
-ERROR Class member `MockTemplateTransformNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:636:9
-ERROR Class member `MockTemplateTransformNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:640:9
-ERROR Class member `MockCodeNode.version` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:722:9
-ERROR Class member `MockCodeNode._run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- --> tests/helpers/workflow/mock_nodes.py:726:9
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/helpers/workflow/mock_nodes.py:749:52
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/helpers/workflow/mock_nodes.py:751:52
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/helpers/workflow/mock_nodes.py:753:52
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/helpers/workflow/mock_nodes.py:755:52
-ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
- --> tests/helpers/workflow/mock_nodes.py:757:52
WARN `URLError` is already caught earlier in this `try` statement, so it never matches here [unreachable-except-clause]
--> tests/pytest_dify.py:155:34
ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
@@ -3212,10 +3132,6 @@
--> tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py:1241:12
ERROR Object of class `NoneType` has no attribute `error` [missing-attribute]
--> tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py:1242:12
-ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
- --> tests/unit_tests/core/app/apps/test_base_app_generator.py:609:9
-ERROR `list[str]` is not assignable to attribute `allowed_file_types` with type `Sequence[FileType] | None` [bad-assignment]
- --> tests/unit_tests/core/app/apps/test_base_app_generator.py:770:35
ERROR Missing argument `model` in function `graphon.model_runtime.entities.model_entities.AIModelEntity.model_construct` [missing-argument]
--> tests/unit_tests/core/app/apps/test_base_app_runner.py:433:53
ERROR Missing argument `label` in function `graphon.model_runtime.entities.model_entities.AIModelEntity.model_construct` [missing-argument]
@@ -5309,8 +5225,6 @@
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:764:12
ERROR Object of class `object` has no attribute `kw` [missing-attribute]
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:765:12
-ERROR Argument `Literal['invalid']` is not assignable to parameter `session_factory` with type `Engine | sessionmaker[Unknown] | None` in function `services.file_service.FileService.__init__` [bad-argument-type]
- --> tests/unit_tests/services/test_file_service.py:92:45
ERROR Argument `Iterator[dict[str, str | dict[str, str]] | str]` is not assignable to parameter `response` with type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` in function `services.snippet_generate_service.SnippetGenerateService._filter_virtual_start_events` [bad-argument-type]
--> tests/unit_tests/services/test_snippet_generate_service.py:88:68
ERROR Keyword argument `loop_count` with type `Literal[1]` is not assignable to parameter `**kwargs` with type `str` in function `typing.MutableMapping.update` [bad-argument-type]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46458 +/- ##
==========================================
- Coverage 90.25% 90.24% -0.01%
==========================================
Files 6439 6439
Lines 405356 405430 +74
Branches 81519 81524 +5
==========================================
+ Hits 365844 365897 +53
- Misses 33097 33118 +21
Partials 6415 6415
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:
|
Replace the test-local `_NodeConfig` TypedDict with the production `ListOperatorNodeData`, and validate the fixture payloads through it. The TypedDict was a hand-written copy of the real model that only existed to keep `variable` as `list[str]`; reading `.variable` off the real model gives the same type without a duplicate declaration. `_build_node` now takes `ListOperatorNodeData | Mapping[str, object]`, so the few tests that still pass a raw mapping keep working.
There was a problem hiding this comment.
5 inline suggestions at 4183cd5247, 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.
3 inline suggestions at 4183cd5247, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
Both sides only moved lines in the pyrefly exclude list: this branch graduates its own test files while upstream graduates different ones. Keep both removals and upstream's new entry.
…passes Address the nine unresolved review comments on PR langgenius#46458 by making the real product types hold in tests rather than bypassing the type checker with cast / Mock(spec=) / object / Any / **kwargs. list_operator node_spec (langgenius#1 type-origin-code, langgenius#2 parse-don't-validate): - _build_node now accepts only the validated ListOperatorNodeData; drop the Mapping[str, object] branch and the internal re-validation. - _filter_by returns the real graphon FilterBy/FilterCondition models and takes a FilterOperator enum, so fixtures are built from origin-code types instead of ad hoc dict[str, object]. workflow mock_nodes (langgenius#3, langgenius#4 parse-don't-validate): - MockNodeMixin.__init__ takes data: BaseNodeData and forwards to the real Node.__init__ contract through a typed callable instead of packing an ad hoc init_kwargs: dict[str, Any]. - MockParameterExtractorNode mirrors the real node output contract: extracted values are flat top-level outputs and process_data no longer re-extracts a nested "parameters" copy via dict.get. - Remove the duplicated @OverRide decorators introduced on several _run methods. base_app_generator (langgenius#5, langgenius#6 precise-type): - _prepare_file_inputs returns File | list[File] | None and _as_file / _as_file_list accept that precise union instead of object. advanced_prompt_transform (langgenius#7, langgenius#8 import-real-class, langgenius#9 no-kwargs): - Delete _StubbedBranchesTransform; the dispatch test now exercises the real AdvancedPromptTransform and asserts real completion/chat output. - The malformed-template case asserts the pydantic boundary rejects the payload (parse-don't-validate) instead of casting untyped data past the checker into get_prompt's defensive guard. - The history fakes spell out max_token_limit / message_limit with types matching TokenBufferMemory.get_history_prompt_messages instead of **kwargs. Allow ARG001 for the advanced_prompt_transform test fakes that intentionally ignore message_limit while mirroring the real signature.
Upstream graduated test_advanced_prompt_transform.py under langgenius#45968 at the same time as this branch, so take the upstream rewrite of that test file (it already carries strict types) and keep this branch's other graduates; pyrefly.toml is rebuilt by set arithmetic from the merge base, this branch and upstream.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 79f8b38e71, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
dify-codereview
| ) | ||
| # The mixin precedes the concrete node in the MRO, so ``super()`` resolves to | ||
| # ``object`` for the type checker. Forward through a callable typed against the | ||
| # real ``Node.__init__`` contract instead of packing args into ``dict[str, Any]``. |
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.
Already resolved by the merge of main (3bbdbdb). The flagged super().__init__(**kwargs) packing is gone: mock_nodes.py now binds node_init: Callable[..., None] = super().__init__ and forwards explicit, typed arguments (data: BaseNodeData), so no ad hoc dict[str, Any] is built at this call site anymore.
There was a problem hiding this comment.
The untyped argument dictionary was removed by merge commit 3bbdbdb5285141636969abef091746dfa1bb0580: mock_nodes.py now preserves the typed BaseNodeData parameter and forwards node_init: Callable[..., None] = super().__init__ explicitly instead of packing arguments into an ad hoc **kwargs dict. This head is newer than the review; please re-review when convenient.
Summary
Graduate these modules out of
api/tests/unit_tests/pyrefly.toml'sproject-excludeslist by removing the suppressions each one relied on.helpers/unit/core/workflow/nodes/list_operator/node_spec.pyhelpers/workflow/mock_nodes.pyservices/test_file_service.pycore/app/apps/test_base_app_generator.pyApproach
mock_nodescarries most of the diff: the twelve mock node classes now declare@overrideonversionand_run, the result-style ones return a realNodeRunResultinstead of a bare mock, and the mixin declares_node_idrather than relying on an attribute it only ever assigns at runtime. Itssuper().__init__call now forwards**init_kwargs: dict[str, Any], which removes four unexpected-keyword errors while keeping the real initialisation.test_advanced_prompt_transform.pykeeps its exclude entry. One of its cases passes a list of non-ChatModelMessagevalues to reach the fall-through branch ofget_prompt, but every value in the declared domain — including an empty list — matches one of the twocasebranches, so that branch cannot be reached from a value the type system allows. The other 28 diagnostics in that file are fixed here; only the fabricated case stays behind.Verification
project-excludes: 155 → 152--config=tests/unit_tests/pyrefly.toml,--disable-project-excludes-heuristics): 29 diagnostics, allmissing-importfor packages absent from the local venv — identical to the clean-tree baselinepytest: 16 + 50 + 43 + 77 + 14 passedruff check/ruff format --check: cleanscripts/check_no_new_*.pyguards exit 0