synapse
A component of the AienOS ecosystem.
Brought by drakestapleton
synapse / scripts / qualify-crumb-synapse.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Combined Crumb-Synapse qualification (ADR 0004 deliverable D5, issue #12). |
| 3 | # |
| 4 | # Builds the pinned reference crumb.c with `cc` only, runs the D5 scenario suite |
| 5 | # (crates/synapse-bench/tests/crumb_synapse_qualification.rs) with crumb.c available, |
| 6 | # re-checks every known defect test, runs the D1 parity and D2 interop scripts, and |
| 7 | # writes evidence/crumb-synapse/ (results.txt, results.json, SHA256SUMS). |
| 8 | # |
| 9 | # Usage: scripts/qualify-crumb-synapse.sh [path-to-aien-architecture-checkout] |
| 10 | # Env: OUT_DIR evidence directory (default <repo>/evidence/crumb-synapse) |
| 11 | # Needs: bash, git, cc, cargo, sha256sum, timeout, coreutils. No Python, no jq. |
| 12 | # |
| 13 | # Exit status: 0 when every scenario is PASS or KNOWN-GAP, each known defect still |
| 14 | # reproduces as recorded, and both sibling scripts pass; 1 otherwise; 3 when the pinned |
| 15 | # crumb.c cannot be found. |
| 16 | set -uo pipefail |
| 17 | |
| 18 | PIN=29780e56c9e6b9111d884e0d4b146737228c19f6 |
| 19 | PIN_SHA256=ef0f6566fb838917a750eb898f66596b76aa15a53d7d61bedac03c4c963ee147 |
| 20 | ARCH=${1:-${AIEN_ARCHITECTURE_REPO:-$HOME/workspace/aien-architecture}} |
| 21 | HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) |
| 22 | OUT_DIR=${OUT_DIR:-$HERE/evidence/crumb-synapse} |
| 23 | SCENARIOS=(S01 S02 S03 S04 S05 S06 S07 S08 S09 S10 S11 S12) |
| 24 | # Known defects: "<ignored test name>|<issue URL>". Each must still fail when run. |
| 25 | # #58 (FIFO record hung sniff/advisory) is fixed: its test s05_fifo_record_refused_advisory_answers |
| 26 | # now runs in the suite above. Add a row here for the next defect found. |
| 27 | DEFECTS=() |
| 28 | T=$(mktemp -d) |
| 29 | trap 'rm -rf "$T"' EXIT |
| 30 | overall=0 |
| 31 | |
| 32 | # ---- pinned crumb.c ---- |
| 33 | git -C "$ARCH" cat-file -e "$PIN^{commit}" 2>/dev/null || { echo "NOT_RUN: $ARCH has no commit $PIN"; exit 3; } |
| 34 | git -C "$ARCH" show "$PIN:tools/crumb/crumb.c" > "$T/crumb.c" || exit 3 |
| 35 | CRUMB_SHA=$(sha256sum "$T/crumb.c" | cut -c1-64) |
| 36 | [ "$CRUMB_SHA" = "$PIN_SHA256" ] || { echo "FAIL crumb.c sha256 $CRUMB_SHA != pinned $PIN_SHA256"; exit 1; } |
| 37 | cc -O2 -std=c11 -o "$T/crumb" "$T/crumb.c" || { echo "FAIL cc build of crumb.c"; exit 1; } |
| 38 | echo "crumb.c @ ${PIN:0:7} sha256 $CRUMB_SHA built with $(cc --version | head -1)" |
| 39 | |
| 40 | COMMIT=$(git -C "$HERE" rev-parse HEAD) |
| 41 | DIRTY=clean |
| 42 | [ -n "$(git -C "$HERE" status --porcelain -- crates scripts Cargo.toml Cargo.lock)" ] && DIRTY=dirty |
| 43 | STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 44 | |
| 45 | # ---- D5 scenario suite ---- |
| 46 | cd "$HERE" || exit 1 |
| 47 | CRUMB_C_BIN="$T/crumb" cargo test -q -p synapse-bench --test crumb_synapse_qualification \ |
| 48 | -- --nocapture --test-threads=1 > "$T/suite.log" 2>&1 |
| 49 | suite_rc=$? |
| 50 | suite_summary=$(grep -E '^test result:' "$T/suite.log" | tail -1) |
| 51 | echo "suite: exit $suite_rc; $suite_summary" |
| 52 | [ $suite_rc -eq 0 ] || { overall=1; grep -E 'panicked|FAILED' "$T/suite.log" | head -20; } |
| 53 | |
| 54 | declare -A STATUS DETAIL |
| 55 | while IFS= read -r line; do |
| 56 | rest=${line#*D5-RESULT } |
| 57 | id=${rest%% *}; rest=${rest#* } |
| 58 | STATUS[$id]=${rest%% *}; DETAIL[$id]=${rest#* } |
| 59 | done < <(grep -o 'D5-RESULT .*' "$T/suite.log") |
| 60 | for id in "${SCENARIOS[@]}"; do |
| 61 | if [ -z "${STATUS[$id]:-}" ]; then |
| 62 | STATUS[$id]=FAIL; DETAIL[$id]="no result line (scenario panicked or did not run)" |
| 63 | fi |
| 64 | case ${STATUS[$id]} in PASS|KNOWN-GAP) ;; *) overall=1 ;; esac |
| 65 | done |
| 66 | |
| 67 | # ---- known defects: each ignored test must still reproduce ---- |
| 68 | DEFECT_ROWS=() |
| 69 | for d in "${DEFECTS[@]}"; do |
| 70 | name=${d%%|*}; url=${d#*|} |
| 71 | timeout 120 cargo test -q -p synapse-bench --test crumb_synapse_qualification \ |
| 72 | -- --ignored --exact "$name" > "$T/defect.log" 2>&1 |
| 73 | if [ $? -ne 0 ]; then |
| 74 | DEFECT_ROWS+=("$name|DEFECT|still reproduces; $url") |
| 75 | else |
| 76 | DEFECT_ROWS+=("$name|DEFECT-NOT-REPRODUCED|test now passes: un-ignore it and close $url") |
| 77 | overall=1 |
| 78 | fi |
| 79 | done |
| 80 | |
| 81 | # ---- sibling scripts (D1 parity, D2 interop) ---- |
| 82 | AIEN_ARCHITECTURE_REPO="$ARCH" bash "$HERE/scripts/crumb-parity.sh" > "$T/parity.log" 2>&1 |
| 83 | parity_rc=$? |
| 84 | parity_line=$(grep -E 'PARITY OK|FAIL' "$T/parity.log" | tail -1) |
| 85 | bash "$HERE/scripts/crumb-coord-interop.sh" "$ARCH" > "$T/interop.log" 2>&1 |
| 86 | interop_rc=$? |
| 87 | interop_line=$(grep -E '^interop:' "$T/interop.log" | tail -1) |
| 88 | [ $parity_rc -eq 0 ] && [ $interop_rc -eq 0 ] || overall=1 |
| 89 | FINISHED=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 90 | |
| 91 | # ---- evidence ---- |
| 92 | mkdir -p "$OUT_DIR" |
| 93 | esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; } |
| 94 | { |
| 95 | echo "Crumb-Synapse combined qualification (ADR 0004 D5, aien-spark/synapse#12)" |
| 96 | echo "synapse commit $COMMIT ($DIRTY)" |
| 97 | echo "crumb.c aien-architecture $PIN sha256 $CRUMB_SHA" |
| 98 | echo "run $STARTED .. $FINISHED" |
| 99 | echo "suite exit $suite_rc; $suite_summary" |
| 100 | echo |
| 101 | printf '%-4s %-11s %s\n' ID STATUS DETAIL |
| 102 | for id in "${SCENARIOS[@]}"; do printf '%-4s %-11s %s\n' "$id" "${STATUS[$id]}" "${DETAIL[$id]}"; done |
| 103 | echo |
| 104 | for r in "${DEFECT_ROWS[@]}"; do IFS='|' read -r n s dd <<< "$r"; echo "defect $s $n: $dd"; done |
| 105 | echo "parity exit $parity_rc; $parity_line" |
| 106 | echo "interop exit $interop_rc; $interop_line" |
| 107 | echo "overall $([ $overall -eq 0 ] && echo "QUALIFIED: every scenario PASS or KNOWN-GAP; open defects: ${#DEFECT_ROWS[@]}" || echo NOT-QUALIFIED)" |
| 108 | echo "limit AEGIS (aienos crates/aienos-aegis) not integrated; exit rule proven against Synapse's Publish capability and Radicle canonical promotion only" |
| 109 | } > "$OUT_DIR/results.txt" |
| 110 | { |
| 111 | echo "{" |
| 112 | echo " \"schema\": \"synapse-crumb-synapse-qualification/v1\"," |
| 113 | echo " \"issue\": \"https://github.com/aien-spark/synapse/issues/12\"," |
| 114 | echo " \"synapse_commit\": \"$COMMIT\"," |
| 115 | echo " \"source_tree\": \"$DIRTY\"," |
| 116 | echo " \"crumb_c\": {\"repo\": \"aien-dev/aien-architecture\", \"commit\": \"$PIN\", \"sha256\": \"$CRUMB_SHA\"}," |
| 117 | echo " \"started_at_utc\": \"$STARTED\"," |
| 118 | echo " \"finished_at_utc\": \"$FINISHED\"," |
| 119 | echo " \"suite\": {\"exit\": $suite_rc, \"summary\": \"$(esc "$suite_summary")\"}," |
| 120 | echo " \"scenarios\": [" |
| 121 | n=${#SCENARIOS[@]}; i=0 |
| 122 | for id in "${SCENARIOS[@]}"; do |
| 123 | i=$((i + 1)); sep=,; [ $i -eq "$n" ] && sep= |
| 124 | echo " {\"id\": \"$id\", \"status\": \"${STATUS[$id]}\", \"detail\": \"$(esc "${DETAIL[$id]}")\"}$sep" |
| 125 | done |
| 126 | echo " ]," |
| 127 | echo " \"defects\": [" |
| 128 | n=${#DEFECT_ROWS[@]}; i=0 |
| 129 | for r in "${DEFECT_ROWS[@]}"; do |
| 130 | IFS='|' read -r dn ds dd <<< "$r" |
| 131 | i=$((i + 1)); sep=,; [ $i -eq "$n" ] && sep= |
| 132 | echo " {\"test\": \"$dn\", \"status\": \"$ds\", \"detail\": \"$(esc "$dd")\"}$sep" |
| 133 | done |
| 134 | echo " ]," |
| 135 | echo " \"parity\": {\"exit\": $parity_rc, \"summary\": \"$(esc "$parity_line")\"}," |
| 136 | echo " \"interop\": {\"exit\": $interop_rc, \"summary\": \"$(esc "$interop_line")\"}," |
| 137 | echo " \"qualified\": $([ $overall -eq 0 ] && echo true || echo false)," |
| 138 | echo " \"limits\": [\"AEGIS not integrated (separate repository); publication gates tested are synapse-auth Capability::Publish and synapse-radicle canonical promotion\"]" |
| 139 | echo "}" |
| 140 | } > "$OUT_DIR/results.json" |
| 141 | # negative-control.txt is written by hand when the control is re-run (see the doc). |
| 142 | (cd "$OUT_DIR" && sha256sum results.json results.txt $(ls negative-control.txt 2>/dev/null) > SHA256SUMS) |
| 143 | |
| 144 | cat "$OUT_DIR/results.txt" |
| 145 | exit $overall |