Commit 0fc44f4
refactor(terraform): reduce ExecuteTerraform complexity 160→9, improve test coverage (#2226)
* Initial plan
* refactor: extract helpers from ExecuteTerraform (complexity 160→26) with unit tests
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* docs: add blog post, roadmap entry, CLAUDE.md update for ExecuteTerraform refactor
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* [autofix.ci] apply automated fixes
* fix: address CodeRabbit issues and improve test coverage for ExecuteTerraform helpers
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* fix: address all CodeRabbit issues, reduce complexity to ≤12, split helpers file to 3 files <600 lines each
- Remove dead `varFile string` param from printAndWriteVarFiles (CodeRabbit 🔴 #1)
- Remove setupTerraformAuthCreator, reuse defaultAuthManagerCreator (CodeRabbit 🔴 #2)
- Split terraform_execute_helpers.go (786 lines) into 3 files all <600 lines (CodeRabbit 🔴 #3):
- terraform_execute_helpers.go: auth/env/init/validation helpers (488 lines)
- terraform_execute_helpers_args.go: arg builders (156 lines)
- terraform_execute_helpers_exec.go: execution pipeline + workspace/TTY/cleanup (320 lines)
- Add mutual exclusion comments to buildInitSubcommandArgs + executeTerraformInitPhase (CodeRabbit 🟡 #4)
- Document buildInitArgs vs buildInitSubcommandArgs workspace/reconfigure asymmetry (CodeRabbit 🟡 #5)
- Restore 'Resolving auth config for terraform command' debug entry log (CodeRabbit 🟡 #6)
- Restore 'Stored authenticated identity for hooks' suffix in utils_auth.go (CodeRabbit 🟡 #7)
- Extract prepareComponentExecution + executeCommandPipeline from ExecuteTerraform,
reducing cyclomatic complexity from 25 → 9 (well below the 15 target)
- Add tests: resolveExitCode (nil/ExitCodeError/generic/wrapped), buildWorkspaceSubcommandArgs
(delete/select/no-subcommand2), buildTerraformCommandArgs (validate subcommand),
prepareComponentExecution (no path error), executeCommandPipeline (TTY error via nil stdin)
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* [autofix.ci] apply automated fixes
* Fix setupTerraformAuth error wrapping and document pre-hook termination behavior
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* Add setupTerraformAuth unit tests to fix unused import compile error
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* fix(tests): address CodeRabbit Pass 4 feedback — strengthen assertions, add ErrInvalidAuthConfig test, clean up empty section
- Add require.Error(t, err) to TestPrepareComponentExecution_NoComponentPath_ReturnsError
(was coverage theater: _ = err with no assertion)
- Add defaultMergedAuthConfigGetter injectable var to setupTerraformAuth so the
ErrInvalidAuthConfig wrap branch is testable without requiring a real MergeComponentAuthFromConfig failure
- Add TestSetupTerraformAuth_MergedConfigError_WrapsWithInvalidAuthConfig covering the
previously-untested ErrInvalidAuthConfig wrap path (non-ErrInvalidComponent errors)
- Remove empty addRegionEnvVarForImport section placeholder from coverage test file
(those 3 tests already exist in terraform_execute_helpers_test.go)
- Update coverage test file header to reflect the correct list of covered functions
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* fix(tests): address CodeRabbit Pass 5 — split oversized test files, fix misleading wsOpts comment, add wsOpts branch test, document defaultMergedAuthConfigGetter injection layers
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* [autofix.ci] apply automated fixes
* fix(tests): remove unused 'os' import from terraform_execute_helpers_test.go after file split
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* fix: audit ExecuteTerraform refactor — lint fixes, test cleanup, fix doc
Lint fixes (16 issues):
- Fix hugeParam: handleVersionSubcommand now takes pointers
- Fix unlambda: defaultMergedAuthConfigGetter uses direct function ref
- Fix filepathJoin: split "infra/networking" into separate segments
- Fix unparam: remove unused planFile from buildApplySubcommandArgs
- Fix forbidigo: add nolint for TF_WORKSPACE (Terraform convention)
- Fix nestif: extract handlePlanStatusUpload from executeMainTerraformCommand
- Fix argument-limit: add nolint for variadic opts parameter
- Fix cyclomatic: extract shouldSkipWorkspaceSetup from runWorkspaceSetup
- Fix cyclomatic: extract runPreExecutionSteps from prepareComponentExecution
- Fix cyclomatic: extract autoGenerateComponentFiles, provisionComponentSource
- Fix cyclomatic/funlen: extract logAndWriteComponentVars, logCliVarsOverrides
- Fix add-constant: add subcommandApply/Deploy/Init/Workspace, dirPermissions
Test cleanup:
- Remove 4 duplicate resolveExitCode tests from _pipeline_test.go
- Clarify tautological cleanup test comment
- Remove unused writeTestFile helper
Add fix doc documenting all audit findings.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address CodeRabbit audit pass 7 — remove duplicates, add coverage
- Remove duplicate TestBuildWorkspaceSubcommandArgs_NoSubCommand2 from _pipeline_test.go
- Remove tautological cleanup tests from _args_test.go (real tests in _coverage_test.go)
- Remove redundant TestWarnOnConflictingEnvVars_NoConflictsNoError
- Add TestAssembleComponentEnvVars_NonNilTenv (tenv != nil branch coverage)
- Add TestBuildTerraformCommandArgs_Init (init switch-case dispatch)
- Add comment to generateConfigFiles re: double GenerateFilesForComponent invocation
- Document logTerraformContext tests as logging-only (not coverage theater)
- Update fix doc with all 10 audit pass 7 items and resolutions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address audit pass 8 — debug-level branch coverage, final cleanup
- Add TestPrintAndWriteVarFiles_DebugLogLevel_Success (item 8)
- Add TestPrintAndWriteVarFiles_DebugLogLevel_CliVarsSection (item 8)
- Add TestPrintAndWriteVarFiles_TraceLogLevel (item 8)
- Validate item 5: storeAutoDetectedIdentity already tested in utils_auth_test.go
(gomock strict controller implicitly verifies GetChain not called)
- Validate item 10: generateConfigFiles comment already added in previous commit
- Update fix doc with all audit pass 8 resolutions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address audit pass 9 — explicit identity guard test, call-site comment
- Add TestStoreAutoDetectedIdentity_ExistingIdentity_NotOverwritten with
explicit GetChain().Times(0) assertion (item 5)
- Add double-invocation comment at generateConfigFiles call site in
runPreExecutionSteps (item 10)
- Update fix doc with pass 9 resolutions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: address CodeRabbit review — error masking, empty workdir, cross-platform test
- Separate provisioning errors from "component does not exist" in
resolveAndProvisionComponentPath — propagate original error directly
- Guard empty _workdir_path in provisionComponentSource to match
prepareInitExecution behavior
- Replace Unix-only "false" command with cross-platform "go run" in
TestResolveExitCode_OsExecExitError
- Remove warnOnConflictingEnvVars coverage theater tests (logging-only
function, NotPanics assertions add no value)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: aknysh <andriy.knysh@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent bb6f71d commit 0fc44f4
File tree
15 files changed
+3368
-720
lines changed- docs/fixes
- internal/exec
- website
- blog
- src/data
15 files changed
+3368
-720
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
365 | 373 | | |
366 | 374 | | |
367 | 375 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
0 commit comments