debugging-failures
它能做什么
这项技能展示如何在不翻阅冗长日志的情况下,找出 Go Ginkgo 测试失败的原因。适合需要快速获得失败细节的开发者和智能体。
适用场景
- ✓当 Ginkgo 测试套件失败,你需要知道哪个测试失败以及原因的时候。
- ✓当测试并行运行导致输出混在一起的时候。
- ✓当你想用相同的随机顺序重跑失败的测试时。
技能链接
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/debugging-failures/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Ginkgo 测试失败了,请帮我找出到底是哪些测试失败了,以及原因。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会用 JSON 报告运行一次测试套件,读取一行结果,然后使用过滤器只提取失败的测试、错误消息、文件位置和捕获的日志。它还可以用相同的种子重新运行,以复现失败。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Debugging Ginkgo failures (especially as an agent)
Ginkgo's terminal output is good for a human; for programmatic diagnosis, prefer a hybrid: terminal for the verdict, JSON + jq for the details. This is empirically the most reliable, lowest-token workflow. Docs: https://onsi.github.io/ginkgo/#reporting-and-profiling-suites.
The workflow: one run, JSON-first diagnosis
# One invocation gives you BOTH the human verdict on the terminal AND a structured report.
# --json-report does NOT suppress console output, so you don't pay for two runs.
ginkgo -r -p --no-color --json-report=report.json --output-dir=.ginkgo-report
- Read the terminal tail for the one-line verdict:
FAIL! -- 5 Passed | 6 Failed | 1 Pending | 1 Skipped. Cheap, immediate. - If there are failures, query the JSON with
jq(filters below) to get exactly the failing specs — stable, addressable, order-independent. - Clean up the report dir when done.
Why hybrid and not one or the other:
- Terminal-only is brittle to parse (free-form text) and, under
-p, interleaves failures in nondeterministic order. - JSON-only is wasteful if you dump it: the full
report.jsonis ~9× the tokens of the terminal output. Ajqfailures-only extraction is a fraction of either. The discipline is filter, don't dump.
Where the JSON lands (use --output-dir deliberately)
--json-report=report.jsonalone writesreport.jsonto the current directory — which scatters into package dirs under-rand risks getting committed.- Prefer
--output-dir=DIRto collect everything in one known place (auto-created). With-r, all suites merge into oneDIR/report.json— ideal: one file, one set ofjqfilters. - Use a gitignored or temp location: a repo-local
.ginkgo-report/(add it to.gitignore) or an absolute temp path (--output-dir=/tmp/ginkgo-report). Don't leavereport.jsonin the working tree. --keep-separate-reports(with-r) writes onePACKAGE_report.jsonper package instead of merging — only reach for it when you must attribute failures per package.
The jq filters (tested against the real schema)
The report is an array of suite reports, each with a .SpecReports[] array.
Verdict / counts per suite:
jq -r '.[] | "\(.SuiteDescription): \([.SpecReports[].State]|group_by(.)|map("\(length) \(.[0])")|join(", "))"' .ginkgo-report/report.json
All failures — name, location, message (the workhorse). Select failed and panicked and timedout — see the trap below:
jq -r '.[].SpecReports[]
| select(.State=="failed" or .State=="panicked" or .State=="timedout")
| "[\(.State|ascii_upcase)] \((.ContainerHierarchyTexts+[.LeafNodeText])|join(" > "))\n \(.Failure.Location.FileName):\(.Failure.Location.LineNumber)\n \(.Failure.Message)"' .ginkgo-report/report.json
Panics — the real user-code line (the headline location lies; see below):
jq -r '.[].SpecReports[] | select(.State=="panicked")
| "PANIC: \(.Failure.ForwardedPanic)\n\(.Failure.Location.FullStackTrace)"' .ginkgo-report/report.json
Drill into one spec by name, with its captured logs:
jq -r '.[].SpecReports[] | select(.LeafNodeText|test("SUBSTRING"))
| "STATE: \(.State)\n\(.Failure.Message)\n--- GinkgoWriter ---\n\(.CapturedGinkgoWriterOutput // "(none)")"' .ginkgo-report/report.json
Slowest specs:
jq '.[0].SpecReports | map([(.ContainerHierarchyTexts+[.LeafNodeText])|join(" "), .RunTime/1e9]) | sort_by(.[1]) | reverse | .[0:10]' .ginkgo-report/report.json
Schema facts you need
State:passed | failed | panicked | pending | skipped | timedout | interrupted | aborted.- Spec name =
ContainerHierarchyTexts(array) +LeafNodeText. Failure.Message— the failure text (Gomega's full expected/got block for assertions).Failure.Location.{FileName,LineNumber,FullStackTrace}.Failure.ForwardedPanic— the panic value (only meaningful forpanicked).Failure.FailureNodeType— e.g.BeforeEachvsIt, so you know a setup node failed.CapturedGinkgoWriterOutput—GinkgoWriterlogs (omitted if empty).SpecEvents[]—By(...)steps and node enter/exit (does not include raw GinkgoWriter text).ParallelProcess— which worker ran the spec (-p).AdditionalFailures[]— failures beyond the primaryFailure(e.g. a failingAfterEachorDeferOnFailurecallback). Usually the primary is
常见问题
为什么不直接读完整日志?
并行运行时,失败消息可能会混在一起,而且完整报告要大得多,所以这项技能会过滤出细节。
什么是种子?
种子是决定随机测试顺序的数字,重复使用它可以复现同一次运行。
它会清理报告文件吗?
会。诊断完成后,这项技能会删除报告文件夹。
详情
作者的原始描述
Diagnose a failing Ginkgo suite as an agent — always run with --json-report into a predictable temp/gitignored location, read the terminal verdict line, then use jq to extract structured failure details (name, message, file:line, panic value, captured logs). Covers the panicked-vs-failed trap, panic locations pointing into the Go runtime, parallel output interleaving, reproducing with --seed, and progress reports for hangs. Use when a suite failed and you need to know why. Also invokable as /ginkgo:debugging-failures.
repo: onsi/ginkgo
热度
- GitHub 星标
- 9.1k
- 排名
- #12299
- 许可证
- MIT
- 更新时间
- 2026/10/9
评论
- …
同一仓库的更多技能
ci
9.1k帮你的智能体为持续集成设置 Ginkgo 测试,使用推荐的参数,能捕捉遗留的 Focus 或 Pending 标记以及不稳定的测试。
decorators
9.1k帮你的智能体正确使用 Ginkgo 测试装饰器,例如 Serial、Ordered、Label、Focus 和超时设置,并解释每一个的作用。
filtering
9.1k帮你的智能体只运行部分 Ginkgo 测试,按正确的优先顺序使用 pending、skip、focus、标签、版本约束和文件过滤器。
ordering-and-flakes
9.1k帮你的智能体控制 Go 测试的执行顺序并处理不稳定的测试,使用 Ginkgo 的 Serial 和 Ordered 设置以及重试选项。