testing-dags by astronomer/agents
npx skills add https://github.com/astronomer/agents --skill testing-dags使用 af 命令在迭代周期中测试、调试和修复 DAG。
使用 uvx 运行所有 af 命令(无需安装):
uvx --from astro-airflow-mcp af <command>
在整个文档中,af 是 uvx --from astro-airflow-mcp af 的简写。
如果用户可以使用 Astro CLI,这些命令可以在无需运行 Airflow 实例的情况下提供快速反馈:
# 解析 DAG 以捕获导入错误、语法问题和 DAG 级别的问题
astro dev parse
# 对 DAG 运行 pytest(运行 tests/ 目录中的测试)
astro dev pytest
在开发过程中使用这些命令进行快速验证。如需针对实时 Airflow 实例进行完整的端到端测试,请继续阅读下面的触发并等待工作流。
当用户要求测试 DAG 时,您的首要且唯一的操作应该是:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
af runs trigger-wait <dag_id>
请勿:
af dags listaf dags getaf dags errorsgrep、ls 或任何其他 bash 命令直接触发 DAG。 如果失败,再进行调试。
┌─────────────────────────────────────┐
│ 1. 触发并等待 │
│ 运行 DAG,等待完成 │
└─────────────────────────────────────┘
↓
┌───────┴───────┐
↓ ↓
┌─────────┐ ┌──────────┐
│ 成功 │ │ 失败 │
│ 完成! │ │ 调试... │
└─────────┘ └──────────┘
↓
┌─────────────────────────────────────┐
│ 2. 调试(仅在失败时) │
│ 获取日志,识别根本原因 │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ 3. 修复并重新测试 │
│ 应用修复,从步骤 1 重新开始 │
└─────────────────────────────────────┘
理念:先尝试,失败再调试。 不要在起飞前检查上浪费时间——直接运行 DAG,如果出现问题再进行诊断。
使用 af runs trigger-wait 测试 DAG:
af runs trigger-wait <dag_id> --timeout 300
示例:
af runs trigger-wait my_dag --timeout 300
为什么这是首选方法:
成功:
{
"dag_run": {
"dag_id": "my_dag",
"dag_run_id": "manual__2025-01-14T...",
"state": "success",
"start_date": "...",
"end_date": "..."
},
"timed_out": false,
"elapsed_seconds": 45.2
}
失败:
{
"dag_run": {
"state": "failed"
},
"timed_out": false,
"elapsed_seconds": 30.1,
"failed_tasks": [
{
"task_id": "extract_data",
"state": "failed",
"try_number": 2
}
]
}
超时:
{
"dag_id": "my_dag",
"dag_run_id": "manual__...",
"state": "running",
"timed_out": true,
"elapsed_seconds": 300.0,
"message": "Timed out after 300 seconds. DAG run is still running."
}
仅在需要更多控制时使用此方法:
# 步骤 1:触发
af runs trigger my_dag
# 返回:{"dag_run_id": "manual__...", "state": "queued"}
# 步骤 2:检查状态
af runs get my_dag manual__2025-01-14T...
# 返回当前状态
DAG 运行成功。为用户总结:
完成!
DAG 仍在运行。选项:
af runs get <dag_id> <dag_run_id>进入阶段 2(调试)以识别根本原因。
当 DAG 运行失败时,使用这些命令进行诊断:
af runs diagnose <dag_id> <dag_run_id>
一次调用返回:
af tasks logs <dag_id> <dag_run_id> <task_id>
示例:
af tasks logs my_dag manual__2025-01-14T... extract_data
针对特定重试尝试:
af tasks logs my_dag manual__2025-01-14T... extract_data --try 2
查找:
如果一个任务显示 upstream_failed,根本原因在于上游任务。使用 af runs diagnose 查找实际失败的任务。
如果因为 DAG 不存在而触发失败:
af dags errors
这将揭示导致 DAG 无法加载的语法错误或缺失的依赖项。
一旦识别出问题:
| 问题 | 修复方法 |
|---|---|
| 缺少导入 | 添加到 DAG 文件 |
| 缺少包 | 添加到 requirements.txt |
| 连接错误 | 检查 af config connections,验证凭据 |
| 变量缺失 | 检查 af config variables,如果需要则创建 |
| 超时 | 增加任务超时时间或优化查询 |
| 权限错误 | 检查连接中的凭据 |
af runs trigger-wait <dag_id>重复测试 → 调试 → 修复循环,直到 DAG 成功。
| 阶段 | 命令 | 用途 |
|---|---|---|
| 测试 | af runs trigger-wait <dag_id> | 主要测试方法 — 从此处开始 |
| 测试 | af runs trigger <dag_id> | 开始运行(替代方案) |
| 测试 | af runs get <dag_id> <run_id> | 检查运行状态 |
| 调试 | af runs diagnose <dag_id> <run_id> | 全面的失败诊断 |
| 调试 | af tasks logs <dag_id> <run_id> <task_id> | 获取任务输出/错误 |
| 调试 | af dags errors | 检查解析错误(如果 DAG 无法加载) |
| 调试 | af dags get <dag_id> | 验证 DAG 配置 |
| 调试 | af dags explore <dag_id> | 完整的 DAG 检查 |
| 配置 | af config connections | 列出连接 |
| 配置 | af config variables | 列出变量 |
af runs trigger-wait my_dag
# 成功!完成。
# 1. 运行并等待
af runs trigger-wait my_dag
# 失败...
# 2. 查找失败的任务
af runs diagnose my_dag manual__2025-01-14T...
# 3. 获取错误详情
af tasks logs my_dag manual__2025-01-14T... extract_data
# 4. [在 DAG 代码中修复问题]
# 5. 重新测试
af runs trigger-wait my_dag
# 1. 触发失败 - 未找到 DAG
af runs trigger-wait my_dag
# 错误:未找到 DAG
# 2. 查找解析错误
af dags errors
# 3. [在 DAG 代码中修复问题]
# 4. 重新测试
af runs trigger-wait my_dag
# 1. 获取失败摘要
af runs diagnose my_dag scheduled__2025-01-14T...
# 2. 从失败任务获取错误
af tasks logs my_dag scheduled__2025-01-14T... failed_task_id
# 3. [修复问题]
# 4. 重新测试
af runs trigger-wait my_dag
af runs trigger-wait my_dag --conf '{"env": "staging", "batch_size": 100}' --timeout 600
# 等待最多 1 小时
af runs trigger-wait my_dag --timeout 3600
# 如果超时,检查当前状态
af runs get my_dag manual__2025-01-14T...
连接被拒绝 / 超时:
af config connections 中的主机/端口是否正确ModuleNotFoundError:
requirements.txt 中缺少包PermissionError:
任务超时:
任务日志通常显示:
重点关注失败任务日志底部的异常。
Astro 部署支持环境升级,这有助于构建您的测试工作流:
astro deploy --dags 自由测试 DAG,实现快速迭代每周安装次数
387
仓库
GitHub 星标数
269
首次出现
2026 年 1 月 23 日
安全审计
安装于
opencode275
codex269
cursor268
github-copilot265
gemini-cli250
claude-code241
Use af commands to test, debug, and fix DAGs in iterative cycles.
Run all af commands using uvx (no installation required):
uvx --from astro-airflow-mcp af <command>
Throughout this document, af is shorthand for uvx --from astro-airflow-mcp af.
If the user has the Astro CLI available, these commands provide fast feedback without needing a running Airflow instance:
# Parse DAGs to catch import errors, syntax issues, and DAG-level problems
astro dev parse
# Run pytest against DAGs (runs tests in tests/ directory)
astro dev pytest
Use these for quick validation during development. For full end-to-end testing against a live Airflow instance, continue to the trigger-and-wait workflow below.
When the user asks to test a DAG, your FIRST AND ONLY action should be:
af runs trigger-wait <dag_id>
DO NOT:
af dags list firstaf dags get firstaf dags errors firstgrep or ls or any other bash commandJust trigger the DAG. If it fails, THEN debug.
┌─────────────────────────────────────┐
│ 1. TRIGGER AND WAIT │
│ Run DAG, wait for completion │
└─────────────────────────────────────┘
↓
┌───────┴───────┐
↓ ↓
┌─────────┐ ┌──────────┐
│ SUCCESS │ │ FAILED │
│ Done! │ │ Debug... │
└─────────┘ └──────────┘
↓
┌─────────────────────────────────────┐
│ 2. DEBUG (only if failed) │
│ Get logs, identify root cause │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ 3. FIX AND RETEST │
│ Apply fix, restart from step 1 │
└─────────────────────────────────────┘
Philosophy: Try first, debug on failure. Don't waste time on pre-flight checks — just run the DAG and diagnose if something goes wrong.
Use af runs trigger-wait to test the DAG:
af runs trigger-wait <dag_id> --timeout 300
Example:
af runs trigger-wait my_dag --timeout 300
Why this is the preferred method:
Success:
{
"dag_run": {
"dag_id": "my_dag",
"dag_run_id": "manual__2025-01-14T...",
"state": "success",
"start_date": "...",
"end_date": "..."
},
"timed_out": false,
"elapsed_seconds": 45.2
}
Failure:
{
"dag_run": {
"state": "failed"
},
"timed_out": false,
"elapsed_seconds": 30.1,
"failed_tasks": [
{
"task_id": "extract_data",
"state": "failed",
"try_number": 2
}
]
}
Timeout:
{
"dag_id": "my_dag",
"dag_run_id": "manual__...",
"state": "running",
"timed_out": true,
"elapsed_seconds": 300.0,
"message": "Timed out after 300 seconds. DAG run is still running."
}
Use this only when you need more control:
# Step 1: Trigger
af runs trigger my_dag
# Returns: {"dag_run_id": "manual__...", "state": "queued"}
# Step 2: Check status
af runs get my_dag manual__2025-01-14T...
# Returns current state
The DAG ran successfully. Summarize for the user:
You're done!
The DAG is still running. Options:
af runs get <dag_id> <dag_run_id>Move to Phase 2 (Debug) to identify the root cause.
When a DAG run fails, use these commands to diagnose:
af runs diagnose <dag_id> <dag_run_id>
Returns in one call:
af tasks logs <dag_id> <dag_run_id> <task_id>
Example:
af tasks logs my_dag manual__2025-01-14T... extract_data
For specific retry attempt:
af tasks logs my_dag manual__2025-01-14T... extract_data --try 2
Look for:
If a task shows upstream_failed, the root cause is in an upstream task. Use af runs diagnose to find which task actually failed.
If the trigger failed because the DAG doesn't exist:
af dags errors
This reveals syntax errors or missing dependencies that prevented the DAG from loading.
Once you identify the issue:
| Issue | Fix |
|---|---|
| Missing import | Add to DAG file |
| Missing package | Add to requirements.txt |
| Connection error | Check af config connections, verify credentials |
| Variable missing | Check af config variables, create if needed |
| Timeout | Increase task timeout or optimize query |
| Permission error | Check credentials in connection |
af runs trigger-wait <dag_id>Repeat the test → debug → fix loop until the DAG succeeds.
| Phase | Command | Purpose |
|---|---|---|
| Test | af runs trigger-wait <dag_id> | Primary test method — start here |
| Test | af runs trigger <dag_id> | Start run (alternative) |
| Test | af runs get <dag_id> <run_id> | Check run status |
| Debug | af runs diagnose <dag_id> <run_id> | Comprehensive failure diagnosis |
| Debug | af tasks logs <dag_id> <run_id> <task_id> |
af runs trigger-wait my_dag
# Success! Done.
# 1. Run and wait
af runs trigger-wait my_dag
# Failed...
# 2. Find failed tasks
af runs diagnose my_dag manual__2025-01-14T...
# 3. Get error details
af tasks logs my_dag manual__2025-01-14T... extract_data
# 4. [Fix the issue in DAG code]
# 5. Retest
af runs trigger-wait my_dag
# 1. Trigger fails - DAG not found
af runs trigger-wait my_dag
# Error: DAG not found
# 2. Find parse error
af dags errors
# 3. [Fix the issue in DAG code]
# 4. Retest
af runs trigger-wait my_dag
# 1. Get failure summary
af runs diagnose my_dag scheduled__2025-01-14T...
# 2. Get error from failed task
af tasks logs my_dag scheduled__2025-01-14T... failed_task_id
# 3. [Fix the issue]
# 4. Retest
af runs trigger-wait my_dag
af runs trigger-wait my_dag --conf '{"env": "staging", "batch_size": 100}' --timeout 600
# Wait up to 1 hour
af runs trigger-wait my_dag --timeout 3600
# If timed out, check current state
af runs get my_dag manual__2025-01-14T...
Connection Refused / Timeout:
af config connections for correct host/portModuleNotFoundError:
requirements.txtPermissionError:
Task Timeout:
Task logs typically show:
Focus on the exception at the bottom of failed task logs.
Astro deployments support environment promotion, which helps structure your testing workflow:
astro deploy --dags for fast iterationWeekly Installs
387
Repository
GitHub Stars
269
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode275
codex269
cursor268
github-copilot265
gemini-cli250
claude-code241
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
100,500 周安装
Expo应用设计指南:使用Expo Router和NativeWind构建跨平台React Native移动应用
359 周安装
OpenAI Agents SDK:构建文本/语音AI智能体、多智能体工作流与防护栏应用
359 周安装
MCP Lark 飞书集成指南:配置环境变量、调用工具与 mcporter 使用教程
360 周安装
skill-creator:基于API/Git的开发者工具,高效创建与管理技能项目
360 周安装
深度研究技能:AI辅助网络研究方法论,提升内容质量与信息全面性
360 周安装
短视频脚本生成器:AI 驱动,按平台和时长优化,提升视频互动与转化率
360 周安装
| Get task output/errors |
| Debug | af dags errors | Check for parse errors (if DAG won't load) |
| Debug | af dags get <dag_id> | Verify DAG config |
| Debug | af dags explore <dag_id> | Full DAG inspection |
| Config | af config connections | List connections |
| Config | af config variables | List variables |