dify/api/tests/unit_tests/libs
GareArc 8a62c1d915
chore(api): pyright + ruff cleanup for openapi/cli surface
Type and lint pass over the openapi controllers, auth pipeline, and
oauth bearer/device-flow plumbing. Down from 36 pyright errors and 16
ruff errors to 0/0; 93 openapi unit tests pass.

Logic fixes:
- libs/oauth_bearer.py: drop private-naming on the friend-API methods
  consumed by _VariantResolver (cache_get / cache_set_positive /
  cache_set_negative / hard_expire / session_factory). They were always
  cross-class accessors — leading underscore was misleading. Add public
  registry property on BearerAuthenticator. _hard_expire row_id widened
  to UUID | str (matches the StringUUID column type).
- libs/oauth_bearer.py: type validate_bearer / bearer_feature_required
  with ParamSpec / PEP-695 so wrapped routes preserve their signature.
- libs/rate_limit.py: same — typed rate_limit decorator.
- services/oauth_device_flow.py: mint_oauth_token / _upsert accept
  Session | scoped_session (Flask-SQLAlchemy proxy). Guard row-is-None
  after upsert.
- controllers/openapi/{chat,completion,workflow}_messages.py: tuple-vs-
  Mapping shape narrowing on AppGenerateService.generate return —
  production returns Mapping, tests mock as (body, status). Validate
  through Pydantic Response model in both shapes.
- controllers/openapi/oauth_device.py: replace flask_restx.reqparse (banned)
  with Pydantic Request/Query models — DeviceCodeRequest, DevicePollRequest,
  DeviceLookupQuery, DeviceMutateRequest. Two PEP-695 generic helpers
  (_validate_json / _validate_query) translate ValidationError to BadRequest.
- controllers/openapi/auth/strategies.py: Protocol param-name match
  (subject_type), Optional narrowing on app/tenant/account_id/subject_email.
- controllers/openapi/auth/steps.py: subject_type-is-None guard before
  mounter dispatch.
- core/app/apps/workflow/generate_task_pipeline.py + models/workflow.py:
  add WorkflowAppLogCreatedFrom.OPENAPI + matching match-case branch.
  Fixes match-exhaustiveness and possibly-unbound created_from.
- libs/device_flow_security.py: pyright ignore on flask after_request
  hook (registered by the framework, pyright sees as unused).
- services/oauth_device_flow.py: rename Exceptions to *Error suffix
  (StateNotFoundError / InvalidTransitionError / UserCodeExhaustedError);
  same for libs/oauth_bearer.py (InvalidBearerError / TokenExpiredError).
  Update all callers across openapi controllers.
- controllers/openapi/{oauth_device,oauth_device_sso}.py +
  services/oauth_device_flow.py: switch logger.error in except blocks
  to logger.exception (TRY400) — keeps the traceback for ops.
- configs/feature/__init__.py: OPENAPI_KNOWN_CLIENT_IDS computed_field
  needs an @property alongside for pyright to see it as a value, not a
  method. Matches the existing line-451 pattern.

