Prompt

How do I set up a test failure explanation tool for debugging failing tests in our CI pipeline?

Artificial Intelligence / AI Code Generation2 observationsLast seen Nov 9, 2026

Latest observation

Nov 9, 2026OpenAI APIWeb search: off

A good “test failure explanation” tool in CI usually has one job: take a failing test, gather the relevant context, and turn it into a concise, actionable summary.

Here’s a practical way to set one up.

1) Decide what the tool should explain

Start with the output you want when a test fails:

  • failing test name
  • error message / stack trace
  • assertions that failed
  • recent code changes in the branch or PR
  • related logs, screenshots, or artifacts
  • likely root cause categories
  • suggested next debugging steps

A useful explanation tool should answer:

  • What failed?
  • Why did it probably fail?
  • Where should I look next?

2) Capture the right CI data

Your CI pipeline should save enough context for the tool to analyze.

Collect:

  • test runner output
  • stack traces
  • stdout/stderr logs
  • JUnit/XML or JSON test reports
  • screenshots/video for UI tests
  • app/server logs
  • environment info
  • git diff or PR diff
  • timing/history of flaky tests

Store as artifacts:

For example:

  • GitHub Actions artifacts
  • GitLab job artifacts
  • Jenkins archived artifacts
  • S3/GCS bucket
  • internal log store

Make sure the tool can fetch them automatically based on the build ID or commit SHA.


3) Create a failure analysis pipeline

A simple architecture:

  1. CI job fails
  2. Post-processing step runs
  3. It collects artifacts and metadata
  4. It sends them to an analysis service or script
  5. The service generates a structured explanation
  6. The explanation is posted back to PR comments, Slack, or the CI summary

You can implement this as:

  • a shell/Python script for a lightweight setup
  • a small internal service
  • an LLM-powered analysis agent if you want natural-language explanations

4) Parse test failures into structured data

Before trying to “explain” anything, normalize the input.

Example fields:

  • test_name
  • suite
  • status
  • failure_type
  • error_message
  • stack_trace
  • log_excerpt
  • commit_sha
  • branch
  • changed_files
  • last_known_good_build

This makes it easier to:

  • search similar failures
  • cluster flaky tests
  • generate better explanations
  • route to the right owner

5) Add heuristics before using AI

Basic rules can solve many failures quickly:

  • assertion mismatch → likely logic regression
  • timeout → performance issue, deadlock, or environment slowness
  • network error → external dependency or mock issue
  • missing file/module → build/package problem
  • test passes locally but not in CI → environment/config/flaky test

A rules layer makes the tool more reliable and cheaper, and it improves AI output by giving it a starting hypothesis.


6) If using an LLM, constrain the prompt

If you use an LLM, don’t just dump raw logs. Give it a structured prompt like:

  • summarize the failure in 3 bullets
  • identify the most likely cause
  • cite evidence from logs
  • note uncertainty if evidence is weak
  • suggest 3 next debugging actions

Example prompt skeleton:

  • “Here is the failing test report, stack trace, relevant logs, and git diff. Explain the failure for an engineer who wants the fastest path to root cause. Return: summary, likely cause, evidence, next steps, and confidence.”

This reduces hallucinations and makes the output consistent.


7) Add historical comparison

One of the best debugging features is comparison against history.

Look up:

  • previous failures of the same test
  • recent flaky patterns
  • changes introduced in the last N commits
  • whether the failure started after a dependency update

This is especially helpful for:

  • flaky tests
  • intermittent CI-only failures
  • failures caused by infrastructure changes

8) Return the explanation where developers already work

Good delivery channels:

  • PR comment
  • GitHub/GitLab check summary
  • Slack alert
  • CI job annotation
  • dashboard link

A strong format is:

Failure summary

  • test_checkout_flow failed in payment.spec.ts

Likely cause

  • API returned 500 from payment service after request payload schema changed

Evidence

  • stack trace line X
  • log line Y
  • diff in file Z

Next steps

  • update payload shape
  • verify mock contract
  • rerun targeted test with verbose logging

9) Keep a feedback loop

Let developers label the explanation:

  • correct
  • partially correct
  • incorrect

Then use that feedback to:

  • improve heuristics
  • tune prompts
  • build a dataset of known failure patterns
  • identify flaky tests and recurring regressions

10) Security and safety

If logs may contain secrets or PII:

  • redact tokens, credentials, emails, keys
  • limit which artifacts are sent to external services
  • prefer self-hosted models or internal services for sensitive repos
  • enforce access control on failure reports

Minimal implementation approach

If you want a quick first version:

  1. Configure CI to upload test logs and reports.
  2. Add a post-failure script.
  3. Parse the failing test + stack trace.
  4. Apply simple heuristics.
  5. Optionally send the structured data to an LLM.
  6. Post the explanation to the PR/CI summary.

A Python-based version is often enough to start.


Example output format

Failed test: test_user_login

Summary:
The test failed because the login API returned 401 instead of 200.

Likely cause:
The auth token fixture appears to be invalid after the recent change to token generation.

Evidence:
- Assertion failed at auth_test.py:84
- Log: "Unauthorized: invalid signature"
- Recent diff modifies JWT secret handling in auth/config.py

Next steps:
1. Verify the token fixture uses the new signing key.
2. Re-run the test with auth debug logs enabled.
3. Check whether other auth tests fail with the same signature error.

Confidence: medium

If you want, I can also give you:

  1. a reference architecture,
  2. a sample Python implementation, or
  3. a GitHub Actions / GitLab CI example for wiring this into your pipeline.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.