Skip to content

Comments

ingest yaml with filename#1630

Merged
yottahmd merged 1 commit intodagu-org:mainfrom
sahalbelam:fname-ingest
Feb 13, 2026
Merged

ingest yaml with filename#1630
yottahmd merged 1 commit intodagu-org:mainfrom
sahalbelam:fname-ingest

Conversation

@sahalbelam
Copy link
Contributor

@sahalbelam sahalbelam commented Feb 4, 2026

now dags can only be ingest with the name.
user has to define ALT_DAGS_DIR variable in base.yaml
Spec is still working. #1609

Summary by CodeRabbit

  • New Features
    • DAG run enqueue now supports filename-based references: Users can trigger DAG execution by specifying an existing YAML DAG filename, in addition to providing inline specifications. The enqueue endpoint accepts either a spec or filename, but not both.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 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.

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 PR extends the enqueue DAG run endpoint to accept either an inline YAML specification or a filename reference pointing to an existing YAML file. The request body is modified with a new optional filename field and a oneOf constraint, while backend logic handles reading and validating YAML files from disk when a filename is provided.

Changes

Cohort / File(s) Summary
API Generation
api/v2/api.gen.go
Updated EnqueueDAGRunFromSpecJSONBody struct: Spec field changed to pointer type, new optional Filename field added, and union json.RawMessage field added to support union-based unmarshalling.
OpenAPI Specification
api/v2/api.yaml
Modified /dags/{fileName}/enqueue endpoint to accept either inline spec or filename via new optional filename field and oneOf constraint instead of requiring spec alone.
Backend Implementation
internal/service/frontend/api/v2/dagruns.go
Added filename-based YAML loading in EnqueueDAGRunFromSpec: validates mutual exclusivity of spec/filename, reads YAML files from disk with 1 MiB size limit, resolves paths via ALT_DAGS_DIR environment variable, and loads final DAG from either inline or file-based content.
Test Updates
internal/service/frontend/api/v2/dags_test.go
Updated test to pass Spec as pointer type (\&spec) instead of value type to match new struct field signature.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Handler as API Handler
    participant FileSystem as File System
    participant Config as Base Config
    participant DAGLoader as DAG Loader

    Client->>Handler: POST /dags/{fileName}/enqueue<br/>(with Filename)
    Handler->>Handler: Validate: not both spec & filename
    Handler->>Config: Read base config
    Config-->>Handler: Config data
    Handler->>Handler: Resolve ALT_DAGS_DIR from env
    Handler->>FileSystem: Read YAML file<br/>(check .yaml/.yml extension)
    FileSystem-->>Handler: File content (≤1 MiB)
    Handler->>DAGLoader: Load DAG from file content
    DAGLoader-->>Handler: DAG object
    Handler-->>Client: 200 OK (DAG run enqueued)
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 0.00% 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 'ingest yaml with filename' accurately describes the main change: adding support for ingesting DAGs via filename instead of only inline spec.

✏️ 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

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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/service/frontend/api/v2/dagruns.go (1)

261-265: ⚠️ Potential issue | 🟡 Minor

Audit metadata should reflect filename-based enqueue.

inline is always true, even when a filename is used, which makes audit logs inaccurate.

🧾 Suggested audit flag fix
-	detailsMap := map[string]any{
-		"dag_name":   dag.Name,
-		"dag_run_id": dagRunId,
-		"inline":     true,
-	}
+	inline := request.Body.Spec != nil
+	detailsMap := map[string]any{
+		"dag_name":   dag.Name,
+		"dag_run_id": dagRunId,
+		"inline":     inline,
+	}
+	if request.Body.Filename != nil {
+		detailsMap["filename"] = *request.Body.Filename
+	}
🤖 Fix all issues with AI agents
In `@internal/service/frontend/api/v2/dagruns.go`:
- Around line 161-166: Update the user-facing error message so it references the
actual API field name `filename` instead of “url”: change the Error returned in
the branch that checks request.Body.Spec and request.Body.Filename (the
conditional using request.Body.Spec == nil && request.Body.Filename == nil ||
request.Body.Spec != nil && request.Body.Filename != nil) to set Message to
something like "either give spec or filename; don't give both" so clients see
the correct field name.
- Around line 193-212: The current code unsafely assumes
obj["env"].([]any)[0].(string) and will panic or miss ALT_DAGS_DIR; change the
logic in the block after yaml.Unmarshal by: validate that obj["env"] exists and
is a []any, iterate over each element, assert each entry is a string, look for a
string that starts with "ALT_DAGS_DIR=" (or split on '=' and compare key),
extract the value into altDagDir when found, and only then trim the prefix and
rebuild filename; if no ALT_DAGS_DIR is found return the existing Error
response; keep using the same variables (obj, altDagDir, filename) and preserve
the yaml.Unmarshal error handling.
🧹 Nitpick comments (1)
api/v2/api.yaml (1)

1614-1622: Constrain filename to allowed basename + extension.

The backend only accepts .yaml/.yml; the schema currently allows any string. Adding a pattern reduces invalid requests and clarifies the contract.

📄 Suggested schema constraint
                 filename:
                   type: string
                   description: "Filename for the yaml file"
+                  pattern: "^[a-zA-Z0-9._-]+\\.(ya?ml)$"

@sahalisro-blip
Copy link
Contributor

for this, config.yaml will have one more variable altDagDir under paths: which will be used for locating the alternate dags
right @yottahmd ?

@yottahmd
Copy link
Collaborator

yottahmd commented Feb 5, 2026

@sahalisro-blip Yes, I think that's correct.

|---------------------|---------|-------------|
| `DAGU_HOME` | - | Base directory that overrides all path configurations |
| `DAGU_DAGS_DIR` | `~/.config/dagu/dags` | Directory for DAG definitions |
| `DAGU_ALT_DAGS_DIR` | - | Additional directory to search for DAG definitions |
Copy link

Choose a reason for hiding this comment

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

Please add default path

~/.config/dagu/alt_dags

Copy link
Collaborator

@yottahmd yottahmd Feb 13, 2026

Choose a reason for hiding this comment

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

Let's keep default value empty to avoid surprises for those users who are not familiar with this config.

@yottahmd yottahmd force-pushed the fname-ingest branch 6 times, most recently from d8ded69 to ec563e6 Compare February 13, 2026 12:35
Copy link
Collaborator

@yottahmd yottahmd left a comment

Choose a reason for hiding this comment

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

LGTM 🚀🚀🚀 Thank you very much!

@yottahmd yottahmd merged commit 228e4ae into dagu-org:main Feb 13, 2026
5 checks passed
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.10%. Comparing base (5394d09) to head (c1cb9d8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/persis/filedag/store.go 57.14% 0 Missing and 3 partials ⚠️
internal/cmd/context.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1630      +/-   ##
==========================================
- Coverage   70.18%   70.10%   -0.08%     
==========================================
  Files         344      344              
  Lines       38257    38260       +3     
==========================================
- Hits        26851    26824      -27     
- Misses       9273     9276       +3     
- Partials     2133     2160      +27     
Files with missing lines Coverage Δ
internal/cmn/config/config.go 76.28% <ø> (ø)
internal/cmn/config/loader.go 80.90% <100.00%> (-2.18%) ⬇️
internal/cmd/context.go 70.27% <50.00%> (-0.35%) ⬇️
internal/persis/filedag/store.go 73.86% <57.14%> (-0.87%) ⬇️

... and 9 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 5394d09...c1cb9d8. 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.

4 participants