Skip to content

5. Prove your teardown works

Do this drill once per axis, before you trust it. Nobody does and everybody should — the entire failure mode this tool addresses is a teardown that reports success while resources survive.

The drill: break a down hook on purpose, tear down, and confirm the tool catches it.

- name: database
down: ./hooks/db-branch.sh delete "$STACK"
down: ./hooks/db-branch.sh delete "$STACK-typo"

A plausible bug: wrong name, wrong region, wrong project. delete on a name that doesn’t exist exits 0, because deleting nothing is not an error.

Terminal window
$ PR=456 pstack up
stack: pr-456
→ up: database
→ compose up (backend, frontend)
✓ up database
✓ assert_live database
✓ compose (compose)
$ PR=456 pstack down
stack: pr-456
→ compose down (all profiles)
→ down: database
→ verify (asserting resources are gone)
✓ compose (compose)
✓ down database
✗ assert_gone database — LEAKED: resource still present after teardown
1 leaked resource(s)
$ echo $?
2

Read those last two step lines together — this is the whole point of the tool.

✓ down database ← the teardown hook SUCCEEDED
✗ assert_gone database ← the resource SURVIVED

A hand-rolled teardown script sees the first line and reports success. It has no second line. That contradiction — a clean down over a surviving resource — is what leaks look like in the wild, and ✓ down + ✗ assert_gone is its signature.

Confirm the resource really is still there, and use -v to see which hook ran:

Terminal window
$ PR=456 pstack down -v
stack: pr-456
→ compose down (all profiles)
$ docker compose -p 'pr-456' -f 'docker-compose.preview.yml' --profile 'backend' --profile 'frontend' down -v --remove-orphans
→ down: database
$ ./hooks/db-branch.sh delete "$STACK-typo"
→ verify (asserting resources are gone)
$ ./hooks/db-branch.sh ping || exit 1
[ "$(./hooks/db-branch.sh count "$STACK")" = "0" ]
✓ compose (compose)
✓ down database
✗ assert_gone database — LEAKED: resource still present after teardown
1 leaked resource(s)

There it is: "$STACK-typo". (A multi-line hook is echoed across multiple lines — only the first carries the $ prefix.)

Terminal window
$ PR=456 pstack down --no-verify
stack: pr-456
→ compose down (all profiles)
→ down: database
✓ compose (compose)
✓ down database
$ echo $?
0

Exit 0. All green. The resource is still there. --no-verify turns pstack into exactly the homegrown script you were trying to replace — use it only when you are deliberately deferring the check to a separate verify step, never to make a red pipeline green.

Terminal window
$ PR=456 pstack down # hook fixed
stack: pr-456
→ compose down (all profiles)
→ down: database
→ verify (asserting resources are gone)
✓ compose (compose)
✓ down database
✓ assert_gone database
$ echo $?
0

Now you have evidence, not hope: you’ve seen this axis’s assert_gone return both answers. An assert_gone you have only ever seen pass may simply be incapable of failing.

Drill checklist per axis — you have tested it when you have seen all three:

State Expected
resource live verify → ✗ on that axis, exit 2
teardown sabotaged down → ✓ down + ✗ assert_gone, exit 2
teardown correct down → ✓ assert_gone, exit 0