Skip to content

refactor: Extract completion-detector logic into testable modules #53

@EivMeyer

Description

@EivMeyer

Problem

Two duplicate implementations of completion detection:

  1. Inline in orchestrator.js (lines 2158-2195) - completion-detector agent created dynamically
  2. File src/agents/git-pusher-agent.json - Same logic as 500-char minified JS string

Issues

  • DRY violation: Same "all validators approved" logic duplicated
  • No constants: Topic names (VALIDATION_RESULT, IMPLEMENTATION_READY) are magic strings
  • Untestable: Inline JS in JSON, no unit tests for injection logic
  • String-boolean hack: approved === true || approved === 'true' scattered in both
  • Two injection paths: startCluster() (line 736-757) AND _injectCompletionAgent() (line 2128-2200)

Affected Files

File Lines Issue
src/orchestrator.js 736-757, 2128-2200 Two injection paths with duplicated placeholder logic
src/agents/git-pusher-agent.json 10 500-char minified trigger script

Existing Test Coverage (DO NOT BREAK)

Test File What It Tests
tests/config-validator.test.js Completion handler validation
tests/integration/trigger-evaluation.test.js helpers.allResponded(), helpers.hasConsensus()
tests/orchestrator-subscription-race.test.js CLUSTER_COMPLETE not lost on fast completion
tests/integration/orchestrator-flow.test.js Full message flow to cluster termination

Acceptance Criteria

  • Single source of truth for "all validators approved" logic
  • Constants module for topic names (TOPICS.VALIDATION_RESULT)
  • Factory function to create completion agents
  • Regression tests BEFORE refactoring
  • Unit tests for extracted modules
  • All existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions