CtrlK
BlogDocsLog inGet started
Tessl Logo

jbaruch/coding-policy

General-purpose coding policy for Baruch's AI agents

73

Quality

91%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

test_script_dir_newline.shskills/herdr-foreman/tests/

#!/usr/bin/env bash
# Outcome tests: a herdr-foreman script still reaches what sits beside it when
# its own directory's name ends in a newline (#592).
#
# A `$(dirname ...)` capture strips that newline, so the script looked beside
# a directory that does not exist. Each case stages one script under such a
# directory with stand-ins that record being reached, and asserts the record.
# wait-report.sh, round-preflight.sh and the classify scripts carry the same
# case in their own suites, beside the fixtures those paths need.
#
# The harness drops `set -e` to aggregate results, so every fixture command is
# checked explicitly (rules/error-handling.md aggregate-reporting carve-out).
#
# Covers:
#   1. foreman.sh            -> puts its own directory on PYTHONPATH.
#   2. start-judge-worker.sh -> runs the foreman.sh beside it.
#   3. sweep-worktrees.sh    -> imports foreman.prune_result from beside it.
#
# Run: bash skills/herdr-foreman/tests/test_script_dir_newline.sh
set -uo pipefail

PASS=0
FAIL=0
pass() { PASS=$((PASS + 1)); }
fail() { FAIL=$((FAIL + 1)); echo "  ✗ FAIL: $*" >&2; }
die() { echo "fatal: $*" >&2; exit 2; }

# An EXIT trap's final status becomes the script's, so cleanup ends on zero.
cleanup() { if [[ -n "${TMP:-}" ]] && ! rm -rf "$TMP"; then echo "warn: could not remove $TMP" >&2; fi; return 0; }

NL=$'\n'

# A fresh staging directory whose name ends in a newline, holding the script.
stage() { # <case> <script> -> STAGE
  STAGE="$TMP/$1/herdr-foreman${NL}"
  mkdir -p "$STAGE" || die "create the staging directory for $1"
  cp "$REAL/$2" "$STAGE/$2" || die "copy $2 into the staging directory"
}

