Skip to content

refactor: Split system_service.py — export_manifest CC=39, validate_manifest CC=35 #114

Description

@vybe

Problem

src/backend/services/system_service.py (713 lines) contains the two highest-complexity functions in the codebase:

Function CC Lines
export_manifest 39 ~190
validate_manifest 35 ~165
configure_permissions 23 ~100

These functions have deeply nested conditionals for manifest field handling.

Proposed Solution

  1. Extract validation rules into a ManifestValidator class with focused methods:

    • validate_agents(), validate_credentials(), validate_permissions()
    • Each validates one section of the manifest
  2. Extract export logic into composable exporters:

    • export_agent() — single agent to manifest dict
    • export_permissions() — permission matrix
    • export_credentials() — credential mapping
  3. Extract configure_permissions into services/permission_service.py

Requires Tests First

These functions have no dedicated unit tests. Add tests before refactoring:

  • Manifest with all fields populated
  • Manifest with minimal fields
  • Invalid manifest structures
  • Permission configuration edge cases

Acceptance Criteria

  • export_manifest CC < 15
  • validate_manifest CC < 15
  • configure_permissions CC < 15
  • Unit tests for all extracted functions
  • system_service.py < 400 lines

Source

Refactor audit 2026-03-13

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions