feat: add configurable env passthrough for step execution#1925
feat: add configurable env passthrough for step execution#1925
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR extends the Dagu Helm chart and configuration system to support configurable environment variable passthrough. It adds schema validation, template helpers for injecting extra environment variables, configuration fields for exact env-name and prefix-based filtering, and new environment loading logic with corresponding tests. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/cmn/config/loader_test.go (1)
461-479: Add one negative assertion in the env-based passthrough test.Line 461 onward verifies positive inclusion but not exclusion of unrelated keys. Mirroring the YAML test’s negative check would harden regression coverage.
💡 Suggested test hardening
func TestLoad_BaseEnvIncludesConfiguredEnvPassthroughFromEnv(t *testing.T) { tempDir := t.TempDir() configFile := filepath.Join(tempDir, "config.yaml") preserveTZEnv(t) t.Setenv("EXACT_FROM_ENV", "exact-value") t.Setenv("PREFIX_FROM_ENV_TOKEN", "prefix-value") + t.Setenv("BLOCKED_FROM_ENV", "blocked-value") t.Setenv("DAGU_ENV_PASSTHROUGH", " EXACT_FROM_ENV , EXACT_FROM_ENV ,,") t.Setenv("DAGU_ENV_PASSTHROUGH_PREFIXES", " PREFIX_FROM_ENV_ , PREFIX_FROM_ENV_ ,,") require.NoError(t, os.WriteFile(configFile, []byte("# minimal config"), 0o600)) cfg := testLoad(t, WithConfigFile(configFile), WithAppHomeDir(tempDir)) baseEnv := cfg.Core.BaseEnv.AsSlice() require.Equal(t, []string{"EXACT_FROM_ENV"}, cfg.Core.EnvPassthrough) require.Equal(t, []string{"PREFIX_FROM_ENV_"}, cfg.Core.EnvPassthroughPrefixes) require.Contains(t, baseEnv, "EXACT_FROM_ENV=exact-value") require.Contains(t, baseEnv, "PREFIX_FROM_ENV_TOKEN=prefix-value") + require.NotContains(t, baseEnv, "BLOCKED_FROM_ENV=blocked-value") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/cmn/config/loader_test.go` around lines 461 - 479, Add a negative assertion to TestLoad_BaseEnvIncludesConfiguredEnvPassthroughFromEnv to ensure unrelated environment variables are not passed through: after computing baseEnv (cfg.Core.BaseEnv.AsSlice()) assert that an unrelated key (e.g., "UNRELATED_ENV=some-value" or simply ensure "UNRELATED_ENV" is not present) is not in baseEnv; use the same style as the existing positive assertions and reference cfg.Core.EnvPassthrough / cfg.Core.EnvPassthroughPrefixes to mirror the YAML test’s exclusion check so the test fails if non-configured keys slip into BaseEnv.internal/cmn/config/env.go (1)
136-145:dedupePreserveOrdercan be linear-time with a seen map.Line 139 repeatedly calls
slices.Contains, making this O(n²). A map-backed check keeps order while reducing overhead.♻️ O(n) dedupe preserving order
func dedupePreserveOrder(values []string) []string { - var deduped []string + deduped := make([]string, 0, len(values)) + seen := make(map[string]struct{}, len(values)) for _, value := range values { - if slices.Contains(deduped, value) { + if _, ok := seen[value]; ok { continue } + seen[value] = struct{}{} deduped = append(deduped, value) } return deduped }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/cmn/config/env.go` around lines 136 - 145, The dedupePreserveOrder function is currently O(n²) because it calls slices.Contains for each element; change it to O(n) by using a map (e.g., map[string]struct{}) named seen to track which strings were already encountered, iterate the input slice once, append each value to deduped only if not present in seen, and mark it in seen to preserve original order while avoiding repeated containment checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/service/worker/handler_test.go`:
- Around line 369-450: The tests set environment variables with t.Setenv but
then reuse the pre-created th.Config and NewTaskHandler, so the config snapshot
won't include the new DAGU_ENV_PASSTHROUGH* values; reinitialize the
configuration or test harness after calling t.Setenv and before constructing the
handler. Concretely: after each block of t.Setenv calls, refresh th.Config (or
recreate th/test harness) so the loader reads the updated env, then call
NewTaskHandler(th.Config) and proceed to create tasks (see test names
HandleTaskStartPreservesConfiguredEnvPassthrough and
HandleTaskRetryPreservesConfiguredEnvPassthrough and usage sites of th.Config,
NewTaskHandler, runtimeexec.CreateTask) to ensure the passthrough settings are
applied.
---
Nitpick comments:
In `@internal/cmn/config/env.go`:
- Around line 136-145: The dedupePreserveOrder function is currently O(n²)
because it calls slices.Contains for each element; change it to O(n) by using a
map (e.g., map[string]struct{}) named seen to track which strings were already
encountered, iterate the input slice once, append each value to deduped only if
not present in seen, and mark it in seen to preserve original order while
avoiding repeated containment checks.
In `@internal/cmn/config/loader_test.go`:
- Around line 461-479: Add a negative assertion to
TestLoad_BaseEnvIncludesConfiguredEnvPassthroughFromEnv to ensure unrelated
environment variables are not passed through: after computing baseEnv
(cfg.Core.BaseEnv.AsSlice()) assert that an unrelated key (e.g.,
"UNRELATED_ENV=some-value" or simply ensure "UNRELATED_ENV" is not present) is
not in baseEnv; use the same style as the existing positive assertions and
reference cfg.Core.EnvPassthrough / cfg.Core.EnvPassthroughPrefixes to mirror
the YAML test’s exclusion check so the test fails if non-configured keys slip
into BaseEnv.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eb9fdb77-6e5c-4f02-bb48-284191f9d10a
📒 Files selected for processing (18)
charts/dagu/Chart.yamlcharts/dagu/README.mdcharts/dagu/templates/_helpers.tplcharts/dagu/templates/configmap.yamlcharts/dagu/templates/coordinator-deployment.yamlcharts/dagu/templates/scheduler-deployment.yamlcharts/dagu/templates/ui-deployment.yamlcharts/dagu/templates/worker-deployment.yamlcharts/dagu/values.schema.jsoncharts/dagu/values.yamlinternal/cmn/config/config.gointernal/cmn/config/definition.gointernal/cmn/config/env.gointernal/cmn/config/env_test.gointernal/cmn/config/key_hints.gointernal/cmn/config/loader.gointernal/cmn/config/loader_test.gointernal/service/worker/handler_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1925 +/- ##
==========================================
+ Coverage 68.59% 68.63% +0.04%
==========================================
Files 462 462
Lines 58222 58322 +100
==========================================
+ Hits 39936 40032 +96
- Misses 14602 14603 +1
- Partials 3684 3687 +3
... and 14 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary
env_passthroughandenv_passthrough_prefixesto extend filtered base environment inheritanceconfig.envPassthrough,config.envPassthroughPrefixes, and sharedextraEnvTesting
Summary by CodeRabbit
Release Notes
New Features
Documentation