-
Notifications
You must be signed in to change notification settings - Fork 251
Description
The file pkg/workflow/safe_outputs_config_generation.go has grown to 1092 lines — well above the 800-line healthy threshold — with no dedicated test file. It mixes two distinct concerns that would benefit from separation.
Current State
| Metric | Value |
|---|---|
| File | pkg/workflow/safe_outputs_config_generation.go |
| Size | 1092 lines |
| Dedicated test file | ❌ None (tested indirectly via safe_outputs_test.go, safe_outputs_tools_test.go, dispatch_workflow_test.go, etc.) |
| Companion helpers file | safe_outputs_config_generation_helpers.go (188 lines — healthy) |
Full File Analysis
Function Distribution
| Function | Lines | Domain |
|---|---|---|
populateDispatchWorkflowFiles() |
~40 | Config generation (pre-pass for dispatch) |
generateSafeOutputsConfig() |
~435 | Config generation (runtime validation rules JSON) |
generateCustomJobToolDefinition() |
~87 | Tools JSON generation (MCP tool schema) |
generateFilteredToolsJSON() |
~251 | Tools JSON generation (filtering + assembly) |
addRepoParameterIfNeeded() |
~156 | Tools JSON generation (repo param injection) |
generateDispatchWorkflowTool() |
~94 | Tools JSON generation (dispatch workflow schema) |
Two Distinct Domains
Domain 1 – Runtime validation config (generateSafeOutputsConfig, populateDispatchWorkflowFiles): Produces the JSON blob embedded in compiled workflows that the safe-outputs handler reads at runtime to validate tool calls (max counts, allowed labels, target repos, etc.).
Domain 2 – MCP tools JSON (generateFilteredToolsJSON, generateCustomJobToolDefinition, addRepoParameterIfNeeded, generateDispatchWorkflowTool): Produces the JSON array of MCP tool definitions exposed to the AI agent, including dynamic dispatch-workflow tools and custom safe-job tools.
Complexity Hotspots
generateSafeOutputsConfig(lines 58–492): 435-line monolithic function with ~35 if-branches, one for each safe-output type. Each branch calls a helper but the accumulation makes the function hard to navigate.addRepoParameterIfNeeded(lines 840–995): 156-line switch statement that duplicatesconfig.AllowedRepos+config.TargetRepoSlugextraction for every tool type. The nestedswitchinside acase(lines 909–963) is a complexity hotspot.
Refactoring Strategy
Proposed File Splits
-
safe_outputs_config_generation.go(keep, trimmed)- Functions:
populateDispatchWorkflowFiles,generateSafeOutputsConfig - Responsibility: Build the runtime validation config JSON embedded in compiled workflows
- Estimated LOC: ~480 lines
- Functions:
-
safe_outputs_tools_generation.go(new)- Functions:
generateFilteredToolsJSON,generateCustomJobToolDefinition,addRepoParameterIfNeeded,generateDispatchWorkflowTool - Responsibility: Build the MCP tool definitions JSON exposed to the AI agent
- Estimated LOC: ~590 lines
- Functions:
Additional Refactoring Opportunities
generateSafeOutputsConfig: Extract the per-output-type config building into small private helpers (similar to what already exists in_helpers.go) to reduce the 435-line function body.addRepoParameterIfNeeded: Replace the largeswitchwith a helpergetRepoConfig(toolName string, safeOutputs *SafeOutputsConfig) (hasAllowedRepos bool, targetRepoSlug string)that uses a map-based dispatch, reducing ~120 lines to ~20.
Test Coverage Plan
No dedicated test file currently exists. Add:
-
safe_outputs_config_generation_test.goTestGenerateSafeOutputsConfig— move/consolidate tests fromsafe_outputs_test.goTestPopulateDispatchWorkflowFiles— unit tests for the pre-pass function- Target coverage: ≥80%
-
safe_outputs_tools_generation_test.goTestGenerateFilteredToolsJSON— move/consolidate fromsafe_outputs_tools_test.goTestGenerateCustomJobToolDefinition— unit tests for schema buildingTestAddRepoParameterIfNeeded— parametric tests for each tool typeTestGenerateDispatchWorkflowTool— input type mapping tests- Target coverage: ≥80%
Implementation Guidelines
- Preserve Behavior: Ensure all existing functionality works identically
- Maintain Package-Private API: All functions are unexported — no API breakage risk
- Incremental Changes: Split first, then refactor internals
- Run Tests Frequently: Verify
make test-unitpasses after each step - Run Linting:
make lintafter adding test files (watch for unused helpers) - Format Code:
make fmtbefore committing
Acceptance Criteria
-
safe_outputs_config_generation.gois ≤500 lines -
safe_outputs_tools_generation.gois created and ≤600 lines - Dedicated test files added for both modules
- All tests pass (
make test-unit) - Code passes linting (
make lint) - Build succeeds (
make build)
Additional Context
- Companion helpers file
safe_outputs_config_generation_helpers.go(188 lines) is already healthy and should not be changed - Callers:
mcp_setup_generator.gocallspopulateDispatchWorkflowFiles; the compiler pipeline callsgenerateSafeOutputsConfigandgenerateFilteredToolsJSONviasafe_outputs_config.go - Workflow run: §22183884465
Priority: Medium
Effort: Small (mechanical split) + Medium (internal refactoring of generateSafeOutputsConfig)
Expected Impact: Improved navigability, easier testing, clearer module responsibilities
Generated by Daily File Diet
- expires on Feb 21, 2026, 1:37 PM UTC