Skip to content

feat: TDD-enabled TypeScript migration for workflow scripts#9

Closed
iamladi wants to merge 6 commits intomainfrom
feat/workflows-tdd-migration
Closed

feat: TDD-enabled TypeScript migration for workflow scripts#9
iamladi wants to merge 6 commits intomainfrom
feat/workflows-tdd-migration

Conversation

@iamladi
Copy link
Owner

@iamladi iamladi commented Jan 25, 2026

Summary

Migrates shell scripts (ci-ralph.sh, workflow-ralph.sh, comments-ralph.sh) to a testable TypeScript architecture with TDD enabled by default, following the recommendations from deep research.

Architecture

  • Functional Core, Imperative Shell pattern for maximum testability
  • Hexagonal Architecture with ports (interfaces) and adapters (implementations)
  • XState for explicit workflow phase orchestration
  • Pure functions for core logic - testable with zero mocks

Key Components

Component Description
src/core/ Pure functions for state management, error detection, phase transitions
src/ports/ Interfaces (IGitHubClient, IClaudeClient, IProcessRunner)
src/adapters/ Real CLI adapters + mock adapters for testing
src/workflows/ XState state machine for phase orchestration
src/services/ Retry logic with exponential backoff, CI polling

Test Coverage

  • 161 tests passing (4 skipped for CLI availability)
  • 95%+ coverage on core modules
  • Zero vi.mock usage - pure functional testing
  • Integration tests for real CLI adapters

Research-Driven Decisions

Based on research/research-workflows-tdd-migration-deep.md:

  • XState over Temporal for phase orchestration (lighter weight, explicit transitions)
  • Effect-style patterns for retry/polling (deterministic time testing ready)
  • Hash-based stuck detection ported from shell scripts
  • Dependency injection for adapter swapping

Test Plan

  • Run bun run test - all 161 tests pass
  • Run bun run test:coverage - 95%+ on core modules
  • TypeScript compiles with zero errors (bun run tsc --noEmit)
  • Manual testing with real GitHub repo and Claude CLI

Related Issues

Closes #4, #5, #6, #7, #8

Migration Notes

This is the foundation for migrating the bash scripts. The actual script replacement will be a follow-up PR that uses these TypeScript modules.

Plan 1 implementation - establishes TDD foundation:
- Add Vitest testing framework with coverage support
- Add TypeScript with strict settings
- Create Hexagonal Architecture port interfaces:
  - IGitHubClient for GitHub CLI interactions
  - IClaudeClient for Claude CLI interactions
  - IProcessRunner for process spawning
- Add initial port interface tests

Closes #4
Plan 2 implementation - mock adapters and functional core:
- Add mock adapters (MockGitHubClient, MockClaudeClient, MockProcessRunner)
- Implement workflow state management with pure functions
- State transitions: setup → planning → implementing → verifying → completed/failed
- All transitions return Result types for error handling
- Query functions: getCurrentPlan, getProgress, isTerminalState, canRetry

26 tests passing, zero vi.mock usage - pure functional testing!

Closes #5
Plan 3 implementation - completing core logic:
- Add error-detector.ts with hash-based stuck detection
- Port detect_stuck from ci-ralph.sh to pure TypeScript
- Add category-aware stuck detection for smarter detection
- Add phase-manager.ts with state machine transitions
- Configure 80% coverage threshold for core/ directory
- 95%+ coverage achieved on all core modules

94 tests passing, zero vi.mock usage!

Closes #6
Plan 4 implementation - imperative shell layer:
- Add GitHubCLIAdapter implementing IGitHubClient
  - CI status, runs, comments, PR operations
  - Polling with configurable intervals and timeouts
  - Job logs retrieval
- Add ClaudeCLIAdapter implementing IClaudeClient
  - Prompt execution with streaming support
  - Session continuation and resumption
  - Availability and version checks
- Add integration tests (skip when CLIs unavailable)
- Add execa dependency for process execution

101 tests passing (4 skipped for CLI availability)

Closes #7
Plan 5 implementation - workflow orchestration:
- Add XState state machine for phase orchestration
  - States: idle → setup → planning → implementing → submitting → verifying → completed/failed
  - Fixing state for CI retry logic
  - Guards for plan completion and retry limits
- Add retry service with exponential backoff
  - Configurable delays, max attempts, jitter
  - Deterministic mode for testing
  - retryWhile for polling patterns
- Add CI poller service
  - Poll until completion or timeout
  - Progress callbacks for monitoring
  - Human-readable status messages
- Add public API index.ts exporting all modules

161 tests passing, comprehensive workflow coverage!

Closes #8
@iamladi
Copy link
Owner Author

iamladi commented Jan 25, 2026

Superseded by PR #10 (V2 implementation)

@iamladi iamladi closed this Jan 25, 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.

Plan 1: Foundation Setup - TypeScript + Vitest + Ports

1 participant