Skip to content

feat: auto-create default base.yaml with comprehensive field reference on first run#1737

Merged
yottahmd merged 3 commits intomainfrom
base-dag-default
Mar 7, 2026
Merged

feat: auto-create default base.yaml with comprehensive field reference on first run#1737
yottahmd merged 3 commits intomainfrom
base-dag-default

Conversation

@yottahmd
Copy link
Copy Markdown
Collaborator

@yottahmd yottahmd commented Mar 7, 2026

When Dagu starts and no base.yaml exists, a fully-commented default is created as a discoverable reference for all inheritable DAG settings. Uses marker file (.base-config-created) to avoid re-creation if the user intentionally deletes the file. Respects the skip_examples config flag.

Summary by CodeRabbit

  • New Features

    • Default base configuration template automatically created on initialization with all options as commented examples for reference.
    • Option to skip automatic template creation via configuration settings.
  • Tests

    • Added tests for initialization logic, file creation, and skip behavior validation.

…e on first run

When Dagu starts and no base.yaml exists, a fully-commented default is
created as a discoverable reference for all inheritable DAG settings.
Uses marker file (.base-config-created) to avoid re-creation if the
user intentionally deletes the file. Respects the skip_examples config
flag.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 7, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1fdd1626-d43d-4ff2-a40f-7c70308b0aca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds automatic initialization of a default base configuration file for DAG settings. When a context is created with a configured base config path, the system lazily creates a template YAML file with commented-out configuration options unless skipped or the file already exists.

Changes

Cohort / File(s) Summary
Context initialization
internal/cmd/context.go
Added filebaseconfig import and initialization logic to create default base config during context setup when path is configured.
Base config storage and templates
internal/persis/filebaseconfig/default_base_config.go, internal/persis/filebaseconfig/store.go
Introduced defaultBaseConfig constant template and enhanced Store with skipDefault flag, WithSkipDefault option, and Initialize() method for lazy creation of default config with marker file tracking.
Base config tests
internal/persis/filebaseconfig/store_test.go
Added comprehensive TestInitialize covering creation, skipping based on file/marker presence, and skipDefault flag behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Context as Context<br/>(cmd)
    participant Store as Store<br/>(filebaseconfig)
    participant FileSystem as File System

    Context->>Store: filebaseconfig.New(WithSkipDefault(...))
    Store-->>Context: Store instance

    Context->>Store: Initialize()
    activate Store
    Store->>Store: Check skipDefault flag
    Store->>FileSystem: Check if base config file exists
    FileSystem-->>Store: File status
    Store->>FileSystem: Check if marker file exists
    FileSystem-->>Store: Marker status
    Store->>FileSystem: Write default config (0600)
    FileSystem-->>Store: File written
    Store->>FileSystem: Write marker file
    FileSystem-->>Store: Marker written
    deactivate Store
    Store-->>Context: nil or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: auto-creating a default base.yaml with a comprehensive field reference on first run, which matches the PR's core functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch base-dag-default

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/persis/filebaseconfig/store.go (1)

66-86: Consider logging or handling the marker file write error.

Line 84 ignores the error when writing the marker file. While the primary config file write is handled correctly, silently ignoring marker file errors could lead to the default config being re-created on every startup if the marker consistently fails to write (e.g., due to permissions issues after the atomic write succeeds).

This is low-risk since re-creating an identical default file is idempotent, but logging a warning would aid debugging.

♻️ Optional: Log marker file write failure
-	_ = os.WriteFile(markerFile, markerContent, filePermissions)
+	if err := os.WriteFile(markerFile, markerContent, filePermissions); err != nil {
+		// Non-fatal: worst case is re-creating the same default on next startup
+		return nil
+	}