main() {
  REAL="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" || die "cannot resolve the herdr-foreman skill dir"
  TMP="$(mktemp -d "${TMPDIR:-/tmp}/foreman-dir-newline.XXXXXX")" || die "mktemp failed"
  trap cleanup EXIT
  local marker="$TMP/marker" out rc err

  if ! mkdir "$TMP/probe${NL}" 2>"$TMP/probe.err"; then
    echo "skipped: this filesystem refuses a name ending in a newline ($(cat "$TMP/probe.err"))" >&2
    exit 0
  fi

  # 1. A stand-in interpreter answers the version probe, then records the
  #    PYTHONPATH it was handed.
  stage launcher foreman.sh
  mkdir -p "$STAGE/foreman" || die "create the foreman package directory"
  cat > "$TMP/fakepy" <<'FAKE' || die "write the stand-in interpreter"
#!/usr/bin/env bash
set -euo pipefail
if [[ "${1:-}" == "-c" ]]; then printf '3.12\n'; exit 0; fi
printf '%s' "$PYTHONPATH" > "${MARKER:?}"
FAKE
  chmod +x "$TMP/fakepy" || die "chmod the stand-in interpreter"
  rm -f "$marker" || die "reset $marker"
  out="$(env -u PYTHONPATH MARKER="$marker" PY_BIN="$TMP/fakepy" bash "$STAGE/foreman.sh" state 2>"$TMP/err")"; rc=$?
  err="$(cat "$TMP/err")"
  # The launcher hands over `pwd`'s spelling of the directory, and so does
  # this; both carry a sentinel across the newline strip.
  local want got
  want="$(cd -- "$STAGE" && pwd && printf x)" || die "enter $STAGE"
  want="${want%$'\n'x}"
  got="$(if [[ -f "$marker" ]]; then cat -- "$marker"; fi; printf x)" || die "read $marker"
  got="${got%x}"
  if [[ $rc -eq 0 && "$got" == "$want" && "$got" == *"$NL" ]]; then
    pass; else fail "foreman.sh: expected PYTHONPATH to be its own directory, got rc=$rc out=$out err=$err"; fi

  # 2.
  stage judge start-judge-worker.sh
  cat > "$STAGE/foreman.sh" <<'STUB' || die "write the foreman.sh stub"
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' "$1" > "${MARKER:?}"
STUB
  rm -f "$marker" || die "reset $marker"
  out="$(MARKER="$marker" bash "$STAGE/start-judge-worker.sh" "$TMP/plan.json" w1:p1 2>"$TMP/err")"; rc=$?
  err="$(cat "$TMP/err")"
  if [[ $rc -eq 0 && -f "$marker" && "$(cat "$marker")" == start-judge ]]; then
    pass; else fail "start-judge-worker.sh: expected foreman.sh start-judge run, got rc=$rc out=$out err=$err"; fi

  # 3. The sweep imports the shared result-shape module from beside itself
  #    before it looks at any repository; an empty root needs nothing else.
  stage sweep sweep-worktrees.sh
  mkdir -p "$STAGE/foreman" "$TMP/sweep-root" || die "create the sweep fixtures"
  : > "$STAGE/foreman/__init__.py" || die "write the package marker"
  cat > "$STAGE/foreman/prune_result.py" <<'PY' || die "write the prune_result stand-in"
import os

with open(os.environ["MARKER"], "w", encoding="utf-8") as handle:
    handle.write("imported")


def prune_schema_error(_payload):
    return None
PY
  rm -f "$marker" || die "reset $marker"
  out="$(MARKER="$marker" bash "$STAGE/sweep-worktrees.sh" "$TMP/sweep-root" 2>"$TMP/err")"; rc=$?
  err="$(cat "$TMP/err")"
  if [[ $rc -eq 0 && -f "$marker" && "$(cat "$marker")" == imported ]]; then
    pass; else fail "sweep-worktrees.sh: expected foreman.prune_result imported from beside it, got rc=$rc out=$out err=$err"; 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

skills

herdr-foreman

tests

__init__.py

fakes.py

test_assign.py

test_attention.py

test_billing.py

test_bounded_run.sh

test_capabilities.py

test_capability_routing.py

test_chronology.py

test_churn.py

test_classify.sh

test_claude_native.py

test_cli.py

test_compose_briefs.sh

test_composer.py

test_composition.py

test_config.py

test_continuity_cli.py

test_cost_report.py

test_diagnostics.py

test_engagement.py

test_entrypoints.py

test_foreman_launcher.sh

test_foreman_queue.py

test_foreman_reset.py

test_foreman_seat.py

test_foreman_tier_check.py

test_freeze.py

test_herdr.py

test_historical.py

test_home.py

test_label_workspaces.sh

test_launch.py

test_legacy_recovery.py

test_load_set.py

test_measure.py

test_members.py

test_memory.py

test_oracle.py

test_parsers.py

test_partition.py

test_planner.py

test_probe.py

test_provision_worktree.sh

test_prune_remote_branches.sh

test_prune_report_caches.py

test_prune_result.py

test_prune_worktrees.sh

test_recovery_cli.py

test_recovery.py

test_renderable.py

test_report_contract.py

test_report_delivery.py

test_report_gates.py

test_report_verdict.py

test_resolve_gates.sh

test_resolve_policy_paths.py

test_restoration.py

test_retrospective_runtime.py

test_retrospective.py

test_review_package.py

test_role_clear.py

test_roster.sh

test_round_preflight.sh

test_runnable.py

test_scoring.py

test_script_dir_newline.sh

test_seat_holds.py

test_selection.py

test_skill_invocations.sh

test_slice_scope_parity.py

test_specialist_cli.py

test_specialist_delivery.py

test_specialist_recovery.py

test_specialist_retention.py

test_stale_grok_delivery.py

test_start_judge_worker.py

test_state.py

test_supervision_cli.py

test_supervision_diagnostics.py

test_supervision_gate.py

test_supervision_replay.py

test_supervision.py

test_sweep_worktrees.sh

test_tier_integration.py

test_tiers.py

test_triggers.py

test_typesafe_client.py

test_verdict_gates.py

test_verify_authority.sh

test_wait_report.sh

tier_fixture.py

bounded-run.sh

compose-briefs.sh

config.example.json

foreman-tier-check.py

foreman.sh

label-workspaces.sh

provision-worktree.sh

prune-remote-branches.sh

prune-report-caches.py

prune-worktrees.sh

resolve-gates.sh

resolve-policy-paths.sh

review-package.sh

roster.sh

round-preflight.sh

SKILL.md

start-judge-worker.sh

state-schema.md

sweep-worktrees.sh

verify-authority.sh

wait-report.sh

README.md

tile.json