Ray's Knowledge Base
Unlock

A test run piped into tail reports tail's exit code, not the suite's

PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A recorded proof passed (exit 0) while the suite output said "1 failed".

Cause#

Without pipeline failure handling, a test run piped into | tail reports the exit code of tail, not the test run.

Fix#

In bash or zsh, enable set -o pipefail before the pipeline. Check its exit status before running another command.

To read only the first command's status in zsh, use ${pipestatus[1]} immediately after the pipeline. In fish, use $pipestatus[1], without braces. Save the value before another command changes it.

Also read the "N failed" line before accepting a proof or gate result. A successful tail is not proof that the suite passed.

Evidence#

Seen with a Python test proof in dftracer-utils: the proof exited 0 while the suite output said "1 failed". The original note did not retain the full test command.

During curation, a local bash check ran false | tail -n 1 and printed default=0. After set -o pipefail, the same pipeline printed pipefail=1. zsh -f -c 'false | tail -n 1; print "first=$pipestatus[1]"' and fish -c 'false | tail -n 1; printf "first=%s\n" $pipestatus[1]' each printed first=1.

Also found by searching

  • proof passed with exit 0 but pytest reports 1 failed
  • pytest | tail exit code is always 0
  • how do I get the exit code of the first command in a pipe in fish or zsh
  • gate passes although the test suite failed