#!/bin/sh # Tests for skills/traceability/trace.sh. # # The RED run for #10 established what a forward trace costs by hand: sixteen # commands, of which the decisive ones were reading issue comments and running a # probe against a claim. This tool does the mechanical half — what git can prove # — and, more importantly, states what it CANNOT prove, so an unverifiable link # never reads as a verified one. set -u ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) SUT="$ROOT/skills/traceability/trace.sh" pass=0 fail=0 WORK=${TMPDIR:-/tmp}/traceability_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 mkdir -p "$WORK/repo/tests" cd "$WORK/repo" || exit 1 git init -q . git config user.email t@example.com git config user.name test # A remote is needed for the tool to turn "#37" into a checkable URL, which is # the point of that section. git remote add origin https://git.d-ma.be/mathias/demo.git printf 'baseline\n' > README.md git add -A && git commit -qm "chore: baseline" printf 'gate\n' > gate.sh printf 'case\n' > tests/gate_test.sh git add -A && git commit -qm "feat(gate): add the thing Implements the decision recorded in #5, filed as #37. Closes #37" SHA=$(git rev-parse --short HEAD) git tag -a v1.2.0 -m "release v1.2.0" printf 'more\n' >> gate.sh git add -A && git commit -qm "chore: later work" cd - >/dev/null || exit 1 out=$(sh "$SUT" "$SHA" "$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 '#5' 'lists every issue the commit references, not just the closing one' check '#37' 'lists the closing reference' check 'tests/gate_test.sh' 'names the test files the commit touched' check 'v1.2.0' 'names the release that contains it' check 'Cannot verify' 'states what it could not verify' check 'issues/37' 'emits a checkable URL for the tracker link it cannot follow' # A commit in no release must say so — "no tag" and "not checked" are different # answers and only one of them is about the commit. last=$(git -C "$WORK/repo" rev-parse --short HEAD) out=$(sh "$SUT" "$last" "$WORK/repo" 2>&1) if printf '%s' "$out" | grep -qi 'no release contains'; then pass=$((pass + 1)); printf ' ok an unreleased commit is reported as unreleased\n' else fail=$((fail + 1)); printf ' FAIL an unreleased commit is reported as unreleased\n%s\n' "$out" fi printf '\ntraceability: %d passed, %d failed\n' "$pass" "$fail" [ "$fail" -eq 0 ]