Short version: a check that starts a local server and asks it a question passed on code we had broken on purpose. The answer came from the server of the previous run, which had never been killed. Since then every check in our gate has to prove it can fail, and a timeout kills the whole process tree, not just the top process.
What the check did
Our e-commerce site generates robots.txt at runtime, not from a file. The
only way to test it before a deploy is to build the app, start it locally and
fetch /robots.txt. The gate did exactly that: start the server in the
background, wait for it, fetch, compare against the rules, stop the server.
We were writing the gate and wanted to see the check go red, so we broke the robots rules in the source on purpose and ran it.
It passed.
Why it passed
The server was started from a subshell, ( ... ) &, and stopped with
kill $!. On Windows (Git Bash) $! is the pid of the subshell, not of
the Node process it started. kill ended the subshell; Node kept running and
kept the port.
On the next run the new server could not bind the port and failed quietly.
curl still got a perfect answer, from the old server, built from the old,
correct code. The check measured the leftover of the previous run, not the
code it was supposed to measure.
Nothing in the output looked wrong. Green is green.
What we changed
- A busy port is an error, never "already running". Before the local server starts, the gate checks the port. If anything is listening, the check fails and says which process to kill. Reusing a busy port is the definition of measuring stale code.
- Kill the tree, not the pid. A timed-out or finished check is stopped
with its whole process tree:
taskkill /Ton Windows, the process group plus every descendant on Linux and macOS. A grandchild (a test runner's worker, a dev server undernpx) is exactly what survives a plainkill. - Every check must be seen failing. The gate got a self-test. It breaks the code on purpose, one mutation per check, and expects each check to go red. If a check stays green on broken code, it has no teeth, and the self-test fails.
The self-test later caught a second, quieter version of the same problem: we
had first tested the tree kill with a single child process. A plain kill
already kills a direct child, so that test could never fail. Only a test with
a grandchild proves the tree kill works.
The general rule
A check that has only ever been green tells you nothing. Before you trust it, break the thing it guards and watch it go red. Then keep doing that, automatically, because checks rot: a renamed file, a changed port, a test runner that now finds zero tests. They all stay green forever.
What we built from it
Ship Gate runs every check with a timeout that kills
the whole process tree, and ship-gate selftest proves two things: that the
gate engine itself still closes on a failure and kills grandchildren, and that
each of your checks fails on deliberately broken code. It reports a stale
mutation separately from a toothless check, because they need different fixes.
The core is open source (Apache 2.0).
Checklist for your own pipeline
- Does any check start a server? Then check the port is free first, and fail if it is not.
- When a check times out, what happens to its children? Test it with a grandchild.
- Pick one check and break the code it guards. Did it go red?
- Does any step pipe a build into
tailortee? Then the exit code you see is not the build's.