Repository navigation
test(api): add Pyrefly-clean unit tests for DocumentContext - #45996
asukaminato0721 merged 1 commit into
Conversation
Covers core.rag.entities.context_entities.DocumentContext with 15 cases. Negative cases use model_validate() because dify's strict type-check-core also checks the test tree: constructing a pydantic model with missing or mistyped arguments is a static error, while model_validate() exercises the same runtime validation path without tripping the gate. Verified locally: pyrefly 1.4.1 -> 0 diagnostics, pytest -> 29 passed, ruff check + format -> clean. Purely additive (1 new file, 0 deletions).
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45996 +/- ##
==========================================
- Coverage 90.10% 90.10% -0.01%
==========================================
Files 6279 6279
Lines 392410 392410
Branches 78562 78562
==========================================
- Hits 353596 353591 -5
- Misses 32725 32731 +6
+ Partials 6089 6088 -1
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:
|
|
pyrefly-org/pyrefly#3390 I impl the check for model_validate so now llm don't need to write such case. |
|
Thanks for the pointer to #45614 — I checked it: it bumps I re-verified the two test modules in this PR against pyrefly 1.5.0-dev.1, using this repo's
So no code change was needed here. I deliberately did not force-push, to avoid dismissing your approval. Following the same type-check thread, I did find that the two sibling test PRs from this batch (#45922 and #45924) were actually failing CI: they imported If you would prefer these two PRs to land after #45614 for merge-order reasons, just say so and I'll hold. Thanks again for the review. |
Summary
Re-submission of #45760, which I closed after
Style Check / Python Stylefailed on dify's strictpyrefly type-check-core. GitHub does not allow reopening a PR whose head branch was force-pushed, so the type-correct rewrite is submitted as a new PR instead.Purely additive: one new test file covering the previously uncovered
core.rag.entities.context_entities.DocumentContext— 15 cases, 0 deletions.Why the negative cases use
model_validatedify type-checks the test tree as well. Constructing a pydantic model with missing or mistyped arguments is a static error there, even though the behaviour under test is a
ValidationErrorat runtime. Negative cases now pass their payload throughModel.model_validate({...}), which goes through the very same pydantic validation path but takes an unvalidated mapping, so it does not trip the type gate. No# type: ignoreis used. Two extra cases assert thatmodel_validateand the constructor produce equal models.Verification (local, Python 3.13)
pyrefly 1.4.1 checkwith this repo's[tool.pyrefly]config: 10 errors -> 0 diagnosticspytest: 29 passed across both rewritten modulesruff check+ruff format --checkwithapi/.ruff.toml: cleanmain(8fb0e237), LF line endings, additive-onlyAI-assisted test generation; assertions reflect the documented behaviour of the target models.