Skip to content

test(api): strictly type plugin model and chunk merger tests - #45230

Open
ShousenZHANG wants to merge 1 commit into
langgenius:mainfrom
ShousenZHANG:refactor/plugin-test-strict-types
Open

ShousenZHANG wants to merge 1 commit into
langgenius:mainfrom
ShousenZHANG:refactor/plugin-test-strict-types

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Summary

Refs #24645, following #45221.

Enable strict Pyrefly checking for the plugin model backwards-invocation and chunk-merger tests. Annotate the existing tests, use the model types exercised by the parameterized cases, and explicitly check that resolved token limits exist before reading their fields.

 tests/unit_tests/pyrefly.toml — project-excludes
- core/plugin/backwards_invocation/test_model.py
- core/plugin/utils/test_chunk_merger.py

Existing cases, assertions and dependency patches are preserved. The converter's empty-list input now has an explicit element type.

Evidence

  • Pyrefly 1.4.0: 37 errors and seven warnings before, zero diagnostics after. Full unit-test, container-test and production type checks pass.
  • Both target files reach 100% type coverage: model backwards invocation 8/24 → 24/24 typed symbols; chunk merger 0/20 → 20/20. Together they add 36 typed symbols.
  • All 61 tests pass on main and this branch, with identical ordered test IDs. All 99 existing assertion predicates are unchanged; three non-null assertions make their existing precondition explicit.
  • Full Ruff format/check, 78 import contracts, response-contract lint, generated billing-client verification and all eight CI guards pass. Guards compare against the merge base.

Production type checking uses the Tencent provider source path for the Windows worktree. Tests run through the local Windows wrapper for readline/libmagic.

Merge Danger

Reversible; scope is two test modules and their strict-check exclusions. With the existing fixtures and parameterized inputs, the tests keep their invocation, billing, MIME, conversion and chunk-integrity assertions. Production behavior is unchanged.

Screenshots

Before After
N/A: test typing and check configuration N/A

Checklist

  • This change requires a documentation update, included: Dify Document
  • 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.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

Backend commands were run individually on Windows; there are no frontend or documentation changes.

From Codex

Copilot AI balanced review requested due to automatic review settings November 1, 2026 04:52

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:M This PR changes 30-99 lines, ignoring generated files. label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-01 04:54:31.546507941 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-01 04:54:06.050435054 +0000
@@ -4140,20 +4140,6 @@
    --> tests/unit_tests/core/plugin/backwards_invocation/test_app.py:439:16
 ERROR Object of class `Account` has no attribute `app_id` [missing-attribute]
    --> tests/unit_tests/core/plugin/backwards_invocation/test_app.py:440:16
-ERROR Object of class `NoneType` has no attribute `context_tokens` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:408:12
-ERROR Object of class `NoneType` has no attribute `max_output_tokens` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:409:12
-ERROR Object of class `NoneType` has no attribute `output_parameter` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:410:12
-ERROR Object of class `NoneType` has no attribute `context_tokens` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:434:12
-ERROR Object of class `NoneType` has no attribute `max_output_tokens` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:435:12
-ERROR Object of class `NoneType` has no attribute `max_output_tokens` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:454:12
-ERROR Object of class `NoneType` has no attribute `output_parameter` [missing-attribute]
-   --> tests/unit_tests/core/plugin/backwards_invocation/test_model.py:455:12
 ERROR Argument `TestPluginDaemonEntities.test_credential_type_helpers._FakeCredential` is not assignable to parameter `self` with type `CredentialType` in function `core.plugin.entities.plugin_daemon.CredentialType.get_name` [bad-argument-type]
    --> tests/unit_tests/core/plugin/entities/test_plugin_daemon.py:313:40
 ERROR Argument `object` is not assignable to parameter `method` with type `str` in function `httpx._api.request` [bad-argument-type]

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 81.60% 81.64% +0.03%
Strict coverage 81.25% 81.28% +0.03%
Typed symbols 85,638 85,674 +36
Untyped symbols 19,389 19,353 -36
Modules 4396 4396 0

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.85%. Comparing base (170dbae) to head (f706481).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #45230   +/-   ##
=======================================
  Coverage   89.85%   89.85%           
=======================================
  Files        6249     6249           
  Lines      398125   398125           
  Branches    80223    80223           
=======================================
+ Hits       357739   357744    +5     
+ Misses      34076    34070    -6     
- Partials     6310     6311    +1     
Flag Coverage Δ
api 89.72% <ø> (+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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants