General-purpose coding policy for Baruch's AI agents
76
95%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Low
Low-risk findings worth noting
#!/usr/bin/env bash
# Outcome-based tests for skills/herdr-teamlead/compose-briefs.sh.
#
# Templates and values are built in the test, so the assertions are about the
# script's own behavior rather than about the shipped templates' current text
# (rules/testing-standards.md — fixtures built in setup, no binary fixtures).
#
# The harness drops `set -e` to aggregate results, so every fixture-setup
# command is checked explicitly and aborts with a fatal diagnostic on failure
# (rules/error-handling.md aggregate-reporting carve-out).
#
# Covers:
# 1. Substitution -> shared + per-role values land in the right files.
# 2. Role wins -> a role value overrides the same shared key.
# 3. Emitted paths -> the JSON names COMMON.md and every brief.
# 4. Unfilled -> a placeholder with no value is exit 2, nothing written.
# 5. Unknown key -> a value no template uses is exit 2, nothing written.
# 6. Atomicity -> a failing second role leaves the first unwritten.
# 7. Missing template -> exit 1 naming the path.
# 8. Bad JSON -> exit 1.
# 9. Idempotent -> a second identical run rewrites the same content.
# 10. Usage -> exit 1 with a usage line.
# 11. Broken grep -> a failing scan is exit 3, never "no placeholders".
# 12. Null value -> exit 2, nothing written (a `null` would render as
# the literal text and leave no placeholder behind).
# 13. Object value -> exit 2 for the same reason.
# 14. Number value -> accepted; an issue number is legitimate text.
#
# Run: bash skills/herdr-teamlead/tests/test_compose_briefs.sh
set -uo pipefail
die() { echo "fatal: $*" >&2; exit 2; }
cleanup() { [[ -n "${TMP:-}" ]] && ! rm -rf "$TMP" && echo "warn: could not remove $TMP" >&2; return 0; }
pass() { PASS=$((PASS+1)); }
fail() { FAIL=$((FAIL+1)); echo " ✗ FAIL: $1" >&2; }
mk_templates() { # <dir>
mkdir -p "$1" || die "could not create $1"
printf 'Checkout: {{SHARED_CHECKOUT}}\nAuthority: {{AUTHORITY_STATEMENT}}\n' > "$1/COMMON.md" \
|| die "could not write COMMON.md"
printf 'Dev on {{BRANCH}} in {{WORKTREE}} for {{ISSUE}}\nReport: {{REPORT}}\n' > "$1/brief-developer.md" \
|| die "could not write brief-developer.md"
printf 'Tester for {{ISSUE}}\nReport: {{REPORT}}\n' > "$1/brief-tester.md" \
|| die "could not write brief-tester.md"
}
run() { # <templates> <values-file> <outdir>
RUN_SEQ=$((RUN_SEQ+1))
OUT="$(bash "$SCRIPT" "$1" "$2" "$3" 2>"$TMP/err.$RUN_SEQ")"
RC=$?
ERRTEXT="$(cat "$TMP/err.$RUN_SEQ")"
}
main() {
SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/compose-briefs.sh"
[[ -f "$SCRIPT" && -r "$SCRIPT" ]] || die "compose-briefs.sh not found at $SCRIPT"
command -v jq >/dev/null 2>&1 || die "jq required for these tests"
TMP="$(mktemp -d -t teamlead-compose-test.XXXXXX)" || die "mktemp failed"
trap cleanup EXIT
TPL="$TMP/templates"; mk_templates "$TPL"
FAIL=0; PASS=0; RUN_SEQ=0
# 1 + 3. A complete round.
local v1="$TMP/v1.json" o1="$TMP/out1"
cat > "$v1" <<'JSON' || die "could not write $v1"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "owner of jbaruch/x"},
"roles": {
"developer": {"BRANCH": "feat/x", "WORKTREE": "/wt/dev", "ISSUE": "#7", "REPORT": "/r/dev.md"},
"tester": {"ISSUE": "#7", "REPORT": "/r/test.md"}
}
}
JSON
run "$TPL" "$v1" "$o1"
if [[ $RC -eq 0 ]] \
&& grep -q "Checkout: /repo" "$o1/COMMON.md" \
&& grep -q "Dev on feat/x in /wt/dev for #7" "$o1/brief-developer.md" \
&& grep -q "Report: /r/test.md" "$o1/brief-tester.md"; then
pass; else fail "substitution: got RC=$RC ERR=$ERRTEXT"; fi
if [[ $RC -eq 0 ]] && printf '%s' "$OUT" | jq -e --arg o "$o1" '
.common == ($o + "/COMMON.md")
and .briefs.developer == ($o + "/brief-developer.md")
and .briefs.tester == ($o + "/brief-tester.md")' >/dev/null 2>&1; then
pass; else fail "emitted paths: got OUT=$OUT"; fi
# 2. A role value beats the shared one.
local v2="$TMP/v2.json" o2="$TMP/out2"
cat > "$v2" <<'JSON' || die "could not write $v2"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a", "ISSUE": "#1", "REPORT": "/shared.md"},
"roles": {"tester": {"ISSUE": "#9"}}
}
JSON
run "$TPL" "$v2" "$o2"
if [[ $RC -eq 0 ]] && grep -q "Tester for #9" "$o2/brief-tester.md"; then
pass; else fail "role override: got RC=$RC ERR=$ERRTEXT"; fi
# 4. A placeholder with no value is a brief that lies to a worker.
local v4="$TMP/v4.json" o4="$TMP/out4"
cat > "$v4" <<'JSON' || die "could not write $v4"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {"developer": {"BRANCH": "feat/x", "ISSUE": "#7", "REPORT": "/r.md"}}
}
JSON
run "$TPL" "$v4" "$o4"
if [[ $RC -eq 2 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "WORKTREE"; then
pass; else fail "unfilled: expected exit 2 naming WORKTREE, got RC=$RC ERR=$ERRTEXT"; fi
if [[ ! -e "$o4/brief-developer.md" ]]; then
pass; else fail "unfilled: nothing may be written on a validation failure"; fi
# 5. A key no template uses is a value the lead believes it sent.
local v5="$TMP/v5.json" o5="$TMP/out5"
cat > "$v5" <<'JSON' || die "could not write $v5"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {"tester": {"ISSUE": "#7", "REPORT": "/r.md", "REPORTS_DIRR": "/typo"}}
}
JSON
run "$TPL" "$v5" "$o5"
if [[ $RC -eq 2 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "REPORTS_DIRR"; then
pass; else fail "unknown key: expected exit 2 naming the typo, got RC=$RC ERR=$ERRTEXT"; fi
# 6. A round is all-or-nothing: a later role failing leaves no earlier file.
local v6="$TMP/v6.json" o6="$TMP/out6"
cat > "$v6" <<'JSON' || die "could not write $v6"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {
"developer": {"BRANCH": "feat/x", "WORKTREE": "/wt", "ISSUE": "#7", "REPORT": "/r.md"},
"tester": {"ISSUE": "#7"}
}
}
JSON
run "$TPL" "$v6" "$o6"
if [[ $RC -eq 2 ]] && [[ ! -e "$o6/brief-developer.md" ]] && [[ ! -e "$o6/COMMON.md" ]]; then
pass; else fail "atomicity: a failed round left files behind (RC=$RC)"; fi
# 6b. The PACKAGED templates compose from the values Step 5 documents — for
# every shipped role, the release brief included. A template that grows
# a placeholder nobody documented fails here before it fails a worker.
local v6b="$TMP/v6b.json" o6b="$TMP/out6b" PKG
PKG="$(dirname "$SCRIPT")/templates"
cat > "$v6b" <<'JSON' || die "could not write $v6b"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "owner of jbaruch/x",
"EXTERNAL_PERMISSION": "none", "ISSUE": "#7", "BRANCH": "feat/x"},
"roles": {
"developer": {"WORKTREE": "/wt/dev", "REPORTS_DIR": "/r", "REPORT": "/r/dev.md"},
"reviewer": {"REPORT": "/r/review.md"},
"tester": {"WORKTREE": "/wt/test", "REPORTS_DIR": "/r", "REPORT": "/r/test.md"},
"release": {"WORKTREE": "/wt/dev", "REPORTS_DIR": "/r", "REPORT": "/r/release.md"}
}
}
JSON
run "$PKG" "$v6b" "$o6b"
if [[ $RC -eq 0 ]] && grep -q 'cd /wt/dev && pwd' "$o6b/brief-release.md" \
&& grep -q 'Skill(skill: "release")' "$o6b/brief-release.md"; then
pass; else fail "packaged templates: expected exit 0 and a filled release brief, got RC=$RC ERR=$ERRTEXT"; fi
# 6c. A REPORT path that would wrap the worker's marker line is refused
# before any file is written: the wait confirms the report's basename on
# one visible row, and a wrap inside the name cannot be confirmed.
local v6c="$TMP/v6c.json" o6c="$TMP/out6c" long_report
long_report="/very/long/reports/directory/that/keeps/going/and/going/round-3/reports/developer-report-for-issue-12.md"
cat > "$v6c" <<JSON || die "could not write $v6c"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {"tester": {"ISSUE": "#7", "REPORT": "${long_report}"}}
}
JSON
run "$TPL" "$v6c" "$o6c"
if [[ $RC -eq 2 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "REPORT for role 'tester'" && [[ ! -e "$o6c" ]]; then
pass; else fail "long REPORT: expected exit 2 naming the role and no output dir at all, got RC=$RC OUT=$OUT ERR=$ERRTEXT"; fi
TEAMLEAD_REPORT_PATH_MAX_COLS=200 run "$TPL" "$v6c" "$o6c"
if [[ $RC -eq 0 ]]; then
pass; else fail "long REPORT under a raised limit: expected exit 0, got RC=$RC ERR=$ERRTEXT"; fi
# 6e. A leading-zero override is decimal downstream: `0200` raises the limit
# like `200` does, with no octal reparse.
TEAMLEAD_REPORT_PATH_MAX_COLS=0200 run "$TPL" "$v6c" "$o6c"
if [[ $RC -eq 0 ]] && ! printf '%s' "$ERRTEXT" | grep -q "value too great"; then
pass; else fail "leading-zero limit: expected exit 0 and no octal error, got RC=$RC ERR=$ERRTEXT"; fi
# 6d. A bad limit override is a precondition failure, never an arithmetic abort.
TEAMLEAD_REPORT_PATH_MAX_COLS=soon run "$TPL" "$v6c" "$o6c"
if [[ $RC -eq 1 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "TEAMLEAD_REPORT_PATH_MAX_COLS must be a positive integer"; then
pass; else fail "bad limit override: expected exit 1 naming it, got RC=$RC OUT=$OUT ERR=$ERRTEXT"; fi
# 7. A role with no template is named, not guessed at.
local v7="$TMP/v7.json" o7="$TMP/out7"
cat > "$v7" <<'JSON' || die "could not write $v7"
{"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"}, "roles": {"scribe": {}}}
JSON
run "$TPL" "$v7" "$o7"
if [[ $RC -eq 1 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "brief-scribe.md"; then
pass; else fail "missing template: expected exit 1 naming it, got RC=$RC ERR=$ERRTEXT"; fi
# 8. Malformed values.
local v8="$TMP/v8.json"
printf '{broken' > "$v8" || die "could not write $v8"
run "$TPL" "$v8" "$TMP/out8"
if [[ $RC -eq 1 && -z "$OUT" ]]; then
pass; else fail "bad JSON: expected exit 1, got RC=$RC"; fi
# 9. Re-running a round rewrites the same content (idempotent).
run "$TPL" "$v1" "$o1"
if [[ $RC -eq 0 ]] && grep -q "Dev on feat/x in /wt/dev for #7" "$o1/brief-developer.md"; then
pass; else fail "idempotent: second run changed the output (RC=$RC)"; fi
# 10. Usage.
OUT="$(bash "$SCRIPT" 2>"$TMP/e10")"; RC=$?
if [[ $RC -eq 1 && -z "$OUT" ]] && grep -q "usage:" "$TMP/e10"; then
pass; else fail "usage: expected exit 1 with a usage line, got RC=$RC"; fi
# 11. A scan that cannot run must never report a clean render. A grep that
# exits 2 (unreadable input, bad pattern) is a tool failure, and
# collapsing it into "no placeholders left" is what would ship an
# unrendered brief to a worker.
local bin="$TMP/brokenbin"
mkdir -p "$bin" || die "could not create $bin"
printf '#!/usr/bin/env bash\nexit 2\n' > "$bin/grep" || die "could not write the failing grep"
chmod +x "$bin/grep" || die "could not chmod the failing grep"
RUN_SEQ=$((RUN_SEQ+1))
OUT="$(PATH="$bin:$PATH" bash "$SCRIPT" "$TPL" "$v1" "$TMP/out11" 2>"$TMP/e11")"; RC=$?
if [[ $RC -eq 3 && -z "$OUT" ]] && grep -q "placeholder scan failed" "$TMP/e11"; then
pass; else fail "broken grep: expected exit 3 naming the scan, got RC=$RC ERR=$(cat "$TMP/e11")"; fi
if [[ ! -e "$TMP/out11/COMMON.md" ]]; then
pass; else fail "broken grep: nothing may be written when the scan failed"; fi
# 12. `jq -r` prints a JSON null as the four characters `null`, which
# substitutes cleanly and leaves no placeholder behind — the brief reads
# as fully rendered while telling a worker its worktree is at `null`.
local v12="$TMP/v12.json" o12="$TMP/out12"
cat > "$v12" <<'JSON' || die "could not write $v12"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {"developer": {"BRANCH": "feat/x", "WORKTREE": null, "ISSUE": "#7", "REPORT": "/r.md"}}
}
JSON
run "$TPL" "$v12" "$o12"
if [[ $RC -eq 2 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "WORKTREE (null)"; then
pass; else fail "null value: expected exit 2 naming it, got RC=$RC ERR=$ERRTEXT"; fi
if [[ ! -e "$o12/brief-developer.md" && ! -e "$o12/COMMON.md" ]]; then
pass; else fail "null value: nothing may be written on a validation failure"; fi
# 13. An object arrives as a JSON fragment the same way.
local v13="$TMP/v13.json" o13="$TMP/out13"
cat > "$v13" <<'JSON' || die "could not write $v13"
{
"shared": {"SHARED_CHECKOUT": {"path": "/repo"}, "AUTHORITY_STATEMENT": "a"},
"roles": {"tester": {"ISSUE": "#7", "REPORT": "/r.md"}}
}
JSON
run "$TPL" "$v13" "$o13"
if [[ $RC -eq 2 && -z "$OUT" ]] && printf '%s' "$ERRTEXT" | grep -q "SHARED_CHECKOUT (object)"; then
pass; else fail "object value: expected exit 2 naming it, got RC=$RC ERR=$ERRTEXT"; fi
# 14. A number is legitimate text — an issue number reads the same either way.
local v14="$TMP/v14.json" o14="$TMP/out14"
cat > "$v14" <<'JSON' || die "could not write $v14"
{
"shared": {"SHARED_CHECKOUT": "/repo", "AUTHORITY_STATEMENT": "a"},
"roles": {"tester": {"ISSUE": 42, "REPORT": "/r.md"}}
}
JSON
run "$TPL" "$v14" "$o14"
if [[ $RC -eq 0 ]] && grep -q "Tester for 42" "$o14/brief-tester.md"; then
pass; else fail "number value: expected it to render, got RC=$RC ERR=$ERRTEXT"; fi
echo "─────────────────────────────────────────────" >&2
if [[ $FAIL -gt 0 ]]; then echo "FAILED: ${FAIL} failed, ${PASS} passed" >&2; exit 1; fi
echo "PASSED: all ${PASS} checks" >&2
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi.tessl-plugin
hooks
rules
skills
adopt-fork-pr
herdr-standup
herdr-teamlead
references
teamlead
tests
migrate-to-plugin
onboard-repo
release
tests