Skip to content

Conversation

@newhook
Copy link
Owner

@newhook newhook commented Jan 30, 2026

Summary

This PR introduces a comprehensive integration test harness for testing work flows end-to-end using mocked external dependencies. The harness enables testing of the full work lifecycle without running actual CLI tools like git, claude, or zellij.

Key additions:

  • TestHarness struct in internal/testutil/harness.go with pre-wired mocks for all external dependencies
  • Fixture helpers for creating test data (beads, works, tasks)
  • Mock configuration helpers for simulating success/failure scenarios
  • Integration tests covering the complete work lifecycle

Changes

Test Harness (internal/testutil/harness.go)

  • TestHarness struct with in-memory SQLite and all mocks pre-wired
  • Mocks included: Git, Worktree, Beads, BeadsReader, OrchestratorManager, NameGenerator, TaskPlanner, WorkService
  • Sensible default mock behaviors (success, no-op)
  • Cleanup method for proper test teardown

Fixture Helpers

  • CreateBead, CreateEpicWithChildren, SetBeadDependency - bead fixtures
  • CreateWork, CreateWorkWithRootIssue, AddBeadToWork - work fixtures
  • CreateTask, CompleteTask, FailTask - task fixtures
  • MockGitPushFails, MockBranchExists, MockClaudeCompletesSuccessfully, MockClaudeFails - mock configuration

Integration Tests

Test File Coverage
work_integration_test.go Work creation: success, epic expansion, branch collision, git push failure, control plane scheduling, cleanup on failure
run_integration_test.go Task assignment: creates tasks from beads, respects dependencies, planning mode, skip assigned beads, spawns orchestrator, idempotent reruns
execution_integration_test.go Task execution: successful completion, failure, partial bead completion, work status transitions, restart, merged detection
review_integration_test.go Review-fix loop: no issues creates PR, issues create fix tasks, max iterations, manual review, fix task dependencies
destroy_integration_test.go Work destruction: cleanup resources, close root issue, terminate zellij tabs, handle partial failures

Issues Resolved

  • ac-gtlh: Create integration test harness for work flows
  • ac-gtlh.1: Create TestHarness struct with pre-wired mocks
  • ac-gtlh.2: Add fixture helpers for test data creation
  • ac-gtlh.3: Write integration test for work creation flow
  • ac-gtlh.4: Write integration test for task assignment flow
  • ac-gtlh.5: Write integration test for task execution simulation
  • ac-gtlh.6: Write integration test for review-fix loop
  • ac-gtlh.7: Write integration test for destroy work flow

Testing

All new tests pass:

go test ./internal/testutil/... ./internal/work/... -v

Test counts:

  • internal/testutil: 9 tests
  • internal/work: 31 integration tests added

🤖 Generated with Claude Code

newhook and others added 7 commits January 30, 2026 11:30
Create TestHarness in internal/testutil/ with:
- In-memory SQLite database with migrations
- Pre-wired mocks for all WorkService dependencies
- Sensible default mock behaviors

Add fixture helpers:
- CreateBead, CreateEpicWithChildren, SetBeadDependency
- CreateWork, AddBeadToWork
- CreateTask, CompleteTask, FailTask
- Mock behavior configuration (GitPushFails, ClaudeFails, etc.)

Also:
- Add PlannerMock generation to task package
- Add AddBeadToWork helper to db package

Implements: ac-gtlh.1, ac-gtlh.2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests cover work record creation in DB, beads added to work_beads table,
CreateWorktree task scheduling, branch name uniqueness handling, epic
expansion with children, use existing branch option, and worker name
generation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests cover worktree removal, work directory deletion, database record
cleanup, root issue closing, zellij tab termination, graceful handling
of partial failures, and configuration options for tab cleanup.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests verify:
- Tasks created from work beads with correct associations
- Bead dependencies respected via task planner
- Planning mode groups beads by complexity
- Already-assigned beads skipped on re-run
- Orchestrator spawned/resumed correctly
- Idempotent behavior on multiple runs
- Error cases: missing worktree, non-existent work
- Auto mode creates estimate task
- Epic beads handled correctly

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests simulate database state changes without running Claude:
- Task status: pending → processing → completed/failed
- Bead status updates within tasks
- Work status: pending → processing → idle/failed/merged

Test coverage includes:
- Successful task completion with multiple beads
- Task and work failure handling
- Partial bead completion tracking
- Work status state machine transitions
- Work failure and restart flow
- Task and bead status reset
- PR merged transition
- Multi-task sequential execution
- Task beads query for work

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add review_integration_test.go with 5 tests covering:
- NoIssuesCreatesPR: When review finds no issues, PR task is created
- IssuesCreateFixTasks: When review creates issues, fix tasks are created
- MaxIterationsForcesPR: When max iterations reached, PR forced
- ManualReviewSkipsAutomation: auto_workflow=false skips automated workflow
- FixTaskDependencies: Fix tasks depend on review, new review depends on fixes

Also add helper methods to test harness:
- CreateWorkWithRootIssue: Create work with specified root issue ID
- CreateReviewTask: Create review task using atomic counter
- AddReviewIssues: Add review issues to bead store as children
- SimulateReviewCompletion: Complete review and check for issues
- CountReviewIterations: Count completed review tasks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix gosec G104 lint error by logging the error from DB.Close() in the
Cleanup method instead of ignoring it. Since Cleanup is used with defer,
returning the error isn't practical, so we log it via h.T.Logf.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@newhook newhook merged commit 099cf09 into main Jan 30, 2026
3 checks passed
@newhook newhook deleted the feat/create-integration-test-harness-for-work-flows branch January 30, 2026 20:31
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.

2 participants