Skip to content

Check real child DAGs and add dagu test flags - #4083

Merged
yohamta0 merged 3 commits into
mainfrom
wt/t12-dagu-test-flags
Nov 23, 2026
Merged

yohamta0 merged 3 commits into
mainfrom
wt/t12-dagu-test-flags

Conversation

@yohamta0

@yohamta0 yohamta0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

#4082 added dagu test with the text report, and made a case with a real step that starts a child run invalid, since it did not check the child yet. This finishes T12 of #4029. The child DAG of a real step is checked by the fail-closed rule, so a real child of side-effect-free steps runs and one with an unhandled source makes the case invalid. It also adds the three flags Spec 101 defines for CI and debugging: --format json, --run, and --keep.

Changes

  • A real dag.run step, a real parallel step, or a real handler resolves its child DAG before the case runs, as an in-process child run loads it. Each source of the fail-closed rule in the child is listed as step <step>, child <DAG>, <source>. A child named by a reference, or one that does not resolve, makes the case invalid.
  • --format json (-f) writes one JSON object to stdout once every case has ended. cases holds file, name, result, duration_ms, failures or errors, and case_dir. invalid_files appears when a file is invalid. Nothing else goes to stdout.
  • --run <regexp> runs only the cases whose name the RE2 expression matches. A case it does not select is not reported, and a test file error still is.
  • --keep keeps each case directory and reports its absolute path: a case directory <path> line in text, case_dir in JSON.
  • An invalid --run or --format exits with status 2.
  • Spec 101 states the error failure: a run that cannot reach a terminal status, such as one with a wait a test cannot settle, fails with "field": "error" and the reason as actual.
  • The --format check is shared with dagu dry: dryOutputFormat is renamed outputFormatParam.

Before: dagu test --format json ... fails with unknown flag: --format, and a case with a real dag.run step is invalid. After:

$ dagu test --format json workflows/failing.test.yaml workflows/smoke.test.yaml
{"cases":[{"file":"workflows/failing.test.yaml","name":"a failed build skips the deploy","result":"fail","duration_ms":124,"failures":[{"field":"status","expected":"succeeded","actual":"failed"},{"step":"deploy","field":"status","expected":"skipped","actual":"aborted"},{"step":"build","field":"attempts","expected":2,"actual":1}]}],"invalid_files":[{"file":"workflows/smoke.test.yaml","errors":[{"message":"reads as a DAG, with steps and no cases; rename it so its name does not end in .test.yaml or .test.yml"}]}]}

$ dagu test --run stops --keep workflows/release.test.yaml
PASS workflows/release.test.yaml: a failed build stops the deploy (0.12s)
  case directory /var/folders/.../T/dagu-case-2228761123
1 case: 1 passed, 0 failed

$ dagu test workflows/parent.test.yaml
PASS workflows/parent.test.yaml: a real child of side-effect-free steps runs in the case (0.31s)
INVALID workflows/parent.test.yaml: a real child with a command step is invalid
  step call, child child, step write: command has side effects; a child of a real step takes no mock; mock call instead
2 cases: 1 passed, 0 failed, 1 invalid

Core change

CheckRealChildren walks the steps and handlers that a case runs for real and start a child run. It checks each resolved child with the fail-closed checker, as a case with a real step and no mocks, and reports its sources under the parent step's label, with the fix "mock <step> instead". The command passes a resolver that loads a document of the parent's file, or the DAG the repository finds, without base-config handlers and with every params[].eval deferred. The report keeps its counts and either writes text as each case ends or, with --format json, collects the cases and encodes them once in writeSummary.

internal/dagtest/realchild.go:19

