test(api): bring the openapi human input form and workspace tests under strict pyrefly #46420
Pyrefly Type Coverage
| Metric | Base | PR | Delta |
| --- | ---: | ---: | ---: |
| Type coverage | 91.04% | 91.06% | +0.02% |
| Strict coverage | 90.70% | 90.72% | +0.02% |
| Typed symbols | 110,354 | 110,387 | +33 |
| Untyped symbols | 10,902 | 10,874 | -28 |
| Modules | 5111 | 5111 | 0 |
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 90.58%. Comparing base (
5d50d5f) to head (64d3f7f).:warning: Report is 40 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #46420 +/- ##
==========================================
+ Coverage 90.54% 90.58% +0.03%
==========================================
Files 6897 6953 +56
Lines 432401 440666 +8265
Branches 86698 87778 +1080
==========================================
+ Hits 391507 399156 +7649
- Misses 34069 34459 +390
- Partials 6825 7051 +226
| Flag | Coverage Δ | |
|---|---|---|
| api | 90.15% <ø> (+0.07%) | :arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Pyrefly Diff
<details>
<summary>base → PR</summary>
--- /tmp/pyrefly_base.txt 2026-12-01 10:03:08.671437531 +0000
+++ /tmp/pyrefly_pr.txt 2026-12-01 10:02:55.459340379 +0000
@@ -1896,40 +1896,6 @@
--> tests/unit_tests/controllers/mcp/test_mcp.py:41:13
ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
--> tests/unit_tests/controllers/mcp/test_mcp.py:61:5
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:129:20
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:148:17
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:161:17
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:179:22
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:206:22
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_human_input_form.py:232:20
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:244:14
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:271:14
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:341:14
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:416:9
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:500:9
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:531:14
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:566:9
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:584:13
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:587:13
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:618:14
-ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
- --> tests/unit_tests/controllers/openapi/test_workspaces.py:732:9
ERROR Object of class `FunctionType` has no attribute `__wrapped__` [missing-attribute]
--> tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py:734:24
ERROR Object of class `FunctionType` has no attribute `__wrapped__` [missing-attribute]
</details>
No reflection please (__dict__, vars, setattr, getattr, __getattr__): construct the object with its fields, or add a typed attribute or method.
<sub>dify-codereview · no-reflection Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=no-reflection;key=25c6ed0ace81d75c -->
No reflection please (__dict__, vars, setattr, getattr, __getattr__): construct the object with its fields, or add a typed attribute or method.
<sub>dify-codereview · no-reflection Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=no-reflection;key=ff7f0832ffccca51 -->
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=db46575229a5a14d -->
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=ce35e8c6545238a2 -->
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.
<sub>dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=parse-dont-validate;key=3b89cbe0402e9a65 -->
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.
<sub>dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=parse-dont-validate;key=6d34c4493b0bfa81 -->
6 inline suggestions at 360032b8a2, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=360032b8a28974cc8d9514967107f56ea0f75d62 -->
This branch has conflicts with main: please rebase onto the latest main. Checked 360032b8a2.
<sub>dify-codereview</sub>
<!-- dify-review:head=360032b8a28974cc8d9514967107f56ea0f75d62;conflict=360032b8a28974cc8d9514967107f56ea0f75d62 -->
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.
<sub>dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=parse-dont-validate;key=eb6995690981343e -->
CI is failing: Style Check / Python Style. Please fix it. 1 inline suggestion at 8839538d35, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 6 review threads are still unresolved.
<sub>dify-codereview</sub>
<!-- dify-review:head=8839538d35733b58eb4b4d4c2200e2bb5f33573d;ci=8839538d35733b58eb4b4d4c2200e2bb5f33573d -->
Updated in f3e8a85e. The cases now use raw JSON and the production model's model_validate_json, which fits because these inputs are intentionally invalid. Each case asserts the exact rejected field. The quota-race test now uses the existing typed handler helper instead of accessing __handler__ directly. All 66 targeted OpenAPI tests, scoped strict Pyrefly, and Ruff lint/format passed.
Fixed in 69ddd90cf9. The type(api).__dict__[method] / vars(view)["__handler__"] reflection in _handler is replaced by class Endpoint[T](Protocol) declaring __handler__: Callable[..., T] and __spec__: EndpointSpec (api/tests/unit_tests/controllers/openapi/test_human_input_form.py:75-85); call sites go through cast(Endpoint[Response], api.get).__handler__(...) / cast(Endpoint[FormSubmitResponse], api.post).__handler__(...).
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Fixed in 69ddd90cf9. Same change in test_workspaces.py: class Endpoint[T](Protocol) at line 100 replaces the __dict__ / vars() lookup, and each call site names the concrete return type.
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Fixed in 69ddd90cf9. The old generic _handler[**P, R](api: object, method: str) -> Callable[Concatenate[object, P], R] is gone. Each handler is cast to a concrete Endpoint — Endpoint[Response] for the form GET, Endpoint[FormSubmitResponse] for the submit POST, and cast(Endpoint[object], view).__spec__ (line 291) for the spec assertion — so no object-typed callable flows through the tests.
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Fixed in 69ddd90cf9. Likewise concrete per call site in test_workspaces.py: Endpoint[MemberListResponse] (GET ×2), Endpoint[MemberInviteResponse] (POST ×3), Endpoint[MemberActionResponse] (DELETE ×3 and PATCH ×3).
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Fixed in 69ddd90cf9. _paused no longer returns a dict[str, object] that tests re-parse: it returns the production HumanInputRequiredResponse itself (test_human_input_form.py:327). The hint test reads the typed fields (event.data.inputs, field.model_dump(mode="json")) and serializes only where the SSE payload is actually needed — payload = json.dumps(event.model_dump(mode="json")) at line 354. The isinstance(data, dict) re-check is removed.
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Fixed in 69ddd90cf9. _paused's return type changed from dict[str, object] (built via response.model_dump(mode="json")) to HumanInputRequiredResponse — the event is parsed once at the boundary into its production model and passed on typed, which is what this thread asked for.
Evidence on that head: both files now use the same Endpoint Protocol + cast seam that test__app_response.py already uses — no __dict__ / vars() reflection remains in either file — and locally pytest tests/unit_tests/controllers/openapi/test_human_input_form.py tests/unit_tests/controllers/openapi/test_workspaces.py = 66 passed, ruff check + ruff format --check clean, scoped pyrefly check = 0 diagnostics.
Avoid cast: nothing checks it. Give the producer a precise return type, take the value as a typed parameter, or narrow with isinstance.
<sub>dify-codereview · avoid-cast Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=avoid-cast;key=e3f4c8ffb652fe8d -->
Avoid cast: nothing checks it. Give the producer a precise return type, take the value as a typed parameter, or narrow with isinstance.
<sub>dify-codereview · avoid-cast Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=avoid-cast;key=f8610e53648ff3b3 -->
CI is failing: Style Check / Python Style. Please fix it. 2 inline suggestions at 69ddd90cf9, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=69ddd90cf9f6b1a97ca1010c9bc9d8ece9e41a35;ci=69ddd90cf9f6b1a97ca1010c9bc9d8ece9e41a35 -->
293ccb8f removes the new workspace test casts. The tests use the existing class-level handler through the shared runtime-checked helper and verify the actual response model before inspecting it. That leaves the invalid-request and error cases intact. All 66 focused tests passed, along with the full core type check and the no-new-cast and no-new-getattr guards.
293ccb8f removes the new casts from the form tests. The shared test helper checks the existing class-level decorator seam at runtime, and the tests check the actual response types before reading fields. The same request, response, and error assertions still run. All 66 focused tests, the full core type check, and both repository guards passed.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=70997d5799487c59 -->
1 inline suggestion at 293ccb8f2f, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=293ccb8f2f1a54c416735daf285ecd9e5be0318e -->
Updated in f93981d5: __handler__ is now typed as Callable[..., object], matching the bare callable assigned by @endpoint. The endpoints accept different parameters, and the existing runtime callable check remains. All 66 focused tests, strict Pyrefly, Ruff, and the scoped guards passed locally.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=5f288c2803d66ba6 -->
1 inline suggestion at f93981d59c, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=f93981d59cc686413d8776f726ecbcdcfea447cb -->
Fixed at head 5bde6a5af1: _DecoratedEndpoint.__spec__ is now annotated as EndpointSpec (imported from controllers.openapi.auth.spec) instead of object, which is exactly the instance @endpoint attaches at api/controllers/openapi/_contract.py:289. The isinstance(spec, EndpointSpec) narrowing in openapi_endpoint_spec therefore became redundant and was dropped, so the helper now returns the precise type directly.
Verified on the new head: ruff format --check and ruff check clean, pyrefly check reports 0 diagnostics for the file.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=79122a2839ef4eab -->
1 inline suggestion at 5bde6a5af1, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=5bde6a5af1535712f8559f8839f7ce2c1e9417d8 -->
Updated in 38c76564: openapi_handler now takes a callable, matching the class-level routes passed to it. The bare handlers have different signatures and response types, so the helper returns a callable and each test narrows the response it expects. The runtime checks are unchanged. All 66 affected tests and scoped strict Pyrefly passed locally.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
<sub>dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.</sub>
<!-- dify-review:rule=precise-types;option=concrete-type;key=c97058efe4ba432d -->
1 inline suggestion at 38c7656476, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
<sub>dify-codereview</sub>
<!-- dify-review:head=38c765647695d99ab954c3f4c37ecd7b61c9cb07 -->
Updated in 64d3f7f3: openapi_endpoint_spec now accepts Callable[..., object], matching the decorated route functions its callers supply. It still returns the production EndpointSpec, and the runtime checks are unchanged. Both affected suites passed (66 tests); scoped strict Pyrefly and Ruff passed as well.
Nothing to flag at 64d3f7f315.
<sub>dify-codereview</sub>
<!-- dify-review:head=64d3f7f315118a53278f509eab89487fa1431870 -->
asukaminato0721
MindOfqc
Why
api/tests/unit_tests/pyrefly.tomlstill lists the OpenAPI human-input-form tests and the OpenAPI workspace tests as strict-mode debt. Neither needs a type suppression, so they should not stay on the list.What changed
The bulk of the work is the
__handler__seam.controllers/openapi/_contract.pyattaches__handler__at decoration time, so it is missing from the decorated function's static type and every directapi.get.__handler__(...)call reportedObject of class FunctionType has no attribute __handler__. A module-level_handlerhelper reads the attribute out of the instance dict and carries the view's real signature throughConcatenate[object, P], which keeps the call sites typed instead of casting the result. Sixteen diagnostics across the two files disappear that way, with the assertions untouched.The rest is annotations: test methods and fixtures declare their returns, the parametrised
recipient_type/exc/expectedarguments are typed, and the hint test narrowsevent["data"]through anisinstancecheck before indexing so the repeatedevent["data"]["inputs"]lookups stop reportingbad-index.api/tests/unit_tests/pyrefly.tomldrops the two entries (199 -> 197).How to test
Locally, with both entries removed from
project-excludes:missing-importerrors, zero warnings, zero non-missing-importerrors, zero remaining diagnostics for either fileos.register_at_forksetup errors before and after (Windows-only, unrelated to these tests)No new
pyrefly: ignore,type: ignore,castortyping.Any.