Refactor: Eliminate duplicate code in prompt-step generators#1854
Merged
Refactor: Eliminate duplicate code in prompt-step generators#1854
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ate code Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate prompt-step generator methods
Refactor: Eliminate duplicate code in prompt-step generators
Oct 17, 2025
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.
Problem
Five prompt-step generator methods (
generateXPIAPromptStep,generateTempFolderPromptStep,generateEditToolPromptStep,generatePlaywrightPromptStep, andgenerateGitHubContextPromptStep) shared nearly identical control flow and rendering logic, creating approximately 113 lines of duplicate code across the workflow compiler.Each method repeated the same pattern with only minor variations:
appendPromptStepwith identical structureWritePromptTextToYAMLThis duplication increased maintenance burden and the risk of inconsistent behavior when making future changes.
Solution
Extracted a shared helper function
generateStaticPromptStepthat encapsulates the common pattern for generating prompt workflow steps. This function accepts:Additionally added
hasEditToolandhasPlaywrightToolhelper functions to match the existinghasGitHubToolpattern, making tool availability checks consistent across the codebase.Example
Before (22 lines of duplicated structure):
After (5 lines - 77% reduction):
Impact
Testing
All existing tests pass with no regressions. Added comprehensive unit tests covering:
Manual verification confirmed that compiled workflows produce identical output to the original implementation across multiple test scenarios (all tools enabled, minimal tools, safety disabled).
Closes #[issue-number]
Original prompt
Fixes #1850
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.