For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Problem

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

  • 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

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

Step-by-Step Guide

Prerequisites

  1. 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

  1. That's it

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

Now everything is working🥳

Now, let's ask it to set up Stakpak Autopilot

Stakpak Autopilot monitors your apps 24/7, detects unexpected changes, fixes what’s safe, and only alerts you when it actually matters.

Monitoring

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

Extra Resources:

and more...

References

Last updated