#!/bin/sh # Tests for skills/lineage/lineage.sh — the decision-archaeology helper. # # The techniques this automates are the ones people skip because they are # fiddly to type: `git log -S` to find when a thing was introduced AND removed, # --diff-filter=D to find files that once existed, and grepping decision records # for the term. A skill that only *describes* those is a skill that gets read and # not run (#11, #19's "small robust tools over prose"). set -u ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) SUT="$ROOT/skills/lineage/lineage.sh" pass=0 fail=0 WORK=${TMPDIR:-/tmp}/lineage_test.$$ if [ ! -f "$SUT" ]; then printf 'FAIL: %s does not exist\n' "$SUT" exit 1 fi cleanup() { rm -rf "$WORK"; } trap cleanup EXIT INT TERM # A repo where a thing was built, written about, and then removed. mkdir -p "$WORK/repo/docs/adr" cd "$WORK/repo" || exit 1 git init -q . git config user.email t@example.com git config user.name test printf 'func WidgetCache() {}\n' > cache.go git add -A && git commit -qm "feat: add WidgetCache for lookup speed" printf -- '---\nadr: 0001\ntitle: use a WidgetCache\n---\nWe chose WidgetCache over a database index.\n' > docs/adr/0001-widgetcache.md git add -A && git commit -qm "docs: record the WidgetCache decision" git rm -q cache.go git commit -qm "revert: drop WidgetCache, it went stale under concurrent writes" cd - >/dev/null || exit 1 out=$(sh "$SUT" WidgetCache "$WORK/repo" 2>&1) check() { if printf '%s' "$out" | grep -q "$1"; then pass=$((pass + 1)); printf ' ok %s\n' "$2" else fail=$((fail + 1)); printf ' FAIL %s\n output had no %s\n%s\n' "$2" "$1" "$out" fi } check 'add WidgetCache' 'finds the commit that introduced it' check 'drop WidgetCache' 'finds the commit that removed it — the revival question' check '0001-widgetcache.md' 'finds the decision record naming it' check 'cache.go' 'names the file that no longer exists' # A no-match must NOT be reported as evidence the idea is new. The first version # of this tool said "it means this is new here" and a pressure test caught it # asserting exactly that about the most-discussed removed feature in this repo — # the search term simply had a space in it. That is the inference the skill's own # anti-pattern table forbids, printed in the tool's voice. out=$(sh "$SUT" NeverExisted "$WORK/repo" 2>&1) if printf '%s' "$out" | grep -q 'NOT evidence the idea is new' \ && printf '%s' "$out" | grep -qi 'identifier'; then pass=$((pass + 1)); printf ' ok a no-match refuses to imply novelty and suggests other terms\n' else fail=$((fail + 1)); printf ' FAIL a no-match refuses to imply novelty and suggests other terms\n%s\n' "$out" fi # The repo actually searched is always stated — a confident null against the # wrong tree is this tool's worst failure mode, and the default is the cwd. out=$(sh "$SUT" WidgetCache "$WORK/repo" 2>&1) if printf '%s' "$out" | grep -q "searching: "; then pass=$((pass + 1)); printf ' ok names the repo it searched\n' else fail=$((fail + 1)); printf ' FAIL names the repo it searched\n%s\n' "$out" fi # The sources it cannot reach are named every run, so their absence never reads # as a null result. if printf '%s' "$out" | grep -q 'brain_query' && printf '%s' "$out" | grep -qi 'closed issues'; then pass=$((pass + 1)); printf ' ok names the sources it cannot search\n' else fail=$((fail + 1)); printf ' FAIL names the sources it cannot search\n%s\n' "$out" fi printf '\nlineage: %d passed, %d failed\n' "$pass" "$fail" [ "$fail" -eq 0 ]