|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Tests for the auto-dev tick's digest-skip filter. A planner's rolling digest issue is its own |
| 4 | +# output, not work; the tick must drop it at the open-issues read. The filter lives as a fenced |
| 5 | +# `jq` block in plugins/auto-dev/skills/auto-dev/SKILL.md (the text the tick follows), and this |
| 6 | +# script extracts that exact block and runs it, so removing or weakening the filter fails here. |
| 7 | +# |
| 8 | +# ./scripts/test-auto-dev-digest-skip.sh |
| 9 | +# |
| 10 | +# Requires: bash 3.2+, jq, awk. |
| 11 | + |
| 12 | +set -uo pipefail |
| 13 | +export LC_ALL=C |
| 14 | + |
| 15 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 16 | +SKILL="$ROOT/plugins/auto-dev/skills/auto-dev/SKILL.md" |
| 17 | +MARKERS='["<!-- auto-dev-shadow-digest ", "<!-- auto-dev-digest "]' |
| 18 | + |
| 19 | +pass=0 |
| 20 | +fail=0 |
| 21 | +ok() { pass=$((pass + 1)); printf ' ok %s\n' "$1"; } |
| 22 | +bad() { fail=$((fail + 1)); printf ' FAIL %s\n' "$1"; [ $# -lt 2 ] || printf ' %s\n' "$2"; } |
| 23 | + |
| 24 | +FILTER="$(mktemp "${TMPDIR:-/tmp}/auto-dev-digest-filter.XXXXXX")" |
| 25 | +trap 'rm -f "$FILTER"' EXIT |
| 26 | + |
| 27 | +awk '/^```jq$/ {grab=1; next} grab && /^```$/ {exit} grab {print}' "$SKILL" > "$FILTER" |
| 28 | + |
| 29 | +if ! grep -q 'auto-dev digest-skip filter' "$FILTER"; then |
| 30 | + bad "SKILL.md carries the digest-skip jq filter" "no fenced jq block marked 'auto-dev digest-skip filter'" |
| 31 | + printf '\n%d passed, %d failed\n' "$pass" "$fail" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | +ok "SKILL.md carries the digest-skip jq filter" |
| 35 | + |
| 36 | +# One paginated --slurp file: a list of pages, each a list of entries (issues and PRs). |
| 37 | +PAGES='[[ |
| 38 | + {"number": 1, "body": "ordinary issue"}, |
| 39 | + {"number": 2, "body": null}, |
| 40 | + {"number": 3, "body": "<!-- auto-dev-shadow-digest repo=Vycari/foreman rev=7 -->\n## digest"}, |
| 41 | + {"number": 4, "body": "\n <!-- auto-dev-digest rev=2 -->\n## digest"} |
| 42 | +],[ |
| 43 | + {"number": 5, "body": "quoting one: <!-- auto-dev-shadow-digest repo=a rev=1 --> mid-body"}, |
| 44 | + {"number": 6, "body": "<!-- auto-dev-shadow-digest repo=x rev=1 -->", "pull_request": {}}, |
| 45 | + {"number": 7, "body": "<!-- auto-dev --> a marker comment is not a digest"} |
| 46 | +]]' |
| 47 | + |
| 48 | +run_filter() { printf '%s' "$PAGES" | jq -c --argjson markers "$1" -f "$FILTER" 2>&1; } |
| 49 | +numbers() { jq -c '[.[].number]'; } |
| 50 | + |
| 51 | +got="$(run_filter "$MARKERS" | numbers)" |
| 52 | +if [ "$got" = "[1,2,5,7]" ]; then |
| 53 | + ok "digest issues (either marker, leading whitespace) are dropped; PRs too; quoted markers stay" |
| 54 | +else |
| 55 | + bad "digest issues are dropped" "got $got, want [1,2,5,7]" |
| 56 | +fi |
| 57 | + |
| 58 | +got="$(run_filter '["<!-- custom-digest "]' | numbers)" |
| 59 | +if [ "$got" = "[1,2,3,4,5,7]" ]; then |
| 60 | + ok "a configured marker list replaces the default" |
| 61 | +else |
| 62 | + bad "a configured marker list replaces the default" "got $got" |
| 63 | +fi |
| 64 | + |
| 65 | +got="$(run_filter '[]' | numbers)" |
| 66 | +if [ "$got" = "[1,2,3,4,5,7]" ]; then |
| 67 | + ok "an empty marker list drops nothing" |
| 68 | +else |
| 69 | + bad "an empty marker list drops nothing" "got $got" |
| 70 | +fi |
| 71 | + |
| 72 | +got="$(run_filter '["", "<!-- auto-dev-digest "]' | numbers)" |
| 73 | +if [ "$got" = "[1,2,3,5,7]" ]; then |
| 74 | + ok "an empty marker string is ignored, not treated as matching every body" |
| 75 | +else |
| 76 | + bad "an empty marker string is ignored" "got $got, want [1,2,3,5,7]" |
| 77 | +fi |
| 78 | + |
| 79 | +printf '\n%d passed, %d failed\n' "$pass" "$fail" |
| 80 | +[ "$fail" -eq 0 ] |
0 commit comments