feat: add DAG core functions — parse, validate, topo sort, resolve env, cron match (0007a, 0007d)

Pure functions for parsing dagu-compatible YAML, validating DAG structure,
topological sorting with parallel levels (Kahn's algorithm), and env variable
resolution. Also adds cron_match for schedule matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 13:05:05 +02:00
parent cb96e85b69
commit c3dfc9315f
21 changed files with 1569 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
---
name: dag_parse
kind: function
lang: go
domain: core
version: "1.0.0"
purity: pure
signature: "func DagParse(data []byte) (DagDefinition, error)"
description: "Parsea YAML de definicion de DAG en formato compatible con Dagu. Soporta schedule como string o lista, env como lista de maps single-key (formato Dagu), handler_on y handlers como aliases, steps con command/script/depends/continue_on, y type graph."
tags: [dag, yaml, parsing, workflow, dagu, pure]
uses_functions: []
uses_types: [dag_definition_go_core, dag_step_go_core, dag_handlers_go_core]
returns: []
returns_optional: false
error_type: ""
imports: [fmt, strings, gopkg.in/yaml.v3]
params:
- name: data
desc: "contenido YAML de un archivo de definicion de DAG en formato Dagu"
output: "DagDefinition con todos los campos normalizados; error si el YAML es sintaticamente invalido"
tested: true
tests:
- "parsea DAG simple con steps y depends"
- "parsea schedule como string y como lista"
- "parsea env en formato lista de maps"
- "parsea handler_on y handlers como alias"
- "parsea continue_on y working_dir a nivel step"
- "parsea type graph"
test_file_path: "functions/core/dag_parse_test.go"
file_path: "functions/core/dag_parse.go"
---
## Ejemplo
```go
data := []byte(`
name: mi-dag
schedule: "0 9 * * *"
steps:
- name: hello
command: echo "hello"
- name: world
command: echo "world"
depends: [hello]
`)
dag, err := DagParse(data)
// dag.Name = "mi-dag"
// dag.Schedule = ["0 9 * * *"]
// dag.Steps[1].Depends = ["hello"]
```
## Notas
Funcion pura (el YAML es inmutable, no hay I/O). Internamente usa un struct rawDag para deserializar loosely y luego normaliza campos polimorficos. La estrategia de normalizacion: schedule string->[]string, env lista->map, handlers single-o-lista->[]DagStep. handler_on tiene precedencia sobre handlers si ambos estan presentes.