Repository navigation
fix(hooks): user-defined hooks now fire under bulk dispatch - #2736
Conversation
Deletes internal/exec/terraform_executor.go and terraform_affected_graph.go, plus the orphaned processTerraformComponent/ executeTerraformAffectedComponentInDepOrder/executeAffectedComponents chain in terraform_utils.go and terraform_affected.go. Confirmed via call-graph grep: none of these have had a live (non-test) caller since the terraform scheduler migration — every --all/--affected/--query path already routes through pkg/scheduler/adapters instead. extractAffectedNodeIDs is relocated (it's still used by the live ExecuteTerraformAffectedWithContext). Split out from the hooks bulk-dispatch fix in this same PR so the behavior change stays independently bisectable from this pure deletion. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…mfile dispatch Component `hooks:` never fired for atmos terraform apply/plan/deploy --all, --affected, --components, or --query — only for single-component invocations — because bulk dispatch only ever wired the CI-reporting hook callback, never the user-defined hooks.RunAll engine, and had no "before" seam at all. Adds a schema.ComponentNodeHooks interface (Before/After) wired into the scheduler's TerraformDispatcher.Dispatch — the single choke point shared by --all/--affected/--query — via pkg/hooks.RunPerComponentHooks. A before-hook failure aborts that node; an after-hook failure fails it even if Terraform itself succeeded, both respecting each hook's existing on_failure (fail/warn/ ignore) semantics rather than inventing new ones. Helmfile gets the same ComponentNodeHooks wiring, giving it its first user-defined hook support (it previously had none, single-component or otherwise). Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR replaces per-component callback hooks with structured before/after node hooks across Terraform and Helmfile, adds shared hook dispatch and error handling, routes affected Terraform execution through scheduler node selection, and updates or removes corresponding tests and execution helpers. ChangesPer-component hook lifecycle
Estimated code review effort: 4 (Complex) | ~60 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant TerraformDispatcher
participant terraformNodeHooks
participant TerraformExecutor
TerraformDispatcher->>terraformNodeHooks: Before component node
terraformNodeHooks-->>TerraformDispatcher: hook result
TerraformDispatcher->>TerraformExecutor: execute node
TerraformExecutor-->>TerraformDispatcher: output and execution error
TerraformDispatcher->>terraformNodeHooks: After component node
terraformNodeHooks-->>TerraformDispatcher: updated outcome
sequenceDiagram
participant helmfileRun
participant ExecuteHelmfile
participant helmfileNodeHooks
participant HelmfileProcess
helmfileRun->>ExecuteHelmfile: run with NodeHooks
ExecuteHelmfile->>helmfileNodeHooks: Before component
helmfileNodeHooks-->>ExecuteHelmfile: hook result
ExecuteHelmfile->>HelmfileProcess: execute Helmfile
HelmfileProcess-->>ExecuteHelmfile: output and execution error
ExecuteHelmfile->>helmfileNodeHooks: After component
helmfileNodeHooks-->>ExecuteHelmfile: hook result
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Resource Changes Found for
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2736 +/- ##
==========================================
+ Coverage 81.68% 81.84% +0.16%
==========================================
Files 1653 1651 -2
Lines 156045 155930 -115
==========================================
+ Hits 127458 127615 +157
+ Misses 21614 21327 -287
- Partials 6973 6988 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Codecov flagged this branch's patch coverage at 79.31% (target 80%) with 36 lines missing across cmd/terraform/utils.go, cmd/helmfile/helmfile.go, internal/exec/helmfile.go, internal/exec/terraform_query.go, pkg/hooks/hooks.go, and pkg/scheduler/adapters/terraform.go. Adds tests targeting the exact uncovered branches (config-init-failure paths, empty-event guards, RunCIHooks error paths, errors.Join behavior, and the NodeHooks Before/After wiring in ExecuteHelmfile/executeTerraformQueryComponent) identified from local coverage profiles. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
internal/exec/terraform_affected_test.go (1)
16-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse one table for the node-ID scenarios.
The empty, single, and multiple-entry cases can share one input/output table and one assertion.
As per coding guidelines, “Use table-driven tests for testing multiple scenarios in Go.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/exec/terraform_affected_test.go` around lines 16 - 42, The TestExtractAffectedNodeIDs test currently duplicates subtests for scenarios that can use a single table-driven test. Replace the separate “empty list,” “single affected,” and “multiple affected” cases with one table of inputs and expected node-ID slices, then iterate over it and assert each result with one assertion pattern.Source: Coding guidelines
pkg/hooks/hooks_test.go (1)
607-638: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the
on_failurecases table-driven.The three cases differ only by mode and expected error; a table removes repeated fixture and invocation logic.
As per coding guidelines, “Use table-driven tests for testing multiple scenarios in Go.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/hooks/hooks_test.go` around lines 607 - 638, Convert the three on_failure subtests in the relevant test function into a table-driven test with fields for the failure mode and expected error outcome. Iterate over the cases, create each fixture using the table’s mode, invoke RunPerComponentHooks with the shared options, and assert error or no error based on the expected result.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/exec/terraform_query_test.go`:
- Line 467: Update the test setup around t.Chdir to construct the fixture path
with filepath.Join using separate path elements, preserving the existing
../../examples/demo-stacks location while making it cross-platform. Ensure the
filepath package is imported if needed.
In `@pkg/schema/schema.go`:
- Around line 799-804: Update the exported After method comment in the relevant
hook interface to remove the claim that it runs after a Before failure. Document
it as running after the component executor completes successfully or with an
error, and preserve the existing behavior that Before failures prevent After
from running.
---
Nitpick comments:
In `@internal/exec/terraform_affected_test.go`:
- Around line 16-42: The TestExtractAffectedNodeIDs test currently duplicates
subtests for scenarios that can use a single table-driven test. Replace the
separate “empty list,” “single affected,” and “multiple affected” cases with one
table of inputs and expected node-ID slices, then iterate over it and assert
each result with one assertion pattern.
In `@pkg/hooks/hooks_test.go`:
- Around line 607-638: Convert the three on_failure subtests in the relevant
test function into a table-driven test with fields for the failure mode and
expected error outcome. Iterate over the cases, create each fixture using the
table’s mode, invoke RunPerComponentHooks with the shared options, and assert
error or no error based on the expected result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2d4d24c1-79e7-4469-8fa5-5900c72fbba4
📒 Files selected for processing (24)
cmd/helmfile/ci_helpers_test.gocmd/helmfile/helmfile.gocmd/helmfile/helmfile_test.gocmd/terraform/utils.gocmd/terraform/utils_hooks_test.goerrors/errors.gointernal/exec/describe_affected_utils_2.gointernal/exec/helmfile.gointernal/exec/helmfile_test.gointernal/exec/terraform_affected.gointernal/exec/terraform_affected_graph.gointernal/exec/terraform_affected_graph_test.gointernal/exec/terraform_affected_test.gointernal/exec/terraform_executor.gointernal/exec/terraform_executor_test.gointernal/exec/terraform_query.gointernal/exec/terraform_query_test.gointernal/exec/terraform_utils.gointernal/exec/terraform_utils_test.gopkg/hooks/hooks.gopkg/hooks/hooks_test.gopkg/scheduler/adapters/terraform.gopkg/scheduler/adapters/terraform_test.gopkg/schema/schema.go
💤 Files with no reviewable changes (7)
- internal/exec/terraform_affected_graph_test.go
- internal/exec/terraform_executor.go
- internal/exec/terraform_affected_graph.go
- internal/exec/terraform_executor_test.go
- internal/exec/describe_affected_utils_2.go
- internal/exec/terraform_utils.go
- internal/exec/terraform_utils_test.go
Corrects the ComponentNodeHooks.After docstring, which implied After runs following a Before failure — TestExecuteHelmfileNodeHooks_BeforeErrorAbortsExecution proves it does not. Also builds test fixture paths with filepath.Join instead of hardcoded forward-slash strings, per the repo's cross-platform test-path rule. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/helmfile/helmfile_test.go`:
- Around line 170-175: Extend TestHelmfileRun_NodeHooksFallbackOnEarlyFailure to
install or inject an observable after-hook that records invocation and the
received error, then assert it runs when helmfileRun fails during diff. Keep the
existing require.Error assertion and verify the hook receives the same failure
rather than only checking that the command returns an error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 994d4370-6f1b-4c5d-ad85-a16856c760d4
📒 Files selected for processing (4)
cmd/helmfile/ci_helpers_test.gocmd/helmfile/helmfile_test.gointernal/exec/terraform_query_test.gopkg/schema/schema.go
🚧 Files skipped from review as they are similar to previous changes (3)
- pkg/schema/schema.go
- internal/exec/terraform_query_test.go
- cmd/helmfile/ci_helpers_test.go
CodeRabbit asked for TestHelmfileRun_NodeHooksFallbackOnEarlyFailure to prove
the fallback after-hook actually runs, not just that helmfileRun returns an
error. Making that assertion real (a hooks: entry that writes an observable
marker file) surfaced a pre-existing bug: supportsComponentHooks() never
included HelmfileComponentType, and stack_processor_merge.go only assigned
comp[hooks] inside the Terraform/Kubernetes/Helm-specific blocks. So the
hooks: section was silently dropped during stack processing for helmfile
components, and GetHooks always found nothing — meaning this PR's stated goal
("fire hooks.RunAll for components under bulk terraform/helmfile dispatch")
did not actually work end-to-end for helmfile until now.
Fixes:
- supportsComponentHooks now includes HelmfileComponentType.
- Consolidated the three duplicated `comp[cfg.HooksSectionName] =
finalComponentHooks` assignments (one per gated type block) into a single
supportsComponentHooks-gated line, so a future hooks-capable type only
needs the one flag flipped.
- Updated the stale TestSupportsComponentTypeHelpers truth-table entry that
had pinned the old (incorrect) helmfile=false behavior.
- cmd/helmfile/testmain_test.go: adds a cross-platform "write a marker file"
test-binary trick (mirroring pkg/hooks' _ATMOS_TEST_WRITE_OUTPUT), used by
the rewritten fallback test to prove the hook fired for real.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
# Conflicts: # pkg/scheduler/adapters/terraform_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/scheduler/adapters/terraform.go (1)
428-428: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
terraformSubCommandApplyhere. The constant already exists in this package, so this branch can match the destroy case instead of hardcoding"apply".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/scheduler/adapters/terraform.go` at line 428, Update the subcommand check in the Terraform adapter to use the existing terraformSubCommandApply constant instead of the hardcoded "apply" string, while preserving the existing terraformSubCommandDestroy comparison and nil guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/scheduler/adapters/terraform.go`:
- Line 428: Update the subcommand check in the Terraform adapter to use the
existing terraformSubCommandApply constant instead of the hardcoded "apply"
string, while preserving the existing terraformSubCommandDestroy comparison and
nil guard.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 69bec733-ca34-460c-b92a-efbd9c852f12
📒 Files selected for processing (4)
cmd/terraform/utils.goerrors/errors.gopkg/scheduler/adapters/terraform.gopkg/schema/schema.go
🚧 Files skipped from review as they are similar to previous changes (2)
- pkg/schema/schema.go
- cmd/terraform/utils.go
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
These changes were released in v1.223.0-rc.11. |
what
hooks:(the user-definedhooks.RunAllengine) now fire foratmos terraform apply/plan/deployunder--all,--affected,--components, and--query— previously they silently never ran in these bulk modes, only for single-component invocations.schema.ComponentNodeHooksinterface (Before/After) wired into the scheduler'sTerraformDispatcher.Dispatch— the one choke point shared by every bulk dispatch path — via a newpkg/hooks.RunPerComponentHookshelper.on_failure: fail|warn|ignoresetting rather than introducing new failure semantics.ComponentNodeHookswiring, which is actually its first user-defined hook support of any kind (it previously had none, single- or multi-component).terraform_executor.go,terraform_affected_graph.go, the associated_test.gofiles, and orphaned helpers interraform_utils.go/terraform_affected.go) that predated the scheduler-based dispatch path and had no live (non-test) callers left.why
before.terraform.applyhook (e.g. zipping a Lambda handler before apply) worked correctly underatmos terraform apply <component> -s <stack>but silently never ran underatmos terraform deploy --all -s <stack>for the identical component/stack/hook config — the subsequent apply then failed because the hook's output never existed. This is exactly how CI normally invokes Atmos, so any hook-dependent component broke the moment it moved from manual single-component testing to a real pipeline run.hooks.RunCIHooks), never the user-defined hook engine (hooks.RunAll), and had no "before" seam of any kind — the code itself documented this as a known, unfixed limitation.references