-
-
Notifications
You must be signed in to change notification settings - Fork 223
feat(cmd): add --default-working-dir flag to start command
#1459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a --default-working-dir option and propagates it from CLI (start/enqueue) through the spec loader and builder into runtime, enabling a default working directory for DAGs without an explicit workingDir and passing that value into sub-DAG execution commands. Changes
Sequence DiagramsequenceDiagram
autonumber
participant User
participant CLI as CLI (start/enqueue)
participant Loader as Spec Loader
participant Builder as Spec Builder
participant Executor as SubDAG Executor
Note over CLI,Loader: CLI reads --default-working-dir flag
User->>CLI: invoke start/enqueue with --default-working-dir
CLI->>Loader: loadDAGWithParams(..., WithDefaultWorkingDir(value))
Loader->>Loader: set LoadOptions.defaultWorkingDir
Loader->>Builder: create BuildOpts with DefaultWorkingDir
Builder->>Builder: buildWorkingDir: choose explicit > DefaultWorkingDir > file dir
Loader-->>CLI: return DAG spec (with resolved workingDir)
CLI->>Executor: launch sub-DAG
Executor->>Executor: buildCommand() adds --default-working-dir if workDir present
Executor-->>User: sub-DAG process started with args (including default working dir)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
internal/cmd/flags.go (1)
160-165:defaultWorkingDirFlagdefinition is consistent and clearFlag name/description match the new behaviour, and leaving
bindViperunset keeps it strictly CLI-scoped, which seems appropriate here. If you ever want config-driven defaults, you could later addbindViper: true, but it’s not required for this PR.internal/core/spec/builder.go (1)
81-86: DefaultWorkingDir threading and precedence look correctAdding
DefaultWorkingDirtoBuildOptsand checking it inbuildWorkingDirbetween explicitspec.WorkingDirand file-based fallback gives the intended override semantics for inherited working dirs, matching the new tests. Since callers (CLI/sub-DAG runner) already pass a concrete working directory, skipping env/path expansion here is reasonable; if you ever expose more user-facing inputs, you might normalise that value before constructingBuildOptsrather than here.Also applies to: 644-680
internal/cmd/start.go (1)
60-60:--default-working-diris correctly wired into DAG loadingAdding
defaultWorkingDirFlagtostartFlagsand threading"default-working-dir"throughloadDAGWithParamsintospec.WithDefaultWorkingDircleanly connects the CLI flag toBuildOpts.DefaultWorkingDirfor both root and sub-DAG runs. The comment mentions sub-DAG inheritance (which is the main use case) but this also intentionally affects root DAGs when the flag is set, as covered byTestWithDefaultWorkingDir.Also applies to: 369-377
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
internal/cmd/enqueue.go(1 hunks)internal/cmd/flags.go(1 hunks)internal/cmd/start.go(2 hunks)internal/core/spec/builder.go(2 hunks)internal/core/spec/loader.go(4 hunks)internal/core/spec/loader_test.go(2 hunks)internal/integration/workingdir_test.go(2 hunks)internal/runtime/executor/dag_runner.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*.go: Backend entrypoint incmd/orchestrates the scheduler and CLI; runtime, persistence, and service layers sit underinternal/*(for exampleinternal/runtime,internal/persistence)
Keep Go filesgofmt/goimportsclean; use tabs, PascalCase for exported symbols (SchedulerClient), lowerCamelCase for locals, andErr...names for package-level errors
Repository linting relies ongolangci-lint; prefer idiomatic Go patterns, minimal global state, and structured logging helpers ininternal/common
Files:
internal/core/spec/builder.gointernal/cmd/start.gointernal/integration/workingdir_test.gointernal/core/spec/loader_test.gointernal/runtime/executor/dag_runner.gointernal/cmd/flags.gointernal/core/spec/loader.gointernal/cmd/enqueue.go
**/*_test.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*_test.go: Co-locate Go tests as*_test.go; favour table-driven cases and cover failure paths
Usestretchr/testify/requireand shared fixtures frominternal/testinstead of duplicating mocks
Files:
internal/integration/workingdir_test.gointernal/core/spec/loader_test.go
🧠 Learnings (1)
📚 Learning: 2025-12-04T10:34:17.051Z
Learnt from: CR
Repo: dagu-org/dagu PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-04T10:34:17.051Z
Learning: Applies to **/*_test.go : Co-locate Go tests as `*_test.go`; favour table-driven cases and cover failure paths
Applied to files:
internal/core/spec/loader_test.go
🧬 Code graph analysis (4)
internal/cmd/start.go (2)
internal/common/logger/context.go (1)
Errorf(75-77)internal/core/spec/loader.go (1)
WithDefaultWorkingDir(124-128)
internal/core/spec/loader_test.go (1)
internal/core/spec/loader.go (3)
LoadYAML(169-183)WithDefaultWorkingDir(124-128)Load(145-166)
internal/runtime/executor/dag_runner.go (2)
internal/common/config/context.go (1)
ConfigFileUsed(26-31)internal/core/dag.go (1)
DAG(33-135)
internal/core/spec/loader.go (1)
internal/core/spec/builder.go (1)
BuildFlag(56-56)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test on ubuntu-latest
🔇 Additional comments (5)
internal/cmd/enqueue.go (1)
32-32: Enqueue now correctly exposes--default-working-dirIncluding
defaultWorkingDirFlaginenqueueFlagskeeps enqueue’s DAG loading behaviour aligned withstart(both can now driveWithDefaultWorkingDirvialoadDAGWithParams). Looks good.internal/core/spec/loader_test.go (1)
3-13: NewTestWithDefaultWorkingDirthoroughly exercises precedence rulesThe added test cases (no file context, default vs file directory, explicit workingDir overriding the default) align with the new loader/builder semantics and should prevent regressions. Use of
t.Parallel,require, andassertis consistent with the existing suite and prior testing guidelines. Based on learnings, this is solid coverage.Also applies to: 549-617
internal/integration/workingdir_test.go (1)
20-22: Integration test expectations now match inherited/override semanticsThe updated description and
assert.Containschecks forcall_child_with_wdvscall_child_no_wdcorrectly encode the new behaviour: explicit subDAGworkingDiroverrides, while a missingworkingDirinherits the parent’s working directory for local runs. This gives good end-to-end coverage of the CLI + loader + executor path.Also applies to: 90-104
internal/runtime/executor/dag_runner.go (1)
119-134: SubDAG executor now correctly passes--default-working-dirtostartConditionally appending
--default-working-dir=<workDir>and moving the DAG path after config arguments keeps the command line well-formed while enabling the loader to resolve a default working directory for child DAGs. Combined withcmd.Dir = workDir, this should give the desired inheritance semantics for local sub-DAG execution.internal/core/spec/loader.go (1)
29-37: Loader-level defaultWorkingDir option is wired cleanly with one minor noteExtending
LoadOptionswithdefaultWorkingDir, addingWithDefaultWorkingDir, and threading that intoBuildOpts.DefaultWorkingDirin bothLoadandLoadYAMLgives a consistent API surface and matches the builder/test expectations.The repository uses keyed fields consistently in
BuildOptscomposite literals. Two emptyBuildOpts{}literals exist inloader_test.go(lines 200, 210), which are safe from field reordering concerns. All other instances explicitly name their fields.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1459 +/- ##
==========================================
- Coverage 59.85% 59.80% -0.06%
==========================================
Files 188 188
Lines 21238 21316 +78
==========================================
+ Hits 12713 12749 +36
- Misses 7202 7234 +32
- Partials 1323 1333 +10
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.