Skip to content

refactor: enterprise-grade quality pass (38 backlog items)#2

Merged
KhaledSalhab-Develeap merged 2 commits into
mainfrom
fix/backlog-enterprise-review
Apr 5, 2026
Merged

refactor: enterprise-grade quality pass (38 backlog items)#2
KhaledSalhab-Develeap merged 2 commits into
mainfrom
fix/backlog-enterprise-review

Conversation

@KhaledSalhab-Develeap
Copy link
Copy Markdown
Collaborator

Summary

Resolves 38 of 45 backlog items from the enterprise-grade review (2026-04-02). All 177 tests pass at 92% coverage.

Changes

CRITICAL (all 6)

  • Split 769-line models.py into models/ subpackage with 5 domain files (C1)
  • Extract client helper functions to reduce nesting depth (C2, C3)
  • Fix in-place mutation in _remap_legacy_fields / Monitor.__init__ (C4)
  • Add typed Outage model; list_outages() now returns list[Outage] (C5)
  • Remove shadow datetime import inside Maintenance.is_active() (C6)

HIGH (10 of 11)

  • _utils.py: _parse_list, _unwrap_list, _validate_id helpers (H2, H3, H8)
  • _protocols.py: _ClientProtocol replaces 5 duplicate mixin stubs (H4)
  • _circuit_breaker.py: CircuitBreaker extracted from client.py (M16)
  • __all__ cleaned up; deprecated symbols emit DeprecationWarning (H5)
  • Race-condition docstrings + raise_on_conflict placeholder (H6, H7)
  • Narrow except Exception to (ValueError, httpx.DecodingError) (H9)
  • HyperpingAuthError omits response_body to prevent token leakage (H10)

MEDIUM (14 of 20)

  • DNS cross-field validation on MonitorCreate (M4)
  • period param Literal-typed with ValueError guard (M9)
  • Client-side email validation in add_subscriber (M10)
  • CircuitBreaker.state typed CircuitState; reads acquire lock (M13, M14)
  • Debug logs sanitize sensitive fields (M15)
  • All tests migrated to Endpoint enum (M17); missing tests added (M21, M22, M23)
  • conftest.py fixture yield-based, closes client after each test (M24)

LOW (all 7)

  • LocalizedText.get() accessor; %-style logging; DeprecationWarning for aliases (L1, L2, L3)
  • ci.yml least-privilege permissions + uv audit step (L4, L5)
  • Dependency bounds narrowed: httpx>=0.27,<1.0, pydantic>=2.0,<3.0 (L6)
  • Circuit breaker error message references recovery_timeout correctly (L7)

Deferred

Items requiring a semver bump or separate PR: M1 (async), M2 (pagination), M3 (per-endpoint CB), M11 (URL validation), M12 (datetime coercion), H11 (SHA pinning), M25 (frozen request models). All documented in BACKLOG.md.

Test plan

  • uv run pytest — 177 passed, 92% coverage (threshold 85%)
  • All existing test classes pass unchanged
  • New tests: test_update_incident_*, test_update_monitor_*, test_pause/resume_monitor, test_get_all_reports, test_get_monitor_report, test_get_monitor_report_not_found
  • BACKLOG.md updated with completion status for all items

CRITICAL (all 6 resolved):
- C1: Split 769-line models.py into models/ subpackage (5 domain files)
- C2/C3: Extract _compute_sleep_time, _should_retry, _parse_error_body,
         _parse_retry_after helpers from client.py (nesting depth reduced)
- C4: Fix in-place mutation in _remap_legacy_fields and Monitor.__init__
- C5: Typed Outage model with frozen=True; list_outages() returns list[Outage]
- C6: Remove shadow datetime import inside Maintenance.is_active()

HIGH (10 of 11 resolved):
- H1: _request return type corrected to dict | list
- H2/H3: _parse_list / _unwrap_list helpers extracted to _utils.py
- H4: _ClientProtocol in _protocols.py replaces 5 duplicate mixin stubs
- H5: Internal endpoint symbols removed from __all__; deprecated symbols
      (HYPERPING_API_BASE, API_PATHS) emit DeprecationWarning via __getattr__
- H6: Race-condition docstrings + raise_on_conflict placeholder added
- H7: O(n) fetch cost documented in get_monitor_report
- H8: _validate_id() guards all resource ID URL interpolations
- H9: Bare except Exception narrowed to (ValueError, httpx.DecodingError)
- H10: HyperpingAuthError omits response_body to prevent token leakage

MEDIUM (14 of 20 resolved):
- M4: DNS-field cross-validation added to MonitorCreate
- M6: APIErrorResponse removed from __all__ (internal-only)
- M7/M8: ping() and default config comments clarified
- M9: period param Literal-typed with ValueError guard
- M10: add_subscriber validates email format client-side
- M13: CircuitBreaker.state typed CircuitState (not str)
- M14: state/failure_count reads acquire _lock (thread safety)
- M15: Debug logs sanitize sensitive field values
- M16: CircuitBreaker extracted to _circuit_breaker.py
- M17: All tests migrated from API_PATHS/HYPERPING_API_BASE to Endpoint enum
- M18: Legacy aliases removed from _incidents_mixin
- M19: _MONITOR_WRITABLE_FIELDS hoisted to module-level frozenset
- M20: params or None pattern applied
- M21/M22/M23: Missing test coverage added (update_incident, pause/resume
              monitor, report parsing with nested outage details)
- M24: conftest fixture converted to yield-based (closes client after test)

LOW (all 7 resolved):
- L1: LocalizedText.get(lang, default) accessor added
- L2: f-string logging replaced with %-style args throughout
- L3: IncidentStatus/IncidentUpdateCreate emit DeprecationWarning (v0.3.0 removal)
- L4: ci.yml given permissions: contents: read
- L5: uv audit step added to ci.yml and publish.yml
- L6: httpx>=0.27,<1.0 and pydantic>=2.0,<3.0
- L7: Circuit breaker message references recovery_timeout correctly

Deferred (require semver bump or separate PR):
- M1 async client, M2 pagination, M3 per-endpoint CB, M11 URL validation,
  M12 datetime coercion, H11 SHA pinning, M25 frozen request models
- Fix all 14 ruff lint errors (unused imports, N811/N813 naming, E501
  line length, import sorting, dead TYPE_CHECKING block)
- Fix all 6 mypy errors (stale type: ignore comments, bare dict type)
- Replace 13 bare assert isinstance() calls with expect_dict() helper
  that survives python -O and gives clear error messages
- Change _ClientProtocol from Protocol to regular base class to avoid
  metaclass/MRO concerns with non-Protocol mixin inheritance
- Remove unused _URL_SCHEME_RE and re import from _monitor_models.py
- Fix em dash in circuit breaker error message (violates project rules)
- Fix CI audit step: use continue-on-error instead of || true so
  vulnerability findings are visible in the build summary
- Remove redundant inner import in test_update_incident_not_found
@KhaledSalhab-Develeap KhaledSalhab-Develeap merged commit c97f741 into main Apr 5, 2026
3 checks passed
@KhaledSalhab-Develeap KhaledSalhab-Develeap deleted the fix/backlog-enterprise-review branch April 9, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant