Skip to content

MPT-21922 finalize helpdesk queues/cases on E2E teardown (+ _process_value refactor)#340

Closed
jentyk wants to merge 1 commit into
mainfrom
refactor/reduce-process-value-complexity
Closed

MPT-21922 finalize helpdesk queues/cases on E2E teardown (+ _process_value refactor)#340
jentyk wants to merge 1 commit into
mainfrom
refactor/reduce-process-value-complexity

Conversation

@jentyk

@jentyk jentyk commented Jun 11, 2026

Copy link
Copy Markdown
Member

This branch carries two changes under MPT-21922.


1. MPT-21922 — E2E helpdesk teardown cleanup (the ticket)

Bug: "[E2E] Queue and Case Status update upon test completions — when test completed, update queue status to disabled and case status to completed." (reported by John McDonnell)

E2E helpdesk fixtures left resources in non-terminal states after a test:

  • created_case / async_created_case had no teardown at all, and CasesService has no delete — so every run left cases lingering open.
  • created_queue tore down via delete, but case_data attaches a case to that queue; deleting a queue with an active case fails (the "TEARDOWN - Unable to delete" path), leaving the queue active too.

Fix (tests/e2e/helper.py, tests/e2e/helpdesk/conftest.py):

  • Add create_fixture_resource_and_finalize + async_create_fixture_resource_and_finalize, mirroring the existing delete-teardown context managers but invoking a terminal-state transition best-effort (errors logged, never raised — same convention as the delete helpers).
  • Wire helpdesk fixtures: queues are disabled and cases are completed on teardown. Fixture ordering means the case is completed before its queue is disabled. Forms and parameters keep their existing delete teardown.

Note: these are E2E tests against the live MPT API, so they require credentials to execute and were not run as part of this change. Verified via make check and pytest --collect-only (32 tests collect cleanly). Teardown is best-effort, so a case that can't reach Completed from its current state logs and moves on rather than failing the test.


2. _process_value cognitive-complexity refactor

Refactors BaseModel._process_value in mpt_api_client/models/model.py to reduce its Cognitive Complexity from 18 to ~4 (allowed: 15), flagged by SonarQube.

The dict- and list-conversion branches are extracted into two flat module-level helpers (_build_model_from_dict, _resolve_list_model_class), removing the nesting that drove the score. Behaviour is unchanged; the redundant trailing isinstance(value, BaseModel) check folds into the final return. Helpers are kept module-level (matching to_snake_case/to_camel_case) to avoid tripping WPS214's method-count limit.


Verification

make check passes clean for both changes (ruff format, ruff check, flake8/WPS, mypy, uv lock --check); 118 model unit tests pass; helpdesk E2E suite collects cleanly.

Extract the dict- and list-conversion branches of
BaseModel._process_value into module-level helpers
(_build_model_from_dict and _resolve_list_model_class). This flattens
the nested conditionals that drove cognitive complexity to 18, bringing
the method under the allowed 15. Behaviour is unchanged; the redundant
trailing isinstance(value, BaseModel) check folds into the final return.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@jentyk jentyk closed this Jun 11, 2026
@jentyk jentyk deleted the refactor/reduce-process-value-complexity branch June 11, 2026 09:24
@jentyk jentyk changed the title refactor: reduce _process_value cognitive complexity below threshold feat(MPT-21922): reduce _process_value cognitive complexity below threshold Jun 11, 2026
@jentyk jentyk marked this pull request as ready for review June 11, 2026 09:26
@jentyk jentyk requested a review from a team as a code owner June 11, 2026 09:26
@jentyk jentyk requested review from d3rky and robcsegal June 11, 2026 09:26
@jentyk jentyk changed the title feat(MPT-21922): reduce _process_value cognitive complexity below threshold MPT-21922 finalize helpdesk queues/cases on E2E teardown (+ _process_value refactor) Jun 11, 2026
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