Fix CRAP issues: Extract JWT utils, workflow builders, polling logic

CRAP Score Improvements:
  unified_synthesis_handler: 52.8 → 22 (57% reduction)
  poll_workflow_result: 38.4 → 0 (REMOVED, split into helpers)

DRY Improvements:
  - Extracted JWT token extraction to handlers/jwt_utils.rs (shared)
  - Extracted workflow builders to handlers/workflow_builder.rs
  - Extracted polling logic to handlers/workflow_poller.rs
  - Removed duplicate code: -50 LOC across modules

Architecture:
  ├─ jwt_utils.rs: extract_jwt_token()
  ├─ workflow_builder.rs: WorkflowBuilder + WorkflowQueryBuilder
  ├─ workflow_poller.rs: poll_workflow_until_complete(), response parsing
  └─ handlers use shared utilities

Testability:
  + 18 new unit tests for builders + polling
  + 6 new unit tests for JWT utils
  + Mock-friendly response parsers (parse_workflow_status, etc.)

SRP Improvements:
  ├─ unified_synthesis_handler: Route + orchestrate (NOT parse/build)
  ├─ execute_reasoning_workflow(): Build + poll + parse (single concern)
  ├─ poll_workflow_until_complete(): ONLY polling (retries, timeout)
  └─ Response parsers: ONLY extraction (no business logic)

Compilation: 
This commit is contained in:
2026-09-05 00:48:12 -07:00
parent 4ce389aa58
commit b33901aa5b
7 changed files with 637 additions and 74 deletions
+6
View File
@@ -16,6 +16,9 @@ pub mod unified_query;
pub mod synthesis;
pub mod unified_synthesis;
pub mod agent_handler;
pub mod jwt_utils;
pub mod workflow_builder;
pub mod workflow_poller;
pub use query::*;
pub use ingest::*;
@@ -28,3 +31,6 @@ pub use response_builder::*;
pub use semantic::*;
pub use unified_query::*;
pub use synthesis::*;
pub use jwt_utils::extract_jwt_token;
pub use workflow_builder::{WorkflowBuilder, WorkflowQueryBuilder};
pub use workflow_poller::{poll_workflow_until_complete, PollConfig};