Skip to content

refactor(api): enable strict typing for archive/schedule/external-api test files - #44885

Merged
wylswz merged 6 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-13
Nov 11, 2026
Merged

wylswz merged 6 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-13

Conversation

@shi-felix

Copy link
Copy Markdown
Contributor

Summary

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

  • Annotate helpers, closures, and parametrized parameters with their real types (botocore BaseClient/AWSRequest/AWSResponse/HTTPHeaders, TypedDict for visual-config cases, MagicMock, Flask).
  • Add @override to the eight setUp overrides and the UserMixin-style stub members (pattern already used in clients/agent_backend/test_client.py).
  • Replace deep Swagger-JSON index chains with a small _at(container, *keys) walker and explicit casts, so nested assertions stay type-clean without loosening types.
  • Keep suppression comments only where the type system cannot see the runtime truth: deliberately invalid inputs (BadRequest.description = {...} to trigger param-error shaping, a minimal error_body_formatter stand-in used before a flask-restx guard raises), and the loosely typed boto3.client(...) factory.

Verification

  • pyrefly check with the unit-test strict config: 0 diagnostics for all 3 files.
  • ruff format + ruff check: clean.
  • scripts/check_no_new_test_doubles.py --base-rev main: no new test doubles.
  • These libs/ files import tests/unit_tests/controllers/conftest, whose chain cannot be collected in this local Windows sandbox (hangs on import, same as events//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-11 00:44:53.902775446 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-11 00:44:40.882681883 +0000
@@ -5371,40 +5371,6 @@
    --> tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel.py:562:45
 ERROR Argument `FakeStreamsRedis` is not assignable to parameter `client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis.streams_channel._StreamsSubscription.__init__` [bad-argument-type]
    --> tests/unit_tests/libs/broadcast_channel/redis/test_streams_channel.py:580:45
-ERROR Argument `dict[@_, @_]` is not assignable to parameter `headers` with type `HTTPHeaders` in function `botocore.awsrequest.AWSResponse.__init__` [bad-argument-type]
-   --> tests/unit_tests/libs/test_archive_storage.py:160:50
-ERROR `dict[str, str]` is not assignable to attribute `description` with type `str | None` [bad-assignment]
-  --> tests/unit_tests/libs/test_external_api.py:84:29
-ERROR Argument `_PassthroughFormatter` is not assignable to parameter `error_body_formatter` with type `ErrorBodyFormatter | None` in function `libs.external_api.ExternalApi.__init__` [bad-argument-type]
-   --> tests/unit_tests/libs/test_external_api.py:285:72
-ERROR Argument `Unknown | None` is not assignable to parameter `blueprint` with type `Blueprint` in function `flask.sansio.app.App.register_blueprint` [bad-argument-type]
-   --> tests/unit_tests/libs/test_external_api.py:399:28
-ERROR Cannot index into `str` [bad-index]
-   --> tests/unit_tests/libs/test_external_api.py:435:12
-ERROR Cannot index into `bool` [bad-index]
-   --> 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 `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]
-   --> tests/unit_tests/libs/test_schedule_utils.py:177:9
-ERROR Class member `TestFrontendBackendIntegration.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:258:9
-ERROR Argument `VisualConfig | str` is not assignable to parameter `frequency` with type `str` in function `services.trigger.schedule_service.ScheduleService.visual_to_cron` [bad-argument-type]
-   --> tests/unit_tests/libs/test_schedule_utils.py:319:60
-ERROR Argument `VisualConfig | str` is not assignable to parameter `visual_config` with type `VisualConfig` in function `services.trigger.schedule_service.ScheduleService.visual_to_cron` [bad-argument-type]
-   --> tests/unit_tests/libs/test_schedule_utils.py:319:84
-ERROR Class member `TestEnhancedCronSyntax.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:389:9
-ERROR Class member `TestTimezoneHandlingEnhanced.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:578:9
-ERROR Class member `TestErrorHandlingEnhanced.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:675:9
-ERROR Class member `TestPerformanceEnhanced.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:719:9
-ERROR Class member `TestRegressionEnhanced.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:787:9
 ERROR Argument `dict[str, list[@_]]` is not assignable to parameter `graph` with type `SQLCoreOperations[str] | str` in function `models.workflow.Workflow.__init__` [bad-argument-type]
    --> tests/unit_tests/services/agent/test_dsl_service.py:115:15
 ERROR `object` is not assignable to dict key `agent_binding` with type `str` [bad-assignment]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 84.91% 85.01% +0.10%
Strict coverage 84.57% 84.67% +0.10%
Typed symbols 89,416 89,522 +106
Untyped symbols 15,951 15,845 -106
Modules 4454 4454 0

@autofix-ci
autofix-ci Bot requested a review from a team October 27, 2026 10:39
@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 90.11%. Comparing base (208a248) to head (4346c30).
⚠️ Report is 74 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44885      +/-   ##
==========================================
+ Coverage   90.02%   90.11%   +0.09%     
==========================================
  Files        6264     6278      +14     
  Lines      391830   392102     +272     
  Branches    78439    78450      +11     
==========================================
+ Hits       352738   353355     +617     
+ Misses      33003    32658     -345     
  Partials     6089     6089              
Flag Coverage Δ
api 89.97% <ø> (+0.15%) ⬆️

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid cast

@asukaminato0721 asukaminato0721 self-assigned this Oct 29, 2026
…t files

Drop the three entries from the pyrefly exclude list now that the files are
annotated, so strict checking covers them here.
auto-merge was automatically disabled October 30, 2026 03:24

Head branch was pushed to by a user without write access

@shi-felix
shi-felix force-pushed the refactor/pyrefly-strict-test-batch-13 branch from 951fa91 to b217e9c Compare October 30, 2026 03:24
@shi-felix

Copy link
Copy Markdown
Contributor Author

Style Check is green again - test_error_component_names_must_not_collide was missing its -> None. Rebased onto main as well; pyrefly.toml now only drops the three exclude lines for this PR's files.

Reviewer asked to avoid `typing.cast`. Replace all sixteen casts with three small narrowing helpers (`_as_mapping`, `_as_items`, `_as_text`) that validate the JSON node before use, so the tests keep the same assertions without an escape hatch. The `check_no_new_cast` guard rejects net-new casts, aliases included.
@shi-felix

Copy link
Copy Markdown
Contributor Author

All sixteen typing.cast calls in test_external_api.py are gone, replaced by three narrowing helpers:

  • _as_mapping — string-keyed mapping
  • _as_items — list
  • _as_text — string

Each validates with isinstance and raises TypeError otherwise, so the assertions stay exactly as they were but no longer need an escape hatch. check_no_new_cast is green. Pushed as 2f3b6f1.

…ct-test-batch-13

Resolve conflict in api/tests/unit_tests/pyrefly.toml by replaying this PR's three exclude-line deletions onto the current main version.
…ct-test-batch-13

`api/tests/unit_tests/pyrefly.toml` is a shared exclusion list, so the merge keeps main's
list and re-applies this branch's three deletions.
`typing.TypedDict` / `typing.override`, main added `zoneinfo.ZoneInfo` for
the new cases. The resolution keeps both, in isort order.
Model the Swagger document slice with pydantic instead of walking nested dicts.

`_responses` / `_error_options` reached into the document with `_as_mapping(_at(...))` chains.
The test now parses the document once into `_Document` (`paths -> get -> responses -> content ->
schema`, plus `components.schemas`) and reads attributes; the `$ref` / `anyOf` accessors get named
fields, and comparisons dump with `exclude_defaults` so only the keys the document actually set
are compared.
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants