Problem Statement
The current test infrastructure faces several challenges with async test coordination, error handling, and resource management in Holochain tryorama tests:
Current Pain Points
- Complex Async Coordination: Manual Promise chaining and callback patterns in multi-agent scenarios lead to difficult-to-debug test failures
- Resource Management: Manual conductor/player lifecycle management with inconsistent cleanup patterns
- Error Handling: Insufficient error context when DHT sync operations fail or timeout
- Test Flakiness: Inconsistent DHT synchronization timing causing intermittent failures
- Limited Observability: Debugging failing tests requires manual console logging and verbose mode
- Code Duplication: Repeated setup/teardown patterns across test files without proper abstraction
Technical Analysis
Current test architecture uses:
- Vitest 3.1.3 + @holochain/tryorama 0.18.2 for Holochain testing
- 4-layer testing strategy: Foundation → Integration → Scenarios → Performance
- Complex multi-agent test coordination with manual resource cleanup
- Async/Promise-based patterns with callback hell in scenario setup
Example of current complexity:
test("Complete user onboarding workflow", async () => {
await runScenarioWithTwoAgents(
async (_scenario: Scenario, alice: PlayerApp, bob: PlayerApp) => {
// Manual Promise chaining
const alicePersonResult = await createPerson(alice.cells[0], samplePerson({...}));
await storePrivateData(alice.cells[0], samplePrivateData({...}));
// ... complex nested async operations with limited error handling
}
);
});
Effect-TS Benefits
Effect-TS provides powerful patterns that directly address our testing challenges:
🛡️ Typed Error Handling
Effect.tryPromise for converting Promise-based tryorama calls with typed error channels
- Structured error types replace generic Promise rejections
- Fail-fast behavior with detailed error context
🧹 Automatic Resource Cleanup
Scope for guaranteed cleanup of conductors, players, and connections
- Automatic resource disposal even when tests fail
- Eliminates manual
scenario.cleanUp() calls
⚡ Fiber-Based Concurrency
- Built-in concurrency primitives for multi-agent operations
- Structured concurrency prevents resource leaks and orphaned operations
- Timeout handling built into the Effect runtime
📊 Built-in Observability
- Automatic tracing and metrics collection
- Structured logging with correlation IDs
- Performance metrics collection without manual instrumentation
🧱 Composable Test Building Blocks
- Pure functions for test data generation
- Reusable service patterns for common operations
- Pipeline composition for complex test scenarios
Implementation Areas
1. Agent Management Service
interface AgentManagementService {
createTestConductor: (config: ConductorConfig) => Effect.Effect<Conductor, AgentError, Scope>
setupMultiAgentScenario: (agentCount: number) => Effect.Effect<PlayerApp[], AgentError, Scope>
syncDHT: (agents: PlayerApp[]) => Effect.Effect<void, SyncError>
}
2. DHT Sync Operations
interface DHTSyncService {
waitForSync: (agents: PlayerApp[], timeout?: Duration) => Effect.Effect<void, SyncTimeout>
retryableSync: (operation: Effect.Effect<T, E>) => Effect.Effect<T, E>
batchOperations: <T>(operations: Effect.Effect<T, E>[]) => Effect.Effect<T[], E>
}
3. Test Data Factories
interface TestDataService {
generatePerson: (overrides?: Partial<Person>) => Effect.Effect<Person, never>
generatePrivateData: (personId: string) => Effect.Effect<PrivateData, never>
generateCommitment: (config: CommitmentConfig) => Effect.Effect<Commitment, never>
}
4. Performance Testing
interface MetricsService {
measureOperation: <T, E>(operation: Effect.Effect<T, E>) => Effect.Effect<T & Metrics, E>
collectSystemMetrics: () => Effect.Effect<SystemMetrics, MetricsError>
generatePerformanceReport: (results: TestResults[]) => Effect.Effect<Report, ReportError>
}
5. Scenario Orchestration
interface ScenarioService {
composeWorkflow: <T>(steps: Effect.Effect<T, E>[]) => Effect.Effect<T[], E>
conditionalSteps: <T>(condition: boolean, step: Effect.Effect<T, E>) => Effect.Effect<Option<T>, E>
parallelScenarios: <T>(scenarios: Effect.Effect<T, E>[]) => Effect.Effect<T[], E>
}
Migration Strategy
Phase 1: Foundation (1 week)
Phase 2: Core Services (2 weeks)
Phase 3: Advanced Features (2 weeks)
Phase 4: Migration & Documentation (1 week)
Acceptance Criteria
✅ Dependencies & Setup
✅ Core Infrastructure
✅ Migration Evidence
✅ Documentation & Adoption
Technical Considerations
Integration Requirements
- Vitest Compatibility: Effect-TS tests must work seamlessly with existing Vitest runner
- Tryorama Integration: Effect services must wrap tryorama APIs without breaking functionality
- TypeScript Configuration: Ensure proper type inference and error reporting
Performance Impact
- Bundle Size: Effect-TS adds ~150KB to test bundle (acceptable for test environment)
- Runtime Overhead: Effect runtime adds <5ms per test (minimal impact)
- Memory Usage: Monitor memory usage with Scope-based resource management
Team Adoption
- Learning Curve: Effect-TS patterns require 1-2 week adoption period
- Documentation: Comprehensive examples and patterns documentation needed
- Pair Programming: Knowledge transfer through collaborative implementation
Backward Compatibility
- Gradual Migration: Existing tests continue working during transition
- Utility Compatibility: Current helper functions remain available
- Configuration: No breaking changes to test runner configuration
Related Issues
This enhancement supports several other initiatives:
- PPR System Testing: Complex multi-agent scenarios benefit from Effect composition
- Performance Testing: Built-in metrics collection for load testing
- CI/CD Reliability: Reduced test flakiness improves deployment confidence
Dependencies
- Requires Effect-TS packages:
effect, @effect/platform, @effect/schema
- Compatible with current Vitest 3.1.3 and @holochain/tryorama 0.18.2
- No breaking changes to existing test infrastructure during migration
Priority: P2-high (testing infrastructure improvement)
Estimated Effort: 6 weeks (phased implementation)
Impact: Improved test reliability, better error handling, enhanced developer experience
Problem Statement
The current test infrastructure faces several challenges with async test coordination, error handling, and resource management in Holochain tryorama tests:
Current Pain Points
Technical Analysis
Current test architecture uses:
Example of current complexity:
Effect-TS Benefits
Effect-TS provides powerful patterns that directly address our testing challenges:
🛡️ Typed Error Handling
Effect.tryPromisefor converting Promise-based tryorama calls with typed error channels🧹 Automatic Resource Cleanup
Scopefor guaranteed cleanup of conductors, players, and connectionsscenario.cleanUp()calls⚡ Fiber-Based Concurrency
📊 Built-in Observability
🧱 Composable Test Building Blocks
Implementation Areas
1. Agent Management Service
2. DHT Sync Operations
3. Test Data Factories
4. Performance Testing
5. Scenario Orchestration
Migration Strategy
Phase 1: Foundation (1 week)
package.jsonrunScenarioWithTwoAgentsutility in EffectPhase 2: Core Services (2 weeks)
Phase 3: Advanced Features (2 weeks)
Phase 4: Migration & Documentation (1 week)
Acceptance Criteria
✅ Dependencies & Setup
effectand related packages added totests/package.json✅ Core Infrastructure
✅ Migration Evidence
✅ Documentation & Adoption
Technical Considerations
Integration Requirements
Performance Impact
Team Adoption
Backward Compatibility
Related Issues
This enhancement supports several other initiatives:
Dependencies
effect,@effect/platform,@effect/schemaPriority: P2-high (testing infrastructure improvement)
Estimated Effort: 6 weeks (phased implementation)
Impact: Improved test reliability, better error handling, enhanced developer experience