Alternatively, if you have access to a logger in this package, log a warning instead of silently ignoring.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/persis/filebaseconfig/store.go` around lines 66 - 86, The Initialize
method currently ignores the error returned by os.WriteFile when creating
markerFile; update Store.Initialize to handle that error by checking the
os.WriteFile return value and emitting a warning (via the package logger if
available, otherwise fmt.Fprintf to stderr) including the markerFile path and
the error; do not change the primary return behavior (still return nil on
success), but ensure failures writing markerFile are logged so repeated
re-creation of defaultBaseConfig can be diagnosed (refer to Store.Initialize,
markerFile, markerContent, and filePermissions).
🤖 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/cmd/context.go`:
- Around line 252-262: The cfg.Core.SkipExamples flag is being misused to
control base config creation; introduce a new boolean option (e.g.,
cfg.Core.SkipBaseConfig) and use it when calling
filebaseconfig.New(cfg.Paths.BaseConfig, filebaseconfig.WithSkipDefault(...))
instead of cfg.Core.SkipExamples so example DAG creation and base-config
auto-creation can be toggled independently; also ensure filebaseconfig.New
failures are not swallowed—when bcErr != nil, call logger.Warn(ctx, "Failed to
create base config store", tag.Error(bcErr)) (similar to the existing
bcStore.Initialize error handling that uses logger.Warn with
tag.Error(initErr)), and keep the existing bcStore.Initialize error logging for
initErr.

In `@internal/persis/filebaseconfig/default_base_config.go`:
- Around line 1-6: This file is missing the required GPL v3 license header; run
the project's license tool to add it: invoke the repository's make addlicense
target (e.g., `make addlicense`) to insert the standard GPLv3 header at the top
of internal/persis/filebaseconfig/default_base_config.go so the header appears
before the package declaration and constants like defaultBaseConfig; do not
manually edit the file header—use the automated tool to ensure the correct
boilerplate is applied.

---

Nitpick comments:
In `@internal/persis/filebaseconfig/store.go`:
- Around line 66-86: The Initialize method currently ignores the error returned
by os.WriteFile when creating markerFile; update Store.Initialize to handle that
error by checking the os.WriteFile return value and emitting a warning (via the
package logger if available, otherwise fmt.Fprintf to stderr) including the
markerFile path and the error; do not change the primary return behavior (still
return nil on success), but ensure failures writing markerFile are logged so
repeated re-creation of defaultBaseConfig can be diagnosed (refer to
Store.Initialize, markerFile, markerContent, and filePermissions).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5216b28-2d7c-4a49-b377-5c98256ecd66

📥 Commits

Reviewing files that changed from the base of the PR and between 8f70874 and a6313b8.

📒 Files selected for processing (4)
  • internal/cmd/context.go
  • internal/persis/filebaseconfig/default_base_config.go
  • internal/persis/filebaseconfig/store.go
  • internal/persis/filebaseconfig/store_test.go

Comment thread internal/cmd/context.go
Comment thread internal/persis/filebaseconfig/default_base_config.go
yottahmd added 2 commits March 8, 2026 01:17
- Log warning when filebaseconfig.New() fails instead of silently ignoring
- Add GPL v3 license headers via make addlicense
- Update SkipExamples comment to document its broader scope (examples + base config)
@yottahmd yottahmd merged commit dc43cdf into main Mar 7, 2026
4 checks passed
@yottahmd yottahmd deleted the base-dag-default branch March 7, 2026 16:39
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.61%. Comparing base (41b5945) to head (d2e0415).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
internal/cmd/context.go 40.00% 2 Missing and 4 partials ⚠️
internal/persis/filebaseconfig/store.go 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1737      +/-   ##
==========================================
- Coverage   69.67%   69.61%   -0.07%     
==========================================
  Files         402      402              
  Lines       44607    44668      +61     
==========================================
+ Hits        31082    31094      +12     
  Misses      11019    11019              
- Partials     2506     2555      +49     
Files with missing lines Coverage Δ
internal/cmn/config/config.go 73.10% <ø> (ø)
internal/persis/filebaseconfig/store.go 72.54% <88.23%> (+13.72%) ⬆️
internal/cmd/context.go 55.75% <40.00%> (-12.61%) ⬇️

... and 16 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb9b32c...d2e0415. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant