Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Reduces compiler.go from 1608 to 1560 lines by extracting non-core logic into focused files, improving maintainability and separation of concerns.

Changes

Created 3 new files:

  • detection.go (17 lines) - Extracted detectTextOutputUsage() for detecting ${{ needs.activation.outputs.text }} patterns
  • domain_sanitization.go (29 lines) - Extracted computeAllowedDomainsForSanitization() for engine-specific domain resolution
  • safe_output_config.go (18 lines) - Extracted parseBaseSafeOutputConfig() used by 10 safe output implementations

Modified:

  • compiler.go - Removed extracted methods, preserved all call sites

Example

Before:

// compiler.go (1608 lines)
func (c *Compiler) detectTextOutputUsage(markdownContent string) bool { ... }
func (c *Compiler) computeAllowedDomainsForSanitization(data *WorkflowData) string { ... }
func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig) { ... }

After:

// detection.go (17 lines)
func (c *Compiler) detectTextOutputUsage(markdownContent string) bool { ... }

// domain_sanitization.go (29 lines)
func (c *Compiler) computeAllowedDomainsForSanitization(data *WorkflowData) string { ... }

// safe_output_config.go (18 lines)
func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig) { ... }

All existing tests pass. No functional changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>[task] Extract detection and validation logic from compiler.go</issue_title>
<issue_description>## Objective
Reduce the complexity of compiler.go (1600+ lines) by extracting detection and validation methods into more focused files.

Context

The main compiler.go file contains a mix of core compilation logic, validation logic, parsing logic, and configuration detection. This is Issue #2 from the semantic function clustering analysis (Priority 2: Medium Impact, Medium Effort). Extracting non-core logic will improve maintainability and separation of concerns.

Related to #3478

Approach

  1. Review compiler.go and identify methods suitable for extraction
  2. Extract detectTextOutputUsage to a detection-focused file (e.g., detection.go or text_output_detection.go)
  3. Extract computeAllowedDomainsForSanitization to a domain-related file (e.g., domain_sanitization.go or integrate into existing validation)
  4. Extract parseBaseSafeOutputConfig if it's primarily validation-focused
  5. Ensure all methods maintain their current functionality
  6. Update tests and imports
  7. Verify full test suite passes

Files to Modify

  • Update: pkg/workflow/compiler.go (remove extracted methods)
  • Create: pkg/workflow/detection.go or similar (for detection methods)
  • Create/Update: Domain-related file for sanitization logic
  • Update: Test files that reference these methods

Acceptance Criteria

  • compiler.go reduced in size by extracting non-core logic
  • detectTextOutputUsage moved to appropriate file
  • computeAllowedDomainsForSanitization moved to appropriate file
  • parseBaseSafeOutputConfig reviewed and potentially extracted
  • All extracted methods maintain current functionality
  • All tests pass
  • Better separation of concerns achieved
  • Compiler file focused on core compilation logic

Estimated Effort

3-4 hours

Benefits

  • Smaller, more focused compiler.go
  • Better separation of concerns
  • Improved testability of extracted components
  • Easier to navigate and understand the compilation process
  • Reduced complexity in the main compiler file

Note

This is a larger refactoring task. Consider breaking it down further if needed, starting with the most straightforward extraction (detectTextOutputUsage) and then proceeding to others.
Related to #3478

AI generated by Plan Command for #3478</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Create detection.go with detectTextOutputUsage method
- Create domain_sanitization.go with computeAllowedDomainsForSanitization method
- Create safe_output_config.go with parseBaseSafeOutputConfig method
- Remove extracted methods from compiler.go
- All tests passing, build successful

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract detection and validation logic from compiler.go Refactor: Extract detection and validation methods from compiler.go Nov 8, 2025
Copilot AI requested a review from pelikhan November 8, 2025 19:15
@pelikhan pelikhan marked this pull request as ready for review November 8, 2025 19:22
Copilot AI review requested due to automatic review settings November 8, 2025 19:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the compiler.go file by extracting three helper functions into separate, focused files to improve code organization and maintainability. This follows the project's "Prefer Many Small Files Over Large Ones" coding guideline.

  • Moves parseBaseSafeOutputConfig to safe_output_config.go (18 lines)
  • Moves computeAllowedDomainsForSanitization to domain_sanitization.go (29 lines)
  • Moves detectTextOutputUsage to detection.go (17 lines)

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/workflow/compiler.go Removed three helper functions (43 lines total) to reduce file size from 1604 to 1561 lines
pkg/workflow/safe_output_config.go New file with safe output configuration parsing logic (18 lines)
pkg/workflow/domain_sanitization.go New file with domain sanitization computation (29 lines)
pkg/workflow/detection.go New file with text output usage detection, includes dedicated logger (17 lines)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 62daa70 into main Nov 8, 2025
8 checks passed
@pelikhan pelikhan deleted the copilot/extract-detection-validation-logic branch November 8, 2025 20:06
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.

[task] Extract detection and validation logic from compiler.go

2 participants