[PR #343] [MERGED] Align integration provider contract and add wrapper/registry contract coverage #313

Closed
opened 2026-03-02 23:35:05 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/343
Author: @AJaySi
Created: 2/11/2026
Status: Merged
Merged: 2/11/2026
Merged by: @AJaySi

Base: mainHead: codex/align-protocols-and-implement-unified-contract-style


📝 Commits (1)

  • badfe79 Align integration provider contract and add contract tests

📊 Changes

6 files changed (+532 additions, -49 deletions)

View changed files

📝 backend/services/integrations/base.py (+12 -22)
📝 backend/services/integrations/enhanced_integration_provider.py (+76 -18)
📝 backend/services/integrations/registry.py (+204 -9)
backend/tests/integrations/test_enhanced_provider_contract.py (+103 -0)
backend/tests/integrations/test_registry_smoke.py (+119 -0)
backend/tests/integrations/test_registry_typing.py (+18 -0)

📄 Description

Motivation

  • Unify the integration provider contract style so the protocol, registry adapters and enhanced wrapper use a single (synchronous) API surface to avoid mixed sync/async behavior and runtime surprises.
  • Ensure all integration dataclass payloads always include required fields such as provider_id, user_id, and state so downstream code can rely on stable shapes.
  • Make each provider implementation satisfy the full provider contract (or else expose capability-specific fallbacks) to simplify the registry/wrapper logic and improve type-safety.

Description

  • Tightened backend/services/integrations/base.py by switching mutable defaults to field(default_factory=...) and clarifying the synchronous IntegrationProvider protocol signature (all required constructor fields remain explicit).
  • Reworked backend/services/integrations/enhanced_integration_provider.py to provide a synchronous wrapper implementing the full contract (get_auth_url, handle_callback, get_connection_status, refresh_token, disconnect, list_connected_accounts), added resilient fallback return objects that always include required dataclass fields, and replaced async sleeps with synchronous backoff.
  • Expanded backend/services/integrations/registry.py provider adapters (gsc, bing, wordpress, wix) so each class implements the full protocol surface and consistently constructs AuthUrlPayload / ConnectionResult / ConnectionStatus / RefreshResult / Account with required fields provided.
  • Added a small contract test suite under backend/tests/integrations/ including runtime smoke tests for get_provider('gsc'|'bing'|'wordpress'|'wix'), enhanced wrapper success/failure contract tests, and a static typing assertion file for the get_provider(...) return contract.

Testing

  • Ran the contract unittests with PYTHONPATH=backend python -m unittest backend.tests.integrations.test_registry_smoke backend.tests.integrations.test_enhanced_provider_contract, which completed successfully (all tests passed).
  • Executed static typing checks with PYTHONPATH=backend python -m mypy --ignore-missing-imports backend/tests/integrations/test_registry_typing.py, which reported no issues in the checked file under the given mypy flags.
  • Verified syntax/compile sanity with python -m py_compile across the modified modules and test files, which succeeded.
  • Added lightweight stubbing in the smoke tests to avoid importing heavy external modules so the runtime smoke tests exercise the registry + enhanced wrapper paths deterministically.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/343 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 2/11/2026 **Status:** ✅ Merged **Merged:** 2/11/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/align-protocols-and-implement-unified-contract-style` --- ### 📝 Commits (1) - [`badfe79`](https://github.com/AJaySi/ALwrity/commit/badfe7958c6ffb97a229a390bdcdd470ec10db25) Align integration provider contract and add contract tests ### 📊 Changes **6 files changed** (+532 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `backend/services/integrations/base.py` (+12 -22) 📝 `backend/services/integrations/enhanced_integration_provider.py` (+76 -18) 📝 `backend/services/integrations/registry.py` (+204 -9) ➕ `backend/tests/integrations/test_enhanced_provider_contract.py` (+103 -0) ➕ `backend/tests/integrations/test_registry_smoke.py` (+119 -0) ➕ `backend/tests/integrations/test_registry_typing.py` (+18 -0) </details> ### 📄 Description ### Motivation - Unify the integration provider contract style so the protocol, registry adapters and enhanced wrapper use a single (synchronous) API surface to avoid mixed sync/async behavior and runtime surprises. - Ensure all integration dataclass payloads always include required fields such as `provider_id`, `user_id`, and `state` so downstream code can rely on stable shapes. - Make each provider implementation satisfy the full provider contract (or else expose capability-specific fallbacks) to simplify the registry/wrapper logic and improve type-safety. ### Description - Tightened `backend/services/integrations/base.py` by switching mutable defaults to `field(default_factory=...)` and clarifying the synchronous `IntegrationProvider` protocol signature (all required constructor fields remain explicit). - Reworked `backend/services/integrations/enhanced_integration_provider.py` to provide a synchronous wrapper implementing the full contract (`get_auth_url`, `handle_callback`, `get_connection_status`, `refresh_token`, `disconnect`, `list_connected_accounts`), added resilient fallback return objects that always include required dataclass fields, and replaced async sleeps with synchronous backoff. - Expanded `backend/services/integrations/registry.py` provider adapters (`gsc`, `bing`, `wordpress`, `wix`) so each class implements the full protocol surface and consistently constructs `AuthUrlPayload` / `ConnectionResult` / `ConnectionStatus` / `RefreshResult` / `Account` with required fields provided. - Added a small contract test suite under `backend/tests/integrations/` including runtime smoke tests for `get_provider('gsc'|'bing'|'wordpress'|'wix')`, enhanced wrapper success/failure contract tests, and a static typing assertion file for the `get_provider(...)` return contract. ### Testing - Ran the contract unittests with `PYTHONPATH=backend python -m unittest backend.tests.integrations.test_registry_smoke backend.tests.integrations.test_enhanced_provider_contract`, which completed successfully (all tests passed). - Executed static typing checks with `PYTHONPATH=backend python -m mypy --ignore-missing-imports backend/tests/integrations/test_registry_typing.py`, which reported no issues in the checked file under the given mypy flags. - Verified syntax/compile sanity with `python -m py_compile` across the modified modules and test files, which succeeded. - Added lightweight stubbing in the smoke tests to avoid importing heavy external modules so the runtime smoke tests exercise the registry + enhanced wrapper paths deterministically. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698c307dad948328a836f460784307b5) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:35:05 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#313
No description provided.