refactor(server): extract TunnelServiceBase to reduce code duplication#595
Open
bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
Open
refactor(server): extract TunnelServiceBase to reduce code duplication#595bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
bianbiandashen wants to merge 1 commit intoamantus-ai:mainfrom
Conversation
NgrokService and CloudflareService shared ~80% identical code for: - Binary discovery across multiple installation paths - Process lifecycle management (spawn, stdout/stderr handling) - Graceful shutdown (SIGTERM -> SIGKILL fallback) - State tracking (isRunning, currentTunnel) - Error handling and timeout management This refactoring: 1. Creates TunnelServiceBase abstract class with common functionality 2. Refactors NgrokService to extend TunnelServiceBase 3. Refactors CloudflareService to extend TunnelServiceBase Subclasses now only need to implement: - getBinaryPaths(): Where to find the binary - getBinaryVersionArgs(): How to verify binary exists - buildStartArgs(): Command line arguments - parseOutput(): Extract tunnel URL from output - getServiceName(): For logging Code reduction: ~150 lines removed from combined services Benefits: - Single place to fix bugs in tunnel lifecycle - Consistent behavior across tunnel providers - Easier to add new tunnel services (e.g., localtunnel) - Better maintainability
|
Found a regression in testability after the refactor. I checked out this branch and ran:
Result: both tests time out. Reason:
Impact:
Suggested fix:
Once updated, these tests should pass and keep coverage parity with pre-refactor behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract common tunnel service functionality into an abstract base class to eliminate code duplication between NgrokService and CloudflareService.
Problem
NgrokServiceandCloudflareServicecontained ~80% identical code:This duplication meant:
Solution
New Abstract Base Class
Refactored NgrokService
Refactored CloudflareService
Code Metrics
While total lines decreased modestly, the key improvement is single source of truth for tunnel lifecycle logic.
Benefits
Backward Compatibility
NgrokTunneltype aliased toTunnelInfoCloudflareTunneltype aliased toTunnelInfoTest Plan