Plus ruff format + import-sort across the openapi tree (pure formatting).
2026-04-28 21:44:54 -07:00
..
_human_input chore: reorg imports (#35308) 2026-04-16 08:50:02 +00:00
broadcast_channel/redis refactor: replace bare dict with dict[str, Any] in controller and core unit tests (#35181) 2026-04-14 17:51:49 +00:00
test_api_token_cache.py fix: redis for api token (#31861) 2026-02-06 16:25:27 +08:00
test_archive_storage.py feat: archive workflow run logs backend (#31310) 2026-01-23 13:11:56 +08:00
test_cron_compatibility.py refactor(api): move workflow knowledge nodes and trigger nodes (#33445) 2026-03-15 15:24:59 +08:00
test_custom_inputs.py Feat/add status filter to workflow runs (#26850) 2025-10-18 12:15:29 +08:00
test_datetime_utils.py test(api): add autospec to MagicMock-based patch usage (#32752) 2026-03-01 04:30:45 +08:00
test_email_i18n.py feat: collaboration (#30781) 2026-04-16 02:21:04 +00:00
test_email.py chore: apply flake8-pytest-style linter rules (#8307) 2024-09-12 18:09:16 +08:00
test_encryption.py fix: Login secret text transmission (#29659) 2025-12-16 16:55:51 +08:00
test_external_api.py feat(refactoring): Support Structured Logging (JSON) (#30170) 2026-01-04 11:46:46 +08:00
test_file_utils.py Add lib test (#25410) 2025-09-09 17:11:49 +08:00
test_flask_utils.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
test_helper.py feat: Human Input Node (#32060) 2026-02-09 14:57:23 +08:00
test_json_in_md_parser.py Fix json in md when use quesion classifier node (#26992) 2025-10-18 11:58:40 +08:00
test_jwt_imports.py chore: bump supabase and pyjwt versions and added tests (#24681) 2025-08-28 13:45:56 +08:00
test_login.py refactor(api): tighten login and wrapper typing (#34447) 2026-04-02 09:36:58 +00:00
test_oauth_base.py rm type ignore (#25715) 2025-10-21 11:26:58 +08:00
test_oauth_bearer_require_scope.py chore(api): pyright + ruff cleanup for openapi/cli surface 2026-04-28 21:44:54 -07:00
test_oauth_clients.py perf: use global httpx client instead of per request create new one (#34311) 2026-04-01 01:19:32 +00:00
test_orjson.py Add lib test (#25410) 2025-09-09 17:11:49 +08:00
test_pandas.py chore(api/tests): apply ruff reformat #7590 (#7591) 2024-08-23 23:52:25 +08:00
test_passport.py test: add comprehensive unit tests for PassportService with exception handling optimization (#22268) 2025-07-12 19:56:20 +08:00
test_password.py test: add unit tests for password validation and hashing (#22003) 2025-07-08 10:00:00 +08:00
test_pyrefly_diagnostics.py fix(ci): make pyrefly diff comments focus on diagnostics (#32778) 2026-03-02 10:11:23 +08:00
test_pyrefly_type_coverage.py refactor: replace bare dict with dict[str, Any] in models, providers, extensions, libs, and test utilities (#35186) 2026-04-14 17:51:25 +00:00
test_rate_limiter.py feat: Human Input Node (#32060) 2026-02-09 14:57:23 +08:00
test_rsa.py chore(deps): bump google-auth from 2.49.0 to 2.49.1 in /api in the google group (#33483) 2026-03-16 13:55:34 +09:00
test_schedule_utils_enhanced.py refactor(api): continue decoupling dify_graph from API concerns (#33580) 2026-03-25 20:32:24 +08:00
test_sendgrid_client.py refactor: replace bare dict with dict[str, Any] in models, providers, extensions, libs, and test utilities (#35186) 2026-04-14 17:51:25 +00:00
test_smtp_client.py refactor: replace bare dict with dict[str, Any] in models, providers, extensions, libs, and test utilities (#35186) 2026-04-14 17:51:25 +00:00
test_time_parser.py Feat/add status filter to workflow runs (#26850) 2025-10-18 12:15:29 +08:00
test_token.py Enabled cross-subdomain console sessions by making the cookie domain configurable and aligning the frontend so it reads the shared CSRF cookie. (#27190) 2025-10-28 10:04:24 +08:00
test_uuid_utils.py Typing test (#24651) 2025-08-28 09:36:39 +08:00
test_workspace_permission.py feat: implement workspace permission checks for member invitations an… (#31202) 2026-01-18 19:35:50 -08:00
test_yarl.py fix: return absolute path as the icon url if CONSOLE_API_URL is empty (#15279) 2025-03-10 13:15:06 +08:00