#!/usr/bin/env bash
# Reproduces the gohawk lab end to end: a four-package Go module with one
# deliberately planted bug per package, then runs go test, go vet and gohawk
# so you can see what each tool does (and does not) catch. Needs Go 1.26+.
set -eu

LAB="${1:-/tmp/gohawk-lab}"
rm -rf "$LAB"
mkdir -p "$LAB/cmd/lab" "$LAB/internal/metrics" "$LAB/internal/pipeline" "$LAB/internal/worker"
cd "$LAB"
go mod init example.com/gohawk-lab

# gohawk installs as a normal Go binary into ./bin
GOBIN="$LAB/bin" go install github.com/kojah/gohawk@latest
GH="$LAB/bin/gohawk"

# --- the four fixtures (copy the files shipped alongside this post) ---
# cmd/lab/main.go        lock not released on an early return  (lockorder)
# internal/metrics/...   file handle leaked in library code    (resourcelifetime)
# internal/pipeline/...  goroutine abandoned on an early return (goroutineownership)
# internal/worker/...    shared local mutated by loop goroutines (concurrentcapture)
# (The file bodies are printed in the post; drop them into the paths above.)

echo "### go test ./...  (nothing fails)"
go test ./... || true
echo "### go vet ./...   (clean: exit 0)"
go vet ./... && echo "vet: clean"
echo "### gohawk ./...   (the conservative default set)"
"$GH" ./... || true
echo "### gohawk list    (the full analyzer catalog)"
"$GH" list
