Extract shared utilities from log parsers to eliminate duplication#3997
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR successfully refactors duplicate code from the Claude and Copilot log parsers by extracting 4 common utility functions into a shared module (log_parser_shared.cjs). The refactoring eliminates approximately 138 lines of duplicate code while maintaining backward compatibility and adding comprehensive test coverage.
Key Changes
- Created a new shared utility module with 4 formatting functions
- Added 19 comprehensive tests covering all edge cases
- Updated both log parsers to use the shared functions via
require() - Properly configured Go embedding for the new module
Reviewed Changes
Copilot reviewed 79 out of 79 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/js/log_parser_shared.cjs |
New shared module with 4 utility functions (formatDuration, formatBashCommand, truncateString, estimateTokens) |
pkg/workflow/js/log_parser_shared.test.cjs |
Comprehensive test suite with 19 tests covering all edge cases |
pkg/workflow/js/parse_claude_log.cjs |
Removed duplicate functions, added import from shared module |
pkg/workflow/js/parse_copilot_log.cjs |
Removed duplicate functions, added import from shared module |
pkg/workflow/js/parse_claude_log.test.cjs |
Added mock for shared module to support testing |
pkg/workflow/js/parse_copilot_log.test.cjs |
Added mock for shared module to support testing |
pkg/workflow/js.go |
Added embedding configuration for the new shared module |
.github/workflows/*.lock.yml |
Regenerated lock files showing proper bundling of shared functions |
The refactoring follows established project patterns, maintains identical functionality, and improves code maintainability by establishing a single source of truth for these formatting utilities. All tests pass and the code is properly formatted and linted.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Both Claude and Copilot log parsers contained identical implementations of formatting utilities (
formatDuration,formatBashCommand,truncateString,estimateTokens), totaling 138 lines of duplicate code across the two files.Changes
log_parser_shared.cjscontaining 4 utility functions with test coverageExample
Before:
After:
Note
formatInitializationSummarywas not extracted - Claude returns{markdown, mcpFailures}while Copilot returnsstringwith premium model info.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.