Overview
The file pkg/workflow/awf_helpers.go has grown to 1131 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.
Current State
- File:
pkg/workflow/awf_helpers.go
- Size: 1131 lines
- Test Coverage:
awf_helpers_test.go is 2480 lines (~2.2x ratio) — good overall coverage, but concentrated in one large test file that should split alongside the source
- Complexity: Mixes several distinct concerns — AWF command/argument construction, firewall version-capability gating, container digest resolution, ARC/DinD chroot rewriting, and env-var exclusion logic — in a single 26-function file
Full File Analysis
Function Inventory (26 top-level functions)
shouldUseWorkflowCallNetworkAllowedInput (L123)
buildModelsJSONPathExportScript (L130)
rewriteArcDindPath (L138), rewriteArcDindEngineCommand (L142)
applyDefaultMaxAICreditsEnvToMap (L153), injectMaxAICreditsExpression (L182)
buildWorkflowCallNetworkAllowedUpdateScript (L197)
BuildAWFCommand (L229–630) — ~400 lines, the single largest function, builds the full awf CLI invocation
BuildAWFArgs (L630–809) — ~180 lines, builds argument list variant
GetAWFCommandPrefix (L809)
buildAWFImageTagWithDigests (L838), lookupContainerDigest (L875)
WrapCommandInShell (L898)
ComputeAWFExcludeEnvVarNames (L930–1023) — ~90 lines
addCliProxyGHTokenToEnv (L1023)
awfSupportsExcludeEnv, awfVersionAtLeast, awfSupportsCliProxy, awfSupportsAllowHostPorts, awfSupportsDockerHostPathPrefix, awfSupportsTokenSteering, awfSupportsChrootConfig, awfSupportsContainerRuntime, awfSupportsLegacySecurity, awfSupportsAPIProxyProviders (L1036–1108) — 9 near-identical version-gate predicates, strong candidate for a small table-driven helper or shared pattern
buildArcDindChrootConfigPatchBody (L1109), buildArcDindChrootConfigPatchBodyBash (L1122)
Complexity hotspots
BuildAWFCommand (L229–630) and BuildAWFArgs (L630–809) together account for over half the file and mix argument assembly, feature-flag branching, and string formatting.
- The 9
awfSupports* predicates (L1036–1108) are structurally duplicate — each just calls awfVersionAtLeast with a different constant — and could be collapsed into a single map-driven capability lookup, reducing both line count and future duplication risk.
Refactoring Strategy
Proposed File Splits
-
awf_command_builder.go
- Functions:
BuildAWFCommand, BuildAWFArgs, GetAWFCommandPrefix, WrapCommandInShell
- Responsibility: Constructing the
awf command line and argument list used to wrap agentic engine execution
- Estimated LOC: ~550
-
awf_capabilities.go
- Functions:
awfVersionAtLeast, awfSupportsExcludeEnv, awfSupportsCliProxy, awfSupportsAllowHostPorts, awfSupportsDockerHostPathPrefix, awfSupportsTokenSteering, awfSupportsChrootConfig, awfSupportsContainerRuntime, awfSupportsLegacySecurity, awfSupportsAPIProxyProviders
- Responsibility: Firewall version-gated feature capability checks (consider collapsing into a single table-driven lookup during the split)
- Estimated LOC: ~90
-
awf_env.go
- Functions:
ComputeAWFExcludeEnvVarNames, addCliProxyGHTokenToEnv, applyDefaultMaxAICreditsEnvToMap, injectMaxAICreditsExpression
- Responsibility: Environment variable computation/injection for the AWF sandbox (exclusions, GH token, max-AI-credits expression)
- Estimated LOC: ~150
-
awf_digest.go
- Functions:
buildAWFImageTagWithDigests, lookupContainerDigest
- Responsibility: Resolving and pinning container image digests for AWF images
- Estimated LOC: ~60
-
awf_arc_dind.go
- Functions:
rewriteArcDindPath, rewriteArcDindEngineCommand, buildModelsJSONPathExportScript, buildArcDindChrootConfigPatchBody, buildArcDindChrootConfigPatchBodyBash
- Responsibility: ARC/DinD-specific path rewriting and chroot config patching
- Estimated LOC: ~80
-
awf_helpers.go (remaining)
- Functions:
shouldUseWorkflowCallNetworkAllowedInput, buildWorkflowCallNetworkAllowedUpdateScript
- Responsibility: Workflow-call network-allowed input handling
- Estimated LOC: ~100
Shared Utilities
No new shared utility file needed; keep helpers colocated with their consuming domain per above split.
Interface Abstractions
- Consider a
firewallCapability table (map[string]constants.Version]) consumed by a single awfSupports(firewallConfig *FirewallConfig, name string) bool to eliminate the 9 near-duplicate predicate functions, exposing typed wrapper constants for call-site clarity if needed.
Test Coverage Plan
Split awf_helpers_test.go (2480 lines) to mirror the new source files:
-
awf_command_builder_test.go
- Test cases:
BuildAWFCommand/BuildAWFArgs across engine types, network modes, proxy configs, ARC/DinD variants
- Target coverage: >80%
-
awf_capabilities_test.go
- Test cases: each
awfSupports* predicate at boundary versions (below/at/above min version), nil FirewallConfig handling
- Target coverage: >80%
-
awf_env_test.go
- Test cases: exclude-env-var computation with/without secrets, CLI proxy token injection, max-AI-credits default/override/expression injection
- Target coverage: >80%
-
awf_digest_test.go
- Test cases: digest lookup success/failure, image tag rewriting with/without digest
- Target coverage: >80%
-
awf_arc_dind_test.go
- Test cases: ARC/DinD path and command rewriting, chroot config patch body (JSON and bash variants)
- Target coverage: >80%
Implementation Guidelines
- Preserve Behavior: Ensure all existing functionality works identically
- Maintain Exports: Keep public API unchanged (exported functions/types)
- Add Tests First: Write tests for each new file before refactoring
- Incremental Changes: Split one module at a time
- Run Tests Frequently: Verify
make test-unit passes after each split
- Update Imports: Ensure all import paths are correct
- Document Changes: Add comments explaining module boundaries
Acceptance Criteria
Additional Context
- Repository Guidelines: Follow patterns in
.github/agents/developer.instructions.agent.md
- Code Organization: Prefer many small files grouped by functionality
- Testing: Match existing test patterns in
pkg/workflow/*_test.go
Priority: Medium
Effort: Medium — 26 functions across 6 well-separated domains, existing tests provide a strong safety net
Expected Impact: Improved maintainability, easier testing, reduced complexity
Generated by 🧹 Daily File Diet · sonnet50 · 54.2 AIC · ⌖ 9.04 AIC · ⊞ 9.5K · ◷
Overview
The file
pkg/workflow/awf_helpers.gohas grown to 1131 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/workflow/awf_helpers.goawf_helpers_test.gois 2480 lines (~2.2x ratio) — good overall coverage, but concentrated in one large test file that should split alongside the sourceFull File Analysis
Function Inventory (26 top-level functions)
shouldUseWorkflowCallNetworkAllowedInput(L123)buildModelsJSONPathExportScript(L130)rewriteArcDindPath(L138),rewriteArcDindEngineCommand(L142)applyDefaultMaxAICreditsEnvToMap(L153),injectMaxAICreditsExpression(L182)buildWorkflowCallNetworkAllowedUpdateScript(L197)BuildAWFCommand(L229–630) — ~400 lines, the single largest function, builds the fullawfCLI invocationBuildAWFArgs(L630–809) — ~180 lines, builds argument list variantGetAWFCommandPrefix(L809)buildAWFImageTagWithDigests(L838),lookupContainerDigest(L875)WrapCommandInShell(L898)ComputeAWFExcludeEnvVarNames(L930–1023) — ~90 linesaddCliProxyGHTokenToEnv(L1023)awfSupportsExcludeEnv,awfVersionAtLeast,awfSupportsCliProxy,awfSupportsAllowHostPorts,awfSupportsDockerHostPathPrefix,awfSupportsTokenSteering,awfSupportsChrootConfig,awfSupportsContainerRuntime,awfSupportsLegacySecurity,awfSupportsAPIProxyProviders(L1036–1108) — 9 near-identical version-gate predicates, strong candidate for a small table-driven helper or shared patternbuildArcDindChrootConfigPatchBody(L1109),buildArcDindChrootConfigPatchBodyBash(L1122)Complexity hotspots
BuildAWFCommand(L229–630) andBuildAWFArgs(L630–809) together account for over half the file and mix argument assembly, feature-flag branching, and string formatting.awfSupports*predicates (L1036–1108) are structurally duplicate — each just callsawfVersionAtLeastwith a different constant — and could be collapsed into a single map-driven capability lookup, reducing both line count and future duplication risk.Refactoring Strategy
Proposed File Splits
awf_command_builder.goBuildAWFCommand,BuildAWFArgs,GetAWFCommandPrefix,WrapCommandInShellawfcommand line and argument list used to wrap agentic engine executionawf_capabilities.goawfVersionAtLeast,awfSupportsExcludeEnv,awfSupportsCliProxy,awfSupportsAllowHostPorts,awfSupportsDockerHostPathPrefix,awfSupportsTokenSteering,awfSupportsChrootConfig,awfSupportsContainerRuntime,awfSupportsLegacySecurity,awfSupportsAPIProxyProvidersawf_env.goComputeAWFExcludeEnvVarNames,addCliProxyGHTokenToEnv,applyDefaultMaxAICreditsEnvToMap,injectMaxAICreditsExpressionawf_digest.gobuildAWFImageTagWithDigests,lookupContainerDigestawf_arc_dind.gorewriteArcDindPath,rewriteArcDindEngineCommand,buildModelsJSONPathExportScript,buildArcDindChrootConfigPatchBody,buildArcDindChrootConfigPatchBodyBashawf_helpers.go(remaining)shouldUseWorkflowCallNetworkAllowedInput,buildWorkflowCallNetworkAllowedUpdateScriptShared Utilities
No new shared utility file needed; keep helpers colocated with their consuming domain per above split.
Interface Abstractions
firewallCapabilitytable (map[string]constants.Version]) consumed by a singleawfSupports(firewallConfig *FirewallConfig, name string) boolto eliminate the 9 near-duplicate predicate functions, exposing typed wrapper constants for call-site clarity if needed.Test Coverage Plan
Split
awf_helpers_test.go(2480 lines) to mirror the new source files:awf_command_builder_test.goBuildAWFCommand/BuildAWFArgsacross engine types, network modes, proxy configs, ARC/DinD variantsawf_capabilities_test.goawfSupports*predicate at boundary versions (below/at/above min version), nilFirewallConfighandlingawf_env_test.goawf_digest_test.goawf_arc_dind_test.goImplementation Guidelines
make test-unitpasses after each splitAcceptance Criteria
BuildAWFCommand/BuildAWFArgsif it exceeds 500 lines)make test-unit)make lint)make build)Additional Context
.github/agents/developer.instructions.agent.mdpkg/workflow/*_test.goPriority: Medium
Effort: Medium — 26 functions across 6 well-separated domains, existing tests provide a strong safety net
Expected Impact: Improved maintainability, easier testing, reduced complexity