Skip to content

refactor(api): enable strict typing for fields/factories test files - #44881

Open
shi-felix wants to merge 3 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-11
Open

shi-felix wants to merge 3 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-11

Conversation

@shi-felix

Copy link
Copy Markdown
Contributor

Summary

Enable strict pyrefly checking for 7 test files under tests/unit_tests/fields/, tests/unit_tests/factories/, and tests/unit_tests/migrations/ by removing them from the strict-mode exclusion list and fixing the resulting diagnostics:

  • Annotate helpers, fixtures, and parametrized parameters with their real types (FileMappingInput, FileUploadConfig, FileType, IndexingStatus, MagicMock, Iterator/Generator returns).
  • Construct the pydantic response models in test_message_fields.py via model_validate (the suite base model sets validate_by_name=True, so behavior is unchanged) instead of unpacking a loosely typed kwargs dict.
  • Narrow optional returns with asserts (parse_file_reference, importlib.util.spec_from_file_location) and annotate nested fake_standardize/_fake_head closures to mirror the patched callables.
  • Keep suppression comments only where the type system cannot see the runtime truth: the SQLAlchemy __table__ stub mismatch on create_all(tables=...), a deliberate dynamic attribute on a decoy Dataset, and raw stored dicts re-validated through pydantic.

Verification

  • pyrefly check with the unit-test strict config: 0 diagnostics for all 7 files.
  • ruff format + ruff check: clean.
  • scripts/check_no_new_test_doubles.py --base-rev main: no new test doubles.
  • pytest: 137 passed across fields/test_message_fields.py (8), fields/test_dataset_fields.py (7), factories/file_factory/test_builders.py (52), factories/file_factory/test_remote.py (42), factories/file_factory/test_validation.py (17), and the uuidv7 migration test (11). fields/test_workflow_draft_variable_fields.py cannot be collected in this local Windows sandbox (the conftest chain hangs on import, same as tests/unit_tests/events/ and tasks/), so that file relies on CI.

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

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-03 02:31:32.446905941 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-03 02:31:20.298744490 +0000
@@ -5658,18 +5658,6 @@
    --> tests/unit_tests/extensions/test_ext_celery.py:103:18
 ERROR Argument `Literal['browser']` is not assignable to parameter `type` with type `EndUserType | SQLCoreOperations[EndUserType]` in function `models.model.EndUser.__init__` [bad-argument-type]
   --> tests/unit_tests/extensions/test_ext_login.py:53:14
-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/factories/file_factory/test_builders.py:85:58
-ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
-   --> tests/unit_tests/factories/file_factory/test_builders.py:164:12
-ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
-   --> tests/unit_tests/factories/file_factory/test_builders.py:196:12
-ERROR Object of class `Dataset` has no attribute `embedding_available` [missing-attribute]
-   --> tests/unit_tests/fields/test_dataset_fields.py:228:5
-ERROR Argument `str` is not assignable to parameter `indexing_status` with type `IndexingStatus | SQLCoreOperations[IndexingStatus]` in function `models.dataset.Document.__init__` [bad-argument-type]
-   --> tests/unit_tests/fields/test_dataset_fields.py:299:25
-ERROR Cannot set item in `OrderedDict[str, bool | list[str] | str]` [unsupported-operation]
-   --> tests/unit_tests/fields/test_workflow_draft_variable_fields.py:142:47
 ERROR Object of class `Subscription` has no attribute `_start_if_needed` [missing-attribute]
    --> tests/unit_tests/libs/broadcast_channel/redis/test_pubsub_channel.py:152:13
 ERROR Object of class `Subscription` has no attribute `_start_if_needed` [missing-attribute]

@autofix-ci
autofix-ci Bot requested a review from a team October 27, 2026 10:05
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 82.88% 83.02% +0.14%
Strict coverage 82.54% 82.68% +0.14%
Typed symbols 85,474 85,617 +143
Untyped symbols 17,725 17,582 -143
Modules 4373 4373 0

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.77%. Comparing base (f185265) to head (04ed5cf).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #44881    +/-   ##
========================================
  Coverage   89.77%   89.77%            
========================================
  Files        6238     6238            
  Lines      390615   390848   +233     
  Branches    79229    79264    +35     
========================================
+ Hits       350671   350883   +212     
- Misses      33851    33865    +14     
- Partials     6093     6100     +7     
Flag Coverage Δ
api 89.64% <ø> (+<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.

@asukaminato0721 asukaminato0721 self-assigned this Oct 28, 2026

@asukaminato0721 asukaminato0721 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.

rebase

Drop the six exclude entries so strict pyrefly checks these modules.
auto-merge was automatically disabled October 30, 2026 03:30

Head branch was pushed to by a user without write access

@shi-felix
shi-felix force-pushed the refactor/pyrefly-strict-test-batch-11 branch from 3a9a83d to a37e0ee Compare October 30, 2026 03:30
@shi-felix

Copy link
Copy Markdown
Contributor Author

Rebased onto main. The uuidv7 migration test was deleted on main, so this PR no longer touches it; pyrefly.toml only drops the six exclude lines for the files kept here.

shi-felix and others added 2 commits November 2, 2026 17:52
The strict-typing cleanup introduced three `typing.cast` calls that the `check_no_new_cast` guard rejects.

Narrow the dumped payload with `assert isinstance(...)` instead, and drop the duplicated assignment that re-read `retrieval_model_dict` in the same test.
@@ -82,7 +94,11 @@ class FileRecords:
@pytest.fixture(autouse=True)
def file_records(monkeypatch: pytest.MonkeyPatch, sqlite_engine: Engine) -> Iterator[FileRecords]:

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.

use sqlite session

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.

2 participants