Skip to content

test(api): bring the list operator node tests under strict pyrefly - #46308

Merged
asukaminato0721 merged 4 commits into
langgenius:mainfrom
MindOfqc:test/pyrefly-list-operator
Nov 15, 2026
Merged

asukaminato0721 merged 4 commits into
langgenius:mainfrom
MindOfqc:test/pyrefly-list-operator

Conversation

@MindOfqc

@MindOfqc MindOfqc commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

api/tests/e2e_tests/contracts/core/workflow/nodes/test_list_operator.py still sits in project-excludes in api/tests/unit_tests/pyrefly.toml, so the strict preset has never checked it. Under strict checking it reports six diagnostics along the fixture chain _build_list_operator_node → list_operator_node → the tests that consume it.

What changed

  • _build_list_operator_node(node_data: ListOperatorNodeData, graph_init_params: InitParams) -> ListOperatorNode
  • list_operator_node() -> ListOperatorNode
  • test_filter_files_by_type(list_operator_node: ListOperatorNode) -> None
  • test_get_file_extract_string_func() -> None
  • Declare the graph-init and runtime-state mocks as MagicMock locally so pyrefly can see variable_pool.get.return_value on them.
  • Drop the corresponding line from project-excludes (208 → 207 entries).

No # pyrefly: ignore, no # type: ignore, no typing.cast.

A note on what this does not do

An earlier revision of this branch replaced the MagicMock() standing in for graph init parameters with a real InitParams, and the runtime state mock with a real RuntimeState. That satisfied pyrefly but broke the test: VariablePool.get returns None when the selector is shorter than SELECTORS_LENGTH (2), and this fixture deliberately uses a single-segment selector ["test_variable"] — the mock is what makes the variable resolve at all. Constructing a real RuntimeState also requires either workflow_id or graph_execution, which the fixture does not model.

So this branch keeps the mocks and narrows their types instead. That is the honest shape of the change: the module was exempt not because it uses mocks, but because its annotations were missing.

How to verify

Project-wide check from api/tests/unit_tests/, using the GitHub output format the CI job uses:

PYREFLY_OUTPUT_FORMAT=github pyrefly check --python-interpreter-path <venv>/Scripts/python.exe
  • Before: INFO 29 diagnostics, all missing-import notes from packages absent in a local venv. CI installs the full dependency set, so they do not appear there.
  • After: still exactly 29 diagnostics, all missing-import, zero WARN, none in the touched file.

Note that min-severity = "warn" in pyrefly.toml, so a stray WARN fails make type-check-core just like an ERROR. The first push of this branch did leave one such warning (Object of class FunctionType has no attribute return_value at line 103) and CI caught it — that is what the local mock-type declarations fix.

Mutation check: reverting only test_list_operator.py while keeping the exemption removed raises the count to 35 and reproduces exactly the six original diagnostics.

Tests: pytest api/tests/e2e_tests/contracts/core/workflow/nodes/test_list_operator.py → 2 passed, unchanged from before.

ruff check and ruff format --check both pass.

Annotate the fixture chain in `test_list_operator.py`, build a real
`InitParams` instead of a bare `MagicMock`, and drop the module's
strict-mode exemption.
@github-actions github-actions Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-13 15:56:36.901753714 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-13 15:56:14.079637710 +0000
@@ -1664,6 +1664,8 @@
    --> tests/e2e_tests/contracts/core/workflow/nodes/test_if_else.py:388:19
 ERROR Argument `dict[str, list[dict[str, list[dict[str, list[str] | str]] | str]] | str]` is not assignable to parameter `node_data` with type `IfElseNodeData | dict[str, object]` in function `_build_if_else_node` [bad-argument-type]
    --> tests/e2e_tests/contracts/core/workflow/nodes/test_if_else.py:453:19
+ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
+   --> tests/e2e_tests/contracts/core/workflow/nodes/test_list_operator.py:103:5
 ERROR `Literal['{invalid-json-schema']` is not assignable to attribute `json_schema` with type `dict[str, Any] | None` [bad-assignment]
    --> tests/e2e_tests/contracts/core/workflow/nodes/test_start_node_json_object.py:209:28
 ERROR Argument `_StubToolRuntime` is not assignable to parameter `runtime` with type `ToolNodeRuntimeProtocol` in function `graphon.nodes.tool.tool_node.ToolNode.__init__` [bad-argument-type]

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 85.99% 86.00% +0.00%
Strict coverage 85.66% 85.66% +0.00%
Typed symbols 91,814 91,818 +4
Untyped symbols 15,013 15,009 -4
Modules 4526 4526 0

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.41%. Comparing base (61c8c3b) to head (a67681b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #46308   +/-   ##
=======================================
  Coverage   90.40%   90.41%           
=======================================
  Files        6334     6334           
  Lines      396673   396673           
  Branches    79711    79711           
=======================================
+ Hits       358631   358644   +13     
+ Misses      31933    31919   -14     
- Partials     6109     6110    +1     
Flag Coverage Δ
api 90.11% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Keep the runtime-state mock the tests already rely on and declare its
type locally, so pyrefly can see `variable_pool.get` without the mock
having to be replaced by a real `RuntimeState` the test data cannot
satisfy.
@github-actions github-actions Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Nov 13, 2026
The list operator fixture handed the node a `MagicMock` runtime state and then
stubbed `variable_pool.get` to return the expected segment.

Build the real objects instead: a `RuntimeState` over a real `VariablePool`
(remembering that `workflow_id` is required), and register the source segment
with `VariablePool.add`. The stub disappears and the node is exercised against
the pool it actually reads from.

The selector stays two segments — `[node_id, variable_name]` — because
`VariablePool.get` returns `None` for anything shorter.

Verified: pyrefly 29 errors / 0 warnings / 0 non-missing-import for the unit
config and 0 for the e2e config, 2 tests pass, ruff clean.
# Conflicts:
#	api/tests/unit_tests/pyrefly.toml
auto-merge was automatically disabled November 15, 2026 09:37

Head branch was pushed to by a user without write access

@MindOfqc

Copy link
Copy Markdown
Contributor Author

Replaced the mocks with real objects.

RuntimeState is now built over a real VariablePool (note workflow_id is required), and the source segment is registered with VariablePool.add, so the variable_pool.get.return_value = ... stub is gone. The selector stays two segments — [node_id, variable_name] — because VariablePool.get returns None for anything shorter.

This was referenced Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants