#!/bin/sh
# 02_budget: byte-count hard budgets (PLAN M2).
# root help <=300B/12 lines; --skill <=1000B/30 lines; each <cmd> -h <=250B/8 lines.
set -e
export CARGO_BUILD_JOBS=2
fail() { echo "budget fail: $1" >&2; exit 1; }
check() {
  name="$1"; bytes="$2"; lines="$3"; maxb="$4"; maxl="$5"
  if [ "$bytes" -gt "$maxb" ]; then fail "$name ${bytes}B > ${maxb}B"; fi
  if [ "$lines" -gt "$maxl" ]; then fail "$name ${lines} lines > ${maxl}"; fi
}
bytes=$(f0rge | wc -c); lines=$(f0rge | wc -l)
check "root help" "$bytes" "$lines" 300 12
bytes=$(f0rge --skill | wc -c); lines=$(f0rge --skill | wc -l)
check "--skill" "$bytes" "$lines" 1000 30
for sub in issue pr task label milestone ci wiki release merge init skill; do
  bytes=$(f0rge "$sub" -h | wc -c); lines=$(f0rge "$sub" -h | wc -l)
  check "$sub -h" "$bytes" "$lines" 250 8
done
echo "budgets ok"
