[Audit] Refactor campaign validation, persistence, and sending complexity hotspots #58

Closed
opened 2026-07-13 20:11:11 +02:00 by zemion · 3 comments
Owner

Xenon flags several campaign backend blocks above the configured complexity threshold.

Source report: /mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260713-1949/xenon.txt

Hotspots include:

  • campaign/validation.py:279 validate_campaign_config rank F
  • persistence/versions.py:757 validate_campaign_partial rank F
  • dev/mock_campaign.py:119 run_mock_campaign_send rank F
  • router.py:1050 _campaign_workspace_delta_response rank E
  • messages/builder.py:434 build_entry_message rank E
  • reports/campaigns.py:352 generate_campaign_report rank E

Acceptance criteria:

  • Split large validation/message/report flows into named, testable helpers.
  • Preserve current campaign behavior and report output.
  • Avoid broad unrelated refactors in the same changeset.
<!-- codex-security-audit-fingerprint:security-audit-20260713-campaign-complexity --> Xenon flags several campaign backend blocks above the configured complexity threshold. Source report: `/mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260713-1949/xenon.txt` Hotspots include: - `campaign/validation.py:279 validate_campaign_config` rank F - `persistence/versions.py:757 validate_campaign_partial` rank F - `dev/mock_campaign.py:119 run_mock_campaign_send` rank F - `router.py:1050 _campaign_workspace_delta_response` rank E - `messages/builder.py:434 build_entry_message` rank E - `reports/campaigns.py:352 generate_campaign_report` rank E Acceptance criteria: - Split large validation/message/report flows into named, testable helpers. - Preserve current campaign behavior and report output. - Avoid broad unrelated refactors in the same changeset.
Author
Owner

Codex State: progress

Summary

  • Refactored the UI-facing partial campaign validation hotspot as a first complexity slice.

Changed Files

  • validate_campaign_partial now delegates to a small collector and section helpers for basics, sender, recipients, template, attachments, and delivery; added focused tests for count aggregation and section filtering.

Verification

  • py_compile for versions.py and tests/test_partial_validation.py; git diff --check for touched files; PYTHONPATH with campaign/files/mail/core python -m unittest tests.test_partial_validation (2 tests OK); campaign unittest discovery (4 tests OK).

Next / Blocked

  • Remaining hotspots in this issue still include validate_campaign_config, build_entry_message, run_mock_campaign_send, workspace delta response, and report generation.

Suggested status label: status/in-progress

## Codex State: progress ### Summary - Refactored the UI-facing partial campaign validation hotspot as a first complexity slice. ### Changed Files - `validate_campaign_partial now delegates to a small collector and section helpers for basics, sender, recipients, template, attachments, and delivery; added focused tests for count aggregation and section filtering.` ### Verification - `py_compile for versions.py and tests/test_partial_validation.py; git diff --check for touched files; PYTHONPATH with campaign/files/mail/core python -m unittest tests.test_partial_validation (2 tests OK); campaign unittest discovery (4 tests OK).` ### Next / Blocked - Remaining hotspots in this issue still include validate_campaign_config, build_entry_message, run_mock_campaign_send, workspace delta response, and report generation. Suggested status label: `status/in-progress`
Author
Owner

Codex State: progress

Summary

  • Refactored the campaign message builder so build_entry_message is now a small orchestration path over extracted context, validation, template rendering, MIME construction, and draft assembly helpers.

Changed Files

  • src/govoplan_campaign/backend/messages/builder.py

Verification

  • python -m py_compile src/govoplan_campaign/backend/messages/builder.py
  • python -m unittest discover tests
  • radon cc: build_entry_message is A (5)
  • xenon --max-absolute C passes for messages/builder.py

Next / Blocked

  • Remaining campaign complexity hotspots from the full audit include validation, mock send, report generation, review-state persistence, and send-job orchestration.

Suggested status label: status/in-progress

## Codex State: progress ### Summary - Refactored the campaign message builder so build_entry_message is now a small orchestration path over extracted context, validation, template rendering, MIME construction, and draft assembly helpers. ### Changed Files - `src/govoplan_campaign/backend/messages/builder.py` ### Verification - `python -m py_compile src/govoplan_campaign/backend/messages/builder.py` - `python -m unittest discover tests` - `radon cc: build_entry_message is A (5)` - `xenon --max-absolute C passes for messages/builder.py` ### Next / Blocked - Remaining campaign complexity hotspots from the full audit include validation, mock send, report generation, review-state persistence, and send-job orchestration. Suggested status label: `status/in-progress`
Author
Owner

Codex State: done

Summary

  • Closed as a duplicate/superseded audit tracker.
  • Fixed items from this issue: partial campaign validation and message building now pass the configured complexity threshold.
  • Remaining referenced hotspots are still open and tracked in govoplan-campaign#54.

Changed Files

  • src/govoplan_campaign/backend/persistence/versions.py
  • src/govoplan_campaign/backend/messages/builder.py
  • tests/test_partial_validation.py

Verification

  • xenon confirms validate_campaign_partial and build_entry_message are below the configured threshold.

Next / Blocked

  • Continue remaining campaign complexity work from govoplan-campaign#54.
## Codex State: done ### Summary - Closed as a duplicate/superseded audit tracker. - Fixed items from this issue: partial campaign validation and message building now pass the configured complexity threshold. - Remaining referenced hotspots are still open and tracked in govoplan-campaign#54. ### Changed Files - `src/govoplan_campaign/backend/persistence/versions.py` - `src/govoplan_campaign/backend/messages/builder.py` - `tests/test_partial_validation.py` ### Verification - `xenon confirms validate_campaign_partial and build_entry_message are below the configured threshold.` ### Next / Blocked - Continue remaining campaign complexity work from govoplan-campaign#54.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: add-ideas/govoplan-campaign#58
No description provided.