Skip to content

test(api): strictly type service API fixtures and conversation tests - #45180

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
ShousenZHANG:refactor/controller-payload-test-types
Oct 31, 2026
Merged

asukaminato0721 merged 2 commits into
langgenius:mainfrom
ShousenZHANG:refactor/controller-payload-test-types

Conversation

@ShousenZHANG

@ShousenZHANG ShousenZHANG commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #24645.

Service API fixtures and conversation tests are excluded from strict Pyrefly checking. Annotate their parameters and returns, use the models' enum fields and required constructor arguments, and remove both exclusions so CI checks them.

The response test uses the real SegmentType enum instead of SimpleNamespace. Following review, remove the two limit-rejection cases. The valid limit boundaries and all remaining test bodies and assertions are preserved.

Evidence

  • GitHub CI for 87afdad: 33 checks passed and 14 were skipped, including successful API controller, integration, unit, Python Style, browser E2E, and Codecov checks.
  • Pyrefly 1.4.0: the complete unit-test and container-test strict configurations pass.
  • The updated CI coverage report covers 4,396 modules: type coverage 81.50% → 81.57%, strict coverage 81.15% → 81.22%, typed symbols 85,533 → 85,604, and untyped symbols 19,496 → 19,423.
  • All 60 remaining conversation tests pass. The revision removes exactly the two requested cases; the remaining test bodies and 59 assert statements are unchanged.
  • The complete Service API suite on this branch has 902 passing tests and the existing Windows SQLite file-lock teardown error in the concurrent-submission test.
  • A clean merge simulation with main 4c521a3 has 903 passing tests; main alone has 905. The ordered test IDs differ only by the two requested removals, and both runs reproduce the same Windows teardown error.
  • Ruff format/check, all 76 import contracts, response-contract lint, the generated billing-client check, and all eight CI guards pass. Production type checking passes with the Tencent provider source directory on PYTHONPATH for the Windows worktree.

Merge Danger

Reversible; scope is tests and strict-check configuration. Given valid fixture inputs, factories return real models with the required fields. Production behavior, including pagination constraints, is unchanged.

Screenshots

Not applicable.

Checklist

  • This change requires a documentation update, included: Dify Document — not required.
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. — not required.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods — equivalent backend commands were run individually on Windows; no frontend changes.

Copilot AI balanced review requested due to automatic review settings October 31, 2026 00:42

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-31 16:20:56.393118790 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-31 16:20:37.152914162 +0000
@@ -2556,10 +2556,6 @@
    --> tests/unit_tests/controllers/service_api/app/test_audio.py:205:16
 ERROR Argument `list[dict[str, Any]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/app/test_completion.py:258:24
-ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:69:39
-ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/app/test_conversation.py:74:39
 ERROR Class member `_FakePauseEntity.get_pause_reasons` is marked as an override, but no parent class has a matching attribute [bad-override]
    --> tests/unit_tests/controllers/service_api/app/test_workflow_events.py:274:9
 ERROR Argument `Literal['app-run']` is not assignable to parameter `triggered_from` with type `SQLCoreOperations[WorkflowRunTriggeredFrom] | WorkflowRunTriggeredFrom` in function `models.workflow.WorkflowRun.__init__` [bad-argument-type]
@@ -2576,28 +2572,6 @@
    --> tests/unit_tests/controllers/service_api/app/test_workflow_events.py:627:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `RuntimeState` in function `core.app.apps.common.workflow_response_converter.WorkflowResponseConverter.workflow_pause_to_stream_response` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/app/test_workflow_events.py:717:33
-ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
-  --> tests/unit_tests/controllers/service_api/conftest.py:39:16
-ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `AppStatus | SQLCoreOperations[AppStatus]` in function `models.model.App.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/conftest.py:106:16
-ERROR Argument `Literal['app']` is not assignable to parameter `type` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `models.model.ApiToken.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/conftest.py:135:14
-ERROR Argument `Literal['dataset']` is not assignable to parameter `type` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `models.model.ApiToken.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/conftest.py:145:14
-ERROR Missing argument `position` in function `models.dataset.Document.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/conftest.py:170:24
-ERROR Missing argument `data_source_type` in function `models.dataset.Document.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/conftest.py:170:24
-ERROR Missing argument `batch` in function `models.dataset.Document.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/conftest.py:170:24
-ERROR Missing argument `created_from` in function `models.dataset.Document.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/conftest.py:170:24
-ERROR Missing argument `created_by` in function `models.dataset.Document.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/conftest.py:170:24
-ERROR Argument `Literal['completed']` is not assignable to parameter `indexing_status` with type `IndexingStatus | SQLCoreOperations[IndexingStatus]` in function `models.dataset.Document.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/conftest.py:175:25
-ERROR Argument `Literal['completed']` is not assignable to parameter `status` with type `SQLCoreOperations[SegmentStatus] | SegmentStatus` in function `models.dataset.DocumentSegment.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/conftest.py:197:16
 ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[datetime] | datetime` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py:868:34
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 81.50% 81.57% +0.07%
Strict coverage 81.15% 81.22% +0.07%
Typed symbols 85,533 85,604 +71
Untyped symbols 19,496 19,423 -73
Modules 4396 4396 0

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.85%. Comparing base (e3ef66b) to head (87afdad).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #45180      +/-   ##
==========================================
+ Coverage   89.84%   89.85%   +0.01%     
==========================================
  Files        6244     6249       +5     
  Lines      397460   398118     +658     
  Branches    80168    80224      +56     
==========================================
+ Hits       357079   357720     +641     
- Misses      34080    34087       +7     
- Partials     6301     6311      +10     
Flag Coverage Δ
api 89.72% <ø> (+0.03%) ⬆️

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 added this pull request to the merge queue Oct 31, 2026
@asukaminato0721 asukaminato0721 self-assigned this Oct 31, 2026
Merged via the queue into langgenius:main with commit 5336037 Oct 31, 2026
49 checks passed
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