func CheckRealChildren(dag *ir.DAG, c Case, resolve func(name string) (*ir.DAG, error)) []Finding {
	...
		child, err := resolve(name)
		if err != nil {
			findings = append(findings, Finding{Source: label, Message: fmt.Sprintf("child DAG %s cannot be resolved: %v; mock it", name, err)})
			continue
		}
		check := checker{fix: fix}
		check.checkDAG(child, Handling{}, true)
		for _, f := range check.findings {
			findings = append(findings, Finding{Source: label + ", child " + name + ", " + f.Source, Message: f.Message})
		}

internal/cmd/test.go:262

		// A case that --run does not select is neither checked nor reported.
		if opts.run != nil && !opts.run.MatchString(c.Name) {
			continue
		}

internal/cmd/test_report_json.go:51

	for _, f := range c.failures {
		failure := jsonFailure{Step: f.step, Field: f.field, Expected: f.expected, Actual: f.actual}
		if f.field == failureTimeout {
			// The JSON report gives the --timeout limit in milliseconds.
			failure.Expected = f.expected.(time.Duration).Milliseconds()
		}
		out.Failures = append(out.Failures, failure)
	}

Testing

  • TestCheckRealChildren: child sources under the parent's label, a child named by a reference, a child that does not resolve, a real handler's child, and no check for dag.enqueue.
  • Conformance TestWorkflowTests/parent.test.yaml (criterion 32): a real child of side-effect-free steps runs and skips its 60-second repeat interval, and a real child with a run step makes the case invalid without running it.
  • TestWorkflowTestJSON: one JSON object, the failure objects of a failed case with numeric attempts, the errors of an invalid case without duration_ms, and invalid_files.
  • TestWorkflowTestJSONTimeout: a timeout failure carries the limit in milliseconds.
  • TestWorkflowTestRun: selection by name, no match (exit 0, zero cases), and a file error still reported.
  • TestWorkflowTestKeep: in text and JSON, the reported absolute path holds the mocked step's redirect file with FAIL, as Spec 101's "Side Effects That Stay Off" example states.
  • TestWorkflowTestArguments gains an invalid --run and an unknown --format.
  • Run locally: the Spec 101 conformance package with -run TestWorkflowTest, by name TestCheckRealChildren, TestCheckFailClosed, TestSchemaAccepts, and gofmt -l and go vet on the touched packages. The rest runs in CI.

Performance

No performance risk: this touches no server request, tick, or SSE path. The child check loads each real child DAG once per case before the case runs. --format json holds one small object per case in memory until the end. --keep leaves each case directory, one run's records and logs, for the user to remove.

Compatibility

CLI only: three new flags on dagu test, and real child runs now run in a case instead of making it invalid. dagu dry --format keeps its behavior and error text.

Exported identifiers

For maintainer approval: dagtest.CheckRealChildren, which the command calls. The resolver is a plain function parameter, with no named type.

Out of scope

The JSON fields that T17 adds: fix, file_fix, default_mocked, auto_approved, and notifications, and the failure fields for outputs, streams, and notifications.

Agent

Claude Code, claude-opus-5-5, xhigh

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The workflow-test command adds case filtering, JSON reports, and retained case directories. Real child DAGs are now resolved and checked during case validation. The changes also update report documentation, CLI references, and conformance tests.

Changes: Workflow Test

Layer / File(s) Summary
CLI options and case selection
internal/cmd/test.go, internal/cmd/dry.go, conformance/spec101_workflow_tests/flags_test.go, conformance/spec101_workflow_tests/workflow_tests_test.go, llms.txt, skills/dagu/references/cli.md, specs/101-workflow-tests.md
The command adds --run, --format, and --keep. It filters cases by name and records retained case directories. The shared output-format parser is also used by dagu dry.
Text and JSON reports
internal/cmd/test_report.go, internal/cmd/test_report_json.go, internal/cmd/test.go, conformance/spec101_workflow_tests/flags_test.go, specs/101-workflow-tests.md
The report writer collects case results and invalid files for JSON output, which is encoded after case execution. Text output continues to report results and includes retained case directories. Tests cover JSON results, errors, durations, and timeouts.
Real child DAG validation
internal/dagtest/realchild.go, internal/dagtest/failclosed.go, internal/cmd/test.go, internal/cmd/test_check.go, internal/dagtest/realchild_test.go, internal/dagtest/testdata/testfiles/*, conformance/spec101_workflow_tests/workflow_tests_test.go, skills/dagu/references/cli.md
Real child DAGs are resolved and checked with fail-closed validation. Findings identify dynamic or unresolved child names and child DAGs with steps or sources that need handling. Fixtures and conformance expectations cover these cases.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DaguTest
  participant CheckRealChildren
  participant childResolver
  participant DAGLoader
  participant CheckFailClosed
  DaguTest->>CheckRealChildren: validate real child steps
  CheckRealChildren->>childResolver: resolve child name
  childResolver->>DAGLoader: load local DAG or search repository
  DAGLoader-->>childResolver: DAG or resolution error
  childResolver-->>CheckRealChildren: resolved DAG or error
  CheckRealChildren->>CheckFailClosed: inspect resolved child
  CheckFailClosed-->>CheckRealChildren: return findings
  CheckRealChildren-->>DaguTest: return findings
Loading

Possibly related issues

  • dagucloud/dagu#4029: This change implements the dagu test flags and child checks described in the issue.
  • dagucloud/dagu#3557: This change updates the CLI reference and regenerates llms.txt, addressing the reported documentation drift in part.

Possibly related PRs

  • dagucloud/dagu#4082: This PR continues the dagu test implementation and replaces the blanket rejection of real child runs with child-DAG checks.
  • dagucloud/dagu#4058: The PR description says the shared RunsCommand predicate is used by the fail-closed checker, which this change invokes for child DAGs.
Merge Risk: Minimal · up to 369db

This adds --run, --format and --keep to dagu test and checks real child DAGs before a case runs. I found no concrete defect, and the earlier concerns about child loading, parameter validation and step lookup were not supported. The change looks ready to merge, subject to the CI run the author mentions.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Check real child DAGs and add dagu test flags" names the two main changes: real child DAG validation and the new dagu test flags (--format, --run, --keep). Both appear in the summaries and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template closely. It gives a summary of the real-child check and the three new flags (--format json, --run, --keep). It lists the changes with before/after CLI output and s…
Full details: Title check

Explanation

The title "Check real child DAGs and add dagu test flags" names the two main changes: real child DAG validation and the new dagu test flags (--format, --run, --keep). Both appear in the summaries and objectives, so the title matches the changeset.

Full details: Description check

Explanation

The description follows the template closely. It gives a summary of the real-child check and the three new flags (--format json, --run, --keep). It lists the changes with before/after CLI output and shows the core code with file and line references. It covers testing with named tests and local commands, and it has a Performance section, a Compatibility section, an Out of scope section, and an Agent entry. Two template items are weaker: the Related Issues section is not filled in (it references #4029 T12 in the summary but has no 'Closes' line), and the checklist items are not ticked. Those gaps are non-critical, so the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3a658338-68cd-4fc9-a9e1-14d46bfcb26b
Commits

Reviewing files that changed from the base of the PR and between 6ac4a85 and 369db37.

Files selected for processing: 15

  • conformance/spec101_workflow_tests/flags_test.go
  • conformance/spec101_workflow_tests/workflow_tests_test.go
  • internal/cmd/dry.go
  • internal/cmd/test.go
  • internal/cmd/test_check.go
  • internal/cmd/test_report.go
  • internal/cmd/test_report_json.go
  • internal/dagtest/failclosed.go
  • internal/dagtest/realchild.go
  • internal/dagtest/realchild_test.go
  • internal/dagtest/testdata/testfiles/children.test.yaml
  • internal/dagtest/testdata/testfiles/children.yaml
  • llms.txt
  • skills/dagu/references/cli.md
  • specs/101-workflow-tests.md
Files with no reviewable changes: 1

  • internal/cmd/test_check.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

This was referenced Nov 23, 2026
@yohamta0
yohamta0 force-pushed the wt/t12-dagu-test-flags branch from 1e52d7e to 1c7a822 Compare November 23, 2026 09:38
@yohamta0 yohamta0 changed the title Add --run, --format, and --keep to dagu test Check real child DAGs and add dagu test flags Nov 23, 2026
@yohamta0
yohamta0 force-pushed the wt/t12-dagu-test-flags branch from 1c7a822 to 23ff070 Compare November 23, 2026 10:21
@yohamta0
yohamta0 marked this pull request as ready for review November 23, 2026 10:21
@yohamta0
yohamta0 force-pushed the wt/t12-dagu-test-flags branch from 23ff070 to 369db37 Compare November 23, 2026 11:07
@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yohamta0
yohamta0 changed the base branch from wt/t12-dagu-test to main November 23, 2026 11:24
A real dag.run step, a real parallel step, or a real handler starts its
child in the case, and the child takes no mocks, so a source of the
fail-closed rule in it must make the case invalid before anything runs.
CheckRealChildren resolves each such child as an in-process child run
loads it and reports its sources under the step's label, and reports a
child that is named by a reference or does not resolve. It replaces the
check that made every such case invalid, so a real child of
side-effect-free steps now runs in the case.
--run selects cases by an RE2 expression on their names, and a test file
error is still reported. --format json writes one JSON object once every
case has ended, so CI can read the outcome of each case. --keep keeps
each case directory and reports its path, so an author can read a case's
logs and redirect files. The format check is shared with dagu dry.
Spec 101's status and the CLI skill reference now list --run, --format,
and --keep, and llms.txt is regenerated. The reference also says that a
real step's child runs in the case and is checked by the fail-closed
rule, in place of the note that such a case is invalid. Spec 101 also
states the error failure: a run that cannot reach a terminal status,
such as one with a wait a test cannot settle, fails with it, so the JSON
report's field and its actual value are written down.
@yohamta0
yohamta0 force-pushed the wt/t12-dagu-test-flags branch from 369db37 to 631638a Compare November 23, 2026 11:25
@yohamta0 yohamta0 added the full-ci Run the Windows, conformance, and E2E checks on this pull request label Nov 23, 2026
@yohamta0
yohamta0 merged commit 5f45acf into main Nov 23, 2026
25 of 31 checks passed
@yohamta0
yohamta0 deleted the wt/t12-dagu-test-flags branch November 23, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the Windows, conformance, and E2E checks on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant