Skip to content

refactor(api): enable strict typing for libs test files - #44882

Open
shi-felix wants to merge 6 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-12
Open

shi-felix wants to merge 6 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-12

Conversation

@shi-felix

Copy link
Copy Markdown
Contributor

Summary

Enable strict pyrefly checking for 7 test files under tests/unit_tests/libs/ by removing them from the strict-mode exclusion list and fixing the resulting diagnostics:

  • Annotate fixtures and parametrized parameters with their real types (Callable[..., None] for config_overrides, Callable[..., Response | str] for the login-protected view, Callable[[MockUser | Account | None], MagicMock] for the user resolver, dict[str, object] for thread-result dicts).
  • Declare -> None / -> datetime / -> Response | str returns; add Generator[...] for yielding fixtures.
  • Add @override to the UserMixin.get_id test double (pattern already used in clients/agent_backend/test_client.py).
  • Keep suppression comments only where the type system cannot see the runtime truth: deliberate invalid inputs in negative tests (extract_tenant_id(None), escape_like_pattern(None), ...), the werkzeug proxy _get_current_object access, and a dynamically assigned tenant_id on an EndUser — matching the # pyrefly: ignore[...] usage already present in the suite.

Verification

  • pyrefly check with the unit-test strict config: 0 diagnostics for all 7 files.
  • ruff format + ruff check: clean.
  • scripts/check_no_new_test_doubles.py --base-rev main: no new test doubles.
  • The libs/ test files import tests/unit_tests/controllers/conftest, whose chain cannot be collected in this local Windows sandbox (hangs on import, same as events/ and tasks/), so runtime coverage relies on CI.

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-02 23:49:35.620886079 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-02 23:49:22.848735435 +0000
@@ -5734,24 +5734,6 @@
    --> tests/unit_tests/libs/test_external_api.py:436:12
 ERROR Cannot index into `str` [bad-index]
    --> tests/unit_tests/libs/test_external_api.py:436:12
-ERROR Class member `User.get_id` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-  --> tests/unit_tests/libs/test_flask_utils.py:18:9
-ERROR `str` is not assignable to dict key `error` with type `None` [bad-assignment]
-  --> tests/unit_tests/libs/test_flask_utils.py:71:35
-ERROR `str` is not assignable to dict key `error` with type `None` [bad-assignment]
-   --> tests/unit_tests/libs/test_flask_utils.py:114:35
-ERROR Object of class `Flask` has no attribute `_get_current_object` [missing-attribute]
-   --> tests/unit_tests/libs/test_flask_utils.py:131:18
-ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[str] | str` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:159:30
-ERROR Argument `Literal['not_a_user_object']` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:169:31
-ERROR Argument `None` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:174:31
-ERROR Argument `dict[str, str]` is not assignable to parameter `user` with type `Account | EndUser` in function `libs.helper.extract_tenant_id` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:181:31
-ERROR Argument `None` is not assignable to parameter `pattern` with type `str` in function `libs.helper.escape_like_pattern` [bad-argument-type]
-   --> tests/unit_tests/libs/test_helper.py:228:38
 ERROR Class member `TestCronCompatibility.setUp` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/libs/test_schedule_utils.py:22:9
 ERROR Class member `TestTimezoneCompatibility.setUp` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 82.88% 83.00% +0.12%
Strict coverage 82.54% 82.66% +0.12%
Typed symbols 85,470 85,590 +120
Untyped symbols 17,723 17,603 -120
Modules 4372 4372 0

@autofix-ci
autofix-ci Bot requested a review from a team October 27, 2026 10:31
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.77%. Comparing base (b5722ed) to head (c5cf66c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44882      +/-   ##
==========================================
- Coverage   89.77%   89.77%   -0.01%     
==========================================
  Files        6239     6237       -2     
  Lines      390924   390745     -179     
  Branches    79291    79213      -78     
==========================================
- Hits       350955   350790     -165     
+ Misses      33869    33856      -13     
+ Partials     6100     6099       -1     
Flag Coverage Δ
api 89.63% <ø> (+<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.

@asukaminato0721 asukaminato0721 self-assigned this Oct 28, 2026
auto-merge was automatically disabled November 2, 2026 23:38

Head branch was pushed to by a user without write access

- test_login.py: use mocker.patch.object instead of direct method assignment (mypy method-assign)
- test_email_i18n.py: add missing -> None return annotation (ruff ANN201)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants