Repository navigation
refactor(api): enable strict typing for archive/schedule/external-api test files - #44885
Conversation
Pyrefly Diffbase → 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]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
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:
|
…t files Drop the three entries from the pyrefly exclude list now that the files are annotated, so strict checking covers them here.
Head branch was pushed to by a user without write access
951fa91 to
b217e9c
Compare
|
Style Check is green again - |
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.
|
All sixteen
Each validates with |
…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.
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:botocoreBaseClient/AWSRequest/AWSResponse/HTTPHeaders,TypedDictfor visual-config cases,MagicMock,Flask).@overrideto the eightsetUpoverrides and theUserMixin-style stub members (pattern already used inclients/agent_backend/test_client.py)._at(container, *keys)walker and explicitcasts, so nested assertions stay type-clean without loosening types.BadRequest.description = {...}to trigger param-error shaping, a minimalerror_body_formatterstand-in used before a flask-restx guard raises), and the loosely typedboto3.client(...)factory.Verification
pyrefly checkwith 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.libs/files importtests/unit_tests/controllers/conftest, whose chain cannot be collected in this local Windows sandbox (hangs on import, same asevents//tasks/), so runtime coverage relies on CI.