# Debug GitHub Actions Tests That Pass Locally but Fail in CI

## Overview

CI failures are one of the most frustrating parts of shipping code. Everything works locally

You push, and GitHub Actions decides to fail.

The logs aren’t always clear, and the issue usually isn’t where you expect it.

In this tutorial, we’ll walk through a realistic scenario where tests pass locally but fail in CI

Then we’ll debug it step by step.

{% hint style="success" %}
Estimated Time: 5 min
{% endhint %}

## Problem

<figure><img src="/files/nd2w0Qh0nRUXyEOch7Yq" alt=""><figcaption></figcaption></figure>

We have a simple Node.js application with tests.

After pushing the same code, the CI pipeline fails in GitHub Actions.

The failure isn’t immediately clear.

The logs show a mix of errors:

* Database connection failure&#x20;
* Test breaking with an undefined value
* warning about the runtime

None of these clearly explain what’s actually wrong.

At this point, all we know is:

The same code behaves differently in CI than it does locally.

## How Stakpak Helps?

Instead of digging through logs and guessing, you can debug and fix CI failures with a single prompt and keep them from happening again, stakpak:

* Inspects the GitHub Actions workflow, logs, and test output
* Analyzes runtime, environment variables, and dependencies
* Connects failures across services, tests, and configuration
* Identifies the actual root cause, not just the symptom
* Applies safe fixes directly to the workflow and configuration

Once fixed, you can set up Autopilot to:

* Continuously monitor CI/CD health
* Detect failures early
* Automatically fix issues when safe
* Escalate only when human judgment is actually needed

## Architecture

### What the app does

This is a small Node.js app that simulates an order workflow.

It includes tests for:

* connecting to a PostgreSQL database
* building an order summary
* running the app logic in CI

Locally, the app has everything it expects, so the tests pass.

In GitHub Actions, the same tests fail with errors like:

* `ECONNREFUSED ::1:5432`
* `items.toSorted is not a function`

At this point, we do not know the root cause yet. We only know the CI environment is behaving differently from local.

You can check the code source [here](https://github.com/noureldin-azzab/gha-debug-demo)

Now that we understand the app, we can start troubleshooting.

## Step-by-Step Guide

### Prerequisites

1. [Install Stakpak](/docs/get-started/install-stakpak.md)
2. Github credentials configured

### Troubleshooting

1. Open stakpak ask it to `Troubleshoot the CICD,The tests work locally but not on github actions`

Now let it do its stakpak magic

<figure><img src="/files/1XTekO6gkXm4lkzdxv6O" alt=""><figcaption></figcaption></figure>

2. That's it

<figure><img src="/files/QDvk90IvsikXWxU3a3mm" alt=""><figcaption></figcaption></figure>

This wasn’t a single bug it was a combination of small issues.

CI was using an older Node version, missing required environment variables, and didn’t have a Postgres database running. These assumptions worked locally but broke in CI.

Now let's push the fix to GitHub and see

<figure><img src="/files/5JlP3rDVWw5zC7Qz3TFE" alt=""><figcaption></figcaption></figure>

Now everything is working🥳

Now, let's ask it to set up Stakpak [Autopilot](/docs/how-it-works/autopilot.md)

{% hint style="info" %}
Stakpak Autopilot monitors your apps 24/7, detects unexpected changes, fixes what’s safe, and only alerts you when it actually matters.
{% endhint %}

### Monitoring

1. All we need to do is to prompt it to `set up stakpak autopilot scheduals to make sure the cicd is healthy`&#x20;

<figure><img src="/files/I5E3k2Nz01E1LeUOypcH" alt=""><figcaption></figcaption></figure>

## Extra Resources:

### Related Use Cases

* [Fix Kubernetes CrashLoopBackOff in Minutes](/docs/tutorial/fix-kubernetes-crashloopbackoff-in-minutes.md)
* [Detect and Fix Missing Backups for a PostgreSQL DB in Production](/docs/tutorial/detect-and-fix-missing-backups-for-a-postgresql-db-in-production.md)
* [Containerize a Python App](/docs/tutorial/containerize-a-python-app.md)

and more...

### References

* [Install Stakpak](/docs/get-started/install-stakpak.md)
* [Configure Stakpak](/docs/get-started/configure-stakpak.md)
* [Autopilot](/docs/how-it-works/autopilot.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stakpak.gitbook.io/docs/tutorial/debug-github-actions-tests-that-pass-locally-but-fail-in-ci.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
